From 0850b0fc56457a33cd2c36c336945ee382dffa71 Mon Sep 17 00:00:00 2001 From: PobreGato <315121269+pobregat0@users.noreply.github.com> Date: Thu, 20 Aug 2026 02:18:20 +0300 Subject: [PATCH] recreate addressbook timers when shared destination is replaced --- libi2pd_client/AddressBook.cpp | 25 +++++++++++++++++++++++++ libi2pd_client/AddressBook.h | 1 + libi2pd_client/ClientContext.cpp | 1 + 3 files changed, 27 insertions(+) diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index 3af6dc3a..eb26164b 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -781,6 +781,31 @@ namespace client m_SubscriptionsUpdateTimer->cancel (); } + void AddressBook::ResetTimers () + { + // both timers run on the shared local destination's service, so they must be + // created anew when that destination is replaced + auto dest = i2p::client::context.GetSharedLocalDestination (); + if (m_SubscriptionsUpdateTimer) + { + m_SubscriptionsUpdateTimer->cancel (); + m_SubscriptionsUpdateTimer = nullptr; + if (dest) + { + m_SubscriptionsUpdateTimer = std::make_unique(dest->GetService ()); + m_SubscriptionsUpdateTimer->expires_after (std::chrono::minutes(INITIAL_SUBSCRIPTION_UPDATE_TIMEOUT)); + m_SubscriptionsUpdateTimer->async_wait (std::bind (&AddressBook::HandleSubscriptionsUpdateTimer, + this, std::placeholders::_1)); + } + } + if (m_AddressCacheUpdateTimer) + { + m_AddressCacheUpdateTimer->cancel (); + m_AddressCacheUpdateTimer = nullptr; + ScheduleCacheUpdate (); // creates it again on the current destination + } + } + void AddressBook::HandleSubscriptionsUpdateTimer (const boost::system::error_code& ecode) { if (ecode != boost::asio::error::operation_aborted) diff --git a/libi2pd_client/AddressBook.h b/libi2pd_client/AddressBook.h index 029e2108..927c597f 100644 --- a/libi2pd_client/AddressBook.h +++ b/libi2pd_client/AddressBook.h @@ -89,6 +89,7 @@ namespace client AddressBook (); ~AddressBook (); void Start (); + void ResetTimers (); // after the shared local destination is replaced void StartResolvers (); void Stop (); std::shared_ptr GetAddress (std::string_view address); diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index b57cf4cd..565d6848 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -250,6 +250,7 @@ namespace client // change shared local destination m_SharedLocalDestination->Release (); CreateNewSharedLocalDestination (); + m_AddressBook.ResetTimers (); // its timers are left on a destination about to go // recreate HTTP proxy auto httpProxy = DetachHttpProxy ();