Skip to content

Commit 355a992

Browse files
committed
fix: Endpoint::node_addr completes with direct addrs or relay ready
1 parent 3e3798f commit 355a992

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

iroh/src/endpoint.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use anyhow::{bail, Context, Result};
2525
use data_encoding::BASE32_DNSSEC;
2626
use iroh_base::{NodeAddr, NodeId, RelayUrl, SecretKey};
2727
use iroh_relay::RelayMap;
28-
use n0_future::time::Duration;
28+
use n0_future::{time::Duration, FutureExt};
2929
use pin_project::pin_project;
3030
use tracing::{debug, instrument, trace, warn};
3131
use url::Url;
@@ -836,8 +836,17 @@ impl Endpoint {
836836
/// The returned [`NodeAddr`] will have the current [`RelayUrl`] and direct addresses
837837
/// as they would be returned by [`Endpoint::home_relay`] and
838838
/// [`Endpoint::direct_addresses`].
839+
///
840+
/// This function is async because it waits for either the node's direct addresses
841+
/// or the node's home relay are initialized.
839842
pub async fn node_addr(&self) -> Result<NodeAddr> {
840-
let addrs = self.direct_addresses().initialized().await?;
843+
// Wait for either the home relay or the direct addresses to be ready.
844+
n0_future::future::race(
845+
async { self.direct_addresses().initialized().await.map(|_| ()) },
846+
async { self.home_relay().initialized().await.map(|_| ()) },
847+
)
848+
.await?;
849+
let addrs = self.direct_addresses().get()?.unwrap_or_default();
841850
let relay = self.home_relay().get()?;
842851
Ok(NodeAddr::from_parts(
843852
self.node_id(),

0 commit comments

Comments
 (0)