From d4eea61b822a92ea99487829bc96ce164a3168fe Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 5 Jun 2024 15:08:51 -0400 Subject: [PATCH] use mt19937 instead rand --- libi2pd/NetDbRequests.cpp | 12 +++++++----- libi2pd/NetDbRequests.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libi2pd/NetDbRequests.cpp b/libi2pd/NetDbRequests.cpp index a17bcdb5..0e632c26 100644 --- a/libi2pd/NetDbRequests.cpp +++ b/libi2pd/NetDbRequests.cpp @@ -10,9 +10,10 @@ #include "I2NPProtocol.h" #include "Transports.h" #include "NetDb.hpp" -#include "NetDbRequests.h" #include "ECIESX25519AEADRatchetSession.h" #include "RouterContext.h" +#include "Timestamp.h" +#include "NetDbRequests.h" namespace i2p { @@ -99,7 +100,8 @@ namespace data NetDbRequests::NetDbRequests (): RunnableServiceWithWork ("NetDbReq"), m_ManageRequestsTimer (GetIOService ()), m_ExploratoryTimer (GetIOService ()), - m_CleanupTimer (GetIOService ()), m_DiscoveredRoutersTimer (GetIOService ()) + m_CleanupTimer (GetIOService ()), m_DiscoveredRoutersTimer (GetIOService ()), + m_Rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL) { } @@ -509,8 +511,8 @@ namespace data if (ecode != boost::asio::error::operation_aborted) { auto numRouters = netdb.GetNumRouters (); - auto nextExploratoryInterval = numRouters < 2500 ? (EXPLORATORY_REQUEST_INTERVAL + rand () % EXPLORATORY_REQUEST_INTERVAL)/2 : - EXPLORATORY_REQUEST_INTERVAL + rand () % EXPLORATORY_REQUEST_INTERVAL_VARIANCE; + auto nextExploratoryInterval = numRouters < 2500 ? (EXPLORATORY_REQUEST_INTERVAL + m_Rng () % EXPLORATORY_REQUEST_INTERVAL)/2 : + EXPLORATORY_REQUEST_INTERVAL + m_Rng () % EXPLORATORY_REQUEST_INTERVAL_VARIANCE; if (numRouters) { if (i2p::transport::transports.IsOnline () && i2p::transport::transports.IsRunning ()) @@ -531,7 +533,7 @@ namespace data void NetDbRequests::ScheduleDiscoveredRoutersRequest () { m_DiscoveredRoutersTimer.expires_from_now (boost::posix_time::milliseconds( - DISCOVERED_REQUEST_INTERVAL + rand () % DISCOVERED_REQUEST_INTERVAL_VARIANCE)); + DISCOVERED_REQUEST_INTERVAL + m_Rng () % DISCOVERED_REQUEST_INTERVAL_VARIANCE)); m_DiscoveredRoutersTimer.async_wait (std::bind (&NetDbRequests::HandleDiscoveredRoutersTimer, this, std::placeholders::_1)); } diff --git a/libi2pd/NetDbRequests.h b/libi2pd/NetDbRequests.h index 1ce5f8c1..1758d498 100644 --- a/libi2pd/NetDbRequests.h +++ b/libi2pd/NetDbRequests.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -119,6 +120,7 @@ namespace data i2p::util::MemoryPoolMt m_RequestedDestinationsPool; boost::asio::deadline_timer m_ManageRequestsTimer, m_ExploratoryTimer, m_CleanupTimer, m_DiscoveredRoutersTimer; + std::mt19937 m_Rng; }; } }