mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
don't select next introducers from existing sessions
This commit is contained in:
parent
db93a7315f
commit
94555b9c43
|
@ -410,20 +410,6 @@ namespace transport
|
||||||
if (session) session->FlushData ();
|
if (session) session->FlushData ();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SSUSession> SSUServer::FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const
|
|
||||||
{
|
|
||||||
if (!router) return nullptr;
|
|
||||||
auto address = router->GetSSUAddress (true); // v4 only
|
|
||||||
if (!address) return nullptr;
|
|
||||||
auto session = FindSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
|
||||||
if (session || !context.SupportsV6 ())
|
|
||||||
return session;
|
|
||||||
// try v6
|
|
||||||
address = router->GetSSUV6Address ();
|
|
||||||
if (!address) return nullptr;
|
|
||||||
return FindSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<SSUSession> SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const
|
std::shared_ptr<SSUSession> SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const
|
||||||
{
|
{
|
||||||
auto& sessions = e.address ().is_v6 () ? m_SessionsV6 : m_Sessions;
|
auto& sessions = e.address ().is_v6 () ? m_SessionsV6 : m_Sessions;
|
||||||
|
@ -662,7 +648,8 @@ namespace transport
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::shared_ptr<SSUSession> > SSUServer::FindIntroducers (int maxNumIntroducers, bool v4)
|
std::list<std::shared_ptr<SSUSession> > SSUServer::FindIntroducers (int maxNumIntroducers,
|
||||||
|
bool v4, std::set<i2p::data::IdentHash>& excluded)
|
||||||
{
|
{
|
||||||
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
std::list<std::shared_ptr<SSUSession> > ret;
|
std::list<std::shared_ptr<SSUSession> > ret;
|
||||||
|
@ -672,6 +659,8 @@ namespace transport
|
||||||
if (s.second->GetRelayTag () && s.second->GetState () == eSessionStateEstablished &&
|
if (s.second->GetRelayTag () && s.second->GetState () == eSessionStateEstablished &&
|
||||||
ts < s.second->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_EXPIRATION)
|
ts < s.second->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_EXPIRATION)
|
||||||
ret.push_back (s.second);
|
ret.push_back (s.second);
|
||||||
|
else
|
||||||
|
excluded.insert (s.second->GetRemoteIdentity ()->GetIdentHash ());
|
||||||
}
|
}
|
||||||
if ((int)ret.size () > maxNumIntroducers)
|
if ((int)ret.size () > maxNumIntroducers)
|
||||||
{
|
{
|
||||||
|
@ -782,7 +771,7 @@ namespace transport
|
||||||
if (numIntroducers < SSU_MAX_NUM_INTRODUCERS)
|
if (numIntroducers < SSU_MAX_NUM_INTRODUCERS)
|
||||||
{
|
{
|
||||||
// create new
|
// create new
|
||||||
auto sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4); // try to find if duplicates
|
auto sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4, excluded); // try to find if duplicates
|
||||||
if (sessions.empty () && !introducers.empty ())
|
if (sessions.empty () && !introducers.empty ())
|
||||||
{
|
{
|
||||||
// bump creation time for previous introducers if no new sessions found
|
// bump creation time for previous introducers if no new sessions found
|
||||||
|
@ -794,7 +783,8 @@ namespace transport
|
||||||
session->SetCreationTime (session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION);
|
session->SetCreationTime (session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION);
|
||||||
}
|
}
|
||||||
// try again
|
// try again
|
||||||
sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4);
|
excluded.clear ();
|
||||||
|
sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4, excluded);
|
||||||
}
|
}
|
||||||
for (const auto& it1: sessions)
|
for (const auto& it1: sessions)
|
||||||
{
|
{
|
||||||
|
@ -831,6 +821,11 @@ namespace transport
|
||||||
excluded.insert (introducer->GetIdentHash ());
|
excluded.insert (introducer->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "SSU: can't find more introducers");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ namespace transport
|
||||||
bool CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
|
bool CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
|
||||||
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest = false);
|
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest = false);
|
||||||
void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest);
|
void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest);
|
||||||
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
|
|
||||||
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
|
std::shared_ptr<SSUSession> FindSession (const boost::asio::ip::udp::endpoint& e) const;
|
||||||
std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded);
|
std::shared_ptr<SSUSession> GetRandomEstablishedV4Session (std::shared_ptr<const SSUSession> excluded);
|
||||||
std::shared_ptr<SSUSession> GetRandomEstablishedV6Session (std::shared_ptr<const SSUSession> excluded);
|
std::shared_ptr<SSUSession> GetRandomEstablishedV6Session (std::shared_ptr<const SSUSession> excluded);
|
||||||
|
@ -101,7 +100,7 @@ namespace transport
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<SSUSession> GetRandomV6Session (Filter filter);
|
std::shared_ptr<SSUSession> GetRandomV6Session (Filter filter);
|
||||||
|
|
||||||
std::list<std::shared_ptr<SSUSession> > FindIntroducers (int maxNumIntroducers, bool v4);
|
std::list<std::shared_ptr<SSUSession> > FindIntroducers (int maxNumIntroducers, bool v4, std::set<i2p::data::IdentHash>& excluded);
|
||||||
void ScheduleIntroducersUpdateTimer ();
|
void ScheduleIntroducersUpdateTimer ();
|
||||||
void ScheduleIntroducersUpdateTimerV6 ();
|
void ScheduleIntroducersUpdateTimerV6 ();
|
||||||
void HandleIntroducersUpdateTimer (const boost::system::error_code& ecode, bool v4);
|
void HandleIntroducersUpdateTimer (const boost::system::error_code& ecode, bool v4);
|
||||||
|
|
Loading…
Reference in a new issue