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
}
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) {
Some(set) => {
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();
block.tryfail += 1;
block.blocktime = set.blocktime;
if block.tryfail >= set.tryfail {
return Some(ipevent.ipdata.clone());
return Some(ipevent.clone());
}
} else {
let starttime = DateTime::parse_from_rfc3339(ipevent.ipdata.date.as_str())
.unwrap()
.with_timezone(&chrono::Local);
let blocktime = set.blocktime;
self.blocklist
.entry(ipevent.ipdata.ip.to_string())
.or_insert(BlockIpData {
ipdata: ipevent.ipdata.clone(),
tryfail: set.tryfail,
tryfail: 0,
starttime,
blocktime: set.blocktime,
blocktime,
});
}
}
@ -207,13 +207,13 @@ impl Context {
// nightly, future use
// let drained: HashMap<String,IpData> = ctx.blocklist.drain_filter(|k,v| v.parse_date() < mindate)
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) => {
let mut block = self.blocklist.get_mut(ip).unwrap();
block.blocktime = set.blocktime.clone();
}
None => {}
}
}*/
let mindate = now - Duration::minutes(blocked.blocktime);
if blocked.starttime < mindate {
self.blocklist.remove(&ip.clone()).unwrap();

View File

@ -96,18 +96,18 @@ pub async fn run() {
}
// 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
if let Some(ip) = filtered_ip {
println!("{}",ip);
if let Some(ipevent) = filtered_ipevent {
println!("{}",ipevent.ipdata);
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{
msgtype: String::from("add"),
mode: String::from("zmq"),
hostname: fqdn.clone(),
ipdata: ip,
ipdata: ipevent.ipdata,
};
send_to_ipbl_ws(&ctx, &event, &mut ret).await;
send_to_ipbl_zmq(&zmqreqsocket, &event, &mut ret).await;