Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
fix(network): give up peer because of handshake timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroqn committed Aug 13, 2020
1 parent 17edc8f commit 339cda1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/network/src/connection/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use futures::channel::mpsc::UnboundedSender;
use log::{debug, error};
use tentacle::{
context::ServiceContext,
error::{DialerErrorKind, ListenErrorKind},
error::{DialerErrorKind, HandshakeErrorKind, ListenErrorKind},
multiaddr::Multiaddr,
service::{ServiceError, ServiceEvent},
traits::ServiceHandle,
Expand Down Expand Up @@ -97,6 +97,9 @@ impl ConnectionServiceKeeper {
let repeated_connection = PeerManagerEvent::RepeatedConnection { ty, sid, addr };
return self.report_peer(repeated_connection);
}
HandshakeError(HandshakeErrorKind::Timeout(reason)) => {
ConnectionErrorKind::TimeOut(reason)
}
HandshakeError(err) => ConnectionErrorKind::SecioHandshake(Box::new(err)),
TransportError(err) => ConnectionErrorKind::from(err),
};
Expand Down
3 changes: 3 additions & 0 deletions core/network/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum ConnectionErrorKind {
#[display(fmt = "handshake {}", _0)]
SecioHandshake(Box<dyn Error + Send>),

#[display(fmt = "timeout {}", _0)]
TimeOut(String),

#[display(fmt = "remote peer doesn't match one in multiaddr")]
PeerIdNotMatch,

Expand Down
5 changes: 5 additions & 0 deletions core/network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ impl PeerManager {
fn connect_failed(&mut self, addr: Multiaddr, error_kind: ConnectionErrorKind) {
use ConnectionErrorKind::{
DNSResolver, Io, MultiaddrNotSuppored, PeerIdNotMatch, ProtocolHandle, SecioHandshake,
TimeOut,
};

let peer_addr: PeerMultiaddr = match addr.clone().try_into() {
Expand Down Expand Up @@ -925,6 +926,10 @@ impl PeerManager {
warn!("give up multiaddr {} because peer id not match", peer_addr);
peer.multiaddrs.give_up(&peer_addr);
}
TimeOut(reason) => {
info!("connect timeout {}", reason);
peer.multiaddrs.inc_failure(&peer_addr);
}
SecioHandshake(_) | ProtocolHandle => {
warn!("give up peer {:?} becasue {}", peer.id, error_kind);
peer.set_connectedness(Connectedness::Unconnectable);
Expand Down

0 comments on commit 339cda1

Please sign in to comment.