dscale 0.5.2

A fast & deterministic simulation framework for benchmarking and testing distributed systems
Documentation
use std::sync::Arc;

use crate::Pid;
use crate::jiffy::Jiffies;
use crate::random::Randomizer;
use crate::topology::Topology;

pub(crate) struct Latency {
    topology: Arc<Topology>,
    randomizer: Randomizer,
}

impl Latency {
    pub(crate) fn new(randomizer: Randomizer, topology: Arc<Topology>) -> Self {
        Self {
            randomizer,
            topology,
        }
    }

    pub(crate) fn random_latency(&mut self, source: Pid, target: Pid) -> Jiffies {
        let distribution = self.topology.get_distribution(source, target);
        Jiffies(self.randomizer.random_usize(distribution))
    }
}