Refactor the dial result into a From impl
This commit is contained in:
parent
e084d0f1dc
commit
fb95de99a6
|
@ -13,6 +13,7 @@ use futures::{
|
||||||
future::{self, FutureExt},
|
future::{self, FutureExt},
|
||||||
sink::SinkExt,
|
sink::SinkExt,
|
||||||
stream::{FuturesUnordered, StreamExt},
|
stream::{FuturesUnordered, StreamExt},
|
||||||
|
TryFutureExt,
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
|
@ -445,8 +446,6 @@ where
|
||||||
+ 'static,
|
+ 'static,
|
||||||
C::Future: Send + 'static,
|
C::Future: Send + 'static,
|
||||||
{
|
{
|
||||||
use CrawlerAction::*;
|
|
||||||
|
|
||||||
// CORRECTNESS
|
// CORRECTNESS
|
||||||
//
|
//
|
||||||
// To avoid hangs, the dialer must only await:
|
// To avoid hangs, the dialer must only await:
|
||||||
|
@ -461,14 +460,22 @@ where
|
||||||
// the handshake has timeouts, so it shouldn't hang
|
// the handshake has timeouts, so it shouldn't hang
|
||||||
connector
|
connector
|
||||||
.call(candidate.addr)
|
.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 },
|
Ok(peer_set_change) => HandshakeConnected { peer_set_change },
|
||||||
Err(e) => {
|
Err((candidate, e)) => {
|
||||||
debug!(?candidate.addr, ?e, "failed to connect to candidate");
|
debug!(?candidate.addr, ?e, "failed to connect to candidate");
|
||||||
HandshakeFailed {
|
HandshakeFailed {
|
||||||
failed_addr: candidate,
|
failed_addr: candidate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.await
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue