Browse Source

try to pick non-slow tunnel

pull/1660/head
orignal 4 years ago
parent
commit
e740d5fc4f
  1. 10
      libi2pd/TunnelPool.cpp

10
libi2pd/TunnelPool.cpp

@ -172,13 +172,16 @@ namespace tunnel
{ {
if (tunnels.empty ()) return nullptr; if (tunnels.empty ()) return nullptr;
uint32_t ind = rand () % (tunnels.size ()/2 + 1), i = 0; uint32_t ind = rand () % (tunnels.size ()/2 + 1), i = 0;
bool skipped = false;
typename TTunnels::value_type tunnel = nullptr; typename TTunnels::value_type tunnel = nullptr;
for (const auto& it: tunnels) for (const auto& it: tunnels)
{ {
if (it->IsEstablished () && it != excluded) if (it->IsEstablished () && it != excluded)
{ {
if(HasLatencyRequirement() && it->LatencyIsKnown() && !it->LatencyFitsRange(m_MinLatency, m_MaxLatency)) { if (it->IsSlow () || (HasLatencyRequirement() && it->LatencyIsKnown() &&
i ++; !it->LatencyFitsRange(m_MinLatency, m_MaxLatency)))
{
i++; skipped = true;
continue; continue;
} }
tunnel = it; tunnel = it;
@ -186,7 +189,8 @@ namespace tunnel
} }
if (i > ind && tunnel) break; if (i > ind && tunnel) break;
} }
if(HasLatencyRequirement() && !tunnel) { if (!tunnel && skipped)
{
ind = rand () % (tunnels.size ()/2 + 1), i = 0; ind = rand () % (tunnels.size ()/2 + 1), i = 0;
for (const auto& it: tunnels) for (const auto& it: tunnels)
{ {

Loading…
Cancel
Save