diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index a41619d6..53a43bd1 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -987,7 +987,8 @@ namespace transport auto ts = i2p::util::GetMillisecondsSinceEpoch (); for (auto it: m_Sessions) { - resentPacketsNum += it.second->Resend (ts); + if (ts >= it.second->GetLastResendTime () + SSU2_RESEND_CHECK_TIMEOUT) + resentPacketsNum += it.second->Resend (ts); if (resentPacketsNum > SSU2_MAX_RESEND_PACKETS) break; } for (auto it: m_PendingOutgoingSessions) diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 42a26c5c..fa888e77 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -90,7 +90,8 @@ namespace transport m_WindowSize (SSU2_MIN_WINDOW_SIZE), m_RTO (SSU2_INITIAL_RTO), 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 + m_MaxPayloadSize (SSU2_MIN_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - 32), // min size + m_LastResendTime (0) { m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState); if (in_RemoteRouter && m_Address) @@ -565,6 +566,7 @@ namespace transport it++; if (!resentPackets.empty ()) { + m_LastResendTime = ts; #if (__cplusplus >= 201703L) // C++ 17 or higher m_SentPackets.merge (resentPackets); #else diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index 6505b233..4dfc529a 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -256,7 +256,8 @@ namespace transport void SendLocalRouterInfo (bool update) override; void SendI2NPMessages (const std::vector >& msgs) override; uint32_t GetRelayTag () const override { return m_RelayTag; }; - size_t Resend (uint64_t ts); // return number or resent packets + size_t Resend (uint64_t ts); // return number of resent packets + uint64_t GetLastResendTime () const { return m_LastResendTime; }; bool IsEstablished () const override { return m_State == eSSU2SessionStateEstablished; }; uint64_t GetConnID () const { return m_SourceConnID; }; SSU2SessionState GetState () const { return m_State; }; @@ -369,6 +370,7 @@ namespace transport size_t m_MaxPayloadSize; std::unique_ptr m_PathChallenge; std::unordered_map m_ReceivedI2NPMsgIDs; // msgID -> timestamp in seconds + uint64_t m_LastResendTime; // in milliseconds }; inline uint64_t CreateHeaderMask (const uint8_t * kh, const uint8_t * nonce)