Skip to content

Commit

Permalink
Adjust free/plus/total ratelimits and improve rate limiter logic with…
Browse files Browse the repository at this point in the history
… dynamic delay
  • Loading branch information
nullchinchilla committed Sep 2, 2024
1 parent 3a85b15 commit 130f372
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions binaries/geph5-exit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions binaries/geph5-exit/src/ratelimit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f32>() * 0.05)).await;
smol::Timer::after(Duration::from_secs_f32(delay)).await;
delay += rand::random::<f32>() * 0.05;
}
}
}
Expand Down

0 comments on commit 130f372

Please sign in to comment.