From fcb56db224d2c874713770edbbc36ec41f298abd Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 17 Apr 2015 10:11:51 -0400 Subject: [PATCH] try to pick an outbound tunnel with same endpoint instead expired --- Streaming.cpp | 2 +- TunnelPool.cpp | 17 +++++++++++++++++ TunnelPool.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Streaming.cpp b/Streaming.cpp index 868e53b0..4d9342c1 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -597,7 +597,7 @@ namespace stream } } if (!m_CurrentOutboundTunnel || !m_CurrentOutboundTunnel->IsEstablished ()) - m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNextOutboundTunnel (); + m_CurrentOutboundTunnel = m_LocalDestination.GetOwner ().GetTunnelPool ()->GetNewOutboundTunnel (m_CurrentOutboundTunnel); if (!m_CurrentOutboundTunnel) { LogPrint (eLogError, "No outbound tunnels in the pool"); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index fd40565a..6315e501 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -131,6 +131,23 @@ namespace tunnel return tunnel; } + std::shared_ptr TunnelPool::GetNewOutboundTunnel (std::shared_ptr old) const + { + if (old && old->IsEstablished ()) return old; + std::shared_ptr tunnel; + if (old) + { + std::unique_lock l(m_OutboundTunnelsMutex); + for (auto it: m_OutboundTunnels) + if (it->IsEstablished () && old->GetEndpointRouter ()->GetIdentHash () == it->GetEndpointRouter ()->GetIdentHash ()) + tunnel = it; + } + + if (!tunnel) + tunnel = GetNextOutboundTunnel (); + return tunnel; + } + void TunnelPool::CreateTunnels () { int num = 0; diff --git a/TunnelPool.h b/TunnelPool.h index fa7b1c16..947bd3cc 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -43,6 +43,7 @@ namespace tunnel std::vector > GetInboundTunnels (int num) const; std::shared_ptr GetNextOutboundTunnel (std::shared_ptr excluded = nullptr) const; std::shared_ptr GetNextInboundTunnel (std::shared_ptr excluded = nullptr) const; + std::shared_ptr GetNewOutboundTunnel (std::shared_ptr old) const; void TestTunnels (); void ProcessGarlicMessage (I2NPMessage * msg);