Simulation

Struct Simulation 

Source
pub struct Simulation<T>
where T: StateMachine,
{ /* private fields */ }
Expand description

A peer-to-peer node simulation.

Implementations§

Source§

impl<T> Simulation<T>

Source

pub fn new(time: LocalTime, rng: Rng, opts: Options) -> Self

Create a new simulation.

Source

pub fn is_done(&self) -> bool

Check whether the simulation is done, ie. there are no more messages to process.

Source

pub fn elapsed(&self) -> LocalDuration

Total amount of simulated time elapsed.

Source

pub fn is_settled(&self) -> bool

Check whether the simulation has settled, ie. the only messages left to process are (periodic) timeouts.

Source

pub fn events(&mut self, node: &IpAddr) -> impl Iterator<Item = T::Event> + '_

Get a node’s emitted events.

Source

pub fn latency(&self, from: IpAddr, to: IpAddr) -> LocalDuration

Get the latency between two nodes. The minimum latency between nodes is 1 millisecond.

Source

pub fn initialize<'a, P: Peer<T>>( self, peers: impl IntoIterator<Item = &'a mut P>, ) -> Self

Initialize peers.

Source

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.

Source

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.

Source

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>

§

impl<T> !Sync for Simulation<T>

§

impl<T> Unpin for Simulation<T>

§

impl<T> !UnwindSafe for Simulation<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.