noteguard

the nostr relay spam guardian
git clone git://jb55.com/noteguard
Log | Files | Refs | README | LICENSE

commit c951f0abb2790e4a3d59cbdc277fcfa24e0323f4
parent 98671c5aa89142a3ea64717dcdceb47403dad0c8
Author: William Casarin <jb55@jb55.com>
Date:   Sun,  7 Jul 2024 22:40:29 -0500

ratelimit: clarify delay second option

Diffstat:
MREADME.md | 4++--
Mnoteguard.toml | 2+-
Msrc/filters/rate_limit.rs | 4++--
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git 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 @@ -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 @@ -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<Vec<String>>, #[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,