diff --git a/iroh-base/src/relay_map.rs b/iroh-base/src/relay_map.rs index 567644ff3f..29c9d43291 100644 --- a/iroh-base/src/relay_map.rs +++ b/iroh-base/src/relay_map.rs @@ -77,7 +77,7 @@ impl RelayMap { url, stun_only: false, stun_port, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } .into(), ); @@ -133,15 +133,31 @@ pub struct RelayNode { /// /// Setting this to `0` means the default STUN port is used. pub stun_port: u16, - /// The QUIC endpoint port of the relay server. + /// Configuration to speak to the QUIC endpoint on the relay server. /// - /// Setting this to `0` means the default QUIC port is used. - #[serde(default = "quic_port")] - pub quic_port: u16, + /// When `None`, we will not attempt to do QUIC address discovery + /// with this relay server. + #[serde(default = "quic_config")] + pub quic: Option, } -fn quic_port() -> u16 { - DEFAULT_QUIC_PORT +fn quic_config() -> Option { + Some(QuicConfig::default()) +} + +/// Configuration for speaking to the QUIC endpoint on the relay +/// server to do QUIC address discovery. +#[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq, PartialOrd, Ord)] +pub struct QuicConfig { + pub port: u16, +} + +impl Default for QuicConfig { + fn default() -> Self { + Self { + port: DEFAULT_QUIC_PORT, + } + } } impl fmt::Display for RelayNode { diff --git a/iroh-net-report/src/lib.rs b/iroh-net-report/src/lib.rs index bed60d04fb..0c0f8fc754 100644 --- a/iroh-net-report/src/lib.rs +++ b/iroh-net-report/src/lib.rs @@ -783,6 +783,7 @@ mod test_utils { use std::sync::Arc; + use iroh_base::relay_map::QuicConfig; use iroh_relay::server; use crate::RelayNode; @@ -791,14 +792,14 @@ mod test_utils { let server = server::Server::spawn(server::testing::server_config()) .await .expect("should serve relay"); + let quic = Some(QuicConfig { + port: server.quic_addr().expect("server sould run quic").port(), + }); let node_desc = RelayNode { url: server.https_url().expect("should work as relay"), stun_only: false, // the checks above and below guarantee both stun and relay stun_port: server.stun_addr().expect("server should serve stun").port(), - quic_port: server - .quic_addr() - .expect("server should server_stun") - .port(), + quic, }; (server, Arc::new(node_desc)) @@ -883,7 +884,7 @@ mod tests { url, stun_port: port, stun_only, - quic_port: 0, + quic: None, } }); RelayMap::from_nodes(nodes).expect("generated invalid nodes") diff --git a/iroh-net/src/defaults.rs b/iroh-net/src/defaults.rs index 1eb16e9f19..d5d43590de 100644 --- a/iroh-net/src/defaults.rs +++ b/iroh-net/src/defaults.rs @@ -1,5 +1,6 @@ //! Default values used in [`iroh-net`][`crate`] +use iroh_base::relay_map::QuicConfig; /// The default QUIC port used by the Relay server to accept QUIC connections /// for QUIC address discovery /// @@ -25,6 +26,8 @@ pub const DEFAULT_METRICS_PORT: u16 = 9090; /// Production configuration. pub mod prod { + use iroh_base::relay_map::QuicConfig; + use super::*; /// Hostname of the default NA relay. @@ -54,7 +57,7 @@ pub mod prod { url: url.into(), stun_only: false, stun_port: DEFAULT_STUN_PORT, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } } @@ -68,7 +71,7 @@ pub mod prod { url: url.into(), stun_only: false, stun_port: DEFAULT_STUN_PORT, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } } @@ -82,7 +85,7 @@ pub mod prod { url: url.into(), stun_only: false, stun_port: DEFAULT_STUN_PORT, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } } } @@ -116,7 +119,7 @@ pub mod staging { url: url.into(), stun_only: false, stun_port: DEFAULT_STUN_PORT, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } } @@ -130,7 +133,7 @@ pub mod staging { url: url.into(), stun_only: false, stun_port: DEFAULT_STUN_PORT, - quic_port: DEFAULT_QUIC_PORT, + quic: Some(QuicConfig::default()), } } } diff --git a/iroh-net/src/test_utils.rs b/iroh-net/src/test_utils.rs index 4e392a1de2..cb87a51aad 100644 --- a/iroh-net/src/test_utils.rs +++ b/iroh-net/src/test_utils.rs @@ -92,11 +92,14 @@ pub async fn run_relay_server_with( let url: RelayUrl = format!("https://{}", server.https_addr().expect("configured")) .parse() .unwrap(); + let quic = Some(iroh_base::relay_map::QuicConfig { + port: server.quic_addr().map_or(DEFAULT_QUIC_PORT, |s| s.port()), + }); let m = RelayMap::from_nodes([RelayNode { url: url.clone(), stun_only: false, stun_port: server.stun_addr().map_or(DEFAULT_STUN_PORT, |s| s.port()), - quic_port: server.quic_addr().map_or(DEFAULT_QUIC_PORT, |s| s.port()), + quic, }]) .unwrap(); Ok((m, url, server))