mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-18 16:49:58 +00:00
send peer tests with random delays
This commit is contained in:
parent
0021501d75
commit
083034fa35
@ -645,14 +645,33 @@ namespace transport
|
|||||||
LogPrint (eLogInfo, "Transports: Started peer test IPv4");
|
LogPrint (eLogInfo, "Transports: Started peer test IPv4");
|
||||||
std::set<i2p::data::IdentHash> excluded;
|
std::set<i2p::data::IdentHash> excluded;
|
||||||
excluded.insert (i2p::context.GetIdentHash ()); // don't pick own router
|
excluded.insert (i2p::context.GetIdentHash ()); // don't pick own router
|
||||||
|
int testDelay = 0;
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (true, excluded); // v4
|
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (true, excluded); // v4
|
||||||
if (router)
|
if (router)
|
||||||
{
|
{
|
||||||
if (!i2p::context.GetTesting ())
|
if (!i2p::context.GetTesting ())
|
||||||
|
{
|
||||||
i2p::context.SetTesting (true);
|
i2p::context.SetTesting (true);
|
||||||
m_SSU2Server->StartPeerTest (router, true);
|
// send first peer test immediately
|
||||||
|
m_SSU2Server->StartPeerTest (router, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
testDelay += PEER_TEST_DELAY_INTERVAL + rand() % PEER_TEST_DELAY_INTERVAL_VARIANCE;
|
||||||
|
if (m_Service)
|
||||||
|
{
|
||||||
|
auto delayTimer = std::make_shared<boost::asio::deadline_timer>(*m_Service);
|
||||||
|
delayTimer->expires_from_now (boost::posix_time::milliseconds (testDelay));
|
||||||
|
delayTimer->async_wait (
|
||||||
|
[this, router, delayTimer](const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
m_SSU2Server->StartPeerTest (router, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
excluded.insert (router->GetIdentHash ());
|
excluded.insert (router->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,14 +683,33 @@ namespace transport
|
|||||||
LogPrint (eLogInfo, "Transports: Started peer test IPv6");
|
LogPrint (eLogInfo, "Transports: Started peer test IPv6");
|
||||||
std::set<i2p::data::IdentHash> excluded;
|
std::set<i2p::data::IdentHash> excluded;
|
||||||
excluded.insert (i2p::context.GetIdentHash ()); // don't pick own router
|
excluded.insert (i2p::context.GetIdentHash ()); // don't pick own router
|
||||||
|
int testDelay = 0;
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (false, excluded); // v6
|
auto router = i2p::data::netdb.GetRandomSSU2PeerTestRouter (false, excluded); // v6
|
||||||
if (router)
|
if (router)
|
||||||
{
|
{
|
||||||
if (!i2p::context.GetTestingV6 ())
|
if (!i2p::context.GetTestingV6 ())
|
||||||
i2p::context.SetTestingV6 (true);
|
{
|
||||||
m_SSU2Server->StartPeerTest (router, false);
|
i2p::context.SetTestingV6 (true);
|
||||||
|
// send first peer test immediately
|
||||||
|
m_SSU2Server->StartPeerTest (router, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
testDelay += PEER_TEST_DELAY_INTERVAL + rand() % PEER_TEST_DELAY_INTERVAL_VARIANCE;
|
||||||
|
if (m_Service)
|
||||||
|
{
|
||||||
|
auto delayTimer = std::make_shared<boost::asio::deadline_timer>(*m_Service);
|
||||||
|
delayTimer->expires_from_now (boost::posix_time::milliseconds (testDelay));
|
||||||
|
delayTimer->async_wait (
|
||||||
|
[this, router, delayTimer](const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
m_SSU2Server->StartPeerTest (router, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
excluded.insert (router->GetIdentHash ());
|
excluded.insert (router->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,8 @@ namespace transport
|
|||||||
|
|
||||||
const uint64_t SESSION_CREATION_TIMEOUT = 15; // in seconds
|
const uint64_t SESSION_CREATION_TIMEOUT = 15; // in seconds
|
||||||
const int PEER_TEST_INTERVAL = 71; // in minutes
|
const int PEER_TEST_INTERVAL = 71; // in minutes
|
||||||
|
const int PEER_TEST_DELAY_INTERVAL = 20; // in milliseconds
|
||||||
|
const int PEER_TEST_DELAY_INTERVAL_VARIANCE = 30; // in milliseconds
|
||||||
const int MAX_NUM_DELAYED_MESSAGES = 150;
|
const int MAX_NUM_DELAYED_MESSAGES = 150;
|
||||||
const int CHECK_PROFILE_NUM_DELAYED_MESSAGES = 15; // check profile after
|
const int CHECK_PROFILE_NUM_DELAYED_MESSAGES = 15; // check profile after
|
||||||
class Transports
|
class Transports
|
||||||
|
Loading…
x
Reference in New Issue
Block a user