1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-02-05 01:34:13 +00:00

fixed crash if no routers available

This commit is contained in:
orignal 2015-04-03 10:02:45 -04:00
parent 19325d552a
commit 321dd252ea
2 changed files with 20 additions and 12 deletions

View File

@ -555,14 +555,13 @@ namespace tunnel
{ {
// trying to create one more oubound tunnel // trying to create one more oubound tunnel
auto inboundTunnel = GetNextInboundTunnel (); auto inboundTunnel = GetNextInboundTunnel ();
if (!inboundTunnel) return; auto router = i2p::data::netdb.GetRandomRouter ();
if (!inboundTunnel || !router) return;
LogPrint ("Creating one hop outbound tunnel..."); LogPrint ("Creating one hop outbound tunnel...");
CreateTunnel<OutboundTunnel> ( CreateTunnel<OutboundTunnel> (
new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > { router },
{ inboundTunnel->GetTunnelConfig ())
i2p::data::netdb.GetRandomRouter () );
},
inboundTunnel->GetTunnelConfig ()));
} }
} }
@ -603,13 +602,12 @@ namespace tunnel
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 5) 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..."); LogPrint ("Creating one hop inbound tunnel...");
CreateTunnel<InboundTunnel> ( CreateTunnel<InboundTunnel> (
new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > new TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > { router })
{ );
i2p::data::netdb.GetRandomRouter ()
}));
} }
} }

View File

@ -297,6 +297,11 @@ namespace tunnel
for (int i = 0; i < numHops; i++) for (int i = 0; i < numHops; i++)
{ {
auto hop = SelectNextHop (prevHop); auto hop = SelectNextHop (prevHop);
if (!hop)
{
LogPrint (eLogError, "Can't select next hop for inbound tunnel");
return;
}
prevHop = hop; prevHop = hop;
hops.push_back (hop); hops.push_back (hop);
} }
@ -329,6 +334,11 @@ namespace tunnel
for (int i = 0; i < m_NumOutboundHops; i++) for (int i = 0; i < m_NumOutboundHops; i++)
{ {
auto hop = SelectNextHop (prevHop); auto hop = SelectNextHop (prevHop);
if (!hop)
{
LogPrint (eLogError, "Can't select next hop for outbound tunnel");
return;
}
prevHop = hop; prevHop = hop;
hops.push_back (hop); hops.push_back (hop);
} }
@ -338,7 +348,7 @@ namespace tunnel
tunnel->SetTunnelPool (shared_from_this ()); tunnel->SetTunnelPool (shared_from_this ());
} }
else 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<OutboundTunnel> tunnel) void TunnelPool::RecreateOutboundTunnel (std::shared_ptr<OutboundTunnel> tunnel)