use HashSet for keys index

This commit is contained in:
yggverse 2025-08-16 18:59:08 +03:00
parent 42f80177ea
commit 4d1455d34e

View file

@ -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<String> = Vec::with_capacity(config.index_capacity);
let mut key: HashSet<String> = 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<String>,
key: &mut HashSet<String>,
tcp: &mut Option<HashMap<SocketAddr, bool>>,
udp: &mut Option<(HashMap<SocketAddr, bool>, 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(())
}