@@ -18,7 +18,7 @@ use snafu::GenerateImplicitData;
1818use tokio:: sync:: RwLock ;
1919use tracing:: { debug, error, warn} ;
2020
21- use crate :: addr:: { NodeAddr , SocketAddrV4 , SocketAddrV6 , Url } ;
21+ use crate :: addr:: { NodeAddr , SocketAddrV4 , SocketAddrV6 } ;
2222use crate :: key:: { secret_key_generate, PublicKey , SecretKey } ;
2323use crate :: stream:: { RecvStream , SendStream } ;
2424use crate :: util:: TOKIO_EXECUTOR ;
@@ -318,7 +318,7 @@ fn make_dns_discovery(secret_key: &iroh::SecretKey) -> Vec<Box<dyn Discovery>> {
318318}
319319
320320fn make_mdns_discovery ( node_id : NodeId , advertise : bool ) -> Option < Box < dyn Discovery > > {
321- match MdnsDiscovery :: new ( node_id , advertise) {
321+ match MdnsDiscovery :: builder ( ) . advertise ( advertise ) . build ( node_id ) {
322322 Err ( e) => {
323323 error ! ( "unable to start MdnsDiscovery service: {e:?}" ) ;
324324 None
@@ -985,9 +985,7 @@ pub fn endpoint_node_addr(ep: &repr_c::Box<Endpoint>, out: &mut NodeAddr) -> End
985985 . await
986986 . as_ref ( )
987987 . expect ( "endpoint not initialized" )
988- . node_addr ( )
989- . initialized ( )
990- . await ;
988+ . node_addr ( ) ;
991989 anyhow:: Ok ( addr)
992990 } ) ;
993991
@@ -1003,30 +1001,32 @@ pub fn endpoint_node_addr(ep: &repr_c::Box<Endpoint>, out: &mut NodeAddr) -> End
10031001 }
10041002}
10051003
1006- /// Get the home relay of this iroh endpoint.
1004+ /// Returns once the endpoint is online.
1005+ ///
1006+ /// We are considered online if we have a home relay and at least one
1007+ /// direct address.
1008+ ///
1009+ /// Will block at most `timeout` milliseconds.
10071010#[ ffi_export]
1008- pub fn endpoint_home_relay ( ep : & repr_c:: Box < Endpoint > , out : & mut Url ) -> EndpointResult {
1011+ pub fn endpoint_online ( ep : & repr_c:: Box < Endpoint > , timeout_ms : u64 ) -> EndpointResult {
1012+ let timeout = Duration :: from_millis ( timeout_ms) ;
10091013 let res = TOKIO_EXECUTOR . block_on ( async move {
1010- let relay_url = ep
1011- . ep
1012- . read ( )
1013- . await
1014- . as_ref ( )
1015- . expect ( "endpoint not initialized" )
1016- . home_relay ( )
1017- . initialized ( )
1018- . await ;
1019- anyhow :: Ok ( relay_url )
1014+ tokio :: time :: timeout ( timeout , async move {
1015+ ep . ep
1016+ . read ( )
1017+ . await
1018+ . as_ref ( )
1019+ . expect ( "endpoint not initialized" )
1020+ . online ( )
1021+ . await ;
1022+ } )
1023+ . await
10201024 } ) ;
1021-
10221025 match res {
1023- Ok ( relay_url) => {
1024- * out = relay_url. into ( ) ;
1025- EndpointResult :: Ok
1026- }
1027- Err ( err) => {
1028- warn ! ( "failed to retrieve relay_url: {err:?}" ) ;
1029- EndpointResult :: AddrError
1026+ Ok ( ( ) ) => EndpointResult :: Ok ,
1027+ Err ( _err) => {
1028+ warn ! ( "online failed timeout" ) ;
1029+ EndpointResult :: Timeout
10301030 }
10311031 }
10321032}
0 commit comments