refactor: rename iroh functions

init_peer_channels() -> init_iroh()
get_or_try_init_peer_channel() -> get_active_or_init_iroh()
get_working_node_addr() -> get_relay_node_addr()
This commit is contained in:
holger krekel
2026-08-29 13:48:51 +02:00
parent 4019ee7ab9
commit 7e2d26f72f
3 changed files with 27 additions and 29 deletions
+2 -2
View File
@@ -1914,9 +1914,9 @@ impl MimeFactory {
}
SystemMessage::IrohNodeAddr => {
let node_addr = context
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await?
.get_working_node_addr()?;
.get_relay_node_addr()?;
// We should not send `null` as relay URL
// as this is the only way to reach the node.
+6 -8
View File
@@ -204,7 +204,7 @@ impl Iroh {
/// Returns the iroh [NodeAddr] with the working relay URL
/// and without direct IP addresses.
pub(crate) fn get_working_node_addr(&self) -> Result<NodeAddr> {
pub(crate) fn get_relay_node_addr(&self) -> Result<NodeAddr> {
let relay_url = self
.working_relay_url
.clone()
@@ -292,7 +292,7 @@ fn downgrade_iroh_write_lock(
impl Context {
/// Create iroh endpoint and gossip.
async fn init_peer_channels(&self) -> Result<Iroh> {
async fn init_iroh(&self) -> Result<Iroh> {
info!(self, "Initializing peer channels.");
// Iroh relays from unpublished transports are not advertised.
let published = published_transports(self).await?;
@@ -372,9 +372,7 @@ impl Context {
}
/// Get or initialize the iroh peer channel.
pub async fn get_or_try_init_peer_channel(
&self,
) -> Result<tokio::sync::RwLockReadGuard<'_, Iroh>> {
pub async fn get_active_or_init_iroh(&self) -> Result<tokio::sync::RwLockReadGuard<'_, Iroh>> {
if !self.get_config_bool(Config::WebxdcRealtimeEnabled).await? {
bail!("Attempt to initialize Iroh when realtime is disabled");
}
@@ -404,7 +402,7 @@ impl Context {
stale.close().await.log_err(self).ok();
}
let iroh = self.init_peer_channels().await?;
let iroh = self.init_iroh().await?;
let mut lock = self.iroh.write().await;
*lock = Some(iroh);
downgrade_iroh_write_lock(lock)
@@ -559,7 +557,7 @@ pub async fn send_webxdc_realtime_advertisement(
// Rendering the message in send_msg() locks `iroh` again,
// so the guard must not be held across it.
let conn = {
let iroh = ctx.get_or_try_init_peer_channel().await?;
let iroh = ctx.get_active_or_init_iroh().await?;
let conn = iroh.join_and_subscribe_gossip(ctx, msg_id).await?;
if iroh.working_relay_url.is_none() {
warn!(ctx, "Not sending realtime advertisement without a relay.");
@@ -584,7 +582,7 @@ pub async fn send_webxdc_realtime_data(ctx: &Context, msg_id: MsgId, data: Vec<u
return Ok(());
}
let iroh = ctx.get_or_try_init_peer_channel().await?;
let iroh = ctx.get_active_or_init_iroh().await?;
iroh.send_webxdc_realtime_data(ctx, msg_id, data).await?;
Ok(())
}
+19 -19
View File
@@ -43,9 +43,9 @@ fn test_relay_probe_url() {
/// Returns the relay of the node address to advertise, if any.
async fn selected_iroh_relay(ctx: &TestContext) -> Result<Option<RelayUrl>> {
let iroh = ctx.get_or_try_init_peer_channel().await?;
let iroh = ctx.get_active_or_init_iroh().await?;
Ok(iroh
.get_working_node_addr()
.get_relay_node_addr()
.ok()
.and_then(|addr| addr.relay_url().cloned()))
}
@@ -137,16 +137,16 @@ async fn test_can_communicate() {
members,
vec![
alice
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await
.unwrap()
.get_working_node_addr()
.get_relay_node_addr()
.unwrap()
.node_id
]
);
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.join_and_subscribe_gossip(bob, bob_webxdc.id)
@@ -158,7 +158,7 @@ async fn test_can_communicate() {
// Alice sends ephemeral message
alice
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await
.unwrap()
.send_webxdc_realtime_data(alice, alice_webxdc.id, "alice -> bob".as_bytes().to_vec())
@@ -179,7 +179,7 @@ async fn test_can_communicate() {
}
}
// Bob sends ephemeral message
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.send_webxdc_realtime_data(bob, bob_webxdc.id, "bob -> alice".as_bytes().to_vec())
@@ -211,16 +211,16 @@ async fn test_can_communicate() {
assert_eq!(
members,
vec![
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.get_working_node_addr()
.get_relay_node_addr()
.unwrap()
.node_id
]
);
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.send_webxdc_realtime_data(bob, bob_webxdc.id, "bob -> alice 2".as_bytes().to_vec())
@@ -297,10 +297,10 @@ async fn test_duplicated_out_of_order_advertisement() -> Result<()> {
members,
vec![
alice
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await
.unwrap()
.get_working_node_addr()
.get_relay_node_addr()
.unwrap()
.node_id
]
@@ -362,16 +362,16 @@ async fn test_can_reconnect() {
members,
vec![
alice
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await
.unwrap()
.get_working_node_addr()
.get_relay_node_addr()
.unwrap()
.node_id
]
);
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.join_and_subscribe_gossip(bob, bob_webxdc.id)
@@ -383,7 +383,7 @@ async fn test_can_reconnect() {
// Alice sends ephemeral message
alice
.get_or_try_init_peer_channel()
.get_active_or_init_iroh()
.await
.unwrap()
.send_webxdc_realtime_data(alice, alice_webxdc.id, "alice -> bob".as_bytes().to_vec())
@@ -432,7 +432,7 @@ async fn test_can_reconnect() {
// Check that sequence number is persisted when leaving the channel.
assert_eq!(bob_sequence_number, bob_sequence_number_after);
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.join_and_subscribe_gossip(bob, bob_webxdc.id)
@@ -442,7 +442,7 @@ async fn test_can_reconnect() {
.await
.unwrap();
bob.get_or_try_init_peer_channel()
bob.get_active_or_init_iroh()
.await
.unwrap()
.send_webxdc_realtime_data(bob, bob_webxdc.id, "bob -> alice".as_bytes().to_vec())
@@ -690,7 +690,7 @@ async fn test_peer_channels_disabled() {
// This internal function should return error
// if accidentally called with the setting disabled.
assert!(alice.ctx.get_or_try_init_peer_channel().await.is_err());
assert!(alice.ctx.get_active_or_init_iroh().await.is_err());
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]