optimized initialization
This commit is contained in:
parent
b66c2ee677
commit
da6ef34b0e
@ -181,15 +181,14 @@ impl Context {
|
|||||||
DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap();
|
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) => {
|
||||||
self.blocklist.insert(
|
self.blocklist
|
||||||
ipdata.ip.to_string(),
|
.entry(ipdata.ip.to_string())
|
||||||
BlockIpData {
|
.or_insert(BlockIpData {
|
||||||
ipdata: ipdata.clone(),
|
ipdata: ipdata.clone(),
|
||||||
tryfail,
|
tryfail,
|
||||||
starttime,
|
starttime,
|
||||||
blocktime: set.blocktime,
|
blocktime: set.blocktime,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ pub fn block(
|
|||||||
tablename: &String,
|
tablename: &String,
|
||||||
ips_add: &Vec<IpData>,
|
ips_add: &Vec<IpData>,
|
||||||
ret: &mut Vec<String>,
|
ret: &mut Vec<String>,
|
||||||
|
fwlen: &mut usize,
|
||||||
) -> std::result::Result<(), Error> {
|
) -> std::result::Result<(), Error> {
|
||||||
// convert chain
|
// convert chain
|
||||||
let ips_add = convert(ips_add);
|
let ips_add = convert(ips_add);
|
||||||
@ -59,7 +60,10 @@ pub fn block(
|
|||||||
// validate and send batch
|
// validate and send batch
|
||||||
let finalized_batch = batch.finalize();
|
let finalized_batch = batch.finalize();
|
||||||
send_and_process(&finalized_batch)?;
|
send_and_process(&finalized_batch)?;
|
||||||
ret.push(format!("{length} ip in memory", length = ips_add.len()));
|
if fwlen < &mut ips_add.len() {
|
||||||
|
ret.push(format!("{length} ip in firewall", length = ips_add.len()));
|
||||||
|
}
|
||||||
|
*fwlen = ips_add.len();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,8 @@ pub async fn process(ctx: &Arc<Mutex<Context>>) {
|
|||||||
let (ipdatatx, mut ipdatarx): (Sender<IpData>, Receiver<IpData>) = channel(ZMQ_CHAN_SIZE);
|
let (ipdatatx, mut ipdatarx): (Sender<IpData>, Receiver<IpData>) = channel(ZMQ_CHAN_SIZE);
|
||||||
|
|
||||||
// initialize the firewall table
|
// initialize the firewall table
|
||||||
//firewall::init(&env!("CARGO_PKG_NAME").to_string());
|
firewall::init(&env!("CARGO_PKG_NAME").to_string());
|
||||||
|
let mut fwlen: usize = 0;
|
||||||
|
|
||||||
// initialize zeromq sockets
|
// initialize zeromq sockets
|
||||||
let reqsocket;
|
let reqsocket;
|
||||||
@ -88,11 +89,14 @@ pub async fn process(ctx: &Arc<Mutex<Context>>) {
|
|||||||
&env!("CARGO_PKG_NAME").to_string(),
|
&env!("CARGO_PKG_NAME").to_string(),
|
||||||
&ctx.get_blocklist_toblock().await,
|
&ctx.get_blocklist_toblock().await,
|
||||||
&mut ret,
|
&mut ret,
|
||||||
|
&mut fwlen,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// log lines
|
// log lines
|
||||||
println!("{ret}", ret = ret.join(", "));
|
if ret.len() > 0 {
|
||||||
|
println!("{ret}", ret = ret.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
let end: DateTime<Local> = Local::now().trunc_subsecs(0);
|
let end: DateTime<Local> = Local::now().trunc_subsecs(0);
|
||||||
if (end - begin) > Duration::seconds(5) {
|
if (end - begin) > Duration::seconds(5) {
|
||||||
|
Loading…
Reference in New Issue
Block a user