From 5425e9aee35fc364adf88dba187b77086cb38a14 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 15 Nov 2016 10:46:58 -0500 Subject: [PATCH] select tunnels correctly --- TunnelPool.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 2680e8b9..e0a3e99e 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -147,26 +147,14 @@ namespace tunnel std::shared_ptr TunnelPool::GetNextOutboundTunnel (std::shared_ptr excluded) const { - std::shared_ptr tun = nullptr; - if (HasLatencyRequriement()) - tun = GetLowestLatencyOutboundTunnel(excluded); - if (! tun) { - std::unique_lock l(m_OutboundTunnelsMutex); - tun = GetNextTunnel (m_OutboundTunnels, excluded); - } - return tun; + std::unique_lock l(m_OutboundTunnelsMutex); + return GetNextTunnel (m_OutboundTunnels, excluded); } std::shared_ptr TunnelPool::GetNextInboundTunnel (std::shared_ptr excluded) const { - std::shared_ptr tun = nullptr; - if (HasLatencyRequriement()) - tun = GetLowestLatencyInboundTunnel(excluded); - if (! tun) { - std::unique_lock l(m_InboundTunnelsMutex); - tun = GetNextTunnel (m_InboundTunnels, excluded); - } - return tun; + std::unique_lock l(m_InboundTunnelsMutex); + return GetNextTunnel (m_InboundTunnels, excluded); } template @@ -179,6 +167,10 @@ namespace tunnel { if (it->IsEstablished () && it != excluded) { + if(HasLatencyRequirement() && !it->LatencyFitsRange(m_MinLatency, m_MaxLatency)) { + i ++; + continue; + } tunnel = it; i++; }