mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-10-15 02:21:20 +00:00
recreate addressbook timers when shared destination is replaced
This commit is contained in:
@@ -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<boost::asio::steady_timer>(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)
|
||||
|
||||
@@ -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<const Address> GetAddress (std::string_view address);
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
Reference in New Issue
Block a user