pub struct Network { /* private fields */ }Expand description
The virtual network: links, cuts, the flight queue, and per-node inboxes.
Implementations§
Source§impl Network
impl Network
Sourcepub fn new(default_link: LinkConfig) -> Self
pub fn new(default_link: LinkConfig) -> Self
A fully connected network using default_link for pairs without
an explicit configuration.
Sourcepub fn set_link_config(&mut self, from: NodeId, to: NodeId, config: LinkConfig)
pub fn set_link_config(&mut self, from: NodeId, to: NodeId, config: LinkConfig)
Overrides the configuration of one directed link.
Sourcepub fn partition(
&mut self,
group_a: impl IntoIterator<Item = NodeId>,
group_b: impl IntoIterator<Item = NodeId>,
)
pub fn partition( &mut self, group_a: impl IntoIterator<Item = NodeId>, group_b: impl IntoIterator<Item = NodeId>, )
Cuts connectivity between two node sets, in both directions. Messages already in flight are unaffected.
Sourcepub fn connected(&self, a: NodeId, b: NodeId) -> bool
pub fn connected(&self, a: NodeId, b: NodeId) -> bool
Whether a send between the two nodes would go through.
Sourcepub fn send(
&mut self,
from: NodeId,
to: NodeId,
payload: Vec<u8>,
now: Micros,
rng: &mut SimRng,
) -> SendOutcome
pub fn send( &mut self, from: NodeId, to: NodeId, payload: Vec<u8>, now: Micros, rng: &mut SimRng, ) -> SendOutcome
Queues a message for delivery, applying the link’s latency, drop,
and duplication behavior. All randomness comes from rng.
Sourcepub fn deliver_due(
&mut self,
now: Micros,
crashed: &BTreeSet<NodeId>,
) -> Vec<Delivery>
pub fn deliver_due( &mut self, now: Micros, crashed: &BTreeSet<NodeId>, ) -> Vec<Delivery>
Moves every message due at or before now into destination
inboxes. Messages addressed to crashed nodes are discarded.
Sourcepub fn next_delivery(&self) -> Option<Micros>
pub fn next_delivery(&self) -> Option<Micros>
The earliest pending delivery time, if any.
Sourcepub fn try_recv(&mut self, node: NodeId) -> Option<Message>
pub fn try_recv(&mut self, node: NodeId) -> Option<Message>
Pops the oldest message from a node’s inbox.
Sourcepub fn clear_inbox(&mut self, node: NodeId)
pub fn clear_inbox(&mut self, node: NodeId)
Drops every buffered message of a node (its volatile state).
Sourcepub fn stats(&self) -> NetworkStats
pub fn stats(&self) -> NetworkStats
Cumulative delivery counters.