From 192a08b5bfb7c9b124fc35b020f909c3a10eac5d Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 27 Jan 2015 22:31:57 -0500 Subject: [PATCH] check tunnel status instead fidning it every time --- Streaming.cpp | 3 ++- TunnelPool.cpp | 16 ++++++---------- TunnelPool.h | 7 +++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Streaming.cpp b/Streaming.cpp index bd6bac48..6e89fa64 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -504,7 +504,8 @@ namespace stream return; } } - m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNextOutboundTunnel (m_CurrentOutboundTunnel); + if (!m_CurrentOutboundTunnel || !m_CurrentOutboundTunnel->IsEstablished ()) + m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNextOutboundTunnel (); if (!m_CurrentOutboundTunnel) { LogPrint ("No outbound tunnels in the pool"); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 1445ee99..7a98621c 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -101,26 +101,22 @@ namespace tunnel return v; } - std::shared_ptr TunnelPool::GetNextOutboundTunnel (std::shared_ptr suggested) const + std::shared_ptr TunnelPool::GetNextOutboundTunnel () const { std::unique_lock l(m_OutboundTunnelsMutex); - return GetNextTunnel (m_OutboundTunnels, suggested); + return GetNextTunnel (m_OutboundTunnels); } - std::shared_ptr TunnelPool::GetNextInboundTunnel (std::shared_ptr suggested) const + std::shared_ptr TunnelPool::GetNextInboundTunnel () const { std::unique_lock l(m_InboundTunnelsMutex); - return GetNextTunnel (m_InboundTunnels, suggested); + return GetNextTunnel (m_InboundTunnels); } template - typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels, - typename TTunnels::value_type suggested) const + typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels) const { - if (tunnels.empty ()) return nullptr; - if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ()) - return suggested; - + if (tunnels.empty ()) return nullptr; CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); uint32_t ind = rnd.GenerateWord32 (0, tunnels.size ()/2), i = 0; typename TTunnels::value_type tunnel = nullptr; diff --git a/TunnelPool.h b/TunnelPool.h index fb057dc0..14f70841 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -39,8 +39,8 @@ namespace tunnel void TunnelCreated (std::shared_ptr createdTunnel); void TunnelExpired (std::shared_ptr expiredTunnel); std::vector > GetInboundTunnels (int num) const; - std::shared_ptr GetNextOutboundTunnel (std::shared_ptr suggested = nullptr) const; - std::shared_ptr GetNextInboundTunnel (std::shared_ptr suggested = nullptr) const; + std::shared_ptr GetNextOutboundTunnel () const; + std::shared_ptr GetNextInboundTunnel () const; void TestTunnels (); void ProcessGarlicMessage (I2NPMessage * msg); @@ -57,8 +57,7 @@ namespace tunnel void RecreateInboundTunnel (std::shared_ptr tunnel); void RecreateOutboundTunnel (std::shared_ptr tunnel); template - typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels, - typename TTunnels::value_type suggested = nullptr) const; + typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels) const; std::shared_ptr SelectNextHop (std::shared_ptr prevHop) const; private: