|
|
@ -501,17 +501,15 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SSU2Session> SSU2Server::GetRandomPeerTestSession ( |
|
|
|
std::shared_ptr<SSU2Session> SSU2Server::GetRandomPeerTestSession ( |
|
|
|
i2p::data::RouterInfo::CompatibleTransports remoteTransports, const i2p::data::IdentHash& excluded) const |
|
|
|
i2p::data::RouterInfo::CompatibleTransports remoteTransports, const i2p::data::IdentHash& excluded) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_Sessions.empty ()) return nullptr; |
|
|
|
if (m_Sessions.empty ()) return nullptr; |
|
|
|
uint16_t ind; |
|
|
|
int ind = m_Rng () % m_Sessions.size (); |
|
|
|
RAND_bytes ((uint8_t *)&ind, sizeof (ind)); |
|
|
|
|
|
|
|
ind %= m_Sessions.size (); |
|
|
|
|
|
|
|
auto it = m_Sessions.begin (); |
|
|
|
auto it = m_Sessions.begin (); |
|
|
|
std::advance (it, ind); |
|
|
|
std::advance (it, ind); |
|
|
|
while (it != m_Sessions.end ()) |
|
|
|
while (it != m_Sessions.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ((it->second->GetRemotePeerTestTransports () & remoteTransports) && |
|
|
|
if (it->second->IsEstablished () && (it->second->GetRemotePeerTestTransports () & remoteTransports) && |
|
|
|
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded) |
|
|
|
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded) |
|
|
|
return it->second; |
|
|
|
return it->second; |
|
|
|
it++; |
|
|
|
it++; |
|
|
@ -520,7 +518,7 @@ namespace transport |
|
|
|
it = m_Sessions.begin (); |
|
|
|
it = m_Sessions.begin (); |
|
|
|
while (it != m_Sessions.end () && ind) |
|
|
|
while (it != m_Sessions.end () && ind) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ((it->second->GetRemotePeerTestTransports () & remoteTransports) && |
|
|
|
if (it->second->IsEstablished () && (it->second->GetRemotePeerTestTransports () & remoteTransports) && |
|
|
|
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded) |
|
|
|
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded) |
|
|
|
return it->second; |
|
|
|
return it->second; |
|
|
|
it++; ind--; |
|
|
|
it++; ind--; |
|
|
|