mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-31 07:31:01 +00:00
Workaround for apparent Entry problems in DashMap
This commit is contained in:
parent
3ef2c4ae71
commit
86c74f9e40
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
src/ip.rs
10
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user