mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
random pick tunnels
This commit is contained in:
parent
c025bcfdfc
commit
e50377e557
|
@ -273,7 +273,7 @@ namespace tunnel
|
|||
OutboundTunnel * tunnel = nullptr;
|
||||
for (auto it: m_OutboundTunnels)
|
||||
{
|
||||
if (i >= ind) return it;
|
||||
if (i >= ind) break;
|
||||
if (it->IsEstablished ())
|
||||
{
|
||||
tunnel = it;
|
||||
|
|
|
@ -91,10 +91,20 @@ namespace tunnel
|
|||
if (tunnels.empty ()) return nullptr;
|
||||
if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ())
|
||||
return suggested;
|
||||
|
||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
||||
uint32_t ind = rnd.GenerateWord32 (0, tunnels.size ()/2), i = 0;
|
||||
typename TTunnels::value_type tunnel = nullptr;
|
||||
for (auto it: tunnels)
|
||||
{
|
||||
if (i >= ind) break;
|
||||
if (it->IsEstablished ())
|
||||
return it;
|
||||
return nullptr;
|
||||
{
|
||||
tunnel = it;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return tunnel;
|
||||
}
|
||||
|
||||
void TunnelPool::CreateTunnels ()
|
||||
|
|
Loading…
Reference in a new issue