From 74ff1f848aceb41006cb1abfbb9a8c142f6a6dd5 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 15 Feb 2026 12:48:21 -0500 Subject: [PATCH] don't try same reseed twice --- libi2pd/Reseed.cpp | 34 +++++++++++++++++++++++----------- libi2pd/Reseed.h | 3 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libi2pd/Reseed.cpp b/libi2pd/Reseed.cpp index 623f20ef..e7176072 100644 --- a/libi2pd/Reseed.cpp +++ b/libi2pd/Reseed.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -113,19 +114,30 @@ namespace data return 0; } - int reseedRetries = 0; - while (reseedRetries < 10) + int numReseeds = httpsReseedHostList.size () + yggReseedHostList.size (); + int reseedAttempts = std::min (numReseeds, MAX_NUM_RESEED_ATTEMPTS); + if (reseedAttempts) { - auto ind = rand () % (httpsReseedHostList.size () + yggReseedHostList.size ()); - bool isHttps = ind < httpsReseedHostList.size (); - std::string reseedUrl = isHttps ? httpsReseedHostList[ind] : - yggReseedHostList[ind - httpsReseedHostList.size ()]; - reseedUrl += "i2pseeds.su3"; - auto num = ReseedFromSU3Url (reseedUrl, isHttps); - if (num > 0) return num; // success - reseedRetries++; + std::mt19937 rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL); + for (int i = 0; i < reseedAttempts; i++) + { + auto ind = rng () % numReseeds; + bool isHttps = ind < httpsReseedHostList.size (); + std::string reseedUrl = isHttps ? httpsReseedHostList[ind] : + yggReseedHostList[ind - httpsReseedHostList.size ()]; + reseedUrl += "i2pseeds.su3"; + auto num = ReseedFromSU3Url (reseedUrl, isHttps); + if (num > 0) return num; // success + + if (isHttps) + httpsReseedHostList.erase (httpsReseedHostList.begin() + ind); + else + yggReseedHostList.erase (yggReseedHostList.begin() + (ind - httpsReseedHostList.size ())); + numReseeds--; + if (!numReseeds) break; + } } - LogPrint (eLogWarning, "Reseed: Failed to reseed from servers after 10 attempts"); + LogPrint (eLogWarning, "Reseed: Failed to reseed from ", numReseeds, " servers after ", reseedAttempts, " attempts"); return 0; } diff --git a/libi2pd/Reseed.h b/libi2pd/Reseed.h index a6de6fa4..d3414a30 100644 --- a/libi2pd/Reseed.h +++ b/libi2pd/Reseed.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2020, The PurpleI2P Project +* Copyright (c) 2013-2025, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -20,6 +20,7 @@ namespace i2p { namespace data { + constexpr int MAX_NUM_RESEED_ATTEMPTS = 10; class Reseeder {