mirror of
https://github.com/YGGverse/yps.git
synced 2026-03-31 17:05:30 +00:00
handle optional response results
This commit is contained in:
parent
a4f82e8bbc
commit
eb6d4633cd
1 changed files with 25 additions and 17 deletions
42
src/main.rs
42
src/main.rs
|
|
@ -40,8 +40,13 @@ fn main() -> Result<()> {
|
|||
todo!()
|
||||
}
|
||||
// start crawler
|
||||
for peer in p.response.unwrap().peers {
|
||||
crawl(peer.key, &config, &mut ygg, &mut key, &mut tcp, &mut udp)?;
|
||||
match p.response {
|
||||
Some(response) => {
|
||||
for peer in response.peers {
|
||||
crawl(peer.key, &config, &mut ygg, &mut key, &mut tcp, &mut udp)?;
|
||||
}
|
||||
}
|
||||
None => println!("node has no peers to connect."),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -54,14 +59,17 @@ fn crawl(
|
|||
tcp: &mut Option<Vec<SocketAddr>>,
|
||||
udp: &mut Option<(Vec<SocketAddr>, Udp)>,
|
||||
) -> Result<()> {
|
||||
if !key.contains(&k) {
|
||||
if config.debug {
|
||||
println!("get peers for `{k}`...");
|
||||
}
|
||||
let p = ygg.remote_peers(&k)?;
|
||||
if p.status == "success" {
|
||||
key.push(k);
|
||||
for (host, peers) in p.response.unwrap() {
|
||||
if key.contains(&k) {
|
||||
return Ok(());
|
||||
}
|
||||
if config.debug {
|
||||
println!("get peers for `{k}`...");
|
||||
}
|
||||
let p = ygg.remote_peers(&k)?;
|
||||
if p.status == "success" {
|
||||
key.push(k);
|
||||
if let Some(response) = p.response {
|
||||
for (host, peers) in response {
|
||||
for port in &config.port {
|
||||
let address = SocketAddr::new(IpAddr::V6(host), *port);
|
||||
if let Some(index) = tcp
|
||||
|
|
@ -94,14 +102,14 @@ fn crawl(
|
|||
crawl(k, config, ygg, key, tcp, udp)?;
|
||||
}
|
||||
}
|
||||
} else if config.debug {
|
||||
println!(
|
||||
"\t{}: peer `{k}` return status `{}`, skip.",
|
||||
WARNING.yellow(),
|
||||
p.status
|
||||
);
|
||||
key.push(k) // ban
|
||||
}
|
||||
} else if config.debug {
|
||||
println!(
|
||||
"\t{}: peer `{k}` return status `{}`, skip.",
|
||||
WARNING.yellow(),
|
||||
p.status
|
||||
);
|
||||
key.push(k) // ban
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue