diff --git a/Tunnel.cpp b/Tunnel.cpp index 110446b4..29c494f2 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -555,14 +555,13 @@ namespace tunnel { // trying to create one more oubound tunnel auto inboundTunnel = GetNextInboundTunnel (); - if (!inboundTunnel) return; + auto router = i2p::data::netdb.GetRandomRouter (); + if (!inboundTunnel || !router) return; LogPrint ("Creating one hop outbound tunnel..."); CreateTunnel ( - new TunnelConfig (std::vector > - { - i2p::data::netdb.GetRandomRouter () - }, - inboundTunnel->GetTunnelConfig ())); + new TunnelConfig (std::vector > { router }, + inboundTunnel->GetTunnelConfig ()) + ); } } @@ -603,13 +602,12 @@ namespace tunnel if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 5) { - // trying to create one more inbound tunnel + // trying to create one more inbound tunnel + auto router = i2p::data::netdb.GetRandomRouter (); LogPrint ("Creating one hop inbound tunnel..."); CreateTunnel ( - new TunnelConfig (std::vector > - { - i2p::data::netdb.GetRandomRouter () - })); + new TunnelConfig (std::vector > { router }) + ); } } diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 12f1a41d..15606959 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -297,6 +297,11 @@ namespace tunnel for (int i = 0; i < numHops; i++) { auto hop = SelectNextHop (prevHop); + if (!hop) + { + LogPrint (eLogError, "Can't select next hop for inbound tunnel"); + return; + } prevHop = hop; hops.push_back (hop); } @@ -329,6 +334,11 @@ namespace tunnel for (int i = 0; i < m_NumOutboundHops; i++) { auto hop = SelectNextHop (prevHop); + if (!hop) + { + LogPrint (eLogError, "Can't select next hop for outbound tunnel"); + return; + } prevHop = hop; hops.push_back (hop); } @@ -338,7 +348,7 @@ namespace tunnel tunnel->SetTunnelPool (shared_from_this ()); } else - LogPrint ("Can't create outbound tunnel. No inbound tunnels found"); + LogPrint (eLogError, "Can't create outbound tunnel. No inbound tunnels found"); } void TunnelPool::RecreateOutboundTunnel (std::shared_ptr tunnel)