pub struct TopicRouter { /* private fields */ }Expand description
Intelligent GossipSub topic manager with priority-based message queuing.
TopicRouter is Send + Sync and designed for concurrent use behind an Arc.
§Example
use ipfrs_network::topic_router::{TopicRouter, TopicConfig, PrioritizedMessage};
use std::time::{Duration, Instant};
let router = TopicRouter::new();
router.register_topic("blocks", TopicConfig::default()).unwrap();
let msg = PrioritizedMessage {
payload: b"hello".to_vec(),
priority: 200,
enqueued_at: Instant::now(),
topic: "blocks".to_string(),
};
router.enqueue("blocks", msg).unwrap();
let popped = router.dequeue("blocks");
assert!(popped.is_some());Implementations§
Source§impl TopicRouter
impl TopicRouter
Sourcepub fn register_topic(
&self,
name: &str,
config: TopicConfig,
) -> Result<(), TopicError>
pub fn register_topic( &self, name: &str, config: TopicConfig, ) -> Result<(), TopicError>
Register a new topic with the given configuration.
§Errors
Returns TopicError::AlreadyRegistered if the topic name has already been registered.
Sourcepub fn unregister_topic(&self, name: &str) -> Result<(), TopicError>
pub fn unregister_topic(&self, name: &str) -> Result<(), TopicError>
Unregister a topic and discard its queue and counters.
§Errors
Returns TopicError::TopicNotFound if the topic has not been registered.
Sourcepub fn enqueue(
&self,
topic: &str,
msg: PrioritizedMessage,
) -> Result<(), TopicError>
pub fn enqueue( &self, topic: &str, msg: PrioritizedMessage, ) -> Result<(), TopicError>
Enqueue a message on the given topic.
§Errors
TopicError::TopicNotFound— topic not registeredTopicError::BelowThreshold— message priority below topic threshold (also counts as dropped)TopicError::QueueFull— queue at capacity (also counts as dropped)
Sourcepub fn dequeue(&self, topic: &str) -> Option<PrioritizedMessage>
pub fn dequeue(&self, topic: &str) -> Option<PrioritizedMessage>
Pop and return the highest-priority message from the topic’s queue.
Returns None if the topic does not exist or the queue is empty.
Sourcepub fn queue_depth(&self, topic: &str) -> usize
pub fn queue_depth(&self, topic: &str) -> usize
Returns the number of messages currently in the topic’s queue.
Returns 0 for unregistered topics.
Sourcepub fn message_count(&self, topic: &str) -> u64
pub fn message_count(&self, topic: &str) -> u64
Returns the total number of messages ever successfully enqueued on the topic (messages that were dropped are not counted here).
Returns 0 for unregistered topics.
Sourcepub fn all_topics(&self) -> Vec<String>
pub fn all_topics(&self) -> Vec<String>
Returns a sorted list of all registered topic names.
Sourcepub fn stats(&self) -> TopicRouterStatsSnapshot
pub fn stats(&self) -> TopicRouterStatsSnapshot
Returns a point-in-time statistics snapshot.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TopicRouter
impl RefUnwindSafe for TopicRouter
impl Send for TopicRouter
impl Sync for TopicRouter
impl Unpin for TopicRouter
impl UnsafeUnpin for TopicRouter
impl UnwindSafe for TopicRouter
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