From 42af7cc1c5257fee8d437bc9c241cb260e8f8c46 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 30 Aug 2024 15:58:02 +0200 Subject: [PATCH] Nerf protocol window sizes Probably due to a unit misunderstanding a long time ago the window sizes were quite insane (especially the default). In practice this was sometimes hidden by other bugs, games trying their best to be lightweight or didn't matter on high-quality internet connections. --- src/network/mtp/impl.cpp | 1 + src/network/mtp/internal.h | 17 +++++++++++++---- src/network/mtp/threads.cpp | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/network/mtp/impl.cpp b/src/network/mtp/impl.cpp index 96baffaf4..483765ea4 100644 --- a/src/network/mtp/impl.cpp +++ b/src/network/mtp/impl.cpp @@ -751,6 +751,7 @@ void Channel::UpdateTimers(float dtime) packet_too_late = current_packet_too_late; packets_successful = current_packet_successful; + // has half the window even been used? if (current_bytes_transfered > (unsigned int) (m_window_size*512/2)) { reasonable_amount_of_data_transmitted = true; } diff --git a/src/network/mtp/internal.h b/src/network/mtp/internal.h index f6ab1f159..4cf6cb57a 100644 --- a/src/network/mtp/internal.h +++ b/src/network/mtp/internal.h @@ -354,15 +354,24 @@ private: static ConnectionCommandPtr create(ConnectionCommandType type); }; -/* maximum window size to use, 0xFFFF is theoretical maximum. don't think about +/* + * Window sizes to use, in packets (not bytes!). + * 0xFFFF is theoretical maximum. don't think about * touching it, the less you're away from it the more likely data corruption * will occur + * + * Note: window sizes directly translate to maximum possible throughput, e.g. + * (2048 * 512 bytes) / 33ms = 15 MiB/s */ + +// Due to backwards compatibility we have different window sizes for what we'll +// accept from peers vs. what we use for sending. #define MAX_RELIABLE_WINDOW_SIZE 0x8000 +#define MAX_RELIABLE_WINDOW_SIZE_SEND 2048 /* starting value for window size */ -#define START_RELIABLE_WINDOW_SIZE 0x400 +#define START_RELIABLE_WINDOW_SIZE 64 /* minimum value for window size */ -#define MIN_RELIABLE_WINDOW_SIZE 0x40 +#define MIN_RELIABLE_WINDOW_SIZE 32 class Channel { @@ -430,7 +439,7 @@ public: void setWindowSize(long size) { - m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE); + m_window_size = (u16)rangelim(size, MIN_RELIABLE_WINDOW_SIZE, MAX_RELIABLE_WINDOW_SIZE_SEND); } private: diff --git a/src/network/mtp/threads.cpp b/src/network/mtp/threads.cpp index d1a1e2a34..778c771f3 100644 --- a/src/network/mtp/threads.cpp +++ b/src/network/mtp/threads.cpp @@ -327,6 +327,7 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacketPtr &p, Channel *c channel->outgoing_reliables_sent.insert(p, (channel->readOutgoingSequenceNumber() - MAX_RELIABLE_WINDOW_SIZE) % (MAX_RELIABLE_WINDOW_SIZE + 1)); + // wtf is this calculation?? ^ } catch (AlreadyExistsException &e) { LOG(derr_con << m_connection->getDesc()