pub struct PeerFlowControl { /* private fields */ }Expand description
Window-based flow control manager for multiple peers.
Tracks per-peer send windows, automatically creates windows for new peers, and provides grow/shrink operations for adaptive congestion control.
Implementations§
Source§impl PeerFlowControl
impl PeerFlowControl
Sourcepub fn new(config: FlowControlConfig) -> Self
pub fn new(config: FlowControlConfig) -> Self
Create a new PeerFlowControl with the given configuration.
Sourcepub fn can_send(&self, peer_id: &str, bytes: u64) -> bool
pub fn can_send(&self, peer_id: &str, bytes: u64) -> bool
Check whether bytes can be sent to peer_id without exceeding
the window. Returns true even if the peer has no window yet
(it would be auto-created on send).
Sourcepub fn send(&mut self, peer_id: &str, bytes: u64) -> Result<(), String>
pub fn send(&mut self, peer_id: &str, bytes: u64) -> Result<(), String>
Record bytes as sent to peer_id.
Auto-creates a window for new peers. Returns an error if sending
bytes would exceed the peer’s window size and increments the
stall counter.
Sourcepub fn ack(&mut self, peer_id: &str, bytes: u64)
pub fn ack(&mut self, peer_id: &str, bytes: u64)
Acknowledge bytes from peer_id, reducing bytes in flight.
If the peer has no window this is a no-op. The in-flight counter is clamped to zero (will not underflow).
Sourcepub fn grow_window(&mut self, peer_id: &str)
pub fn grow_window(&mut self, peer_id: &str)
Grow the window for peer_id by growth_factor, clamped to max_window.
No-op if the peer has no window.
Sourcepub fn shrink_window(&mut self, peer_id: &str)
pub fn shrink_window(&mut self, peer_id: &str)
Shrink the window for peer_id by shrink_factor, clamped to min_window.
No-op if the peer has no window.
Sourcepub fn get_window(&self, peer_id: &str) -> Option<&FlowWindow>
pub fn get_window(&self, peer_id: &str) -> Option<&FlowWindow>
Get a reference to the flow window for peer_id, if it exists.
Sourcepub fn utilization(&self, peer_id: &str) -> Option<f64>
pub fn utilization(&self, peer_id: &str) -> Option<f64>
Compute the utilization ratio (bytes_in_flight / window_size) for
peer_id. Returns None if the peer has no window.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove the flow window for peer_id. Returns true if the peer
was present.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Return the number of peers with active flow windows.
Sourcepub fn stats(&self) -> FlowControlStats
pub fn stats(&self) -> FlowControlStats
Compute aggregate statistics across all peers.
Auto Trait Implementations§
impl Freeze for PeerFlowControl
impl RefUnwindSafe for PeerFlowControl
impl Send for PeerFlowControl
impl Sync for PeerFlowControl
impl Unpin for PeerFlowControl
impl UnsafeUnpin for PeerFlowControl
impl UnwindSafe for PeerFlowControl
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