Workaround for apparent Entry problems in DashMap

This commit is contained in:
Mike Dilger 2024-02-20 22:32:25 +13:00
parent 3ef2c4ae71
commit 86c74f9e40
2 changed files with 11 additions and 18 deletions

View File

@ -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
}
}
}

View File

@ -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 {