Skip to content

Commit

Permalink
Fix network panic (#2990)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanlee42 authored Oct 27, 2021
1 parent 6227d9a commit 2fa5857
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions network-p2p/peerset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,6 @@ impl Peerset {
let before = peer_reputation.reputation();
let after = reput_tick(before);
trace!(target: "peerset", "Fleeting {}: {} -> {}", peer_id, before, after);
if after < BANNED_THRESHOLD {
self.message_queue.push_back(Message::Banned(peer_id))
}
peer_reputation.set_reputation(after);
drop(peer_reputation);
// If the peer has no connection to it,
Expand All @@ -533,6 +530,9 @@ impl Peerset {
peersstate::Peer::NotConnected(peer) => {
if peer.last_connected_or_discovered() + FORGET_AFTER < now {
peer.forget_peer();
if after < BANNED_THRESHOLD {
self.message_queue.push_back(Message::Banned(peer_id))
}
}
}
peersstate::Peer::Unknown(_) => {
Expand Down
6 changes: 2 additions & 4 deletions network-p2p/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ impl Protocol {
);
}
self.peerset_handle.report_peer(who, rep::GENESIS_MISMATCH);
self.behaviour.disconnect_peer(&who, set_id);
return CustomMessageOutcome::Banned(who);
return CustomMessageOutcome::None;
}
if status.version < MIN_VERSION || CURRENT_VERSION < status.min_supported_version {
log!(
Expand All @@ -501,8 +500,7 @@ impl Protocol {
"Peer {:?} using unsupported protocol version {}", who, status.version
);
self.peerset_handle.report_peer(who, rep::BAD_PROTOCOL);
self.behaviour.disconnect_peer(&who, set_id);
return CustomMessageOutcome::Banned(who);
return CustomMessageOutcome::None;
}
debug!(target: "network-p2p", "Connected {}", who);
let peer = Peer {
Expand Down
2 changes: 0 additions & 2 deletions network-p2p/src/protocol/generic_proto/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,8 +1235,6 @@ impl NetworkBehaviour for GenericProto {
let mut entry = if let Entry::Occupied(entry) = self.peers.entry((*peer_id, set_id)) {
entry
} else {
error!(target: "sub-libp2p", "inject_connection_closed: State mismatch in the custom protos handler");
debug_assert!(false);
return;
};
match mem::replace(entry.get_mut(), PeerState::Poisoned) {
Expand Down
4 changes: 3 additions & 1 deletion network-p2p/src/request_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour {
endpoint: &ConnectedPoint,
) {
for (p, _) in self.protocols.values_mut() {
NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint)
if p.is_connected(peer_id) {
NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint)
}
}
}

Expand Down

0 comments on commit 2fa5857

Please sign in to comment.