Skip to content

Commit 833e60d

Browse files
authored
chore: release prep (#55)
Updates the following dependencies: - `iroh` - `iroh-base`
1 parent fb24b05 commit 833e60d

File tree

5 files changed

+51
-43
lines changed

5 files changed

+51
-43
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ required-features = ["headers"] # Do not build unless generating headers.
1919
[dependencies]
2020
anyhow = "1"
2121
bytes = "1.10"
22-
iroh = { version = "0.92", features = ["discovery-local-network"] }
23-
iroh-base = { version = "0.92", features = ["ticket"] }
22+
iroh = { version = "0.93", features = ["discovery-local-network"] }
23+
iroh-base = { version = "0.93", features = ["ticket"] }
2424
once_cell = "1.21"
25-
rand = "0.8"
25+
rand = "0.9.2"
2626
safer-ffi = { version = "0.1.13" }
2727
socket2 = "0.5.10"
2828
tokio = { version = "1.45.1", features = ["rt-multi-thread"] }

irohnet.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,6 @@ void
634634
endpoint_free (
635635
Endpoint_t * ep);
636636

637-
/** \brief
638-
* Get the home relay of this iroh endpoint.
639-
*/
640-
EndpointResult_t
641-
endpoint_home_relay (
642-
Endpoint_t * const * ep,
643-
Url_t * out);
644-
645637
/** \brief
646638
* Let the endpoint know that the underlying network conditions might have changed.
647639
*
@@ -660,6 +652,19 @@ endpoint_node_addr (
660652
Endpoint_t * const * ep,
661653
NodeAddr_t * out);
662654

655+
/** \brief
656+
* Returns once the endpoint is online.
657+
*
658+
* We are considered online if we have a home relay and at least one
659+
* direct address.
660+
*
661+
* Will block at most `timeout` milliseconds.
662+
*/
663+
EndpointResult_t
664+
endpoint_online (
665+
Endpoint_t * const * ep,
666+
uint64_t timeout_ms);
667+
663668
/** \brief
664669
* Enables tracing for iroh.
665670
*

main.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ run_server (EndpointConfig_t * config, slice_ref_uint8_t alpn_slice, bool json_o
2525
return -1;
2626
}
2727

28+
// Ensure we are online, waiting 5 seconds max
29+
int timeout_res = endpoint_online(&ep, 5000);
30+
if (timeout_res != 0) {
31+
fprintf(stderr, "failed to get a home relay\n");
32+
return -1;
33+
}
34+
2835
// Print details
2936
NodeAddr_t node_addr = node_addr_default();
3037
int addr_res = endpoint_node_addr(&ep, &node_addr);
@@ -35,11 +42,7 @@ run_server (EndpointConfig_t * config, slice_ref_uint8_t alpn_slice, bool json_o
3542
char * node_id_str = public_key_as_base32(&node_addr.node_id);
3643

3744
Url_t * relay_url = url_default();
38-
int relay_url_res = endpoint_home_relay(&ep, relay_url);
39-
if (relay_url_res != 0) {
40-
fprintf(stderr, "failed to get my home relay");
41-
return -1;
42-
}
45+
relay_url = node_addr.relay_url;
4346

4447
char * relay_url_str = url_as_str(relay_url);
4548

src/endpoint.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use snafu::GenerateImplicitData;
1818
use tokio::sync::RwLock;
1919
use tracing::{debug, error, warn};
2020

21-
use crate::addr::{NodeAddr, SocketAddrV4, SocketAddrV6, Url};
21+
use crate::addr::{NodeAddr, SocketAddrV4, SocketAddrV6};
2222
use crate::key::{secret_key_generate, PublicKey, SecretKey};
2323
use crate::stream::{RecvStream, SendStream};
2424
use crate::util::TOKIO_EXECUTOR;
@@ -318,7 +318,7 @@ fn make_dns_discovery(secret_key: &iroh::SecretKey) -> Vec<Box<dyn Discovery>> {
318318
}
319319

320320
fn 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
}

src/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn secret_key_free(key: repr_c::Box<SecretKey>) {
9797
#[ffi_export]
9898
pub fn secret_key_default() -> repr_c::Box<SecretKey> {
9999
Box::new(SecretKey {
100-
key: iroh::SecretKey::generate(rand::rngs::OsRng),
100+
key: iroh::SecretKey::generate(&mut rand::rng()),
101101
})
102102
.into()
103103
}
@@ -125,7 +125,7 @@ pub fn secret_key_from_base32(
125125
#[ffi_export]
126126
pub fn secret_key_generate() -> repr_c::Box<SecretKey> {
127127
Box::new(SecretKey {
128-
key: iroh::SecretKey::generate(rand::rngs::OsRng),
128+
key: iroh::SecretKey::generate(&mut rand::rng()),
129129
})
130130
.into()
131131
}

0 commit comments

Comments
 (0)