From cded6206dcc0ca1f00e17ed97481c84d2fac16c2 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 7 Jul 2017 15:12:34 -0400 Subject: [PATCH] cleanup unused destinations --- libi2pd_client/ClientContext.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libi2pd_client/ClientContext.cpp b/libi2pd_client/ClientContext.cpp index d516def8..d8a9d84f 100644 --- a/libi2pd_client/ClientContext.cpp +++ b/libi2pd_client/ClientContext.cpp @@ -38,6 +38,7 @@ namespace client if (!m_SharedLocalDestination) { m_SharedLocalDestination = CreateNewLocalDestination (); // non-public, DSA + m_SharedLocalDestination->Acquire (); m_Destinations[m_SharedLocalDestination->GetIdentity ()->GetIdentHash ()] = m_SharedLocalDestination; m_SharedLocalDestination->Start (); } @@ -246,6 +247,19 @@ namespace client i2p::config::ParseConfig(config); Stop(); Start(); + + // delete unused destinations + std::unique_lock l(m_DestinationsMutex); + for (auto it = m_Destinations.begin (); it != m_Destinations.end ();) + { + auto dest = it->second; + if (dest->GetRefCounter () > 0) ++it; // skip + else + { + dest->Stop (); + it = m_Destinations.erase (it); + } + } } bool ClientContext::LoadPrivateKeys (i2p::data::PrivateKeys& keys, const std::string& filename, i2p::data::SigningKeyType sigType)