pub struct PeerScoring { /* private fields */ }Expand description
Manages per-peer ban scores and a ban list.
Thread-safe usage: wrap in Arc<RwLock<PeerScoring>> if shared.
Implementations§
Source§impl PeerScoring
impl PeerScoring
Sourcepub fn with_config(ban_threshold: i32, ban_duration: u64) -> Self
pub fn with_config(ban_threshold: i32, ban_duration: u64) -> Self
Create with custom threshold and ban duration.
Sourcepub fn register_peer(&mut self, peer_id: u64, addr: SocketAddr)
pub fn register_peer(&mut self, peer_id: u64, addr: SocketAddr)
Register a new peer (call when peer connects).
Sourcepub fn remove_peer(&mut self, peer_id: u64)
pub fn remove_peer(&mut self, peer_id: u64)
Remove a peer (call when peer disconnects).
Sourcepub fn record_misbehavior(
&mut self,
peer_id: u64,
violation: Misbehavior,
now: u64,
) -> ScoreAction
pub fn record_misbehavior( &mut self, peer_id: u64, violation: Misbehavior, now: u64, ) -> ScoreAction
Record a misbehavior event for a peer.
Returns an action the caller should take (either None or Ban).
Sourcepub fn is_banned(&self, addr: &SocketAddr, now: u64) -> bool
pub fn is_banned(&self, addr: &SocketAddr, now: u64) -> bool
Check whether an address is currently banned.
Sourcepub fn ban_address(&mut self, addr: SocketAddr, reason: String, now: u64)
pub fn ban_address(&mut self, addr: SocketAddr, reason: String, now: u64)
Manually ban an address.
Sourcepub fn unban_address(&mut self, addr: &SocketAddr) -> bool
pub fn unban_address(&mut self, addr: &SocketAddr) -> bool
Manually unban an address.
Sourcepub fn sweep_expired_bans(&mut self, now: u64) -> usize
pub fn sweep_expired_bans(&mut self, now: u64) -> usize
Remove expired bans.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Number of tracked peers.
Trait Implementations§
Source§impl Debug for PeerScoring
impl Debug for PeerScoring
Auto Trait Implementations§
impl Freeze for PeerScoring
impl RefUnwindSafe for PeerScoring
impl Send for PeerScoring
impl Sync for PeerScoring
impl Unpin for PeerScoring
impl UnsafeUnpin for PeerScoring
impl UnwindSafe for PeerScoring
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more