pub struct PeerConnectionLimiter { /* private fields */ }Expand description
Rate-based connection limiter that enforces per-peer limits, a global cap, and a cooldown period between connections from the same peer.
Implementations§
Source§impl PeerConnectionLimiter
impl PeerConnectionLimiter
Sourcepub fn new(config: LimiterConfig) -> Self
pub fn new(config: LimiterConfig) -> Self
Create a new limiter with the given configuration.
Sourcepub fn try_connect(&mut self, peer_id: &str) -> Result<(), String>
pub fn try_connect(&mut self, peer_id: &str) -> Result<(), String>
Attempt to accept a connection from peer_id.
Returns Ok(()) if the connection is accepted, or Err with a
human-readable reason if rejected.
Sourcepub fn disconnect(&mut self, peer_id: &str) -> Result<(), String>
pub fn disconnect(&mut self, peer_id: &str) -> Result<(), String>
Record a disconnection for peer_id.
Returns Err if the peer has no active connections or is unknown.
Sourcepub fn is_allowed(&self, peer_id: &str) -> bool
pub fn is_allowed(&self, peer_id: &str) -> bool
Check whether a connection from peer_id would be allowed without
modifying any state.
Sourcepub fn active_for_peer(&self, peer_id: &str) -> usize
pub fn active_for_peer(&self, peer_id: &str) -> usize
Return the number of active connections for the given peer, or 0 if
the peer is not tracked.
Sourcepub fn total_active(&self) -> usize
pub fn total_active(&self) -> usize
Return the total number of active connections across all peers.
Sourcepub fn reset_peer(&mut self, peer_id: &str)
pub fn reset_peer(&mut self, peer_id: &str)
Clear all connection info for the specified peer. The peer is removed from the internal tracking map and the global active count is adjusted.
Sourcepub fn stats(&self) -> LimiterStats
pub fn stats(&self) -> LimiterStats
Return an aggregate statistics snapshot.
Sourcepub fn config(&self) -> &LimiterConfig
pub fn config(&self) -> &LimiterConfig
Return a reference to the current configuration.
Sourcepub fn current_tick(&self) -> u64
pub fn current_tick(&self) -> u64
Return the current tick value.
Sourcepub fn peer_info(&self, peer_id: &str) -> Option<&PeerConnectionInfo>
pub fn peer_info(&self, peer_id: &str) -> Option<&PeerConnectionInfo>
Return a reference to a peer’s info, if tracked.
Auto Trait Implementations§
impl Freeze for PeerConnectionLimiter
impl RefUnwindSafe for PeerConnectionLimiter
impl Send for PeerConnectionLimiter
impl Sync for PeerConnectionLimiter
impl Unpin for PeerConnectionLimiter
impl UnsafeUnpin for PeerConnectionLimiter
impl UnwindSafe for PeerConnectionLimiter
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> 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