Codechange: differentiate between UDP, TCP and compatibility MTU values

This commit is contained in:
Rubidium
2021-04-18 14:49:39 +02:00
committed by rubidium42
parent 8b302761d4
commit d6000c2ec5
8 changed files with 20 additions and 18 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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);

View File

@@ -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;

View File

@@ -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 */