From 384cb7a8bd1a79eda05aff755d2e49c3dde695bc Mon Sep 17 00:00:00 2001 From: dr7ana Date: Mon, 11 Dec 2023 10:17:46 -0800 Subject: [PATCH] dont bomb with bootstrap reqs --- llarp/link/link_manager.cpp | 5 +++-- llarp/nodedb.cpp | 21 +++++++++++---------- llarp/nodedb.hpp | 2 +- llarp/router/router.cpp | 4 +++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index b04cfad6b..8ec85bf32 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -391,8 +391,10 @@ namespace llarp logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code); s.conn.close_connection(error_code); }); + itr->second = std::make_shared(ci.shared_from_this(), control_stream, rc); log::critical(logcat, "Successfully configured inbound connection fom {}; storing RC...", rid); + node_db->put_rc(rc); } // TODO: should we add routes here now that Router::SessionOpen is gone? @@ -620,14 +622,13 @@ namespace llarp const RemoteRC& source, std::string payload, std::function func) { _router.loop()->call([this, source, payload, f = std::move(func)]() { - if (auto conn = ep.get_conn(source); conn) { log::critical(logcat, "Dispatched bootstrap fetch request!"); conn->control_stream->command("bfetch_rcs"s, std::move(payload), std::move(f)); return; } - + log::critical(logcat, "Queuing bootstrap fetch request"); auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, f); diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index 000f51734..6e6f2beb5 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -512,7 +512,7 @@ namespace llarp { if (error) { - auto& fail_count = (_using_bootstrap_fallback) ? bootstrap_failures : fetch_failures; + auto& fail_count = (_using_bootstrap_fallback) ? bootstrap_attempts : fetch_failures; auto& THRESHOLD = (_using_bootstrap_fallback) ? MAX_BOOTSTRAP_FETCH_ATTEMPTS : MAX_FETCH_ATTEMPTS; @@ -638,7 +638,7 @@ namespace llarp void NodeDB::fallback_to_bootstrap() { - auto at_max_failures = bootstrap_failures >= MAX_BOOTSTRAP_FETCH_ATTEMPTS; + auto at_max_failures = bootstrap_attempts >= MAX_BOOTSTRAP_FETCH_ATTEMPTS; // base case: we have failed to query all bootstraps, or we received a sample of // the network, but the sample was unusable or unreachable. We will also enter this @@ -646,7 +646,7 @@ namespace llarp // checking not using_bootstrap_fallback) if (at_max_failures || not _using_bootstrap_fallback) { - bootstrap_failures = 0; + bootstrap_attempts = 0; // Fail case: if we have returned to the front of the bootstrap list, we're in a // bad spot; we are unable to do anything @@ -667,6 +667,7 @@ namespace llarp // By passing the last conditional, we ensure this is set to true _using_bootstrap_fallback = true; _needs_rebootstrap = false; + ++bootstrap_attempts; _router.link_manager().fetch_bootstrap_rcs( _bootstraps->current(), @@ -675,12 +676,12 @@ namespace llarp [this](oxen::quic::message m) mutable { if (not m) { - ++bootstrap_failures; + // ++bootstrap_attempts; log::warning( logcat, "BootstrapRC fetch request to {} failed (error {}/{})", fetch_source, - bootstrap_failures, + bootstrap_attempts, MAX_BOOTSTRAP_FETCH_ATTEMPTS); fallback_to_bootstrap(); return; @@ -704,12 +705,12 @@ namespace llarp } catch (const std::exception& e) { - ++bootstrap_failures; + // ++bootstrap_attempts; log::warning( logcat, "Failed to parse BootstrapRC fetch response from {} (error {}/{}): {}", fetch_source, - bootstrap_failures, + bootstrap_attempts, MAX_BOOTSTRAP_FETCH_ATTEMPTS, e.what()); fallback_to_bootstrap(); @@ -719,7 +720,7 @@ namespace llarp // We set this to the max allowable value because if this result is bad, we won't // try this bootstrap again. If this result is undersized, we roll right into the // next call to fallback_to_bootstrap() and hit the base case, rotating sources - bootstrap_failures = MAX_BOOTSTRAP_FETCH_ATTEMPTS; + // bootstrap_attempts = MAX_BOOTSTRAP_FETCH_ATTEMPTS; if (rids.size() == BOOTSTRAP_SOURCE_COUNT) { @@ -728,13 +729,13 @@ namespace llarp } else { - ++bootstrap_failures; + // ++bootstrap_attempts; log::warning( logcat, "BootstrapRC fetch response from {} returned insufficient number of RC's (error " "{}/{})", fetch_source, - bootstrap_failures, + bootstrap_attempts, MAX_BOOTSTRAP_FETCH_ATTEMPTS); fallback_to_bootstrap(); } diff --git a/llarp/nodedb.hpp b/llarp/nodedb.hpp index 91541ec76..f8e99372a 100644 --- a/llarp/nodedb.hpp +++ b/llarp/nodedb.hpp @@ -162,7 +162,7 @@ namespace llarp - bootstrap_failures: tracks errors fetching both RC's from bootstrasps and RID requests they mediate. This is a different counter as we only bootstrap in problematic cases */ - std::atomic fetch_failures{0}, bootstrap_failures{0}; + std::atomic fetch_failures{0}, bootstrap_attempts{0}; std::atomic _using_bootstrap_fallback{false}, _needs_rebootstrap{false}, _needs_initial_fetch{true}, _initial_completed{false}; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index d21c8edef..a700aaf9c 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -894,6 +894,8 @@ namespace llarp next_rc_gossip = now_timepoint + RouterContact::STALE_AGE - random_delta; } + + report_stats(); } if (needs_initial_fetch()) @@ -901,7 +903,7 @@ namespace llarp if (not _config->bootstrap.seednode) node_db()->fetch_initial(); } - else if (needs_rebootstrap() and next_bootstrap_attempt > now_timepoint) + else if (needs_rebootstrap() and now_timepoint > next_bootstrap_attempt) { node_db()->fallback_to_bootstrap(); }