1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

dont bomb with bootstrap reqs

This commit is contained in:
dr7ana 2023-12-11 10:17:46 -08:00
parent e0c1069790
commit f725c07f2d
4 changed files with 18 additions and 14 deletions

View file

@ -391,8 +391,10 @@ namespace llarp
logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code); logcat, "BTRequestStream closed unexpectedly (ec:{}); closing connection...", error_code);
s.conn.close_connection(error_code); s.conn.close_connection(error_code);
}); });
itr->second = std::make_shared<link::Connection>(ci.shared_from_this(), control_stream, rc); itr->second = std::make_shared<link::Connection>(ci.shared_from_this(), control_stream, rc);
log::critical(logcat, "Successfully configured inbound connection fom {}; storing RC...", rid); 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? // 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<void(oxen::quic::message m)> func) const RemoteRC& source, std::string payload, std::function<void(oxen::quic::message m)> func)
{ {
_router.loop()->call([this, source, payload, f = std::move(func)]() { _router.loop()->call([this, source, payload, f = std::move(func)]() {
if (auto conn = ep.get_conn(source); conn) if (auto conn = ep.get_conn(source); conn)
{ {
log::critical(logcat, "Dispatched bootstrap fetch request!"); log::critical(logcat, "Dispatched bootstrap fetch request!");
conn->control_stream->command("bfetch_rcs"s, std::move(payload), std::move(f)); conn->control_stream->command("bfetch_rcs"s, std::move(payload), std::move(f));
return; return;
} }
log::critical(logcat, "Queuing bootstrap fetch request"); log::critical(logcat, "Queuing bootstrap fetch request");
auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, f); auto pending = PendingControlMessage(std::move(payload), "bfetch_rcs"s, f);

View file

@ -512,7 +512,7 @@ namespace llarp
{ {
if (error) if (error)
{ {
auto& fail_count = (_using_bootstrap_fallback) ? bootstrap_failures : fetch_failures; auto& fail_count = (_using_bootstrap_fallback) ? bootstrap_attempts : fetch_failures;
auto& THRESHOLD = auto& THRESHOLD =
(_using_bootstrap_fallback) ? MAX_BOOTSTRAP_FETCH_ATTEMPTS : MAX_FETCH_ATTEMPTS; (_using_bootstrap_fallback) ? MAX_BOOTSTRAP_FETCH_ATTEMPTS : MAX_FETCH_ATTEMPTS;
@ -638,7 +638,7 @@ namespace llarp
void void
NodeDB::fallback_to_bootstrap() 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 // 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 // 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) // checking not using_bootstrap_fallback)
if (at_max_failures || 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 // 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 // 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 // By passing the last conditional, we ensure this is set to true
_using_bootstrap_fallback = true; _using_bootstrap_fallback = true;
_needs_rebootstrap = false; _needs_rebootstrap = false;
++bootstrap_attempts;
_router.link_manager().fetch_bootstrap_rcs( _router.link_manager().fetch_bootstrap_rcs(
_bootstraps->current(), _bootstraps->current(),
@ -675,12 +676,12 @@ namespace llarp
[this](oxen::quic::message m) mutable { [this](oxen::quic::message m) mutable {
if (not m) if (not m)
{ {
++bootstrap_failures; // ++bootstrap_attempts;
log::warning( log::warning(
logcat, logcat,
"BootstrapRC fetch request to {} failed (error {}/{})", "BootstrapRC fetch request to {} failed (error {}/{})",
fetch_source, fetch_source,
bootstrap_failures, bootstrap_attempts,
MAX_BOOTSTRAP_FETCH_ATTEMPTS); MAX_BOOTSTRAP_FETCH_ATTEMPTS);
fallback_to_bootstrap(); fallback_to_bootstrap();
return; return;
@ -704,12 +705,12 @@ namespace llarp
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
++bootstrap_failures; // ++bootstrap_attempts;
log::warning( log::warning(
logcat, logcat,
"Failed to parse BootstrapRC fetch response from {} (error {}/{}): {}", "Failed to parse BootstrapRC fetch response from {} (error {}/{}): {}",
fetch_source, fetch_source,
bootstrap_failures, bootstrap_attempts,
MAX_BOOTSTRAP_FETCH_ATTEMPTS, MAX_BOOTSTRAP_FETCH_ATTEMPTS,
e.what()); e.what());
fallback_to_bootstrap(); 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 // 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 // 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 // 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) if (rids.size() == BOOTSTRAP_SOURCE_COUNT)
{ {
@ -728,13 +729,13 @@ namespace llarp
} }
else else
{ {
++bootstrap_failures; // ++bootstrap_attempts;
log::warning( log::warning(
logcat, logcat,
"BootstrapRC fetch response from {} returned insufficient number of RC's (error " "BootstrapRC fetch response from {} returned insufficient number of RC's (error "
"{}/{})", "{}/{})",
fetch_source, fetch_source,
bootstrap_failures, bootstrap_attempts,
MAX_BOOTSTRAP_FETCH_ATTEMPTS); MAX_BOOTSTRAP_FETCH_ATTEMPTS);
fallback_to_bootstrap(); fallback_to_bootstrap();
} }

View file

@ -162,7 +162,7 @@ namespace llarp
- bootstrap_failures: tracks errors fetching both RC's from bootstrasps and RID requests - 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 they mediate. This is a different counter as we only bootstrap in problematic cases
*/ */
std::atomic<int> fetch_failures{0}, bootstrap_failures{0}; std::atomic<int> fetch_failures{0}, bootstrap_attempts{0};
std::atomic<bool> _using_bootstrap_fallback{false}, _needs_rebootstrap{false}, std::atomic<bool> _using_bootstrap_fallback{false}, _needs_rebootstrap{false},
_needs_initial_fetch{true}, _initial_completed{false}; _needs_initial_fetch{true}, _initial_completed{false};

View file

@ -894,6 +894,8 @@ namespace llarp
next_rc_gossip = now_timepoint + RouterContact::STALE_AGE - random_delta; next_rc_gossip = now_timepoint + RouterContact::STALE_AGE - random_delta;
} }
report_stats();
} }
if (needs_initial_fetch()) if (needs_initial_fetch())
@ -901,7 +903,7 @@ namespace llarp
if (not _config->bootstrap.seednode) if (not _config->bootstrap.seednode)
node_db()->fetch_initial(); 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(); node_db()->fallback_to_bootstrap();
} }