From 85fa728d41b8449bad0d6f288cd5693a60bc1917 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 23 Jan 2018 14:40:05 -0500 Subject: [PATCH] change shared local destination upon reload --- libi2pd_client/ClientContext.cpp | 20 +++++++++++++------- libi2pd_client/ClientContext.h | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index 41b8615a..d8aa10d8 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -36,13 +36,7 @@ namespace client void ClientContext::Start () { if (!m_SharedLocalDestination) - { - m_SharedLocalDestination = CreateNewLocalDestination (); // non-public, DSA - m_SharedLocalDestination->Acquire (); - m_Destinations[m_SharedLocalDestination->GetIdentity ()->GetIdentHash ()] = m_SharedLocalDestination; - m_SharedLocalDestination->Start (); - } - + CreateNewSharedLocalDestination (); m_AddressBook.Start (); @@ -267,6 +261,10 @@ namespace client // delete not updated tunnels (not in config anymore) VisitTunnels ([](I2PService * s)->bool { return s->isUpdated; }); + // change shared local destination + m_SharedLocalDestination->Release (); + CreateNewSharedLocalDestination (); + // delete unused destinations std::unique_lock l(m_DestinationsMutex); for (auto it = m_Destinations.begin (); it != m_Destinations.end ();) @@ -407,6 +405,14 @@ namespace client return localDestination; } + void ClientContext::CreateNewSharedLocalDestination () + { + m_SharedLocalDestination = CreateNewLocalDestination (); // non-public, DSA + m_SharedLocalDestination->Acquire (); + m_Destinations[m_SharedLocalDestination->GetIdentity ()->GetIdentHash ()] = m_SharedLocalDestination; + m_SharedLocalDestination->Start (); + } + std::shared_ptr ClientContext::FindLocalDestination (const i2p::data::IdentHash& destination) const { auto it = m_Destinations.find (destination); diff --git a/libi2pd_client/ClientContext.h b/libi2pd_client/ClientContext.h index 8f7143bb..2d5d140f 100644 --- a/libi2pd_client/ClientContext.h +++ b/libi2pd_client/ClientContext.h @@ -99,6 +99,8 @@ namespace client template void VisitTunnels (Visitor v); // Visitor: (I2PService *) -> bool, true means retain + void CreateNewSharedLocalDestination (); + private: std::mutex m_DestinationsMutex;