From 2ae721f131e2136371a6be778dd95365f355c71b Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Wed, 16 Dec 2020 10:17:27 -0500 Subject: [PATCH] Fix ratelimit build, tweak ratelimit example --- examples/ratelimiting.rs | 4 ++-- src/lib.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/ratelimiting.rs b/examples/ratelimiting.rs index 20eb5a2..6ccbaec 100644 --- a/examples/ratelimiting.rs +++ b/examples/ratelimiting.rs @@ -12,7 +12,7 @@ async fn main() -> Result<()> { Server::new() .add_route("/", handle_request) - .ratelimit("/limit", 2, Duration::from_secs(60)) + .ratelimit("/limit", 2, Duration::from_secs(10)) .serve_ip("localhost:1965") .await } @@ -22,7 +22,7 @@ async fn handle_request(request: Request) -> Result { if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) { document.add_text("You're on a rate limited page!") - .add_text("You can only access this page twice per minute"); + .add_text("You can only access this page twice every 10 seconds"); } else { document.add_text("You're on a normal page!") .add_text("You can access this page as much as you like."); diff --git a/src/lib.rs b/src/lib.rs index d0ea57d..22e5c71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1056,12 +1056,11 @@ async fn send_response_body(mut body: Option, stream: &mut (impl AsyncWrit #[cfg(feature="ratelimiting")] /// Every 5 minutes, remove excess keys from all ratelimiters -async fn prune_ratelimit_log(rate_limits: Arc>>) -> Never { +async fn prune_ratelimit_log(rate_limits: &'static RoutingNode>) -> Never { let mut interval = interval(tokio::time::Duration::from_secs(10)); - let log = rate_limits.as_ref(); loop { interval.tick().await; - log.iter().for_each(RateLimiter::trim_keys_verbose); + rate_limits.iter().for_each(RateLimiter::trim_keys_verbose); } }