Skip to content

fix: Endpoint::node_addr completes with direct addrs or relay ready #3190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion iroh/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeAddr> {
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(),
Expand Down Expand Up @@ -2308,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 {:?}",
Expand Down
Loading