diff --git a/src/config.rs b/src/config.rs index e46d82e..ff6c9e7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -158,12 +158,16 @@ impl Context { let mut res: Vec = vec![]; let now: DateTime = Local::now().trunc_subsecs(0); for (_, block) in self.blocklist.iter_mut() { - let set = self.cfg.sets.get(&block.ipdata.src.to_string()).unwrap(); - if block.tryfail >= set.tryfail { - res.push(block.ipdata.clone()); - if block.tryfail == set.tryfail { - block.starttime = DateTime::from(now); + match self.cfg.sets.get(&block.ipdata.src) { + Some(set) => { + if block.tryfail >= set.tryfail { + res.push(block.ipdata.clone()); + if block.tryfail == set.tryfail { + block.starttime = DateTime::from(now); + } + } } + None => {} } } res diff --git a/src/ipblc.rs b/src/ipblc.rs index 016c80b..34cce08 100644 --- a/src/ipblc.rs +++ b/src/ipblc.rs @@ -49,8 +49,8 @@ pub async fn run() { compare_files_changes(&ctxclone, &mut blrx, &ipeventtx).await; }); - let ipevent_init = IpEvent { - msgtype: String::from("init"), + let ipevent_bootstrap = IpEvent { + msgtype: String::from("bootstrap"), ipdata: IpData { ip: "".to_string(), src: "".to_string(), @@ -59,7 +59,7 @@ pub async fn run() { mode: "".to_string(), }, }; - send_to_ipbl_zmq(&zmqreqsocket, &ipevent_init).await; + send_to_ipbl_zmq(&zmqreqsocket, &ipevent_bootstrap).await; loop { let mut ret: Vec = Vec::new(); @@ -77,7 +77,7 @@ pub async fn run() { let mut ctx = ctxclone.write().await; - if received_ip.ipdata.ip == "".to_string() && received_ip.msgtype == "init".to_string() { + if received_ip.msgtype == "bootstrap".to_string() { for ip_to_send in ctx.get_blocklist_toblock().await { let event = IpEvent{ msgtype: String::from("init"), @@ -85,7 +85,6 @@ pub async fn run() { }; send_to_ipbl_zmq(&zmqreqsocket, &event).await; } - continue; } // refresh context blocklist @@ -242,7 +241,7 @@ async fn compare_files_changes( } for ip in iplist { let ipevent = IpEvent { - msgtype: String::from("file"), + msgtype: String::from("add"), ipdata: ip, }; ipeventtx.send(ipevent).await.unwrap();