pub struct Simulation<T>where
T: StateMachine,{ /* private fields */ }Expand description
A peer-to-peer node simulation.
Implementations§
Source§impl<T> Simulation<T>where
T: StateMachine + 'static,
T::DisconnectReason: Clone + Into<Disconnect<T::DisconnectReason>>,
<T::Message as ToOwned>::Owned: Debug + Clone,
impl<T> Simulation<T>where
T: StateMachine + 'static,
T::DisconnectReason: Clone + Into<Disconnect<T::DisconnectReason>>,
<T::Message as ToOwned>::Owned: Debug + Clone,
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Check whether the simulation is done, ie. there are no more messages to process.
Sourcepub fn elapsed(&self) -> LocalDuration
pub fn elapsed(&self) -> LocalDuration
Total amount of simulated time elapsed.
Sourcepub fn is_settled(&self) -> bool
pub fn is_settled(&self) -> bool
Check whether the simulation has settled, ie. the only messages left to process are (periodic) timeouts.
Sourcepub fn events(&mut self, node: &IpAddr) -> impl Iterator<Item = T::Event> + '_
pub fn events(&mut self, node: &IpAddr) -> impl Iterator<Item = T::Event> + '_
Get a node’s emitted events.
Sourcepub fn latency(&self, from: IpAddr, to: IpAddr) -> LocalDuration
pub fn latency(&self, from: IpAddr, to: IpAddr) -> LocalDuration
Get the latency between two nodes. The minimum latency between nodes is 1 millisecond.
Sourcepub fn initialize<'a, P: Peer<T>>(
self,
peers: impl IntoIterator<Item = &'a mut P>,
) -> Self
pub fn initialize<'a, P: Peer<T>>( self, peers: impl IntoIterator<Item = &'a mut P>, ) -> Self
Initialize peers.
Sourcepub fn run_while<'a, P: Peer<T>>(
&mut self,
peers: impl IntoIterator<Item = &'a mut P>,
pred: impl Fn(&Self) -> bool,
)
pub fn run_while<'a, P: Peer<T>>( &mut self, peers: impl IntoIterator<Item = &'a mut P>, pred: impl Fn(&Self) -> bool, )
Run the simulation while the given predicate holds.
Sourcepub fn step<'a, P: Peer<T>>(
&mut self,
peers: impl IntoIterator<Item = &'a mut P>,
) -> bool
pub fn step<'a, P: Peer<T>>( &mut self, peers: impl IntoIterator<Item = &'a mut P>, ) -> bool
Process one scheduled input from the inbox, using the provided peers.
This function should be called until it returns false, or some desired state is reached.
Returns true if there are more messages to process.
Sourcepub fn schedule(
&mut self,
node: &IpAddr,
out: Io<<T::Message as ToOwned>::Owned, T::Event, T::DisconnectReason, SocketAddr>,
)
pub fn schedule( &mut self, node: &IpAddr, out: Io<<T::Message as ToOwned>::Owned, T::Event, T::DisconnectReason, SocketAddr>, )
Process a protocol output event from a node.
Auto Trait Implementations§
impl<T> !Freeze for Simulation<T>
impl<T> !RefUnwindSafe for Simulation<T>
impl<T> Send for Simulation<T>where
<<T as StateMachine>::Message as ToOwned>::Owned: Send,
<T as StateMachine>::Event: Send,
<T as StateMachine>::DisconnectReason: Send,
impl<T> !Sync for Simulation<T>
impl<T> Unpin for Simulation<T>where
<<T as StateMachine>::Message as ToOwned>::Owned: Unpin,
<T as StateMachine>::DisconnectReason: Unpin,
impl<T> !UnwindSafe for Simulation<T>
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