pub struct PeerPriorityQueue {
pub urgent: Vec<QueuedMessage>,
pub normal: Vec<QueuedMessage>,
pub background: Vec<QueuedMessage>,
pub peer_counts: HashMap<String, usize>,
pub current_bytes: u64,
pub config: QueueConfig,
pub stats: QueueStats,
}Expand description
Multi-level priority queue for outbound peer messages.
See the module documentation for a full description of the backpressure strategy and dequeue ordering.
Fields§
§urgent: Vec<QueuedMessage>FIFO sub-queue for MessagePriority::Urgent messages.
normal: Vec<QueuedMessage>FIFO sub-queue for MessagePriority::Normal messages.
background: Vec<QueuedMessage>FIFO sub-queue for MessagePriority::Background messages.
peer_counts: HashMap<String, usize>Current pending message count keyed by peer identifier.
current_bytes: u64Sum of payload_bytes for all currently queued messages.
config: QueueConfigConfiguration controlling limits and weights.
stats: QueueStatsCumulative statistics.
Implementations§
Source§impl PeerPriorityQueue
impl PeerPriorityQueue
Sourcepub fn new(config: QueueConfig) -> Self
pub fn new(config: QueueConfig) -> Self
Create a new queue with the supplied configuration.
Sourcepub fn enqueue(&mut self, msg: QueuedMessage) -> bool
pub fn enqueue(&mut self, msg: QueuedMessage) -> bool
Attempt to enqueue msg.
Returns true when the message was accepted, false when it was
dropped because either the global byte budget or the per-peer message
cap would be exceeded.
Sourcepub fn dequeue(&mut self) -> Option<QueuedMessage>
pub fn dequeue(&mut self) -> Option<QueuedMessage>
Dequeue the highest-priority available message.
Priority order is Urgent → Normal → Background. Returns None when
all sub-queues are empty.
Sourcepub fn dequeue_n(&mut self, n: usize) -> Vec<QueuedMessage>
pub fn dequeue_n(&mut self, n: usize) -> Vec<QueuedMessage>
Dequeue up to n messages, returning however many were available.
Sourcepub fn stats(&self) -> &QueueStats
pub fn stats(&self) -> &QueueStats
Reference to the current queue statistics.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> usize
pub fn remove_peer(&mut self, peer_id: &str) -> usize
Remove all pending messages for peer_id.
Returns the number of messages removed. Updates current_bytes,
peer_counts, and the relevant stats fields.
Auto Trait Implementations§
impl Freeze for PeerPriorityQueue
impl RefUnwindSafe for PeerPriorityQueue
impl Send for PeerPriorityQueue
impl Sync for PeerPriorityQueue
impl Unpin for PeerPriorityQueue
impl UnsafeUnpin for PeerPriorityQueue
impl UnwindSafe for PeerPriorityQueue
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