diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index 895fbc089234..e9cce0866fde 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -68,12 +68,12 @@ pub trait PeersInfo: Send + Sync { pub trait Peers: PeersInfo { /// Adds a peer to the peer set with UDP `SocketAddr`. fn add_peer(&self, peer: PeerId, tcp_addr: SocketAddr) { - self.add_peer_kind(peer, PeerKind::Basic, tcp_addr, None); + self.add_peer_kind(peer, PeerKind::Static, tcp_addr, None); } /// Adds a peer to the peer set with TCP and UDP `SocketAddr`. fn add_peer_with_udp(&self, peer: PeerId, tcp_addr: SocketAddr, udp_addr: SocketAddr) { - self.add_peer_kind(peer, PeerKind::Basic, tcp_addr, Some(udp_addr)); + self.add_peer_kind(peer, PeerKind::Static, tcp_addr, Some(udp_addr)); } /// Adds a trusted [`PeerId`] to the peer set. @@ -163,6 +163,8 @@ pub enum PeerKind { /// Basic peer kind. #[default] Basic, + /// Static peer, added via JSON-RPC. + Static, /// Trusted peer. Trusted, } @@ -173,6 +175,11 @@ impl PeerKind { matches!(self, Self::Trusted) } + /// Returns `true` if the peer is static. + pub const fn is_static(&self) -> bool { + matches!(self, Self::Static) + } + /// Returns `true` if the peer is basic. pub const fn is_basic(&self) -> bool { matches!(self, Self::Basic) diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index 1093bc8c50e5..b3fa43252ec1 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -562,7 +562,7 @@ where } } NetworkHandleMessage::RemovePeer(peer_id, kind) => { - self.swarm.state_mut().remove_peer(peer_id, kind); + self.swarm.state_mut().remove_peer_kind(peer_id, kind); } NetworkHandleMessage::DisconnectPeer(peer_id, reason) => { self.swarm.sessions_mut().disconnect(peer_id, reason); diff --git a/crates/net/network/src/state.rs b/crates/net/network/src/state.rs index 7fa5b6d2c08f..7334e483b2b4 100644 --- a/crates/net/network/src/state.rs +++ b/crates/net/network/src/state.rs @@ -278,9 +278,10 @@ where self.peers_manager.add_peer_kind(peer_id, kind, addr, None) } - pub(crate) fn remove_peer(&mut self, peer_id: PeerId, kind: PeerKind) { + /// Removes a peer and its address with the given kind from the peerset. + pub(crate) fn remove_peer_kind(&mut self, peer_id: PeerId, kind: PeerKind) { match kind { - PeerKind::Basic => self.peers_manager.remove_peer(peer_id), + PeerKind::Basic | PeerKind::Static => self.peers_manager.remove_peer(peer_id), PeerKind::Trusted => self.peers_manager.remove_peer_from_trusted_set(peer_id), } }