From 080ddde68db9ce86dc73a4f0a027b8aea34c390b Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 3 Oct 2025 19:01:16 +0000 Subject: [PATCH] refactor: assert that Iroh node addresses have home relay URL With newer Iroh it is possible to obtain own node address before home relay is selected and accidentally send own address without relay URL. It took me some time to debug why Iroh 0.92.0 did not work with iroh-relay 0.92.0 so I'm adding these assertions even while we still use Iroh 0.35.0. --- src/headerdef.rs | 5 +++++ src/mimefactory.rs | 19 +++++++++++-------- src/peer_channels.rs | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/headerdef.rs b/src/headerdef.rs index 1669c91c1..8102bcb81 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -119,6 +119,11 @@ pub enum HeaderDef { AuthenticationResults, /// Node address from iroh where direct addresses have been removed. + /// + /// The node address sent in this header must have + /// a non-null relay URL as contacting home relay + /// is the only way to reach the node without + /// direct addresses and global discovery. IrohNodeAddr, /// Advertised gossip topic for one webxdc. diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 59da34031..cefab8476 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1522,16 +1522,19 @@ impl MimeFactory { )); } SystemMessage::IrohNodeAddr => { + let node_addr = context + .get_or_try_init_peer_channel() + .await? + .get_node_addr() + .await?; + + // We should not send `null` as relay URL + // as this is the only way to reach the node. + debug_assert!(node_addr.relay_url().is_some()); headers.push(( HeaderDef::IrohNodeAddr.into(), - mail_builder::headers::text::Text::new(serde_json::to_string( - &context - .get_or_try_init_peer_channel() - .await? - .get_node_addr() - .await?, - )?) - .into(), + mail_builder::headers::text::Text::new(serde_json::to_string(&node_addr)?) + .into(), )); } SystemMessage::CallAccepted => { diff --git a/src/peer_channels.rs b/src/peer_channels.rs index 0299affad..c74a4d695 100644 --- a/src/peer_channels.rs +++ b/src/peer_channels.rs @@ -185,9 +185,14 @@ impl Iroh { } /// Get the iroh [NodeAddr] without direct IP addresses. + /// + /// The address is guaranteed to have home relay URL set + /// as it is the only way to reach the node + /// without global discovery mechanisms. pub(crate) async fn get_node_addr(&self) -> Result { let mut addr = self.router.endpoint().node_addr().await?; addr.direct_addresses = BTreeSet::new(); + debug_assert!(addr.relay_url().is_some()); Ok(addr) }