ratelimit: clarify delay second option

This commit is contained in:
William Casarin 2024-07-07 22:40:29 -05:00
parent 98671c5aa8
commit c951f0abb2
3 changed files with 5 additions and 5 deletions

View file

@ -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.

View file

@ -2,5 +2,5 @@
pipeline = ["ratelimit"]
[filters.ratelimit]
notes_per_second = 1
delay_seconds = 1
whitelist = ["127.0.0.1"]

View file

@ -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,