Skip to content

Commit

Permalink
Revert "removed unused argument"
Browse files Browse the repository at this point in the history
This reverts commit c87f755.
  • Loading branch information
melekes committed Feb 16, 2023
1 parent a87e65f commit f1dc623
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions client/network/src/protocol/notifications/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,15 @@ impl Notifications {
/// Disconnects the given peer if we are connected to it.
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);
self.disconnect_peer_inner(peer_id, set_id);
self.disconnect_peer_inner(peer_id, set_id, None);
}

/// Inner implementation of `disconnect_peer`.
fn disconnect_peer_inner(
&mut self,
peer_id: &PeerId,
set_id: sc_peerset::SetId,
ban: Option<Duration>,
) {
let mut entry = if let Entry::Occupied(entry) = self.peers.entry((*peer_id, set_id)) {
entry
Expand All @@ -441,7 +442,12 @@ impl Notifications {
PeerState::DisabledPendingEnable { connections, timer_deadline, timer: _ } => {
trace!(target: "sub-libp2p", "PSM <= Dropped({}, {:?})", peer_id, set_id);
self.peerset.dropped(set_id, *peer_id, DropReason::Unknown);
*entry.into_mut() = PeerState::Disabled { connections, backoff_until: Some(timer_deadline) }
let backoff_until = Some(if let Some(ban) = ban {
cmp::max(timer_deadline, Instant::now() + ban)
} else {
timer_deadline
});
*entry.into_mut() = PeerState::Disabled { connections, backoff_until }
},

// Enabled => Disabled.
Expand Down Expand Up @@ -489,7 +495,8 @@ impl Notifications {
.iter()
.any(|(_, s)| matches!(s, ConnectionState::Opening)));

*entry.into_mut() = PeerState::Disabled { connections, backoff_until: None }
let backoff_until = ban.map(|dur| Instant::now() + dur);
*entry.into_mut() = PeerState::Disabled { connections, backoff_until }
},

// Incoming => Disabled.
Expand Down Expand Up @@ -524,6 +531,13 @@ impl Notifications {
*connec_state = ConnectionState::Closing;
}

let backoff_until = match (backoff_until, ban) {
(Some(a), Some(b)) => Some(cmp::max(a, Instant::now() + b)),
(Some(a), None) => Some(a),
(None, Some(b)) => Some(Instant::now() + b),
(None, None) => None,
};

debug_assert!(!connections
.iter()
.any(|(_, s)| matches!(s, ConnectionState::OpenDesiredByRemote)));
Expand Down

0 comments on commit f1dc623

Please sign in to comment.