handle optional response results

This commit is contained in:
yggverse 2025-08-16 18:11:50 +03:00
parent a4f82e8bbc
commit eb6d4633cd

View file

@ -40,9 +40,14 @@ fn main() -> Result<()> {
todo!() todo!()
} }
// start crawler // start crawler
for peer in p.response.unwrap().peers { match p.response {
Some(response) => {
for peer in response.peers {
crawl(peer.key, &config, &mut ygg, &mut key, &mut tcp, &mut udp)?; crawl(peer.key, &config, &mut ygg, &mut key, &mut tcp, &mut udp)?;
} }
}
None => println!("node has no peers to connect."),
}
Ok(()) Ok(())
} }
@ -54,14 +59,17 @@ fn crawl(
tcp: &mut Option<Vec<SocketAddr>>, tcp: &mut Option<Vec<SocketAddr>>,
udp: &mut Option<(Vec<SocketAddr>, Udp)>, udp: &mut Option<(Vec<SocketAddr>, Udp)>,
) -> Result<()> { ) -> Result<()> {
if !key.contains(&k) { if key.contains(&k) {
return Ok(());
}
if config.debug { if config.debug {
println!("get peers for `{k}`..."); println!("get peers for `{k}`...");
} }
let p = ygg.remote_peers(&k)?; let p = ygg.remote_peers(&k)?;
if p.status == "success" { if p.status == "success" {
key.push(k); key.push(k);
for (host, peers) in p.response.unwrap() { if let Some(response) = p.response {
for (host, peers) in response {
for port in &config.port { for port in &config.port {
let address = SocketAddr::new(IpAddr::V6(host), *port); let address = SocketAddr::new(IpAddr::V6(host), *port);
if let Some(index) = tcp if let Some(index) = tcp
@ -94,6 +102,7 @@ fn crawl(
crawl(k, config, ygg, key, tcp, udp)?; crawl(k, config, ygg, key, tcp, udp)?;
} }
} }
}
} else if config.debug { } else if config.debug {
println!( println!(
"\t{}: peer `{k}` return status `{}`, skip.", "\t{}: peer `{k}` return status `{}`, skip.",
@ -102,7 +111,6 @@ fn crawl(
); );
key.push(k) // ban key.push(k) // ban
} }
}
Ok(()) Ok(())
} }