mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
random shuffle of tunnels for peer test pairs
This commit is contained in:
parent
0e502c49b5
commit
56619caa71
@ -361,31 +361,43 @@ namespace tunnel
|
|||||||
|
|
||||||
// new tests
|
// new tests
|
||||||
std::vector<std::pair<std::shared_ptr<OutboundTunnel>, std::shared_ptr<InboundTunnel> > > newTests;
|
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);
|
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
||||||
auto it1 = m_OutboundTunnels.begin ();
|
for (auto& it: m_OutboundTunnels)
|
||||||
std::unique_lock<std::mutex> l2(m_InboundTunnelsMutex);
|
outboundTunnels.push_back (it);
|
||||||
auto it2 = m_InboundTunnels.begin ();
|
}
|
||||||
while (it1 != m_OutboundTunnels.end () && it2 != m_InboundTunnels.end ())
|
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 ())
|
||||||
{
|
{
|
||||||
bool failed = false;
|
failed = true;
|
||||||
if ((*it1)->IsFailed ())
|
++it1;
|
||||||
{
|
|
||||||
failed = true;
|
|
||||||
++it1;
|
|
||||||
}
|
|
||||||
if ((*it2)->IsFailed ())
|
|
||||||
{
|
|
||||||
failed = true;
|
|
||||||
++it2;
|
|
||||||
}
|
|
||||||
if (!failed)
|
|
||||||
{
|
|
||||||
newTests.push_back(std::make_pair (*it1, *it2));
|
|
||||||
++it1; ++it2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
if ((*it2)->IsFailed ())
|
||||||
|
{
|
||||||
|
failed = true;
|
||||||
|
++it2;
|
||||||
|
}
|
||||||
|
if (!failed)
|
||||||
|
{
|
||||||
|
newTests.push_back(std::make_pair (*it1, *it2));
|
||||||
|
++it1; ++it2;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (auto& it: newTests)
|
for (auto& it: newTests)
|
||||||
{
|
{
|
||||||
uint32_t msgID;
|
uint32_t msgID;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user