MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / GetRandomPeerTestSession

Method GetRandomPeerTestSession

libi2pd/SSU2.cpp:608–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606 }
607
608 std::shared_ptr<SSU2Session> SSU2Server::GetRandomPeerTestSession (
609 i2p::data::RouterInfo::CompatibleTransports remoteTransports, const i2p::data::IdentHash& excluded)
610 {
611 if (m_Sessions.empty ()) return nullptr;
612 int ind = m_Rng () % m_Sessions.size ();
613 auto it = m_Sessions.begin ();
614 std::advance (it, ind);
615 while (it != m_Sessions.end ())
616 {
617 if (it->second->IsEstablished () && (it->second->GetRemotePeerTestTransports () & remoteTransports) &&
618 it->second->GetRemoteVersion () >= i2p::data::NETDB_MIN_PEER_TEST_VERSION &&
619 it->second->GetRemoteIdentity ()->GetIdentHash () != excluded)
620 return it->second;
621 it++;
622 }
623 // not found, try from beginning
624 it = m_Sessions.begin ();
625 while (it != m_Sessions.end () && ind)
626 {
627 if (it->second->IsEstablished () && (it->second->GetRemotePeerTestTransports () & remoteTransports) &&
628 it->second->GetRemoteVersion () >= i2p::data::NETDB_MIN_PEER_TEST_VERSION &&
629 it->second->GetRemoteIdentity ()->GetIdentHash () != excluded)
630 return it->second;
631 it++; ind--;
632 }
633 return nullptr;
634 }
635
636 void SSU2Server::AddRelay (uint32_t tag, std::shared_ptr<SSU2Session> relay)
637 {

Callers 1

HandlePeerTestMethod · 0.80

Calls 4

GetRemoteVersionMethod · 0.80
IsEstablishedMethod · 0.45
GetRemoteIdentityMethod · 0.45

Tested by

no test coverage detected