hopr_transport_probe/
config.rs

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