pub struct PeerMessagePrioritizer {
pub queues: HashMap<String, Vec<PrioritizedMessage>>,
pub config: AgingConfig,
pub stats: PrioritizerStats,
pub current_tick: u64,
pub next_id: u64,
}Expand description
Multi-level outbound message prioritizer with per-peer queues and aging.
§Ordering guarantee
Within a peer’s queue messages are sorted so that:
- Higher
effective_prioritycomes first. - Among messages with the same
effective_priority, the one enqueued earliest (lowestenqueued_tick) comes first (FIFO).
Fields§
§queues: HashMap<String, Vec<PrioritizedMessage>>Per-peer queues; each Vec is kept sorted (front = highest priority).
config: AgingConfigAging and capacity configuration.
stats: PrioritizerStatsRunning statistics.
current_tick: u64Logical clock advanced via advance_tick.
next_id: u64Counter used to assign unique message identifiers.
Implementations§
Source§impl PeerMessagePrioritizer
impl PeerMessagePrioritizer
Sourcepub fn new(config: AgingConfig) -> Self
pub fn new(config: AgingConfig) -> Self
Create a new prioritizer with the supplied configuration.
Sourcepub fn enqueue(
&mut self,
peer_id: String,
priority: MessagePriority,
payload_bytes: u64,
) -> Option<u64>
pub fn enqueue( &mut self, peer_id: String, priority: MessagePriority, payload_bytes: u64, ) -> Option<u64>
Enqueue a new message for peer_id.
If the peer’s queue is already at max_queue_size:
- Attempt to drop the lowest-priority message (
Backgroundfirst, thenNormal). - If the queue is still full after the drop attempt, return
None.
On success, returns Some(msg_id).
Sourcepub fn dequeue(&mut self, peer_id: &str) -> Option<PrioritizedMessage>
pub fn dequeue(&mut self, peer_id: &str) -> Option<PrioritizedMessage>
Remove and return the highest-priority message for peer_id, or None
if the peer has no queued messages.
Sourcepub fn advance_tick(&mut self)
pub fn advance_tick(&mut self)
Advance the logical clock by one tick and apply aging promotions.
Any message whose waiting time (current_tick - enqueued_tick) meets or
exceeds promote_after_ticks and whose effective_priority is below
Urgent is promoted by one level. Queues that had at least one
promotion are re-sorted to preserve the ordering invariant.
Sourcepub fn stats(&self) -> &PrioritizerStats
pub fn stats(&self) -> &PrioritizerStats
Return a reference to the accumulated statistics.
Sourcepub fn queue_depth(&self, peer_id: &str) -> usize
pub fn queue_depth(&self, peer_id: &str) -> usize
Return the number of messages currently queued for peer_id.
Auto Trait Implementations§
impl Freeze for PeerMessagePrioritizer
impl RefUnwindSafe for PeerMessagePrioritizer
impl Send for PeerMessagePrioritizer
impl Sync for PeerMessagePrioritizer
impl Unpin for PeerMessagePrioritizer
impl UnsafeUnpin for PeerMessagePrioritizer
impl UnwindSafe for PeerMessagePrioritizer
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