From ebd0575385ce51e18f1991ef457d1fede6dba831 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 1 Jun 2026 16:29:07 -0400 Subject: [PATCH] limit i2p.streaming.maxOutboundSpeed per session --- libi2pd/Garlic.cpp | 2 +- libi2pd/Garlic.h | 4 ++++ libi2pd/Streaming.cpp | 24 ++++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libi2pd/Garlic.cpp b/libi2pd/Garlic.cpp index 1d19fc71..087aced7 100644 --- a/libi2pd/Garlic.cpp +++ b/libi2pd/Garlic.cpp @@ -28,7 +28,7 @@ namespace garlic { GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner, bool attachLeaseSet): m_Owner (owner), m_LeaseSetUpdateStatus (attachLeaseSet ? eLeaseSetUpdated : eLeaseSetDoNotSend), - m_LeaseSetUpdateMsgID (0), m_IsWithJava (false), m_NumSentPackets (0) + m_LeaseSetUpdateMsgID (0), m_IsWithJava (false), m_NumSentPackets (0), m_LastSendTime (0) { } diff --git a/libi2pd/Garlic.h b/libi2pd/Garlic.h index ef395678..5577a22a 100644 --- a/libi2pd/Garlic.h +++ b/libi2pd/Garlic.h @@ -139,6 +139,9 @@ namespace garlic int NumSentPackets () const { return m_NumSentPackets; } void SetNumSentPackets (int numSentPackets) { m_NumSentPackets = numSentPackets; } + uint64_t LastSendTime () const { return m_LastSendTime; } + void SetLastSendTime (uint64_t lastSendTime) { m_LastSendTime = lastSendTime; } + GarlicDestination * GetOwner () const { return m_Owner; } void SetOwner (GarlicDestination * owner) { m_Owner = owner; } @@ -163,6 +166,7 @@ namespace garlic std::shared_ptr m_SharedRoutingPath; bool m_IsWithJava; // based on choked value from streaming int m_NumSentPackets; // for limit number of sent messages in streaming + uint64_t m_LastSendTime; // for limit OB speed in streaming public: diff --git a/libi2pd/Streaming.cpp b/libi2pd/Streaming.cpp index 25d154b7..762975bb 100644 --- a/libi2pd/Streaming.cpp +++ b/libi2pd/Streaming.cpp @@ -1123,6 +1123,7 @@ namespace stream { int numSentPackets = m_RoutingSession->NumSentPackets (); m_RoutingSession->SetNumSentPackets (numSentPackets + numPackets); + m_RoutingSession->SetLastSendTime (ts); } if (m_Status == eStreamStatusClosing && m_SendBuffer.IsEmpty ()) SendClose (); @@ -1617,9 +1618,22 @@ namespace stream { if (m_PacingTime) { - auto numPackets = std::lldiv (m_PacingTimeRem + ts*1000 - m_LastSendTime*1000, m_PacingTime); - m_NumPacketsToSend = numPackets.quot; - m_PacingTimeRem = numPackets.rem; + if (m_RoutingSession) + { + uint64_t lastSendTime = m_RoutingSession->LastSendTime (); + if (lastSendTime) + { + auto numPackets = std::lldiv (m_PacingTimeRem + ts*1000 - lastSendTime*1000, m_PacingTime); + m_NumPacketsToSend = numPackets.quot; + m_PacingTimeRem = numPackets.rem; + } + else + { + auto numPackets = std::lldiv (m_PacingTimeRem + ts*1000 - m_LastSendTime*1000, m_PacingTime); + m_NumPacketsToSend = numPackets.quot; + m_PacingTimeRem = numPackets.rem; + } + } } else { @@ -1627,7 +1641,7 @@ namespace stream m_NumPacketsToSend = 1; m_PacingTimeRem = 0; } m_IsSendTime = true; - if (m_WindowIncCounter && (m_WindowSize < m_MaxWindowSize || m_WindowDropTargetSize) && !m_SendBuffer.IsEmpty () && m_PacingTime > m_MinPacingTime) + if (m_NumPacketsToSend && m_WindowIncCounter && (m_WindowSize < m_MaxWindowSize || m_WindowDropTargetSize) && !m_SendBuffer.IsEmpty () && m_PacingTime > m_MinPacingTime) { float winSize = m_WindowSize; if (m_WindowDropTargetSize) @@ -1821,6 +1835,8 @@ namespace stream if (m_IsTimeOutResend) ScheduleResend (); SendPackets (packets); m_LastSendTime = ts; + if (m_RoutingSession) + m_RoutingSession->SetLastSendTime (ts); m_IsSendTime = false; } else if (!m_IsClientChoked && !m_IsClientChoked2)