fixed updates & gc
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2023-01-15 23:54:15 +01:00
parent af38ea1d84
commit bdedca78e7
2 changed files with 12 additions and 12 deletions

View File

@ -169,7 +169,7 @@ impl Context {
res res
} }
pub async fn update_blocklist(&mut self, ipevent: &IpEvent) -> Option<IpData> { pub async fn update_blocklist(&mut self, ipevent: &IpEvent) -> Option<IpEvent> {
match self.cfg.sets.get(&ipevent.ipdata.src) { match self.cfg.sets.get(&ipevent.ipdata.src) {
Some(set) => { Some(set) => {
if self.blocklist.contains_key(&ipevent.ipdata.ip) if self.blocklist.contains_key(&ipevent.ipdata.ip)
@ -178,21 +178,21 @@ impl Context {
{ {
let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap(); let mut block = self.blocklist.get_mut(&ipevent.ipdata.ip).unwrap();
block.tryfail += 1; block.tryfail += 1;
block.blocktime = set.blocktime;
if block.tryfail >= set.tryfail { if block.tryfail >= set.tryfail {
return Some(ipevent.ipdata.clone()); return Some(ipevent.clone());
} }
} else { } else {
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str()) let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
.unwrap() .unwrap()
.with_timezone(&chrono::Local); .with_timezone(&chrono::Local);
let blocktime = set.blocktime;
self.blocklist self.blocklist
.entry(ipevent.ipdata.ip.to_string()) .entry(ipevent.ipdata.ip.to_string())
.or_insert(BlockIpData { .or_insert(BlockIpData {
ipdata: ipevent.ipdata.clone(), ipdata: ipevent.ipdata.clone(),
tryfail: set.tryfail, tryfail: 0,
starttime, starttime,
blocktime: set.blocktime, blocktime,
}); });
} }
} }
@ -207,13 +207,13 @@ impl Context {
// nightly, future use // nightly, future use
// let drained: HashMap<String,IpData> = ctx.blocklist.drain_filter(|k,v| v.parse_date() < mindate) // let drained: HashMap<String,IpData> = ctx.blocklist.drain_filter(|k,v| v.parse_date() < mindate)
for (ip, blocked) in self.blocklist.clone().iter() { for (ip, blocked) in self.blocklist.clone().iter() {
match self.cfg.sets.get(&blocked.ipdata.src) { /*match self.cfg.sets.get(&blocked.ipdata.src) {
Some(set) => { Some(set) => {
let mut block = self.blocklist.get_mut(ip).unwrap(); let mut block = self.blocklist.get_mut(ip).unwrap();
block.blocktime = set.blocktime.clone(); block.blocktime = set.blocktime.clone();
} }
None => {} None => {}
} }*/
let mindate = now - Duration::minutes(blocked.blocktime); let mindate = now - Duration::minutes(blocked.blocktime);
if blocked.starttime < mindate { if blocked.starttime < mindate {
self.blocklist.remove(&ip.clone()).unwrap(); self.blocklist.remove(&ip.clone()).unwrap();

View File

@ -96,18 +96,18 @@ pub async fn run() {
} }
// refresh context blocklist // refresh context blocklist
let filtered_ip = ctx.update_blocklist(&received_ip).await; let filtered_ipevent = ctx.update_blocklist(&received_ip).await;
// send ip list to ws and zmq sockets // send ip list to ws and zmq sockets
if let Some(ip) = filtered_ip { if let Some(ipevent) = filtered_ipevent {
println!("{}",ip); println!("{}",ipevent.ipdata);
if received_ip.msgtype != "init" { if received_ip.msgtype != "init" {
println!("sending {} to ws and zmq", ip.ip); println!("sending {} to ws and zmq", ipevent.ipdata.ip);
let event = IpEvent{ let event = IpEvent{
msgtype: String::from("add"), msgtype: String::from("add"),
mode: String::from("zmq"), mode: String::from("zmq"),
hostname: fqdn.clone(), hostname: fqdn.clone(),
ipdata: ip, ipdata: ipevent.ipdata,
}; };
send_to_ipbl_ws(&ctx, &event, &mut ret).await; send_to_ipbl_ws(&ctx, &event, &mut ret).await;
send_to_ipbl_zmq(&zmqreqsocket, &event, &mut ret).await; send_to_ipbl_zmq(&zmqreqsocket, &event, &mut ret).await;