Skip to main content

hopr_builder/
config.rs

1use std::{collections::HashSet, net::SocketAddr, time::Duration};
2
3use serde_with::serde_as;
4
5/// Configuration of the Exit node (see [`HoprServerIpForwardingReactor`](crate::exit::HoprServerIpForwardingReactor))
6/// and the Entry node.
7#[serde_as]
8#[derive(
9    Clone, Debug, Eq, PartialEq, smart_default::SmartDefault, serde::Deserialize, serde::Serialize, validator::Validate,
10)]
11pub struct SessionIpForwardingConfig {
12    /// Controls whether allowlisting should be done via `target_allow_list`.
13    /// If set to `false`, the node will act as an Exit node for any target.
14    ///
15    /// Defaults to `true`.
16    #[serde(default = "just_true")]
17    #[default(true)]
18    pub use_target_allow_list: bool,
19
20    /// Enforces only the given target addresses (after DNS resolution).
21    ///
22    /// This is used only if `use_target_allow_list` is set to `true`.
23    /// If left empty (and `use_target_allow_list` is `true`), the node will not act as an Exit node.
24    ///
25    /// Defaults to empty.
26    #[serde(default)]
27    #[serde_as(as = "HashSet<serde_with::DisplayFromStr>")]
28    pub target_allow_list: HashSet<SocketAddr>,
29
30    /// Delay between retries in seconds to reach a TCP target.
31    ///
32    /// Defaults to 2 seconds.
33    #[serde(default = "default_target_retry_delay")]
34    #[default(default_target_retry_delay())]
35    #[serde_as(as = "serde_with::DurationSeconds<u64>")]
36    pub tcp_target_retry_delay: Duration,
37
38    /// Maximum number of retries to reach a TCP target before giving up.
39    ///
40    /// Default is 10.
41    #[serde(default = "default_max_tcp_target_retries")]
42    #[default(default_max_tcp_target_retries())]
43    #[validate(range(min = 1))]
44    pub max_tcp_target_retries: u32,
45
46    /// Specifies the default `listen_host` for Session listening sockets
47    /// at an Entry node.
48    #[serde(default = "default_entry_listen_host")]
49    #[default(default_entry_listen_host())]
50    #[serde_as(as = "serde_with::DisplayFromStr")]
51    pub default_entry_listen_host: SocketAddr,
52}
53
54fn default_target_retry_delay() -> Duration {
55    Duration::from_secs(2)
56}
57
58fn default_entry_listen_host() -> SocketAddr {
59    "127.0.0.1:0".parse().unwrap()
60}
61
62fn default_max_tcp_target_retries() -> u32 {
63    10
64}
65
66fn just_true() -> bool {
67    true
68}