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 colored::*;
use config::Config; use config::Config;
use std::{ use std::{
collections::HashMap, collections::{HashMap, HashSet},
net::{IpAddr, SocketAddr, TcpStream}, net::{IpAddr, SocketAddr, TcpStream},
time::Duration, time::Duration,
}; };
@ -23,7 +23,7 @@ fn main() -> Result<()> {
panic!("at least one TCP or UDP protocol is required for scan!") panic!("at least one TCP or UDP protocol is required for scan!")
} }
let mut ygg = Yggdrasil::init(&config.socket)?; 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 { let mut tcp = if config.tcp {
Some(HashMap::with_capacity(config.index_capacity)) Some(HashMap::with_capacity(config.index_capacity))
} else { } else {
@ -70,7 +70,7 @@ fn crawl(
k: String, k: String,
config: &Config, config: &Config,
ygg: &mut Yggdrasil, ygg: &mut Yggdrasil,
key: &mut Vec<String>, key: &mut HashSet<String>,
tcp: &mut Option<HashMap<SocketAddr, bool>>, tcp: &mut Option<HashMap<SocketAddr, bool>>,
udp: &mut Option<(HashMap<SocketAddr, bool>, Udp)>, udp: &mut Option<(HashMap<SocketAddr, bool>, Udp)>,
) -> Result<()> { ) -> Result<()> {
@ -82,7 +82,7 @@ fn crawl(
} }
let p = ygg.remote_peers(&k)?; let p = ygg.remote_peers(&k)?;
if p.status == "success" { if p.status == "success" {
key.push(k); assert!(key.insert(k));
if let Some(response) = p.response { if let Some(response) = p.response {
for (host, peers) in response { for (host, peers) in response {
for port in &config.port { for port in &config.port {
@ -127,7 +127,7 @@ fn crawl(
WARNING.yellow(), WARNING.yellow(),
p.status p.status
); );
key.push(k) // ban assert!(key.insert(k)) // ban
} }
Ok(()) Ok(())
} }