hopr_transport_probe/
config.rs

1use serde::{Deserialize, Serialize};
2use validator::Validate;
3
4/// Configuration for the probing mechanism
5#[derive(Debug, Clone, Copy, PartialEq, smart_default::SmartDefault, Validate, Serialize, Deserialize)]
6#[serde(deny_unknown_fields)]
7pub struct ProbeConfig {
8    /// The waiting time for a reply from the probe.
9    #[default(default_max_probe_timeout())]
10    #[serde(default = "default_max_probe_timeout", with = "humantime_serde")]
11    pub timeout: std::time::Duration,
12
13    /// Maximum number of parallel probes performed by the mechanism
14    #[validate(range(min = 1))]
15    #[default(default_max_parallel_probes())]
16    #[serde(default = "default_max_parallel_probes")]
17    pub max_parallel_probes: usize,
18
19    /// The delay between individual probing rounds for neighbor discovery
20    #[serde(default = "default_probing_interval", with = "humantime_serde")]
21    #[default(default_probing_interval())]
22    pub interval: std::time::Duration,
23
24    /// The time threshold after which it is reasonable to recheck the nearest neighbor
25    #[serde(default = "default_recheck_threshold", with = "humantime_serde")]
26    #[default(default_recheck_threshold())]
27    pub recheck_threshold: std::time::Duration,
28}
29
30/// The maximum time waiting for a reply from the probe
31const DEFAULT_MAX_PROBE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);
32
33/// The maximum number of parallel probes the heartbeat performs
34const DEFAULT_MAX_PARALLEL_PROBES: usize = 50;
35
36/// Delay before repeating probing rounds, must include enough time to traverse NATs
37const DEFAULT_REPEATED_PROBING_DELAY: std::time::Duration = std::time::Duration::from_secs(5);
38
39/// Time after which the availability of a node gets rechecked
40const DEFAULT_PROBE_RECHECK_THRESHOLD: std::time::Duration = std::time::Duration::from_secs(60);
41
42#[inline]
43const fn default_max_probe_timeout() -> std::time::Duration {
44    DEFAULT_MAX_PROBE_TIMEOUT
45}
46
47#[inline]
48const fn default_max_parallel_probes() -> usize {
49    DEFAULT_MAX_PARALLEL_PROBES
50}
51
52#[inline]
53const fn default_probing_interval() -> std::time::Duration {
54    DEFAULT_REPEATED_PROBING_DELAY
55}
56
57#[inline]
58const fn default_recheck_threshold() -> std::time::Duration {
59    DEFAULT_PROBE_RECHECK_THRESHOLD
60}