iroh/
defaults.rs

1//! Default values used in [`iroh`][`crate`]
2
3/// The default QUIC port used by the Relay server to accept QUIC connections
4/// for QUIC address discovery
5///
6/// The port is "QUIC" typed on a phone keypad.
7pub use iroh_relay::defaults::DEFAULT_RELAY_QUIC_PORT;
8use url::Url;
9
10/// The default HTTP port used by the Relay server.
11pub const DEFAULT_HTTP_PORT: u16 = 80;
12
13/// The default HTTPS port used by the Relay server.
14pub const DEFAULT_HTTPS_PORT: u16 = 443;
15
16/// The default metrics port used by the Relay server.
17pub const DEFAULT_METRICS_PORT: u16 = 9090;
18
19/// Production configuration.
20pub mod prod {
21    use iroh_relay::{RelayConfig, RelayMap};
22
23    use super::*;
24    use crate::RelayUrl;
25
26    /// Hostname of the default NA east relay.
27    pub const NA_EAST_RELAY_HOSTNAME: &str = "use1-1.relay.n0.iroh.link.";
28    /// Hostname of the default NA west relay.
29    pub const NA_WEST_RELAY_HOSTNAME: &str = "usw1-1.relay.n0.iroh.link.";
30    /// Hostname of the default EU relay.
31    pub const EU_RELAY_HOSTNAME: &str = "euc1-1.relay.n0.iroh.link.";
32    /// Hostname of the default Asia-Pacific relay.
33    pub const AP_RELAY_HOSTNAME: &str = "aps1-1.relay.n0.iroh.link.";
34
35    /// Get the default [`RelayMap`].
36    pub fn default_relay_map() -> RelayMap {
37        RelayMap::from_iter([
38            default_na_east_relay(),
39            default_na_west_relay(),
40            default_eu_relay(),
41            default_ap_relay(),
42        ])
43    }
44
45    /// Get the default [`RelayConfig`] for NA east.
46    pub fn default_na_east_relay() -> RelayConfig {
47        // The default NA east relay server run by number0.
48        let url: Url = format!("https://{NA_EAST_RELAY_HOSTNAME}")
49            .parse()
50            .expect("default url");
51        RelayConfig::from(RelayUrl::from(url))
52    }
53
54    /// Get the default [`RelayConfig`] for NA west.
55    pub fn default_na_west_relay() -> RelayConfig {
56        // The default NA west relay server run by number0.
57        let url: Url = format!("https://{NA_WEST_RELAY_HOSTNAME}")
58            .parse()
59            .expect("default url");
60        RelayConfig::from(RelayUrl::from(url))
61    }
62
63    /// Get the default [`RelayConfig`] for EU.
64    pub fn default_eu_relay() -> RelayConfig {
65        // The default EU relay server run by number0.
66        let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
67            .parse()
68            .expect("default_url");
69        RelayConfig::from(RelayUrl::from(url))
70    }
71
72    /// Get the default [`RelayConfig`] for Asia-Pacific.
73    pub fn default_ap_relay() -> RelayConfig {
74        // The default Asia-Pacific relay server run by number0.
75        let url: Url = format!("https://{AP_RELAY_HOSTNAME}")
76            .parse()
77            .expect("default_url");
78        RelayConfig::from(RelayUrl::from(url))
79    }
80}
81
82/// Staging configuration.
83///
84/// Used by tests and might have incompatible changes deployed
85///
86/// Note: we have staging servers in EU and NA, but no corresponding staging server for AP at this time.
87pub mod staging {
88    use iroh_relay::{RelayConfig, RelayMap};
89
90    use super::*;
91    use crate::RelayUrl;
92
93    /// Hostname of the default NA relay.
94    pub const NA_EAST_RELAY_HOSTNAME: &str = "use1-1.staging-relay.n0.iroh.link.";
95    /// Hostname of the default EU relay.
96    pub const EU_RELAY_HOSTNAME: &str = "euc1-1.staging-relay.n0.iroh.link.";
97
98    /// Get the default [`RelayMap`].
99    pub fn default_relay_map() -> RelayMap {
100        RelayMap::from_iter([default_na_east_relay(), default_eu_relay()])
101    }
102
103    /// Get the default [`RelayConfig`] for NA east.
104    pub fn default_na_east_relay() -> RelayConfig {
105        // The default NA east relay server run by number0.
106        let url: Url = format!("https://{NA_EAST_RELAY_HOSTNAME}")
107            .parse()
108            .expect("default url");
109        RelayConfig::from(RelayUrl::from(url))
110    }
111
112    /// Get the default [`RelayConfig`] for EU.
113    pub fn default_eu_relay() -> RelayConfig {
114        // The default EU relay server run by number0.
115        let url: Url = format!("https://{EU_RELAY_HOSTNAME}")
116            .parse()
117            .expect("default_url");
118        RelayConfig::from(RelayUrl::from(url))
119    }
120}
121
122/// Contains all timeouts that we use in `iroh`.
123pub(crate) mod timeouts {
124    use n0_future::time::Duration;
125
126    // Timeouts for net_report
127
128    /// Maximum duration to wait for a net_report.
129    pub(crate) const NET_REPORT_TIMEOUT: Duration = Duration::from_secs(10);
130}
131
132#[cfg(test)]
133pub(crate) mod tests {
134    use std::time::Duration;
135
136    use n0_tracing_test::traced_test;
137
138    use super::staging::NA_EAST_RELAY_HOSTNAME;
139    use crate::dns::DnsResolver;
140
141    const TIMEOUT: Duration = Duration::from_secs(5);
142    const STAGGERING_DELAYS: &[u64] = &[200, 300];
143
144    #[tokio::test]
145    #[traced_test]
146    async fn test_dns_lookup_ipv4_ipv6() {
147        let resolver = DnsResolver::new();
148        let res: Vec<_> = resolver
149            .lookup_ipv4_ipv6_staggered(NA_EAST_RELAY_HOSTNAME, TIMEOUT, STAGGERING_DELAYS)
150            .await
151            .unwrap()
152            .collect();
153        assert!(!res.is_empty());
154        dbg!(res);
155    }
156}