mirror of
https://github.com/YGGverse/yps.git
synced 2026-04-01 01:15:28 +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!()
|
todo!()
|
||||||
}
|
}
|
||||||
// start crawler
|
// start crawler
|
||||||
for peer in p.response.unwrap().peers {
|
match p.response {
|
||||||
crawl(peer.key, &config, &mut ygg, &mut key, &mut tcp, &mut udp)?;
|
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(())
|
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) {
|
||||||
if config.debug {
|
return Ok(());
|
||||||
println!("get peers for `{k}`...");
|
}
|
||||||
}
|
if config.debug {
|
||||||
let p = ygg.remote_peers(&k)?;
|
println!("get peers for `{k}`...");
|
||||||
if p.status == "success" {
|
}
|
||||||
key.push(k);
|
let p = ygg.remote_peers(&k)?;
|
||||||
for (host, peers) in p.response.unwrap() {
|
if p.status == "success" {
|
||||||
|
key.push(k);
|
||||||
|
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,14 +102,14 @@ fn crawl(
|
||||||
crawl(k, config, ygg, key, tcp, udp)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue