pub struct PeerBandwidthAllocator {
pub peers: HashMap<String, PeerAllocation>,
pub total_bps: u64,
pub strategy: AllocationStrategy,
}Expand description
Allocates outbound bandwidth fairly across peers.
Fields§
§peers: HashMap<String, PeerAllocation>All tracked peers, keyed by peer_id.
total_bps: u64Total available bandwidth budget in bps.
strategy: AllocationStrategyActive allocation strategy.
Implementations§
Source§impl PeerBandwidthAllocator
impl PeerBandwidthAllocator
Sourcepub fn new(total_bps: u64, strategy: AllocationStrategy) -> Self
pub fn new(total_bps: u64, strategy: AllocationStrategy) -> Self
Creates a new allocator with the given budget and strategy.
Sourcepub fn add_peer(
&mut self,
peer_id: String,
weight: f64,
min_bps: u64,
max_bps: u64,
)
pub fn add_peer( &mut self, peer_id: String, weight: f64, min_bps: u64, max_bps: u64, )
Registers a new peer. If the peer already exists it is updated in place.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Removes a peer and returns true if it existed.
Sourcepub fn run_allocation(&mut self)
pub fn run_allocation(&mut self)
Runs the configured allocation strategy and stores results in each peer’s
allocated_bps field.
Sourcepub fn allocation_for(&self, peer_id: &str) -> Option<u64>
pub fn allocation_for(&self, peer_id: &str) -> Option<u64>
Returns the last allocated bandwidth for peer_id, or None if unknown.
Sourcepub fn stats(&self) -> AllocationStats
pub fn stats(&self) -> AllocationStats
Returns aggregate statistics for the current state.
Auto Trait Implementations§
impl Freeze for PeerBandwidthAllocator
impl RefUnwindSafe for PeerBandwidthAllocator
impl Send for PeerBandwidthAllocator
impl Sync for PeerBandwidthAllocator
impl Unpin for PeerBandwidthAllocator
impl UnsafeUnpin for PeerBandwidthAllocator
impl UnwindSafe for PeerBandwidthAllocator
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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