From a69eade1f4359be6fe53b1f30c0ae5185a713b96 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 25 Aug 2024 21:35:33 -0400 Subject: [PATCH] use pool's rng for random tunnel/remote lease selection --- libi2pd/Datagram.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libi2pd/Datagram.cpp b/libi2pd/Datagram.cpp index 3f2fc8d0..5db072a4 100644 --- a/libi2pd/Datagram.cpp +++ b/libi2pd/Datagram.cpp @@ -417,7 +417,14 @@ namespace datagram auto sz = ls.size(); if (sz) { - auto idx = rand() % sz; + int idx = -1; + if (m_LocalDestination) + { + auto pool = m_LocalDestination->GetTunnelPool (); + if (pool) + idx = m_LocalDestination->GetTunnelPool ()->GetRng ()() % sz; + } + if (idx < 0) idx = rand () % sz; path->remoteLease = ls[idx]; } else @@ -443,7 +450,14 @@ namespace datagram auto sz = ls.size(); if (sz) { - auto idx = rand() % sz; + int idx = -1; + if (m_LocalDestination) + { + auto pool = m_LocalDestination->GetTunnelPool (); + if (pool) + idx = m_LocalDestination->GetTunnelPool ()->GetRng ()() % sz; + } + if (idx < 0) idx = rand () % sz; path->remoteLease = ls[idx]; } else