Browse Source

don't use expired introducer even if we a session with it

pull/2072/head
orignal 4 months ago
parent
commit
b3314380cc
  1. 19
      libi2pd/SSU2.cpp

19
libi2pd/SSU2.cpp

@ -775,8 +775,12 @@ namespace transport
auto address = session->GetAddress (); auto address = session->GetAddress ();
if (!address) return; if (!address) return;
session->WaitForIntroduction (); session->WaitForIntroduction ();
auto ts = i2p::util::GetSecondsSinceEpoch ();
std::vector<int> indices; int i = 0;
// try to find existing session first // try to find existing session first
for (auto& it: address->ssu->introducers) for (auto& it: address->ssu->introducers)
{
if (it.iTag && ts < it.iExp)
{ {
auto it1 = m_SessionsByRouterHash.find (it.iH); auto it1 = m_SessionsByRouterHash.find (it.iH);
if (it1 != m_SessionsByRouterHash.end ()) if (it1 != m_SessionsByRouterHash.end ())
@ -784,23 +788,23 @@ namespace transport
it1->second->Introduce (session, it.iTag); it1->second->Introduce (session, it.iTag);
return; return;
} }
else
indices.push_back(i);
}
i++;
} }
// we have to start a new session to an introducer // we have to start a new session to an introducer
auto ts = i2p::util::GetSecondsSinceEpoch ();
std::shared_ptr<i2p::data::RouterInfo> r; std::shared_ptr<i2p::data::RouterInfo> r;
uint32_t relayTag = 0; uint32_t relayTag = 0;
if (!address->ssu->introducers.empty ()) if (!indices.empty ())
{ {
std::vector<int> indices;
for (int i = 0; i < (int)address->ssu->introducers.size (); i++) indices.push_back(i);
if (indices.size () > 1) if (indices.size () > 1)
std::shuffle (indices.begin(), indices.end(), std::mt19937(std::random_device()())); std::shuffle (indices.begin(), indices.end(), std::mt19937(ts));
for (auto i: indices) for (auto i: indices)
{ {
const auto& introducer = address->ssu->introducers[indices[i]]; const auto& introducer = address->ssu->introducers[indices[i]];
if (introducer.iTag && ts < introducer.iExp) // introducer is not expired, because in indices
{
r = i2p::data::netdb.FindRouter (introducer.iH); r = i2p::data::netdb.FindRouter (introducer.iH);
if (r && r->IsReachableFrom (i2p::context.GetRouterInfo ())) if (r && r->IsReachableFrom (i2p::context.GetRouterInfo ()))
{ {
@ -809,7 +813,6 @@ namespace transport
} }
} }
} }
}
if (r) if (r)
{ {
if (relayTag) if (relayTag)

Loading…
Cancel
Save