mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 22:55:40 +00:00
Introduce sc_peerset::DropReason (#7996)
* Introduce sc_peerset::DropReason * Fix peerset tests
This commit is contained in:
@@ -604,7 +604,7 @@ impl Peerset {
|
||||
///
|
||||
/// Must only be called after the PSM has either generated a `Connect` message with this
|
||||
/// `PeerId`, or accepted an incoming connection with this `PeerId`.
|
||||
pub fn dropped(&mut self, set_id: SetId, peer_id: PeerId) {
|
||||
pub fn dropped(&mut self, set_id: SetId, peer_id: PeerId, reason: DropReason) {
|
||||
// We want reputations to be up-to-date before adjusting them.
|
||||
self.update_time();
|
||||
|
||||
@@ -620,6 +620,10 @@ impl Peerset {
|
||||
error!(target: "peerset", "Received dropped() for non-connected node"),
|
||||
}
|
||||
|
||||
if let DropReason::Refused = reason {
|
||||
self.on_remove_from_peers_set(set_id, peer_id);
|
||||
}
|
||||
|
||||
self.alloc_slots();
|
||||
}
|
||||
|
||||
@@ -704,6 +708,17 @@ impl Stream for Peerset {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reason for calling [`Peerset::dropped`].
|
||||
pub enum DropReason {
|
||||
/// Substream or connection has been closed for an unknown reason.
|
||||
Unknown,
|
||||
/// Substream or connection has been explicitly refused by the target. In other words, the
|
||||
/// peer doesn't actually belong to this set.
|
||||
///
|
||||
/// This has the side effect of calling [`PeersetHandle::remove_from_peers_set`].
|
||||
Refused,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use libp2p::PeerId;
|
||||
|
||||
Reference in New Issue
Block a user