From c951f0abb2790e4a3d59cbdc277fcfa24e0323f4 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sun, 7 Jul 2024 22:40:29 -0500 Subject: [PATCH] ratelimit: clarify delay second option --- README.md | 4 ++-- noteguard.toml | 2 +- src/filters/rate_limit.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1fc0401..b899651 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The `pipeline` config specifies the order in which filters are run. When the fir pipeline = ["ratelimit"] [filters.ratelimit] -notes_per_second = 1 +delay_seconds = 1 whitelist = ["127.0.0.1"] ``` @@ -34,7 +34,7 @@ The ratelimit filter limits the rate at which notes are written to the relay per Settings: -- `notes_per_second`: the delay in seconds between accepted notes. 1 means only one note can be written per second. 2 means only 1 note can be written every 2 seconds, etc. TODO: rename this because its confusing. +- `delay_seconds`: the delay in seconds between accepted notes. 1 means only one note can be written per second. 2 means only 1 note can be written every 2 seconds, etc. - `whitelist`: a list of IP4 or IP6 addresses that are allowed to bypass the ratelimit. diff --git a/noteguard.toml b/noteguard.toml index d9eccb2..df49009 100644 --- a/noteguard.toml +++ b/noteguard.toml @@ -2,5 +2,5 @@ pipeline = ["ratelimit"] [filters.ratelimit] -notes_per_second = 1 +delay_seconds = 1 whitelist = ["127.0.0.1"] diff --git a/src/filters/rate_limit.rs b/src/filters/rate_limit.rs index ea4f7bc..d4b398b 100644 --- a/src/filters/rate_limit.rs +++ b/src/filters/rate_limit.rs @@ -9,7 +9,7 @@ pub struct RateInfo { #[derive(Deserialize, Default)] pub struct RateLimit { - pub notes_per_second: u64, + pub delay_seconds: u64, pub whitelist: Option>, #[serde(skip)] @@ -27,7 +27,7 @@ impl NoteFilter for RateLimit { if self.sources.contains_key(&msg.source_info) { let now = Instant::now(); let entry = self.sources.get_mut(&msg.source_info).expect("impossiburu"); - if now - entry.last_note < Duration::from_secs(self.notes_per_second) { + if now - entry.last_note < Duration::from_secs(self.delay_seconds) { return OutputMessage::new( msg.event.id.clone(), Action::Reject,