Browse Source

use mt19937 instead rand

pull/2072/head
orignal 6 months ago
parent
commit
d4eea61b82
  1. 12
      libi2pd/NetDbRequests.cpp
  2. 2
      libi2pd/NetDbRequests.h

12
libi2pd/NetDbRequests.cpp

@ -10,9 +10,10 @@ @@ -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 @@ -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 @@ -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 @@ -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));
}

2
libi2pd/NetDbRequests.h

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
#include <inttypes.h>
#include <memory>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <list>
@ -119,6 +120,7 @@ namespace data @@ -119,6 +120,7 @@ namespace data
i2p::util::MemoryPoolMt<RequestedDestination> m_RequestedDestinationsPool;
boost::asio::deadline_timer m_ManageRequestsTimer, m_ExploratoryTimer,
m_CleanupTimer, m_DiscoveredRoutersTimer;
std::mt19937 m_Rng;
};
}
}

Loading…
Cancel
Save