Skip to content

Commit

Permalink
do not accept incoming conns if peer was banned
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Feb 23, 2023
1 parent 3859201 commit 7e59d05
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/network/src/protocol/notifications/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl Notifications {
}

/// Disconnects the given peer if we are connected to it.
///
///
/// Note the peer will be banned for 10s after this.
pub fn disconnect_peer(&mut self, peer_id: &PeerId, set_id: sc_peerset::SetId) {
trace!(target: "sub-libp2p", "External API => Disconnect({}, {:?})", peer_id, set_id);
Expand Down Expand Up @@ -1592,6 +1592,12 @@ impl NetworkBehaviour for Notifications {

// Disabled => Disabled | Incoming
PeerState::Disabled { mut connections, backoff_until } => {
// Do not accept incoming connections if the peer is still banned.
if backoff_until.map_or(false, |t| t > Instant::now()) {
*entry.into_mut() = PeerState::Disabled { connections, backoff_until };
return
}

if let Some((_, connec_state)) =
connections.iter_mut().find(|(c, _)| *c == connection_id)
{
Expand Down

0 comments on commit 7e59d05

Please sign in to comment.