Browse Source

random shuffle of tunnels for peer test pairs

pull/2016/head
orignal 10 months ago
parent
commit
56619caa71
  1. 24
      libi2pd/TunnelPool.cpp

24
libi2pd/TunnelPool.cpp

@ -361,12 +361,25 @@ namespace tunnel @@ -361,12 +361,25 @@ namespace tunnel
// new tests
std::vector<std::pair<std::shared_ptr<OutboundTunnel>, std::shared_ptr<InboundTunnel> > > newTests;
std::random_device rd;
std::mt19937 rnd(rd());
std::vector<std::shared_ptr<OutboundTunnel> > outboundTunnels;
{
std::unique_lock<std::mutex> l1(m_OutboundTunnelsMutex);
auto it1 = m_OutboundTunnels.begin ();
std::unique_lock<std::mutex> l2(m_InboundTunnelsMutex);
auto it2 = m_InboundTunnels.begin ();
while (it1 != m_OutboundTunnels.end () && it2 != m_InboundTunnels.end ())
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
for (auto& it: m_OutboundTunnels)
outboundTunnels.push_back (it);
}
std::shuffle (outboundTunnels.begin(), outboundTunnels.end(), rnd);
std::vector<std::shared_ptr<InboundTunnel> > inboundTunnels;
{
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
for (auto& it: m_InboundTunnels)
inboundTunnels.push_back (it);
}
std::shuffle (inboundTunnels.begin(), inboundTunnels.end(), rnd);
auto it1 = outboundTunnels.begin ();
auto it2 = inboundTunnels.begin ();
while (it1 != outboundTunnels.end () && it2 != inboundTunnels.end ())
{
bool failed = false;
if ((*it1)->IsFailed ())
@ -385,7 +398,6 @@ namespace tunnel @@ -385,7 +398,6 @@ namespace tunnel
++it1; ++it2;
}
}
}
for (auto& it: newTests)
{
uint32_t msgID;

Loading…
Cancel
Save