@@ -25,7 +25,7 @@ use anyhow::{bail, Context, Result};
25
25
use data_encoding:: BASE32_DNSSEC ;
26
26
use iroh_base:: { NodeAddr , NodeId , RelayUrl , SecretKey } ;
27
27
use iroh_relay:: RelayMap ;
28
- use n0_future:: time:: Duration ;
28
+ use n0_future:: { time:: Duration , FutureExt } ;
29
29
use pin_project:: pin_project;
30
30
use tracing:: { debug, instrument, trace, warn} ;
31
31
use url:: Url ;
@@ -836,8 +836,17 @@ impl Endpoint {
836
836
/// The returned [`NodeAddr`] will have the current [`RelayUrl`] and direct addresses
837
837
/// as they would be returned by [`Endpoint::home_relay`] and
838
838
/// [`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.
839
842
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 ( ) ;
841
850
let relay = self . home_relay ( ) . get ( ) ?;
842
851
Ok ( NodeAddr :: from_parts (
843
852
self . node_id ( ) ,
0 commit comments