From c49e17ad405db6de64bdf8d2a2c37199b9c828d3 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 May 2024 11:53:18 -0400 Subject: [PATCH] use timestamp to reset rng --- libi2pd/NetDb.cpp | 4 ++-- libi2pd/TunnelPool.cpp | 3 ++- libi2pd/TunnelPool.h | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index a5620749..f4d450fd 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -1490,7 +1490,7 @@ namespace data if (eligible.size () > NETDB_MAX_EXPLORATORY_SELECTION_SIZE) { std::sample (eligible.begin(), eligible.end(), std::back_inserter(m_ExploratorySelection), - NETDB_MAX_EXPLORATORY_SELECTION_SIZE, std::mt19937(std::random_device()())); + NETDB_MAX_EXPLORATORY_SELECTION_SIZE, std::mt19937(ts)); } else std::swap (m_ExploratorySelection, eligible); @@ -1498,7 +1498,7 @@ namespace data if (m_ExploratorySelection.size () > NETDB_MAX_EXPLORATORY_SELECTION_SIZE) { // reduce number of eligible to max selection size - std::shuffle (m_ExploratorySelection.begin(), m_ExploratorySelection.end(), std::mt19937(std::random_device()())); + std::shuffle (m_ExploratorySelection.begin(), m_ExploratorySelection.end(), std::mt19937(ts)); m_ExploratorySelection.resize (NETDB_MAX_EXPLORATORY_SELECTION_SIZE); } #endif diff --git a/libi2pd/TunnelPool.cpp b/libi2pd/TunnelPool.cpp index f723c5a2..1cbe04c1 100644 --- a/libi2pd/TunnelPool.cpp +++ b/libi2pd/TunnelPool.cpp @@ -45,7 +45,8 @@ namespace tunnel m_NumInboundHops (numInboundHops), m_NumOutboundHops (numOutboundHops), m_NumInboundTunnels (numInboundTunnels), m_NumOutboundTunnels (numOutboundTunnels), m_InboundVariance (inboundVariance), m_OutboundVariance (outboundVariance), - m_IsActive (true), m_CustomPeerSelector(nullptr), m_Rng(m_Rd()) + m_IsActive (true), m_CustomPeerSelector(nullptr), + m_Rng(i2p::util::GetMonotonicMicroseconds ()%1000000LL) { if (m_NumInboundTunnels > TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY) m_NumInboundTunnels = TUNNEL_POOL_MAX_INBOUND_TUNNELS_QUANTITY; diff --git a/libi2pd/TunnelPool.h b/libi2pd/TunnelPool.h index 88108135..c879a6ea 100644 --- a/libi2pd/TunnelPool.h +++ b/libi2pd/TunnelPool.h @@ -154,7 +154,6 @@ namespace tunnel int m_MinLatency = 0; // if > 0 this tunnel pool will try building tunnels with minimum latency by ms int m_MaxLatency = 0; // if > 0 this tunnel pool will try building tunnels with maximum latency by ms - std::random_device m_Rd; std::mt19937 m_Rng; public: