From e044fcd7a4182d3bde7ba258108967fc0c0e1864 Mon Sep 17 00:00:00 2001 From: Frando Date: Wed, 19 Feb 2025 11:35:55 +0100 Subject: [PATCH 1/2] fix: Endpoint::node_addr completes with direct addrs or relay ready --- iroh/src/endpoint.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index 3654ad3fcb..9024d15474 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -836,8 +836,17 @@ impl Endpoint { /// The returned [`NodeAddr`] will have the current [`RelayUrl`] and direct addresses /// as they would be returned by [`Endpoint::home_relay`] and /// [`Endpoint::direct_addresses`]. + /// + /// This function is async because it waits for either the node's direct addresses + /// or the node's home relay are initialized. pub async fn node_addr(&self) -> Result { - let addrs = self.direct_addresses().initialized().await?; + // Wait for either the home relay or the direct addresses to be ready. + n0_future::future::race( + async { self.direct_addresses().initialized().await.map(|_| ()) }, + async { self.home_relay().initialized().await.map(|_| ()) }, + ) + .await?; + let addrs = self.direct_addresses().get()?.unwrap_or_default(); let relay = self.home_relay().get()?; Ok(NodeAddr::from_parts( self.node_id(), From 5fa3a1ff119de62d87aa531ca68f634a5d86895d Mon Sep 17 00:00:00 2001 From: Frando Date: Wed, 19 Feb 2025 12:46:00 +0100 Subject: [PATCH 2/2] fix: make conn_type_stream test pass again --- iroh/src/endpoint.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iroh/src/endpoint.rs b/iroh/src/endpoint.rs index 9024d15474..90cb3b0ee3 100644 --- a/iroh/src/endpoint.rs +++ b/iroh/src/endpoint.rs @@ -2317,6 +2317,8 @@ mod tests { let ep1_nodeid = ep1.node_id(); let ep2_nodeid = ep2.node_id(); + // wait for the direct addresses to be initialized. + ep1.direct_addresses().initialized().await.unwrap(); let ep1_nodeaddr = ep1.node_addr().await.unwrap(); tracing::info!( "node id 1 {ep1_nodeid}, relay URL {:?}",