Browse Source

random pick tunnels

pull/93/head
orignal 10 years ago
parent
commit
e50377e557
  1. 2
      Tunnel.cpp
  2. 14
      TunnelPool.cpp

2
Tunnel.cpp

@ -273,7 +273,7 @@ namespace tunnel @@ -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;

14
TunnelPool.cpp

@ -91,10 +91,20 @@ namespace tunnel @@ -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…
Cancel
Save