hunter: remove evil hosts from redis again
This commit is contained in:
parent
ad8080d9cf
commit
21e670cd2c
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user