mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
find all introducers at the time
This commit is contained in:
parent
9c8c3b9174
commit
b5618af308
@ -662,24 +662,29 @@ namespace transport
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<SSUSession *> SSUServer::FindIntroducers (int maxNumIntroducers, bool v4)
|
std::list<std::shared_ptr<SSUSession> > SSUServer::FindIntroducers (int maxNumIntroducers, bool v4)
|
||||||
{
|
{
|
||||||
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
std::set<SSUSession *> ret;
|
std::list<std::shared_ptr<SSUSession> > ret;
|
||||||
auto filter = [&ret, ts](std::shared_ptr<SSUSession> session)->bool
|
const auto& sessions = v4 ? m_Sessions : m_SessionsV6;
|
||||||
{
|
for (const auto& s : sessions)
|
||||||
return session->GetRelayTag () && !ret.count (session.get ()) &&
|
{
|
||||||
session->GetState () == eSessionStateEstablished &&
|
if (s.second->GetRelayTag () && s.second->GetState () == eSessionStateEstablished &&
|
||||||
ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION;
|
ts < s.second->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
|
||||||
};
|
ret.push_back (s.second);
|
||||||
for (int i = 0; i < maxNumIntroducers; i++)
|
}
|
||||||
|
if ((int)ret.size () > maxNumIntroducers)
|
||||||
{
|
{
|
||||||
auto session = v4 ? GetRandomV4Session (filter) : GetRandomV6Session (filter);
|
// shink ret randomly
|
||||||
if (session)
|
int sz = ret.size () - maxNumIntroducers;
|
||||||
ret.insert (session.get ());
|
for (int i = 0; i < sz; i++)
|
||||||
else
|
{
|
||||||
break;
|
auto ind = rand () % ret.size ();
|
||||||
}
|
auto it = ret.begin ();
|
||||||
|
std::advance (it, ind);
|
||||||
|
ret.erase (it);
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,7 +775,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 - numIntroducers, v4);
|
auto sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4); // try to find if duplicates
|
||||||
for (const auto& it1: sessions)
|
for (const auto& it1: sessions)
|
||||||
{
|
{
|
||||||
const auto& ep = it1->GetRemoteEndpoint ();
|
const auto& ep = it1->GetRemoteEndpoint ();
|
||||||
|
@ -100,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::set<SSUSession *> FindIntroducers (int maxNumIntroducers, bool v4);
|
std::list<std::shared_ptr<SSUSession> > FindIntroducers (int maxNumIntroducers, bool v4);
|
||||||
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…
x
Reference in New Issue
Block a user