Skip to main content

PeerMessagePrioritizer

Struct PeerMessagePrioritizer 

Source
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:

  1. Higher effective_priority comes first.
  2. Among messages with the same effective_priority, the one enqueued earliest (lowest enqueued_tick) comes first (FIFO).

Fields§

§queues: HashMap<String, Vec<PrioritizedMessage>>

Per-peer queues; each Vec is kept sorted (front = highest priority).

§config: AgingConfig

Aging and capacity configuration.

§stats: PrioritizerStats

Running statistics.

§current_tick: u64

Logical clock advanced via advance_tick.

§next_id: u64

Counter used to assign unique message identifiers.

Implementations§

Source§

impl PeerMessagePrioritizer

Source

pub fn new(config: AgingConfig) -> Self

Create a new prioritizer with the supplied configuration.

Source

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:

  1. Attempt to drop the lowest-priority message (Background first, then Normal).
  2. If the queue is still full after the drop attempt, return None.

On success, returns Some(msg_id).

Source

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.

Source

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.

Source

pub fn stats(&self) -> &PrioritizerStats

Return a reference to the accumulated statistics.

Source

pub fn queue_depth(&self, peer_id: &str) -> usize

Return the number of messages currently queued for peer_id.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more