mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-07 07:44:13 +00:00
random pick tunnels
This commit is contained in:
parent
c025bcfdfc
commit
e50377e557
@ -273,7 +273,7 @@ namespace tunnel
|
|||||||
OutboundTunnel * tunnel = nullptr;
|
OutboundTunnel * tunnel = nullptr;
|
||||||
for (auto it: m_OutboundTunnels)
|
for (auto it: m_OutboundTunnels)
|
||||||
{
|
{
|
||||||
if (i >= ind) return it;
|
if (i >= ind) break;
|
||||||
if (it->IsEstablished ())
|
if (it->IsEstablished ())
|
||||||
{
|
{
|
||||||
tunnel = it;
|
tunnel = it;
|
||||||
|
@ -91,10 +91,20 @@ namespace tunnel
|
|||||||
if (tunnels.empty ()) return nullptr;
|
if (tunnels.empty ()) return nullptr;
|
||||||
if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ())
|
if (suggested && tunnels.count (suggested) > 0 && suggested->IsEstablished ())
|
||||||
return suggested;
|
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)
|
for (auto it: tunnels)
|
||||||
|
{
|
||||||
|
if (i >= ind) break;
|
||||||
if (it->IsEstablished ())
|
if (it->IsEstablished ())
|
||||||
return it;
|
{
|
||||||
return nullptr;
|
tunnel = it;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tunnel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TunnelPool::CreateTunnels ()
|
void TunnelPool::CreateTunnels ()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user