mirror of https://github.com/oxen-io/lokinet
dont bomb with bootstrap reqs
This commit is contained in:
parent
e0c1069790
commit
f725c07f2d
|
@ -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<link::Connection>(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<void(oxen::quic::message m)> 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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<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},
|
||||
_needs_initial_fetch{true}, _initial_completed{false};
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue