version 1.0.1, fix bug in garbage collect of expired ip address
This commit is contained in:
parent
bda1611582
commit
dc7cad13fe
35
Cargo.lock
generated
35
Cargo.lock
generated
@ -13,9 +13,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7ed72e1635e121ca3e79420540282af22da58be50de153d36f81ddc6b83aa9e"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@ -91,9 +91,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.17"
|
||||
version = "3.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b"
|
||||
checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
@ -166,36 +166,36 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bfc52cbddcfd745bf1740338492bb0bd83d76c67b445f91c5fb29fae29ecaa1"
|
||||
checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115"
|
||||
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca0bae1fe9752cf7fd9b0064c674ae63f97b37bc714d745cbde0afb7ec4e6765"
|
||||
checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "842fc63b931f4056a24d59de13fb1272134ce261816e063e634ad0c15cdc5306"
|
||||
checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577"
|
||||
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
@ -310,13 +310,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.46"
|
||||
version = "0.1.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad2bfd338099682614d3ee3fe0cd72e0b6a41ca6a87f6a74a3bd593c91650501"
|
||||
checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"js-sys",
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
@ -344,7 +345,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ipblc"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ipblc"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2021"
|
||||
authors = ["PaulBSD <paul@paulbsd.com>"]
|
||||
description = "ipblc is a tool that search and send attacking ip addresses to ipbl"
|
||||
|
@ -161,8 +161,10 @@ impl Context {
|
||||
for (_, block) in self.blocklist.iter_mut() {
|
||||
let set = self.cfg.sets.get(&block.ipdata.src.to_string()).unwrap();
|
||||
if block.tryfail >= set.tryfail {
|
||||
block.starttime = now;
|
||||
res.push(block.ipdata.clone());
|
||||
if block.tryfail == set.tryfail {
|
||||
block.starttime = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
res
|
||||
@ -198,10 +200,10 @@ impl Context {
|
||||
let now: DateTime<Local> = Local::now().trunc_subsecs(0);
|
||||
// nightly, future use
|
||||
//let drained: HashMap<String,IpData> = ctx.blocklist.drain_filter(|k,v| v.parse_date() < mindate)
|
||||
for (id, blocked) in self.blocklist.clone().iter() {
|
||||
for (ip, blocked) in self.blocklist.clone().iter() {
|
||||
let mindate = now - Duration::minutes(blocked.blocktime);
|
||||
if blocked.starttime < mindate {
|
||||
self.blocklist.remove(&id.to_string()).unwrap();
|
||||
self.blocklist.remove(&ip.clone()).unwrap();
|
||||
removed.push(blocked.ipdata.clone());
|
||||
}
|
||||
}
|
||||
@ -320,8 +322,8 @@ impl Config {
|
||||
}
|
||||
|
||||
pub async fn load(&mut self, ctx: Context) -> Result<(), ReqError> {
|
||||
self.get_sets(&ctx).await?;
|
||||
self.get_trustnets(&ctx).await?;
|
||||
self.get_sets(&ctx).await?;
|
||||
self.get_zmq_config(&ctx).await?;
|
||||
Ok(())
|
||||
}
|
||||
@ -494,7 +496,7 @@ mod test {
|
||||
ip1.starttime = now - Duration::minutes(61);
|
||||
|
||||
let mut ip2 = ctx.blocklist.get_mut(&"1.1.1.2".to_string()).unwrap();
|
||||
ip2.starttime = now - Duration::minutes(61);
|
||||
ip2.starttime = now - Duration::minutes(62);
|
||||
ctx
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user