From 130f37204191c94ff9dd7fd20d478322445da482 Mon Sep 17 00:00:00 2001 From: nullchinchilla Date: Mon, 2 Sep 2024 13:42:22 -0400 Subject: [PATCH] Adjust free/plus/total ratelimits and improve rate limiter logic with dynamic delay --- binaries/geph5-exit/src/main.rs | 6 +++--- binaries/geph5-exit/src/ratelimit.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/binaries/geph5-exit/src/main.rs b/binaries/geph5-exit/src/main.rs index 80a69c40..377535e4 100644 --- a/binaries/geph5-exit/src/main.rs +++ b/binaries/geph5-exit/src/main.rs @@ -49,15 +49,15 @@ struct ConfigFile { } fn default_free_ratelimit() -> u32 { - 500 + 300 } fn default_plus_ratelimit() -> u32 { - 100000 + 25000 } fn default_total_ratelimit() -> u32 { - 100000 + 125000 } #[derive(Deserialize)] diff --git a/binaries/geph5-exit/src/ratelimit.rs b/binaries/geph5-exit/src/ratelimit.rs index 3a68ba25..1b2cc094 100644 --- a/binaries/geph5-exit/src/ratelimit.rs +++ b/binaries/geph5-exit/src/ratelimit.rs @@ -126,16 +126,18 @@ impl RateLimiter { if bytes == 0 { return; } - // let multiplier = (1.0 / (1.0 - get_load().min(0.999)) - 1.0) / 2.0; + let multiplier = (1.0 / (1.0 - get_load().min(0.999)) - 1.0) / 2.0; - // let bytes = bytes as f32 * (multiplier.max(1.0)); + let bytes = bytes as f32 * (multiplier.max(1.0)); if let Some(inner) = &self.inner { + let mut delay: f32 = 0.05; while inner .check_n((bytes as u32).try_into().unwrap()) .unwrap() .is_err() { - smol::Timer::after(Duration::from_secs_f32(rand::random::() * 0.05)).await; + smol::Timer::after(Duration::from_secs_f32(delay)).await; + delay += rand::random::() * 0.05; } } }