Skip to content

Commit 081d99b

Browse files
committed
don't start iroh when adding peers late
1 parent 93b737e commit 081d99b

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
@@ -137,17 +137,13 @@ impl Iroh {
137137
Ok(Some(join_rx))
138138
}
139139

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

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

320324
/// Cache a peers [NodeId] for one topic.
@@ -335,6 +339,7 @@ pub(crate) async fn iroh_add_peer_for_topic(
335339
}
336340

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

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

0 commit comments

Comments
 (0)