Browse Source

don't try introducer with invalid address. Terminate session immediately if appropriate introducer not found

pull/2072/head
orignal 5 months ago
parent
commit
12653f2fe4
  1. 26
      libi2pd/SSU2.cpp

26
libi2pd/SSU2.cpp

@ -796,6 +796,7 @@ namespace transport
// we have to start a new session to an introducer // we have to start a new session to an introducer
std::vector<i2p::data::IdentHash> newRouters; std::vector<i2p::data::IdentHash> newRouters;
std::shared_ptr<i2p::data::RouterInfo> r; std::shared_ptr<i2p::data::RouterInfo> r;
std::shared_ptr<const i2p::data::RouterInfo::Address> addr;
uint32_t relayTag = 0; uint32_t relayTag = 0;
if (!indices.empty ()) if (!indices.empty ())
{ {
@ -812,7 +813,16 @@ namespace transport
if (r->IsReachableFrom (i2p::context.GetRouterInfo ())) if (r->IsReachableFrom (i2p::context.GetRouterInfo ()))
{ {
relayTag = introducer.iTag; relayTag = introducer.iTag;
if (relayTag) break; addr = address->IsV6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address ();
if (!addr->host.is_unspecified () && addr->port &&
!i2p::transport::transports.IsInReservedRange(addr->host))
break;
else
{
// address is invalid, try next introducer
relayTag = 0;
addr = nullptr;
}
} }
} }
else if (!i2p::data::IsRouterBanned (introducer.iH)) else if (!i2p::data::IsRouterBanned (introducer.iH))
@ -821,16 +831,9 @@ namespace transport
} }
if (r) if (r)
{ {
if (relayTag) if (relayTag && addr)
{ {
// introducer and tag found connect to it through SSU2 // introducer and tag found connect to it through SSU2
auto addr = address->IsV6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address ();
if (addr)
{
bool isValidEndpoint = !addr->host.is_unspecified () && addr->port &&
!i2p::transport::transports.IsInReservedRange(addr->host);
if (isValidEndpoint)
{
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port)); auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port));
if (!s) if (!s)
{ {
@ -851,14 +854,15 @@ namespace transport
s->SetOnEstablished ([session, s, relayTag]() {s->Introduce (session, relayTag); }); s->SetOnEstablished ([session, s, relayTag]() {s->Introduce (session, relayTag); });
} }
} }
} else
} session->Done ();
} }
else else
{ {
// introducers not found, try to request them // introducers not found, try to request them
for (auto& it: newRouters) for (auto& it: newRouters)
i2p::data::netdb.RequestDestination (it); i2p::data::netdb.RequestDestination (it);
session->Done (); // don't wait for connect timeout
} }
} }

Loading…
Cancel
Save