pub struct Broadcaster {
replica_id: String,
config: BroadcastConfig,
peers: BTreeSet<String>,
seen: HashSet<Hash>,
seen_order: VecDeque<Hash>,
timestamp: u64,
pending_events: VecDeque<BroadcastEvent>,
peer_heads: HashMap<String, HashSet<Hash>>,
}Expand description
Gossip-based broadcaster for head dissemination.
The broadcaster maintains:
- A set of known peers
- A buffer of seen message IDs (for deduplication)
- Pending outgoing messages
Fields§
§replica_id: StringOur replica ID.
config: BroadcastConfigConfiguration.
peers: BTreeSet<String>Known peers (BTreeSet for deterministic iteration order).
seen: HashSet<Hash>Message IDs we’ve seen (for deduplication).
seen_order: VecDeque<Hash>Order of seen messages (for LRU eviction).
timestamp: u64Current logical timestamp.
pending_events: VecDeque<BroadcastEvent>Pending events to be processed.
peer_heads: HashMap<String, HashSet<Hash>>Track which peers have which heads (optimization).
Implementations§
Source§impl Broadcaster
impl Broadcaster
Sourcepub fn with_config(
replica_id: impl Into<String>,
config: BroadcastConfig,
) -> Self
pub fn with_config( replica_id: impl Into<String>, config: BroadcastConfig, ) -> Self
Create a broadcaster with custom configuration.
Sourcepub fn replica_id(&self) -> &str
pub fn replica_id(&self) -> &str
Get our replica ID.
Sourcepub fn remove_peer(&mut self, peer: &str)
pub fn remove_peer(&mut self, peer: &str)
Remove a peer.
Sourcepub fn receive(&mut self, from: impl Into<String>, message: BroadcastMessage)
pub fn receive(&mut self, from: impl Into<String>, message: BroadcastMessage)
Receive a message from a peer.
Sourcepub fn poll_event(&mut self) -> Option<BroadcastEvent>
pub fn poll_event(&mut self) -> Option<BroadcastEvent>
Get the next pending event.
Sourcepub fn has_pending_events(&self) -> bool
pub fn has_pending_events(&self) -> bool
Check if there are pending events.
Sourcepub fn drain_events(&mut self) -> Vec<BroadcastEvent>
pub fn drain_events(&mut self) -> Vec<BroadcastEvent>
Get all pending events.
Sourcefn select_peers(&self, n: usize) -> Vec<String>
fn select_peers(&self, n: usize) -> Vec<String>
Select n random peers.
Sourcefn select_peers_excluding(&self, n: usize, exclude: &[&str]) -> Vec<String>
fn select_peers_excluding(&self, n: usize, exclude: &[&str]) -> Vec<String>
Select n random peers, excluding some.
Sourcepub fn stats(&self) -> BroadcastStats
pub fn stats(&self) -> BroadcastStats
Get statistics about the broadcaster.
Auto Trait Implementations§
impl Freeze for Broadcaster
impl RefUnwindSafe for Broadcaster
impl Send for Broadcaster
impl Sync for Broadcaster
impl Unpin for Broadcaster
impl UnwindSafe for Broadcaster
Blanket Implementations§
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