iroh_net/defaults.rs
1//! Default values used in [`iroh-net`][`crate`]
2
3use url::Url;
4
5use crate::relay::{RelayMap, RelayNode};
6
7/// The default STUN port used by the Relay server.
8///
9/// The STUN port as defined by [RFC
10/// 8489](<https://www.rfc-editor.org/rfc/rfc8489#section-18.6>)
11pub const DEFAULT_STUN_PORT: u16 = 3478;
12
13/// The default HTTP port used by the Relay server.
14pub const DEFAULT_HTTP_PORT: u16 = 80;
15
16/// The default HTTPS port used by the Relay server.
17pub const DEFAULT_HTTPS_PORT: u16 = 443;
18
19/// The default metrics port used by the Relay server.
20pub const DEFAULT_METRICS_PORT: u16 = 9090;
21
22/// Production configuration.
23pub mod prod {
24 use super::*;
25
26 /// Hostname of the default NA relay.
27 pub const NA_RELAY_HOSTNAME: &str = "use1-1.relay.iroh.network.";
28 /// Hostname of the default EU relay.
29 pub const EU_RELAY_HOSTNAME: &str = "euw1-1.relay.iroh.network.";
30 /// Hostname of the default Asia-Pacific relay.
31 pub const AP_RELAY_HOSTNAME: &str = "aps1-1.relay.iroh.network.";
32
33 /// Get the default [`RelayMap`].
34 pub fn default_relay_map() -> RelayMap {
35 RelayMap::from_nodes([
36 default_na_relay_node(),
37 default_eu_relay_node(),
38 default_ap_relay_node(),
39 ])
40 .expect("default nodes invalid")
41 }
42
43 /// Get the default [`RelayNode`] for NA.
44 pub fn default_na_relay_node() -> RelayNode {
45 // The default NA relay server run by number0.
46 let url: Url = format!("https://{NA_RELAY_HOSTNAME}")
47 .parse()
48 .expect("default url");
49 RelayNode {
50 url: url.into(),
51 stun_only: false,
52 stun_port: DEFAULT_STUN_PORT,
53 }
54 }
55
56 /// Get the default [`RelayNode`] for EU.
57 pub fn default_eu_relay_node() -> RelayNode {
58 // The default EU relay server run by number0.
59 let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
60 .parse()
61 .expect("default_url");
62 RelayNode {
63 url: url.into(),
64 stun_only: false,
65 stun_port: DEFAULT_STUN_PORT,
66 }
67 }
68
69 /// Get the default [`RelayNode`] for Asia-Pacific
70 pub fn default_ap_relay_node() -> RelayNode {
71 // The default Asia-Pacific relay server run by number0.
72 let url: Url = format!("https://{AP_RELAY_HOSTNAME}")
73 .parse()
74 .expect("default_url");
75 RelayNode {
76 url: url.into(),
77 stun_only: false,
78 stun_port: DEFAULT_STUN_PORT,
79 }
80 }
81}
82
83/// Staging configuration.
84///
85/// Used by tests and might have incompatible changes deployed
86///
87/// Note: we have staging servers in EU and NA, but no corresponding staging server for AP at this time.
88pub mod staging {
89 use super::*;
90
91 /// Hostname of the default NA relay.
92 pub const NA_RELAY_HOSTNAME: &str = "staging-use1-1.relay.iroh.network.";
93 /// Hostname of the default EU relay.
94 pub const EU_RELAY_HOSTNAME: &str = "staging-euw1-1.relay.iroh.network.";
95
96 /// Get the default [`RelayMap`].
97 pub fn default_relay_map() -> RelayMap {
98 RelayMap::from_nodes([default_na_relay_node(), default_eu_relay_node()])
99 .expect("default nodes invalid")
100 }
101
102 /// Get the default [`RelayNode`] for NA.
103 pub fn default_na_relay_node() -> RelayNode {
104 // The default NA relay server run by number0.
105 let url: Url = format!("https://{NA_RELAY_HOSTNAME}")
106 .parse()
107 .expect("default url");
108 RelayNode {
109 url: url.into(),
110 stun_only: false,
111 stun_port: DEFAULT_STUN_PORT,
112 }
113 }
114
115 /// Get the default [`RelayNode`] for EU.
116 pub fn default_eu_relay_node() -> RelayNode {
117 // The default EU relay server run by number0.
118 let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
119 .parse()
120 .expect("default_url");
121 RelayNode {
122 url: url.into(),
123 stun_only: false,
124 stun_port: DEFAULT_STUN_PORT,
125 }
126 }
127}
128
129/// Contains all timeouts that we use in `iroh-net`.
130pub(crate) mod timeouts {
131 use std::time::Duration;
132
133 // Timeouts for netcheck
134
135 /// Maximum duration to wait for a netcheck report.
136 pub(crate) const NETCHECK_REPORT_TIMEOUT: Duration = Duration::from_secs(10);
137
138 /// The maximum amount of time netcheck will spend gathering a single report.
139 pub(crate) const OVERALL_REPORT_TIMEOUT: Duration = Duration::from_secs(5);
140
141 /// The total time we wait for all the probes.
142 ///
143 /// This includes the STUN, ICMP and HTTPS probes, which will all
144 /// start at different times based on the ProbePlan.
145 pub(crate) const PROBES_TIMEOUT: Duration = Duration::from_secs(3);
146
147 /// How long to await for a captive-portal result.
148 ///
149 /// This delay is chosen so it starts after good-working STUN probes
150 /// would have finished, but not too long so the delay is bearable if
151 /// STUN is blocked.
152 pub(crate) const CAPTIVE_PORTAL_DELAY: Duration = Duration::from_millis(200);
153
154 /// Timeout for captive portal checks
155 ///
156 /// Must be lower than [`OVERALL_REPORT_TIMEOUT`] minus
157 /// [`CAPTIVE_PORTAL_DELAY`].
158 pub(crate) const CAPTIVE_PORTAL_TIMEOUT: Duration = Duration::from_secs(2);
159
160 pub(crate) const DNS_TIMEOUT: Duration = Duration::from_secs(3);
161
162 /// The amount of time we wait for a hairpinned packet to come back.
163 pub(crate) const HAIRPIN_CHECK_TIMEOUT: Duration = Duration::from_millis(100);
164
165 /// Default Pinger timeout
166 pub(crate) const DEFAULT_PINGER_TIMEOUT: Duration = Duration::from_secs(5);
167
168 /// Timeouts specifically used in the iroh-relay
169 pub(crate) mod relay {
170 use super::*;
171
172 /// Timeout used by the relay client while connecting to the relay server,
173 /// using `TcpStream::connect`
174 pub(crate) const DIAL_NODE_TIMEOUT: Duration = Duration::from_millis(1500);
175 /// Timeout for expecting a pong from the relay server
176 pub(crate) const PING_TIMEOUT: Duration = Duration::from_secs(5);
177 /// Timeout for the entire relay connection, which includes dns, dialing
178 /// the server, upgrading the connection, and completing the handshake
179 pub(crate) const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
180 /// Timeout for our async dns resolver
181 pub(crate) const DNS_TIMEOUT: Duration = Duration::from_secs(1);
182
183 /// Maximum time the client will wait to receive on the connection, since
184 /// the last message. Longer than this time and the client will consider
185 /// the connection dead.
186 pub(crate) const CLIENT_RECV_TIMEOUT: Duration = Duration::from_secs(120);
187
188 /// Maximum time the server will attempt to get a successful write to the connection.
189 #[cfg(feature = "iroh-relay")]
190 #[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
191 pub(crate) const SERVER_WRITE_TIMEOUT: Duration = Duration::from_secs(2);
192 }
193}