From eee36175e676a7e76eca4cd9a3c3bc28e029deaa Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 15 Apr 2026 18:39:28 -0400 Subject: [PATCH] ignore i2cp.closeIdleTime for tunnels on shared destinations --- libi2pd_client/I2PService.cpp | 30 ++++++++++++++++++++++++------ libi2pd_client/I2PService.h | 6 ++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/libi2pd_client/I2PService.cpp b/libi2pd_client/I2PService.cpp index 2e09d49a..e3d05022 100644 --- a/libi2pd_client/I2PService.cpp +++ b/libi2pd_client/I2PService.cpp @@ -39,6 +39,30 @@ namespace client if (m_LocalDestination) m_LocalDestination->Release (); } + void I2PService::Start () + { + if (m_CloseIdleTime) + { + if (m_LocalDestination && m_LocalDestination->GetRefCounter () <= 1) + { + if (!m_IdleCheckTimer) m_IdleCheckTimer.reset (new boost::asio::steady_timer(m_LocalDestination->GetService ())); + m_LastActivityTime = i2p::util::GetMonotonicMilliseconds (); + ScheduleIdleCheckTimer (); + } + else + LogPrint (eLogError, "I2PService: i2cp.closeIdleTime can't be set for ", GetName (), " on shared destination"); + } + } + + void I2PService::Stop () + { + if (m_IdleCheckTimer) + { + m_IdleCheckTimer->cancel (); + m_IdleCheckTimer = nullptr; + } + } + void I2PService::ClearHandlers () { if(m_ConnectTimeout) @@ -58,12 +82,6 @@ namespace client { if (idleTime > 0 && idleTime < I2P_SERVICE_MIN_CLOSE_IDLE_TIME) idleTime = I2P_SERVICE_MIN_CLOSE_IDLE_TIME; m_CloseIdleTime = idleTime; - if (m_CloseIdleTime) - { - if (!m_IdleCheckTimer) m_IdleCheckTimer.reset (new boost::asio::steady_timer(m_LocalDestination->GetService ())); - m_LastActivityTime = i2p::util::GetMonotonicMilliseconds (); - ScheduleIdleCheckTimer (); - } } void I2PService::UpdateLastActivityTime () diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index c2136e3d..3a799cba 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -69,8 +69,8 @@ namespace client void CreateStream(StreamRequestComplete complete, std::shared_ptr address, uint16_t port); auto& GetService () { return m_LocalDestination->GetService (); } - virtual void Start () = 0; - virtual void Stop () = 0; + virtual void Start (); + virtual void Stop (); virtual const char* GetName() const { return "Generic I2P Service"; } @@ -237,6 +237,7 @@ namespace client virtual ~ServiceAcceptor () { Stop(); } void Start () override { + I2PService::Start (); m_Acceptor.reset (new typename Protocol::acceptor (GetService (), m_LocalEndpoint)); // update the local end point in case port has been set zero and got updated now m_LocalEndpoint = m_Acceptor->local_endpoint(); @@ -251,6 +252,7 @@ namespace client m_Acceptor.reset (nullptr); } ClearHandlers(); + I2PService::Stop (); } const typename Protocol::endpoint& GetLocalEndpoint () const { return m_LocalEndpoint; };