summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-18 14:49:39 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-25 21:27:54 +0200
commitd6000c2ec5f61c599d8859b981f2dac6a92e0755 (patch)
tree41418504a0c6e9701295228873bfc2c6d66fe313 /src/network/core
parent8b302761d4ca51f41eaff4097c9afa4f3aec5ec5 (diff)
downloadopenttd-d6000c2ec5f61c599d8859b981f2dac6a92e0755.tar.xz
Codechange: differentiate between UDP, TCP and compatibility MTU values
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/config.h8
-rw-r--r--src/network/core/packet.cpp2
-rw-r--r--src/network/core/packet.h2
-rw-r--r--src/network/core/tcp.cpp2
-rw-r--r--src/network/core/udp.cpp4
5 files changed, 10 insertions, 8 deletions
diff --git a/src/network/core/config.h b/src/network/core/config.h
index 1483419ea..572b4720d 100644
--- a/src/network/core/config.h
+++ b/src/network/core/config.h
@@ -30,7 +30,9 @@ static const uint16 NETWORK_DEFAULT_PORT = 3979; ///< The defau
static const uint16 NETWORK_ADMIN_PORT = 3977; ///< The default port for admin network
static const uint16 NETWORK_DEFAULT_DEBUGLOG_PORT = 3982; ///< The default port debug-log is sent to (TCP)
-static const uint16 SEND_MTU = 1460; ///< Number of bytes we can pack in a single packet
+static const uint16 UDP_MTU = 1460; ///< Number of bytes we can pack in a single UDP packet
+static const uint16 TCP_MTU = 1460; ///< Number of bytes we can pack in a single TCP packet
+static const uint16 COMPAT_MTU = 1460; ///< Number of bytes we can pack in a single packet for backward compatibility
static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use?
static const byte NETWORK_GAME_INFO_VERSION = 4; ///< What version of game-info do we use?
@@ -46,14 +48,14 @@ static const uint NETWORK_PASSWORD_LENGTH = 33; ///< The maxim
static const uint NETWORK_CLIENTS_LENGTH = 200; ///< The maximum length for the list of clients that controls a company, in bytes including '\0'
static const uint NETWORK_CLIENT_NAME_LENGTH = 25; ///< The maximum length of a client's name, in bytes including '\0'
static const uint NETWORK_RCONCOMMAND_LENGTH = 500; ///< The maximum length of a rconsole command, in bytes including '\0'
-static const uint NETWORK_GAMESCRIPT_JSON_LENGTH = SEND_MTU - 3; ///< The maximum length of a gamescript json string, in bytes including '\0'. Must not be longer than SEND_MTU including header (3 bytes)
+static const uint NETWORK_GAMESCRIPT_JSON_LENGTH = COMPAT_MTU-3; ///< The maximum length of a gamescript json string, in bytes including '\0'. Must not be longer than COMPAT_MTU including header (3 bytes)
static const uint NETWORK_CHAT_LENGTH = 900; ///< The maximum length of a chat message, in bytes including '\0'
static const uint NETWORK_GRF_NAME_LENGTH = 80; ///< Maximum length of the name of a GRF
/**
* Maximum number of GRFs that can be sent.
- * This limit is reached when PACKET_UDP_SERVER_RESPONSE reaches the maximum size of SEND_MTU bytes.
+ * This limit is reached when PACKET_UDP_SERVER_RESPONSE reaches the maximum size of UDP_MTU bytes.
*/
static const uint NETWORK_MAX_GRF_COUNT = 62;
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp
index 39531c0a4..40e664055 100644
--- a/src/network/core/packet.cpp
+++ b/src/network/core/packet.cpp
@@ -39,7 +39,7 @@ Packet::Packet(NetworkSocketHandler *cs, size_t limit, size_t initial_read_size)
/**
* Creates a packet to send
* @param type The type of the packet to send
- * @param limit The maximum number of bytes the packet may have. Default is SEND_MTU.
+ * @param limit The maximum number of bytes the packet may have. Default is COMPAT_MTU.
* Be careful of compatibility with older clients/servers when changing
* the limit as it might break things if the other side is not expecting
* much larger packets than what they support.
diff --git a/src/network/core/packet.h b/src/network/core/packet.h
index db051005c..d55dad316 100644
--- a/src/network/core/packet.h
+++ b/src/network/core/packet.h
@@ -56,7 +56,7 @@ private:
public:
Packet(NetworkSocketHandler *cs, size_t limit, size_t initial_read_size = sizeof(PacketSize));
- Packet(PacketType type, size_t limit = SEND_MTU);
+ Packet(PacketType type, size_t limit = COMPAT_MTU);
static void AddToQueue(Packet **queue, Packet *packet);
static Packet *PopFromQueue(Packet **queue);
diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp
index be70efdd2..72e66a0b5 100644
--- a/src/network/core/tcp.cpp
+++ b/src/network/core/tcp.cpp
@@ -126,7 +126,7 @@ Packet *NetworkTCPSocketHandler::ReceivePacket()
if (!this->IsConnected()) return nullptr;
if (this->packet_recv == nullptr) {
- this->packet_recv = new Packet(this, SEND_MTU);
+ this->packet_recv = new Packet(this, TCP_MTU);
}
Packet *p = this->packet_recv;
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 8872fa295..e8299f7b6 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -119,8 +119,8 @@ void NetworkUDPSocketHandler::ReceivePackets()
struct sockaddr_storage client_addr;
memset(&client_addr, 0, sizeof(client_addr));
- /* The limit is SEND_MTU, but also allocate that much as we need to read the whole packet in one go. */
- Packet p(this, SEND_MTU, SEND_MTU);
+ /* The limit is UDP_MTU, but also allocate that much as we need to read the whole packet in one go. */
+ Packet p(this, UDP_MTU, UDP_MTU);
socklen_t client_len = sizeof(client_addr);
/* Try to receive anything */