From 7fef5f5654df6065c3129c23f6a2111d3cc76b84 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 15 Nov 2016 10:37:58 -0500 Subject: [PATCH] when selecting tunnels if we can't find a low latency tunnel fall back to regular selection algorithm --- TunnelPool.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 625c7d11..2680e8b9 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -147,18 +147,26 @@ namespace tunnel std::shared_ptr TunnelPool::GetNextOutboundTunnel (std::shared_ptr excluded) const { + std::shared_ptr tun = nullptr; if (HasLatencyRequriement()) - return GetLowestLatencyOutboundTunnel(excluded); - std::unique_lock l(m_OutboundTunnelsMutex); - return GetNextTunnel (m_OutboundTunnels, excluded); + tun = GetLowestLatencyOutboundTunnel(excluded); + if (! tun) { + std::unique_lock l(m_OutboundTunnelsMutex); + tun = GetNextTunnel (m_OutboundTunnels, excluded); + } + return tun; } std::shared_ptr TunnelPool::GetNextInboundTunnel (std::shared_ptr excluded) const { + std::shared_ptr tun = nullptr; if (HasLatencyRequriement()) - return GetLowestLatencyInboundTunnel(excluded); - std::unique_lock l(m_InboundTunnelsMutex); - return GetNextTunnel (m_InboundTunnels, excluded); + tun = GetLowestLatencyInboundTunnel(excluded); + if (! tun) { + std::unique_lock l(m_InboundTunnelsMutex); + tun = GetNextTunnel (m_InboundTunnels, excluded); + } + return tun; } template