Skip to content

Commit 080ddde

Browse files
committed
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.
1 parent 209a802 commit 080ddde

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/headerdef.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ pub enum HeaderDef {
119119
AuthenticationResults,
120120

121121
/// Node address from iroh where direct addresses have been removed.
122+
///
123+
/// The node address sent in this header must have
124+
/// a non-null relay URL as contacting home relay
125+
/// is the only way to reach the node without
126+
/// direct addresses and global discovery.
122127
IrohNodeAddr,
123128

124129
/// Advertised gossip topic for one webxdc.

src/mimefactory.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,16 +1522,19 @@ impl MimeFactory {
15221522
));
15231523
}
15241524
SystemMessage::IrohNodeAddr => {
1525+
let node_addr = context
1526+
.get_or_try_init_peer_channel()
1527+
.await?
1528+
.get_node_addr()
1529+
.await?;
1530+
1531+
// We should not send `null` as relay URL
1532+
// as this is the only way to reach the node.
1533+
debug_assert!(node_addr.relay_url().is_some());
15251534
headers.push((
15261535
HeaderDef::IrohNodeAddr.into(),
1527-
mail_builder::headers::text::Text::new(serde_json::to_string(
1528-
&context
1529-
.get_or_try_init_peer_channel()
1530-
.await?
1531-
.get_node_addr()
1532-
.await?,
1533-
)?)
1534-
.into(),
1536+
mail_builder::headers::text::Text::new(serde_json::to_string(&node_addr)?)
1537+
.into(),
15351538
));
15361539
}
15371540
SystemMessage::CallAccepted => {

src/peer_channels.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,14 @@ impl Iroh {
185185
}
186186

187187
/// Get the iroh [NodeAddr] without direct IP addresses.
188+
///
189+
/// The address is guaranteed to have home relay URL set
190+
/// as it is the only way to reach the node
191+
/// without global discovery mechanisms.
188192
pub(crate) async fn get_node_addr(&self) -> Result<NodeAddr> {
189193
let mut addr = self.router.endpoint().node_addr().await?;
190194
addr.direct_addresses = BTreeSet::new();
195+
debug_assert!(addr.relay_url().is_some());
191196
Ok(addr)
192197
}
193198

0 commit comments

Comments
 (0)