From 4d1455d34ec06f45d65c4b7039c12818727e9c0e Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 16 Aug 2025 18:59:08 +0300 Subject: [PATCH] use HashSet for keys index --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83526bd..ad6a5ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use anyhow::Result; use colored::*; use config::Config; use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, net::{IpAddr, SocketAddr, TcpStream}, time::Duration, }; @@ -23,7 +23,7 @@ fn main() -> Result<()> { panic!("at least one TCP or UDP protocol is required for scan!") } let mut ygg = Yggdrasil::init(&config.socket)?; - let mut key: Vec = Vec::with_capacity(config.index_capacity); + let mut key: HashSet = HashSet::with_capacity(config.index_capacity); let mut tcp = if config.tcp { Some(HashMap::with_capacity(config.index_capacity)) } else { @@ -70,7 +70,7 @@ fn crawl( k: String, config: &Config, ygg: &mut Yggdrasil, - key: &mut Vec, + key: &mut HashSet, tcp: &mut Option>, udp: &mut Option<(HashMap, Udp)>, ) -> Result<()> { @@ -82,7 +82,7 @@ fn crawl( } let p = ygg.remote_peers(&k)?; if p.status == "success" { - key.push(k); + assert!(key.insert(k)); if let Some(response) = p.response { for (host, peers) in response { for port in &config.port { @@ -127,7 +127,7 @@ fn crawl( WARNING.yellow(), p.status ); - key.push(k) // ban + assert!(key.insert(k)) // ban } Ok(()) }