for testing

This commit is contained in:
Paul 2022-09-18 00:00:25 +02:00
parent c2eff44009
commit 3e2fc8ddde

View File

@ -168,24 +168,29 @@ impl Context {
} }
pub async fn update_blocklist(&mut self, ipdata: &IpData) -> Option<IpData> { pub async fn update_blocklist(&mut self, ipdata: &IpData) -> Option<IpData> {
if self.blocklist.contains_key(&ipdata.ip) { if self.blocklist.contains_key(&ipdata.ip)
&& self.hostname == ipdata.hostname
&& ipdata.src == "file"
{
let mut block = self.blocklist.get_mut(&ipdata.ip).unwrap(); let mut block = self.blocklist.get_mut(&ipdata.ip).unwrap();
block.tryfail += 1; block.tryfail += 1;
let set = self.cfg.sets.get(&ipdata.src.to_string()).unwrap(); match self.cfg.sets.get(&ipdata.src) {
Some(set) => {
if block.tryfail >= set.tryfail { if block.tryfail >= set.tryfail {
return Some(block.ipdata.clone()); return Some(block.ipdata.clone());
} }
return None; }
} else { None => {}
}
}
if !self.blocklist.contains_key(&ipdata.ip) {
let mut tryfail = 0; let mut tryfail = 0;
let mut send = false;
let starttime: DateTime<FixedOffset> =
DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap();
match self.cfg.sets.get(&ipdata.src) { match self.cfg.sets.get(&ipdata.src) {
Some(set) => { Some(set) => {
let starttime: DateTime<FixedOffset> =
DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap();
if ipdata.mode == "zmq".to_string() { if ipdata.mode == "zmq".to_string() {
tryfail = 100; tryfail = 100;
send = true;
} }
self.blocklist.insert( self.blocklist.insert(
ipdata.ip.to_string(), ipdata.ip.to_string(),
@ -199,11 +204,8 @@ impl Context {
} }
None => {} None => {}
} }
match send { };
true => return Some(ipdata.clone()), None
false => return None,
}
}
} }
pub async fn gc_blocklist(&mut self) -> Vec<IpData> { pub async fn gc_blocklist(&mut self) -> Vec<IpData> {