pub struct PeerBanList { /* private fields */ }Expand description
Manages a list of banned peers with temporary and permanent ban support.
Bans are tracked using a logical tick counter rather than wall-clock time, allowing deterministic testing and integration with tick-based event loops.
Implementations§
Source§impl PeerBanList
impl PeerBanList
Sourcepub fn ban_temporary(
&mut self,
peer_id: &str,
reason: &str,
ttl_ticks: Option<u64>,
)
pub fn ban_temporary( &mut self, peer_id: &str, reason: &str, ttl_ticks: Option<u64>, )
Ban a peer temporarily. Uses default_temp_ttl_ticks when ttl_ticks is None.
If the ban list is at capacity, the ban is silently dropped. If the peer is already banned, the entry is updated (re-banned).
Sourcepub fn ban_permanent(&mut self, peer_id: &str, reason: &str)
pub fn ban_permanent(&mut self, peer_id: &str, reason: &str)
Ban a peer permanently. The ban will not expire until explicitly removed via unban.
If the ban list is at capacity, the ban is silently dropped. If the peer is already banned, the entry is updated (re-banned).
Sourcepub fn unban(&mut self, peer_id: &str) -> bool
pub fn unban(&mut self, peer_id: &str) -> bool
Remove a ban for the given peer. Returns true if the peer was banned.
Sourcepub fn is_banned(&mut self, peer_id: &str) -> bool
pub fn is_banned(&mut self, peer_id: &str) -> bool
Check whether a peer is currently banned, respecting temporary ban expiry.
A temporary ban is considered expired if current_tick >= expires_tick.
Expired entries are lazily removed on access.
Sourcepub fn get_ban(&self, peer_id: &str) -> Option<&BanEntry>
pub fn get_ban(&self, peer_id: &str) -> Option<&BanEntry>
Get the ban entry for a peer, if it exists and is still active.
Note: This does not perform lazy expiry cleanup. Use is_banned for
an expiry-aware check, or call tick_cleanup periodically.
Sourcepub fn tick_cleanup(&mut self)
pub fn tick_cleanup(&mut self)
Advance the current tick by one and remove all expired temporary bans.
Sourcepub fn banned_count(&self) -> usize
pub fn banned_count(&self) -> usize
Return the number of currently active bans (including not-yet-cleaned expired ones).
Sourcepub fn list_banned(&self) -> Vec<&BanEntry>
pub fn list_banned(&self) -> Vec<&BanEntry>
Return references to all current ban entries.
Sourcepub fn stats(&self) -> BanListStats
pub fn stats(&self) -> BanListStats
Return aggregate statistics about the ban list.
Sourcepub fn current_tick(&self) -> u64
pub fn current_tick(&self) -> u64
Return the current logical tick.
Trait Implementations§
Source§impl Clone for PeerBanList
impl Clone for PeerBanList
Source§fn clone(&self) -> PeerBanList
fn clone(&self) -> PeerBanList
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PeerBanList
impl RefUnwindSafe for PeerBanList
impl Send for PeerBanList
impl Sync for PeerBanList
impl Unpin for PeerBanList
impl UnsafeUnpin for PeerBanList
impl UnwindSafe for PeerBanList
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more