diff --git a/libi2pd/Tunnel.cpp b/libi2pd/Tunnel.cpp index b9e0a661..37b0abda 100644 --- a/libi2pd/Tunnel.cpp +++ b/libi2pd/Tunnel.cpp @@ -877,6 +877,7 @@ namespace tunnel void Tunnels::ManageOutboundTunnels (uint64_t ts, std::vector >& toRecreate) { + size_t numEstablishedOutboundTunnels = 0; for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();) { auto tunnel = *it; @@ -903,12 +904,13 @@ namespace tunnel } if (ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT) tunnel->SetState (eTunnelStateExpiring); + numEstablishedOutboundTunnels++; } ++it; } } - if (m_OutboundTunnels.size () < 3) + if (numEstablishedOutboundTunnels < 3) { // trying to create one more outbound tunnel auto inboundTunnel = GetNextInboundTunnel (); @@ -926,6 +928,7 @@ namespace tunnel void Tunnels::ManageInboundTunnels (uint64_t ts, std::vector >& toRecreate) { + size_t numEstablishedInboundTunnels = 0; for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();) { auto tunnel = *it; @@ -955,12 +958,13 @@ namespace tunnel tunnel->SetState (eTunnelStateExpiring); else // we don't need to cleanup expiring tunnels tunnel->Cleanup (); + numEstablishedInboundTunnels++; } it++; } } - if (m_InboundTunnels.empty ()) + if (!numEstablishedInboundTunnels) { LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel"); CreateZeroHopsInboundTunnel (nullptr); @@ -977,7 +981,7 @@ namespace tunnel return; } - if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3) + if (m_OutboundTunnels.empty () || numEstablishedInboundTunnels < 3) { // trying to create one more inbound tunnel auto router = i2p::transport::transports.RoutesRestricted() ?