From 52fcda96e141094ceef5c9dbc92d46879328b41f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 1 Jul 2020 18:54:46 -0400 Subject: [PATCH] Adding IP to the rate limit request line. (#882) * Adding IP to the rate limit request line. * Adding IP to the rate limit request line. --- server/src/rate_limit/rate_limiter.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/rate_limit/rate_limiter.rs b/server/src/rate_limit/rate_limiter.rs index 3e2ea787..20a617c2 100644 --- a/server/src/rate_limit/rate_limiter.rs +++ b/server/src/rate_limit/rate_limiter.rs @@ -10,7 +10,7 @@ pub struct RateLimitBucket { allowance: f64, } -#[derive(Eq, PartialEq, Hash, Debug, EnumIter, Copy, Clone)] +#[derive(Eq, PartialEq, Hash, Debug, EnumIter, Copy, Clone, AsRefStr)] pub enum RateLimitType { Message, Register, @@ -80,12 +80,21 @@ impl RateLimiter { if rate_limit.allowance < 1.0 { debug!( - "Rate limited IP: {}, time_passed: {}, allowance: {}", - ip, time_passed, rate_limit.allowance + "Rate limited type: {}, IP: {}, time_passed: {}, allowance: {}", + type_.as_ref(), + ip, + time_passed, + rate_limit.allowance ); Err( APIError { - message: format!("Too many requests. {} per {} seconds", rate, per), + message: format!( + "Too many requests. type: {}, IP: {}, {} per {} seconds", + type_.as_ref(), + ip, + rate, + per + ), } .into(), ) -- 2.44.1