diff --git a/src/globals.rs b/src/globals.rs index 8cdb69d..9927167 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -52,16 +52,13 @@ lazy_static! { impl Globals { pub fn ban(ipaddr: std::net::IpAddr, bankind: Ban) -> u64 { - let mut ban_seconds: u64 = 0; - GLOBALS - .ip_data - .entry(ipaddr) - .and_modify(|ipdata| ban_seconds = ipdata.ban(bankind)) - .or_insert({ - let (ipdata, seconds) = IpData::new(bankind); - ban_seconds = seconds; - ipdata - }); - ban_seconds + if let Some(mut ipdata) = GLOBALS.ip_data.get_mut(&ipaddr) { + ipdata.ban(bankind) + } else { + let mut ipdata = IpData::new(); + let seconds = ipdata.ban(bankind); + GLOBALS.ip_data.insert(ipaddr, ipdata); + seconds + } } } diff --git a/src/ip.rs b/src/ip.rs index cb5cf39..eacbb05 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -17,17 +17,13 @@ pub struct IpData { } impl IpData { - pub fn new(ban: Ban) -> (IpData, u64) { - let mut ipdata = IpData { + pub fn new() -> IpData { + IpData { ban_until: Time::now(), number_of_error_exits: 0, number_of_too_many_error_bans: 0, number_of_timeouts: 0, - }; - - let seconds = ipdata.ban(ban); - - (ipdata, seconds) + } } pub fn ban(&mut self, ban: Ban) -> u64 {