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

prevent introset publish spam
pull/1837/head
majestrate 3 years ago committed by GitHub
commit 9e4bd2cd44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,6 +24,9 @@ namespace llarp
constexpr auto intro_spread_slices = 4; constexpr auto intro_spread_slices = 4;
/// spacing frequency at which we try to build paths for introductions /// spacing frequency at which we try to build paths for introductions
constexpr std::chrono::milliseconds intro_path_spread = default_lifetime / intro_spread_slices; 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 /// 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 /// spread, above, should be able to maintain more than this number of paths
/// normally once things are going). /// normally once things are going).

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

Loading…
Cancel
Save