Skip to content

Commit

Permalink
Refactor the dial result into a From impl
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 authored and dconnolly committed Apr 13, 2021
1 parent e084d0f commit fb95de9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions zebra-network/src/peer_set/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use futures::{
future::{self, FutureExt},
sink::SinkExt,
stream::{FuturesUnordered, StreamExt},
TryFutureExt,
};
use tokio::{
net::{TcpListener, TcpStream},
Expand Down Expand Up @@ -445,8 +446,6 @@ where
+ 'static,
C::Future: Send + 'static,
{
use CrawlerAction::*;

// CORRECTNESS
//
// To avoid hangs, the dialer must only await:
Expand All @@ -461,14 +460,22 @@ where
// the handshake has timeouts, so it shouldn't hang
connector
.call(candidate.addr)
.map(move |res| match res {
.map_err(|e| (candidate, e))
.map(Into::into)
.await
}

impl From<Result<Change<SocketAddr, Client>, (MetaAddr, BoxError)>> for CrawlerAction {
fn from(dial_result: Result<Change<SocketAddr, Client>, (MetaAddr, BoxError)>) -> Self {
use CrawlerAction::*;
match dial_result {
Ok(peer_set_change) => HandshakeConnected { peer_set_change },
Err(e) => {
Err((candidate, e)) => {
debug!(?candidate.addr, ?e, "failed to connect to candidate");
HandshakeFailed {
failed_addr: candidate,
}
}
})
.await
}
}
}

0 comments on commit fb95de9

Please sign in to comment.