From 42f1396f23a31f7e6db86fc764f6ec9ef40ee73d Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 15 Feb 2026 17:25:41 -0500 Subject: [PATCH] connect to reseed with timeout --- libi2pd/Reseed.cpp | 25 ++++++++++++++++++------- libi2pd/Reseed.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libi2pd/Reseed.cpp b/libi2pd/Reseed.cpp index e7176072..718c75ba 100644 --- a/libi2pd/Reseed.cpp +++ b/libi2pd/Reseed.cpp @@ -686,10 +686,17 @@ namespace data } if (supported) { - s.lowest_layer().connect (ep, ecode); + s.lowest_layer().async_connect (ep, + [&ecode](const boost::system::error_code& ec) + { + ecode = ec; + }); + service.run_for (std::chrono::seconds (RESEED_CONNECT_TIMEOUT)); + if (!service.stopped()) s.lowest_layer().close (); + if (!ecode) { - LogPrint (eLogDebug, "Reseed: Resolved to ", ep.address ()); + LogPrint (eLogDebug, "Reseed: Connected to ", ep.address ()); connected = true; break; } @@ -801,13 +808,17 @@ namespace data for (const auto& it: endpoints) { boost::asio::ip::tcp::endpoint ep = it; - if ( - i2p::util::net::IsYggdrasilAddress (ep.address ()) && - i2p::context.SupportsMesh () - ) + if (i2p::util::net::IsYggdrasilAddress (ep.address ()) && i2p::context.SupportsMesh ()) { LogPrint (eLogDebug, "Reseed: Yggdrasil: Resolved to ", ep.address ()); - s.connect (ep, ecode); + s.async_connect (ep, + [&ecode](const boost::system::error_code& ec) + { + ecode = ec; + }); + service.run_for (std::chrono::seconds (2*RESEED_CONNECT_TIMEOUT)); + if (!service.stopped()) s.close (); + if (!ecode) { connected = true; diff --git a/libi2pd/Reseed.h b/libi2pd/Reseed.h index d3414a30..53458a04 100644 --- a/libi2pd/Reseed.h +++ b/libi2pd/Reseed.h @@ -21,6 +21,7 @@ namespace i2p namespace data { constexpr int MAX_NUM_RESEED_ATTEMPTS = 10; + constexpr int RESEED_CONNECT_TIMEOUT = 5; // in seconds class Reseeder {