From 43f5ba286cb2b6224adf46d09a90457e805e6056 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 9 Jun 2024 15:25:19 -0400 Subject: [PATCH] update congestion caps before initial publishing --- libi2pd/RouterContext.cpp | 34 +++++++++++++++++++++------------- libi2pd/RouterContext.h | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/libi2pd/RouterContext.cpp b/libi2pd/RouterContext.cpp index b14baba9..2e37b489 100644 --- a/libi2pd/RouterContext.cpp +++ b/libi2pd/RouterContext.cpp @@ -1330,7 +1330,10 @@ namespace i2p if (ecode != boost::asio::error::operation_aborted) { if (m_RouterInfo.IsReachableBy (i2p::data::RouterInfo::eAllTransports)) + { + UpdateCongestion (); HandlePublishTimer (ecode); + } else { UpdateTimestamp (i2p::util::GetSecondsSinceEpoch ()); @@ -1469,23 +1472,28 @@ namespace i2p { if (ecode != boost::asio::error::operation_aborted) { - auto c = i2p::data::RouterInfo::eLowCongestion; - if (!AcceptsTunnels () || !m_ShareRatio) - c = i2p::data::RouterInfo::eRejectAll; - else - { - int congestionLevel = GetCongestionLevel (true); - if (congestionLevel > CONGESTION_LEVEL_HIGH) - c = i2p::data::RouterInfo::eHighCongestion; - else if (congestionLevel > CONGESTION_LEVEL_MEDIUM) - c = i2p::data::RouterInfo::eMediumCongestion; - } - if (m_RouterInfo.UpdateCongestion (c)) - UpdateRouterInfo (); + UpdateCongestion (); ScheduleCongestionUpdate (); } } + void RouterContext::UpdateCongestion () + { + auto c = i2p::data::RouterInfo::eLowCongestion; + if (!AcceptsTunnels () || !m_ShareRatio) + c = i2p::data::RouterInfo::eRejectAll; + else + { + int congestionLevel = GetCongestionLevel (true); + if (congestionLevel > CONGESTION_LEVEL_HIGH) + c = i2p::data::RouterInfo::eHighCongestion; + else if (congestionLevel > CONGESTION_LEVEL_MEDIUM) + c = i2p::data::RouterInfo::eMediumCongestion; + } + if (m_RouterInfo.UpdateCongestion (c)) + UpdateRouterInfo (); + } + void RouterContext::ScheduleCleanupTimer () { if (m_CleanupTimer) diff --git a/libi2pd/RouterContext.h b/libi2pd/RouterContext.h index bc43d6a8..09c3678f 100644 --- a/libi2pd/RouterContext.h +++ b/libi2pd/RouterContext.h @@ -230,6 +230,7 @@ namespace garlic void HandlePublishResendTimer (const boost::system::error_code& ecode); void ScheduleCongestionUpdate (); void HandleCongestionUpdateTimer (const boost::system::error_code& ecode); + void UpdateCongestion (); void ScheduleCleanupTimer (); void HandleCleanupTimer (const boost::system::error_code& ecode);