hopr_transport_mixer/
config.rs1use std::time::Duration;
2
3pub const HOPR_MIXER_MINIMUM_DEFAULT_DELAY_IN_MS: u64 = 0;
4pub const HOPR_MIXER_DEFAULT_DELAY_RANGE_IN_MS: u64 = 200;
5pub const HOPR_MIXER_DELAY_METRIC_WINDOW: u64 = 100;
6pub const HOPR_MIXER_CAPACITY: usize = 20_000;
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq, smart_default::SmartDefault)]
10pub struct MixerConfig {
11 #[default(Duration::from_millis(HOPR_MIXER_MINIMUM_DEFAULT_DELAY_IN_MS))]
13 pub min_delay: Duration,
14 #[default(Duration::from_millis(HOPR_MIXER_DEFAULT_DELAY_RANGE_IN_MS))]
16 pub delay_range: Duration,
17 #[default(HOPR_MIXER_CAPACITY)]
22 pub capacity: usize,
23 #[default(HOPR_MIXER_DELAY_METRIC_WINDOW)]
24 pub metric_delay_window: u64,
25}
26
27impl MixerConfig {
28 pub fn random_delay(&self) -> Duration {
31 let max_delay = self.min_delay.saturating_add(self.delay_range);
32
33 let random_delay = if max_delay.as_millis() == 0 {
34 max_delay.as_millis() as u64
35 } else {
36 hopr_crypto_random::random_integer(self.min_delay.as_millis() as u64, Some(max_delay.as_millis() as u64))
37 };
38
39 Duration::from_millis(random_delay)
40 }
41}