From 7aedc371cf25e18acdb9eb14fa75a5a83e7de1a9 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Thu, 20 Apr 2023 20:11:12 +0200 Subject: [PATCH] Have AuthRegister and AbsoluteRegister cancel each other out --- src/limit.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/limit.rs b/src/limit.rs index 5b007b9..b12069f 100644 --- a/src/limit.rs +++ b/src/limit.rs @@ -100,7 +100,7 @@ impl LimitedRequester { } fn can_send_request(&mut self, limit_type: LimitType) -> bool { - let limits = &self.limits_rate; + let limits = &self.limits_rate.clone(); // Check if all of the limits in this vec have at least one remaining request let constant_limits: Vec<&LimitType> = [ &LimitType::Error, @@ -115,6 +115,17 @@ impl LimitedRequester { if limit.remaining == 0 { return false; } + // AbsoluteRegister and AuthRegister can cancel each other out. + if limit.bucket == LimitType::AbsoluteRegister + && limits.get(&LimitType::AuthRegister).unwrap().remaining == 0 + { + return false; + } + if limit.bucket == LimitType::AuthRegister + && limits.get(&LimitType::AbsoluteRegister).unwrap().remaining == 0 + { + return false; + } } None => return false, }