From c8e34052a7b62e398d9fcdd65a4bb43b8552e583 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 9 Dec 2014 21:07:54 -0500 Subject: [PATCH] some cleanup --- I2NPProtocol.cpp | 4 ++-- Tunnel.cpp | 11 +++++++---- Tunnel.h | 2 +- TunnelPool.h | 5 ++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index c75b4d93902..6668fe2a23e 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -161,7 +161,7 @@ namespace i2p buf[32] = 1; // 1 tag rnd.GenerateBlock (buf + 33, 32); // tag if (pool) - pool->GetGarlicDestination ().SubmitSessionKey (buf, buf + 33); // introduce new key-tag to garlic engine + pool->GetLocalDestination ().SubmitSessionKey (buf, buf + 33); // introduce new key-tag to garlic engine else LogPrint ("Destination for encrypteed reply not specified"); buf += 65; @@ -563,7 +563,7 @@ namespace i2p case eI2NPGarlic: LogPrint ("Garlic"); if (msg->from && msg->from->GetTunnelPool ()) - msg->from->GetTunnelPool ()->GetGarlicDestination ().ProcessGarlicMessage (msg); + msg->from->GetTunnelPool ()->GetLocalDestination ().ProcessGarlicMessage (msg); else i2p::context.ProcessGarlicMessage (msg); break; diff --git a/Tunnel.cpp b/Tunnel.cpp index eff9965c158..8e52020dab3 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -221,7 +221,7 @@ namespace tunnel m_PendingTunnels.clear ();*/ for (auto& it: m_Pools) - delete it.second; + delete it; m_Pools.clear (); } @@ -291,7 +291,7 @@ namespace tunnel { auto pool = new TunnelPool (localDestination, numInboundHops, numOutboundHops); std::unique_lock l(m_PoolsMutex); - m_Pools[pool->GetIdentHash ()] = pool; + m_Pools.push_back (pool); return pool; } @@ -300,7 +300,10 @@ namespace tunnel if (pool) { StopTunnelPool (pool); - m_Pools.erase (pool->GetLocalDestination ().GetIdentHash ()); + { + std::unique_lock l(m_PoolsMutex); + m_Pools.remove (pool); + } for (auto it: m_PendingTunnels) if (it.second->GetTunnelPool () == pool) it.second->SetTunnelPool (nullptr); @@ -551,7 +554,7 @@ namespace tunnel std::unique_lock l(m_PoolsMutex); for (auto it: m_Pools) { - TunnelPool * pool = it.second; + TunnelPool * pool = it; if (pool->IsActive ()) { pool->CreateTunnels (); diff --git a/Tunnel.h b/Tunnel.h index 520ef61bda6..a8dc77cff03 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -157,7 +157,7 @@ namespace tunnel std::mutex m_TransitTunnelsMutex; std::map m_TransitTunnels; std::mutex m_PoolsMutex; - std::map m_Pools; + std::list m_Pools; TunnelPool * m_ExploratoryPool; i2p::util::Queue m_Queue; diff --git a/TunnelPool.h b/TunnelPool.h index d12629a1f0c..a697e9f73a3 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -30,9 +30,8 @@ namespace tunnel ~TunnelPool (); const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); }; - const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; - const i2p::data::LocalDestination& GetLocalDestination () const { return m_LocalDestination; }; - i2p::garlic::GarlicDestination& GetGarlicDestination () const { return m_LocalDestination; }; + const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); }; + i2p::garlic::GarlicDestination& GetLocalDestination () const { return m_LocalDestination; }; bool IsExploratory () const { return GetIdentHash () == i2p::context.GetIdentHash (); }; void CreateTunnels ();