pub struct Simulator {
pub config: SimulatorConfig,
pub network: Network<u64, ChaCha12Rng>,
/* private fields */
}
test-utils
only.Expand description
A simulator for the gossip protocol
Fields§
§config: SimulatorConfig
Configuration of the simulator.
network: Network<u64, ChaCha12Rng>
The Network
Implementations§
Source§impl Simulator
impl Simulator
Sourcepub fn new(
simulator_config: SimulatorConfig,
network_config: impl Into<NetworkConfig>,
) -> Self
pub fn new( simulator_config: SimulatorConfig, network_config: impl Into<NetworkConfig>, ) -> Self
Creates a new simulator.
Sourcepub fn rng(&mut self) -> ChaCha12Rng
pub fn rng(&mut self) -> ChaCha12Rng
Creates a new random number generator, derived from the simuator’s RNG.
Sourcepub fn random_peer(&mut self) -> u64
pub fn random_peer(&mut self) -> u64
Returns the peer id of a random peer.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Returns the number of peers.
Sourcepub fn remove_peers(&mut self, n: usize)
pub fn remove_peers(&mut self, n: usize)
Removes n
peers from the network.
Sourcepub fn report(&mut self) -> NetworkReport<u64>
pub fn report(&mut self) -> NetworkReport<u64>
Returns a report on the current state of the network.
Sourcepub fn bootstrap(&mut self, bootstrap_mode: BootstrapMode) -> NetworkReport<u64>
pub fn bootstrap(&mut self, bootstrap_mode: BootstrapMode) -> NetworkReport<u64>
Bootstraps the network.
See BootstrapMode
for details.
Returns the NetworkReport
after finishing the bootstrap.
Sourcepub fn gossip_round(&mut self, messages: Vec<(u64, Bytes)>) -> usize
pub fn gossip_round(&mut self, messages: Vec<(u64, Bytes)>) -> usize
Runs a round of gossiping.
messages
is a list of (sender, message)
pairs. All messages will be sent simultaneously.
The round will run until all peers received all messages, or until SimulatorConfig::gossip_round_timeout
is elapsed.
Returns the number of undelivered messages.
Sourcepub fn round_stats_average(&self) -> RoundStatsAvg
pub fn round_stats_average(&self) -> RoundStatsAvg
Calculates the RoundStatsAvg
of all gossip rounds.