From d5b61ed544db61662832fcd7d5ad1eaf03268fb3 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 17 Apr 2021 14:33:53 -0400 Subject: [PATCH] select different routers for peer test --- libi2pd/NetDb.cpp | 7 ++++--- libi2pd/NetDb.hpp | 2 +- libi2pd/Transports.cpp | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index bc49d720..80029ece 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -1149,12 +1149,13 @@ namespace data }); } - std::shared_ptr NetDb::GetRandomPeerTestRouter (bool v4) const + std::shared_ptr NetDb::GetRandomPeerTestRouter (bool v4, const std::set& excluded) const { return GetRandomRouter ( - [v4](std::shared_ptr router)->bool + [v4, &excluded](std::shared_ptr router)->bool { - return !router->IsHidden () && router->IsPeerTesting (v4); + return !router->IsHidden () && router->IsPeerTesting (v4) && + !excluded.count (router->GetIdentHash ()); }); } diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index 891bc35d..b782872c 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -85,7 +85,7 @@ namespace data std::shared_ptr GetRandomRouter () const; std::shared_ptr GetRandomRouter (std::shared_ptr compatibleWith, bool reverse) const; std::shared_ptr GetHighBandwidthRandomRouter (std::shared_ptr compatibleWith, bool reverse) const; - std::shared_ptr GetRandomPeerTestRouter (bool v4) const; + std::shared_ptr GetRandomPeerTestRouter (bool v4, const std::set& excluded) const; std::shared_ptr GetRandomSSUV6Router () const; // TODO: change to v6 peer test later std::shared_ptr GetRandomIntroducer () const; std::shared_ptr GetClosestFloodfill (const IdentHash& destination, const std::set& excluded, bool closeThanUsOnly = false) const; diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index cf136608..4ad13518 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -587,10 +587,11 @@ namespace transport if (i2p::context.SupportsV4 ()) { LogPrint (eLogInfo, "Transports: Started peer test ipv4"); + std::set excluded; bool statusChanged = false; for (int i = 0; i < 5; i++) { - auto router = i2p::data::netdb.GetRandomPeerTestRouter (true); // v4 + auto router = i2p::data::netdb.GetRandomPeerTestRouter (true, excluded); // v4 if (router) { auto addr = router->GetSSUAddress (true); // ipv4 @@ -601,8 +602,9 @@ namespace transport statusChanged = true; i2p::context.SetStatus (eRouterStatusTesting); // first time only } - m_SSUServer->CreateSession (router, addr, true); // peer test v4 + m_SSUServer->CreateSession (router, addr, true); // peer test v4 } + excluded.insert (router->GetIdentHash ()); } } if (!statusChanged) @@ -611,10 +613,11 @@ namespace transport if (i2p::context.SupportsV6 ()) { LogPrint (eLogInfo, "Transports: Started peer test ipv6"); + std::set excluded; bool statusChanged = false; for (int i = 0; i < 5; i++) { - auto router = i2p::data::netdb.GetRandomPeerTestRouter (false); // v6 + auto router = i2p::data::netdb.GetRandomPeerTestRouter (false, excluded); // v6 if (router) { auto addr = router->GetSSUV6Address (); @@ -627,6 +630,7 @@ namespace transport } m_SSUServer->CreateSession (router, addr, true); // peer test v6 } + excluded.insert (router->GetIdentHash ()); } } if (!statusChanged)