Merge pull request #1801 from majestrate/introset-publish-spam-fix-2021-11-16

prevent introset publish spam
This commit is contained in:
majestrate 2021-12-27 10:04:48 -05:00 committed by GitHub
commit 9e4bd2cd44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -24,6 +24,9 @@ namespace llarp
constexpr auto intro_spread_slices = 4;
/// spacing frequency at which we try to build paths for introductions
constexpr std::chrono::milliseconds intro_path_spread = default_lifetime / intro_spread_slices;
/// how long away from expiration in millseconds do we consider an intro to become stale
constexpr std::chrono::milliseconds intro_stale_threshold =
default_lifetime - intro_path_spread;
/// Minimum paths to keep around for intros; mainly used at startup (the
/// spread, above, should be able to maintain more than this number of paths
/// normally once things are going).

View File

@ -104,8 +104,7 @@ namespace llarp
std::set<Introduction, CompareIntroTimestamp> intros;
if (const auto maybe =
GetCurrentIntroductionsWithFilter([now](const service::Introduction& intro) -> bool {
return not intro.ExpiresSoon(
now, path::default_lifetime - path::min_intro_lifetime);
return not intro.ExpiresSoon(now, path::intro_stale_threshold);
}))
{
intros.insert(maybe->begin(), maybe->end());
@ -734,13 +733,13 @@ namespace llarp
if (not m_PublishIntroSet)
return false;
auto next_pub = m_state->m_LastPublishAttempt
+ (m_state->m_IntroSet.HasStaleIntros(
now, path::default_lifetime - path::intro_path_spread)
const auto lastEventAt = std::max(m_state->m_LastPublishAttempt, m_state->m_LastPublish);
const auto next_pub = lastEventAt
+ (m_state->m_IntroSet.HasStaleIntros(now, path::intro_stale_threshold)
? IntrosetPublishRetryCooldown
: IntrosetPublishInterval);
return now >= next_pub and m_LastIntrosetRegenAttempt + 1s <= now;
return now >= next_pub;
}
void