Skip to content

Commit

Permalink
try to create new sessions with introducers if existing are about to …
Browse files Browse the repository at this point in the history
…expire
  • Loading branch information
orignal committed Oct 4, 2024
1 parent 7f3a04a commit bce9630
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libi2pd/SSU2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ namespace transport
if (!session)
i2p::context.RemoveSSU2Introducer (ident, v4);
}
int numOldSessions = 0;
if (newList.size () < SSU2_MAX_NUM_INTRODUCERS)
{
auto sessions = FindIntroducers (SSU2_MAX_NUM_INTRODUCERS - newList.size (), v4, excluded);
Expand All @@ -1297,7 +1298,10 @@ namespace transport
{
if (std::find_if (newList.begin (), newList.end (),
[&ident = it.first](const auto& s){ return ident == s.first; }) == newList.end ())
{
sessions.push_back (session);
numOldSessions++;
}
}
}
impliedList.clear ();
Expand Down Expand Up @@ -1326,9 +1330,17 @@ namespace transport
}
introducers = newList;

if (introducers.size () < SSU2_MAX_NUM_INTRODUCERS)
if (introducers.size () < SSU2_MAX_NUM_INTRODUCERS || numOldSessions)
{
for (auto i = introducers.size (); i < SSU2_MAX_NUM_INTRODUCERS; i++)
// we need to create more sessions with relay tag

// exclude all existing sessions
excluded.clear ();
for (const auto& [ident, s] : m_SessionsByRouterHash)
excluded.insert (ident);

// sesssion about to expire are not counted
for (auto i = introducers.size (); i < SSU2_MAX_NUM_INTRODUCERS + numOldSessions; i++)
{
auto introducer = i2p::data::netdb.GetRandomSSU2Introducer (v4, excluded);
if (introducer)
Expand Down

0 comments on commit bce9630

Please sign in to comment.