mirror of
https://github.com/YGGverse/yps.git
synced 2026-03-31 17:05:30 +00:00
collect crawl status for entries found, print totals
This commit is contained in:
parent
0aa60d6580
commit
42f80177ea
1 changed files with 33 additions and 15 deletions
42
src/main.rs
42
src/main.rs
|
|
@ -6,6 +6,7 @@ use anyhow::Result;
|
|||
use colored::*;
|
||||
use config::Config;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
net::{IpAddr, SocketAddr, TcpStream},
|
||||
time::Duration,
|
||||
};
|
||||
|
|
@ -24,13 +25,13 @@ fn main() -> Result<()> {
|
|||
let mut ygg = Yggdrasil::init(&config.socket)?;
|
||||
let mut key: Vec<String> = Vec::with_capacity(config.index_capacity);
|
||||
let mut tcp = if config.tcp {
|
||||
Some(Vec::with_capacity(config.index_capacity))
|
||||
Some(HashMap::with_capacity(config.index_capacity))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut udp = config.udp.as_ref().map(|bind| {
|
||||
let server = Udp::init(bind).unwrap();
|
||||
let index = Vec::with_capacity(config.index_capacity);
|
||||
let index = HashMap::with_capacity(config.index_capacity);
|
||||
(index, server)
|
||||
});
|
||||
println!("crawler started...");
|
||||
|
|
@ -48,6 +49,20 @@ fn main() -> Result<()> {
|
|||
}
|
||||
None => println!("node has no peers to connect."),
|
||||
}
|
||||
println!("operation completed!");
|
||||
if !key.is_empty() {
|
||||
println!("\tkeys crawled: {}", key.len());
|
||||
}
|
||||
if let Some(tcp) = tcp {
|
||||
println!("\tTCP: {}", tcp.len());
|
||||
println!("\t\tfound: {}", tcp.values().filter(|v| **v).count());
|
||||
println!("\t\ttotal: {}", tcp.len());
|
||||
}
|
||||
if let Some((udp, _)) = udp {
|
||||
println!("\tUDP: {}", udp.len());
|
||||
println!("\t\tfound: {}", udp.values().filter(|v| **v).count());
|
||||
println!("\t\ttotal: {}", udp.len());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +71,8 @@ fn crawl(
|
|||
config: &Config,
|
||||
ygg: &mut Yggdrasil,
|
||||
key: &mut Vec<String>,
|
||||
tcp: &mut Option<Vec<SocketAddr>>,
|
||||
udp: &mut Option<(Vec<SocketAddr>, Udp)>,
|
||||
tcp: &mut Option<HashMap<SocketAddr, bool>>,
|
||||
udp: &mut Option<(HashMap<SocketAddr, bool>, Udp)>,
|
||||
) -> Result<()> {
|
||||
if key.contains(&k) {
|
||||
return Ok(());
|
||||
|
|
@ -73,26 +88,29 @@ fn crawl(
|
|||
for port in &config.port {
|
||||
let address = SocketAddr::new(IpAddr::V6(host), *port);
|
||||
if let Some(index) = tcp
|
||||
&& !index.contains(&address)
|
||||
&& !index.contains_key(&address)
|
||||
{
|
||||
let url = format!("tcp://{address}");
|
||||
if TcpStream::connect_timeout(&address, Duration::from_secs(1)).is_ok() {
|
||||
let result =
|
||||
TcpStream::connect_timeout(&address, Duration::from_secs(1)).is_ok();
|
||||
if result {
|
||||
println!("\t{}: {url}", SUCCESS.green())
|
||||
} else if config.debug {
|
||||
println!("\t{}: {url}", FAILURE.red())
|
||||
}
|
||||
index.push(address)
|
||||
assert!(index.insert(address, result).is_none())
|
||||
}
|
||||
if let Some((index, server)) = udp {
|
||||
if let Some((index, server)) = udp
|
||||
&& !index.contains_key(&address)
|
||||
{
|
||||
let url = format!("udp://{address}");
|
||||
if !index.contains(&address) {
|
||||
if server.check(address) {
|
||||
let result = server.check(address);
|
||||
if result {
|
||||
println!("\t{}: {url}", SUCCESS.green())
|
||||
} else if config.debug {
|
||||
println!("\t{}: {url}", FAILURE.red())
|
||||
}
|
||||
index.push(address)
|
||||
}
|
||||
assert!(index.insert(address, result).is_none())
|
||||
}
|
||||
}
|
||||
for k in peers.keys {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue