hunter: remove evil hosts from redis again

This commit is contained in:
Astro 2022-12-26 02:49:43 +01:00
parent ad8080d9cf
commit 21e670cd2c
3 changed files with 16 additions and 4 deletions

View File

@ -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<impl Stream<Item = String> + '_, RedisError> {
self.scan_prefix("h:")
.await

View File

@ -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 {

View File

@ -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<f64>, mean_interval: Option<Duration>) {