From 21e670cd2cecabcef5d7edc66d039dc4b638c3de Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 26 Dec 2022 02:49:43 +0100 Subject: [PATCH] hunter: remove evil hosts from redis again --- cave/src/store.rs | 6 ++++++ hunter/src/main.rs | 8 ++++++-- hunter/src/scheduler.rs | 6 ++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cave/src/store.rs b/cave/src/store.rs index a6cabcc..d4c7926 100644 --- a/cave/src/store.rs +++ b/cave/src/store.rs @@ -362,6 +362,12 @@ impl Store { .await } + pub async fn remove_host(&mut self, host: &str) -> Result<(), RedisError> { + redis::Cmd::del(format!("h:{}", host)) + .query_async::<_, ()>(self) + .await + } + pub async fn get_hosts(&mut self) -> Result + '_, RedisError> { self.scan_prefix("h:") .await diff --git a/hunter/src/main.rs b/hunter/src/main.rs index ea7d433..5a20044 100644 --- a/hunter/src/main.rs +++ b/hunter/src/main.rs @@ -45,11 +45,15 @@ async fn main() { cave::systemd::status("Loading known hosts from redis"); let mut n = 1; - let hosts = store.get_hosts() + let mut store_ = store.clone(); + let hosts = store_.get_hosts() .await.expect("get_hosts"); pin_mut!(hosts); while let Some(host) = hosts.next().await { - scheduler.introduce(host).await; + if scheduler.introduce(host.clone()).await == false { + log::debug!("Remove host {}", host); + store.remove_host(&host).await.expect("remove_host"); + } n += 1; if n > 1000 { diff --git a/hunter/src/scheduler.rs b/hunter/src/scheduler.rs index 37ff1b8..257c6a8 100644 --- a/hunter/src/scheduler.rs +++ b/hunter/src/scheduler.rs @@ -43,12 +43,12 @@ impl Scheduler { self.queue.len() } - pub async fn introduce(&mut self, host: String) { + pub async fn introduce(&mut self, host: String) -> bool { if EVIL_DOMAINS.iter().any(|domain| { let o = host.len().saturating_sub(domain.len()); &host[o..] == *domain } ) { - return; + return false; } let now = Instant::now(); @@ -61,6 +61,8 @@ impl Scheduler { }); self.queue.insert(now, host); } + + true } pub fn reenqueue(&mut self, host: Host, new_post_ratio: Option, mean_interval: Option) {