From fd41fba069f14fb8e53f9caf27d147c37c0b6d9e Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 27 Jul 2022 20:00:03 -0400 Subject: [PATCH] variable retranmission window --- libi2pd/SSU2Session.cpp | 16 ++++++++++++++-- libi2pd/SSU2Session.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 96635cec..5b451e00 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -24,7 +24,7 @@ namespace transport m_Server (server), m_Address (addr), m_RemoteTransports (0), m_DestConnID (0), m_SourceConnID (0), m_State (eSSU2SessionStateUnknown), m_SendPacketNum (0), m_ReceivePacketNum (0), m_IsDataReceived (false), - m_WindowSize (SSU2_MAX_WINDOW_SIZE), m_RelayTag (0), + m_WindowSize (SSU2_MIN_WINDOW_SIZE), m_RelayTag (0), m_ConnectTimer (server.GetService ()), m_TerminationReason (eSSU2TerminationReasonNormalClose), m_MaxPayloadSize (SSU2_MIN_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - 32) // min size { @@ -428,6 +428,8 @@ namespace transport #else m_SentPackets.insert (resentPackets.begin (), resentPackets.end ()); #endif + m_WindowSize >>= 1; // /2 + if (m_WindowSize < SSU2_MIN_WINDOW_SIZE) m_WindowSize = SSU2_MIN_WINDOW_SIZE; } SendQueue (); } @@ -1451,8 +1453,18 @@ namespace transport while (it != m_SentPackets.end () && it->first < firstPacketNum) it++; // find first acked packet if (it == m_SentPackets.end () || it->first > lastPacketNum) return; // not found auto it1 = it; - while (it1 != m_SentPackets.end () && it1->first <= lastPacketNum) it1++; + int numPackets = 0; + while (it1 != m_SentPackets.end () && it1->first <= lastPacketNum) + { + it1++; + numPackets++; + } m_SentPackets.erase (it, it1); + if (numPackets > 0) + { + m_WindowSize += numPackets; + if (m_WindowSize > SSU2_MAX_WINDOW_SIZE) m_WindowSize = SSU2_MAX_WINDOW_SIZE; + } } void SSU2Session::HandleFirstFragment (const uint8_t * buf, size_t len) diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index 7a9f5842..deb198f8 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -38,6 +38,7 @@ namespace transport const int SSU2_RESEND_INTERVAL = 3; // in seconds const int SSU2_MAX_NUM_RESENDS = 5; const int SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT = 30; // in seconds + const size_t SSU2_MIN_WINDOW_SIZE = 8; // in packets const size_t SSU2_MAX_WINDOW_SIZE = 128; // in packets const size_t SSU2_MAX_OUTGOING_QUEUE_SIZE = 300; // in messages const int SSU2_MAX_NUM_ACK_RANGES = 32; // to send