Skip to content

Commit 329bbba

Browse files
committed
don't start iroh when adding peers late
1 parent 2272c9c commit 329bbba

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/peer_channels.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,13 @@ impl Iroh {
138138
Ok(Some(join_rx))
139139
}
140140

141-
/// Add gossip peers to realtime channel if it is already active.
142-
pub async fn maybe_add_gossip_peers(&self, topic: TopicId, peers: Vec<NodeAddr>) -> Result<()> {
141+
/// Add gossip peer to realtime channel if it is already active.
142+
pub async fn maybe_add_gossip_peer(&self, topic: TopicId, peer: NodeAddr) -> Result<()> {
143143
if self.iroh_channels.read().await.get(&topic).is_some() {
144-
for peer in &peers {
145-
self.router.endpoint().add_node_addr(peer.clone())?;
146-
}
144+
self.router.endpoint().add_node_addr(peer.clone())?;
147145

148-
self.gossip.subscribe_with_opts(
149-
topic,
150-
JoinOptions::with_bootstrap(peers.into_iter().map(|peer| peer.node_id)),
151-
);
146+
self.gossip
147+
.subscribe_with_opts(topic, JoinOptions::with_bootstrap(vec![peer.node_id]));
152148
}
153149
Ok(())
154150
}
@@ -316,6 +312,14 @@ impl Context {
316312
}
317313
}
318314
}
315+
316+
pub(crate) async fn maybe_add_gossip_peer(&self, topic: TopicId, peer: NodeAddr) -> Result<()> {
317+
if let Some(iroh) = &*self.iroh.read().await {
318+
info!(self, "Adding (maybe existing) peer to gossip: {peer:?}");
319+
iroh.maybe_add_gossip_peer(topic, peer).await?;
320+
}
321+
Ok(())
322+
}
319323
}
320324

321325
/// Cache a peers [NodeId] for one topic.
@@ -336,6 +340,7 @@ pub(crate) async fn iroh_add_peer_for_topic(
336340
}
337341

338342
/// Add gossip peer from `Iroh-Node-Addr` header to WebXDC message identified by `instance_id`.
343+
/// This should not start iroh, because receiving a NodeAddr does not mean you want to participate.
339344
pub async fn add_gossip_peer_from_header(
340345
context: &Context,
341346
instance_id: MsgId,
@@ -371,8 +376,7 @@ pub async fn add_gossip_peer_from_header(
371376
let relay_server = node_addr.relay_url().map(|relay| relay.as_str());
372377
iroh_add_peer_for_topic(context, instance_id, topic, node_id, relay_server).await?;
373378

374-
let iroh = context.get_or_try_init_peer_channel().await?;
375-
iroh.maybe_add_gossip_peers(topic, vec![node_addr]).await?;
379+
context.maybe_add_gossip_peer(topic, node_addr).await?;
376380
Ok(())
377381
}
378382

0 commit comments

Comments
 (0)