Struct nakamoto_net::simulator::Simulation
source · pub struct Simulation<T>where
T: StateMachine,{ /* private fields */ }
Expand description
A peer-to-peer node simulation.
Implementations
sourceimpl<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> !RefUnwindSafe for Simulation<T>
impl<T> Send for Simulation<T>where
<T as StateMachine<SocketAddr>>::DisconnectReason: Send,
<T as StateMachine<SocketAddr>>::Event: Send,
<<T as StateMachine<SocketAddr>>::Message as ToOwned>::Owned: Send,
impl<T> !Sync for Simulation<T>
impl<T> Unpin for Simulation<T>where
<T as StateMachine<SocketAddr>>::DisconnectReason: Unpin,
<<T as StateMachine<SocketAddr>>::Message as ToOwned>::Owned: Unpin,
impl<T> !UnwindSafe for Simulation<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more