mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(net/peer): set rpc added peer as static (#9201)
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user