feat: misc updates in config and ip modules
This commit is contained in:
parent
6e0dc256b0
commit
3f298af976
@ -17,7 +17,7 @@ use std::path::Path;
|
|||||||
pub const GIT_VERSION: &str = git_version!(args = ["--always", "--dirty="]);
|
pub const GIT_VERSION: &str = git_version!(args = ["--always", "--dirty="]);
|
||||||
const MASTERSERVER: &str = "ipbl.paulbsd.com";
|
const MASTERSERVER: &str = "ipbl.paulbsd.com";
|
||||||
const WSSUBSCRIPTION: &str = "ipbl";
|
const WSSUBSCRIPTION: &str = "ipbl";
|
||||||
const CONFIG_RETRY: u64 = 1;
|
const CONFIG_RETRY: u64 = 2;
|
||||||
const WEB_CLIENT_TIMEOUT: i64 = 5;
|
const WEB_CLIENT_TIMEOUT: i64 = 5;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -126,7 +126,7 @@ impl Context {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("error loading config: {err}, retrying in {CONFIG_RETRY} secs");
|
println!("error loading config: {err}, retrying in {CONFIG_RETRY}s");
|
||||||
last_in_err = true;
|
last_in_err = true;
|
||||||
sleep_s(CONFIG_RETRY).await;
|
sleep_s(CONFIG_RETRY).await;
|
||||||
}
|
}
|
||||||
@ -641,6 +641,19 @@ mod test {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
ctx.update_blocklist(&mut IpEvent {
|
||||||
|
msgtype: String::from("add"),
|
||||||
|
mode: String::from("ws"),
|
||||||
|
hostname: String::from("localhost"),
|
||||||
|
ipdata: IpData {
|
||||||
|
t: 6,
|
||||||
|
ip: "2a00:1450:4007:805::2003".to_string(),
|
||||||
|
hostname: "testgood".to_string(),
|
||||||
|
date: now.to_rfc3339().to_string(),
|
||||||
|
src: "http".to_string(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
let ip1 = ctx.blocklist.get_mut(&"1.1.1.1".to_string()).unwrap();
|
let ip1 = ctx.blocklist.get_mut(&"1.1.1.1".to_string()).unwrap();
|
||||||
ip1.starttime = DateTime::from(now) - Duration::minutes(61);
|
ip1.starttime = DateTime::from(now) - Duration::minutes(61);
|
||||||
@ -655,8 +668,14 @@ mod test {
|
|||||||
let ctx = prepare_test_data().await;
|
let ctx = prepare_test_data().await;
|
||||||
|
|
||||||
let pending = ctx.get_blocklist_pending().await;
|
let pending = ctx.get_blocklist_pending().await;
|
||||||
assert_eq!(pending.len(), 4);
|
assert_eq!(pending.len(), 5);
|
||||||
let ips = ["1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"];
|
let ips = [
|
||||||
|
"1.1.1.1",
|
||||||
|
"1.1.1.2",
|
||||||
|
"1.1.1.3",
|
||||||
|
"1.1.1.4",
|
||||||
|
"2a00:1450:4007:805::2003",
|
||||||
|
];
|
||||||
for i in ips {
|
for i in ips {
|
||||||
let ip = ctx
|
let ip = ctx
|
||||||
.blocklist
|
.blocklist
|
||||||
@ -674,7 +693,7 @@ mod test {
|
|||||||
let mut ctx = prepare_test_data().await;
|
let mut ctx = prepare_test_data().await;
|
||||||
ctx.gc_blocklist().await;
|
ctx.gc_blocklist().await;
|
||||||
let toblock = ctx.get_blocklist_toblock().await;
|
let toblock = ctx.get_blocklist_toblock().await;
|
||||||
assert_eq!(toblock.len(), 2);
|
assert_eq!(toblock.len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
10
src/ip.rs
10
src/ip.rs
@ -162,12 +162,14 @@ pub fn filter(
|
|||||||
fn parse_date(input: regex::Captures) -> DateTime<Local> {
|
fn parse_date(input: regex::Captures) -> DateTime<Local> {
|
||||||
let mut ymd: Vec<u32> = vec![];
|
let mut ymd: Vec<u32> = vec![];
|
||||||
let mut hms: Vec<u32> = vec![];
|
let mut hms: Vec<u32> = vec![];
|
||||||
|
let ymd_range = 2..5;
|
||||||
|
let hms_range = 5..8;
|
||||||
|
|
||||||
for capture in 2..5 {
|
for cap in ymd_range {
|
||||||
ymd.push(input.get(capture).unwrap().as_str().parse::<u32>().unwrap());
|
ymd.push(input.get(cap).unwrap().as_str().parse::<u32>().unwrap());
|
||||||
}
|
}
|
||||||
for capture in 5..8 {
|
for cap in hms_range {
|
||||||
hms.push(input.get(capture).unwrap().as_str().parse::<u32>().unwrap());
|
hms.push(input.get(cap).unwrap().as_str().parse::<u32>().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
let date: DateTime<Local> =
|
let date: DateTime<Local> =
|
||||||
|
Loading…
Reference in New Issue
Block a user