From 24f0ff6c00ef0e39e4ba4f2a94b7dcfa452ab4cb Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Apr 2014 16:27:37 -0400 Subject: [PATCH] pick tunnels from exploratory pool for exploratory --- NetDb.cpp | 5 +++-- Tunnel.h | 1 + TunnelPool.cpp | 17 ++++++++++++++++- TunnelPool.h | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 57b5029a..1855ac30 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -532,8 +532,9 @@ namespace data void NetDb::Explore () { - auto outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel (); - auto inbound = i2p::tunnel::tunnels.GetNextInboundTunnel (); + auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); + auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; + auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; if (outbound && inbound) { CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); diff --git a/Tunnel.h b/Tunnel.h index d1d77fe9..16ffa9e4 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -117,6 +117,7 @@ namespace tunnel Tunnel * GetPendingTunnel (uint32_t replyMsgID); InboundTunnel * GetNextInboundTunnel (); OutboundTunnel * GetNextOutboundTunnel (); + TunnelPool * GetExploratoryPool () const { return m_ExploratoryPool; }; TransitTunnel * GetTransitTunnel (uint32_t tunnelID); void AddTransitTunnel (TransitTunnel * tunnel); void AddOutboundTunnel (OutboundTunnel * newTunnel); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 9b552101..33f6cbda 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -86,7 +86,22 @@ namespace tunnel m_LastOutboundTunnel = tunnel; return tunnel; } - + + InboundTunnel * TunnelPool::GetNextInboundTunnel () + { + return GetNextTunnel (m_InboundTunnels); + } + + template + typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels) + { + if (tunnels.empty ()) return nullptr; + for (auto it: tunnels) + if (!it->IsFailed ()) + return it; + return nullptr; + } + void TunnelPool::CreateTunnels () { int num = m_InboundTunnels.size (); diff --git a/TunnelPool.h b/TunnelPool.h index 0e18bcd4..1ff66cf3 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -37,6 +37,7 @@ namespace tunnel void TunnelExpired (OutboundTunnel * expiredTunnel); std::vector GetInboundTunnels (int num) const; OutboundTunnel * GetNextOutboundTunnel (); + InboundTunnel * GetNextInboundTunnel (); const i2p::data::IdentHash& GetIdentHash () { return m_LocalDestination.GetIdentHash (); }; void TestTunnels (); @@ -46,6 +47,8 @@ namespace tunnel void CreateInboundTunnel (); void CreateOutboundTunnel (); + template + typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels); private: