|
|
@ -18,19 +18,11 @@ pub(crate) enum RateLimitType {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Rate limiting based on rate type and IP addr
|
|
|
|
/// Rate limiting based on rate type and IP addr
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct RateLimiter {
|
|
|
|
pub struct RateLimiter {
|
|
|
|
buckets: HashMap<RateLimitType, HashMap<IpAddr, RateLimitBucket>>,
|
|
|
|
buckets: HashMap<RateLimitType, HashMap<IpAddr, RateLimitBucket>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for RateLimiter {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
buckets: HashMap::<RateLimitType, HashMap<IpAddr, RateLimitBucket>>::new(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl RateLimiter {
|
|
|
|
impl RateLimiter {
|
|
|
|
fn insert_ip(&mut self, ip: &IpAddr) {
|
|
|
|
fn insert_ip(&mut self, ip: &IpAddr) {
|
|
|
|
for rate_limit_type in RateLimitType::iter() {
|
|
|
|
for rate_limit_type in RateLimitType::iter() {
|
|
|
|