@@ -138,17 +138,13 @@ impl Iroh {
138
138
Ok ( Some ( join_rx) )
139
139
}
140
140
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 < ( ) > {
143
143
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 ( ) ) ?;
147
145
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] ) ) ;
152
148
}
153
149
Ok ( ( ) )
154
150
}
@@ -316,6 +312,14 @@ impl Context {
316
312
}
317
313
}
318
314
}
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
+ }
319
323
}
320
324
321
325
/// Cache a peers [NodeId] for one topic.
@@ -336,6 +340,7 @@ pub(crate) async fn iroh_add_peer_for_topic(
336
340
}
337
341
338
342
/// 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.
339
344
pub async fn add_gossip_peer_from_header (
340
345
context : & Context ,
341
346
instance_id : MsgId ,
@@ -371,8 +376,7 @@ pub async fn add_gossip_peer_from_header(
371
376
let relay_server = node_addr. relay_url ( ) . map ( |relay| relay. as_str ( ) ) ;
372
377
iroh_add_peer_for_topic ( context, instance_id, topic, node_id, relay_server) . await ?;
373
378
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 ?;
376
380
Ok ( ( ) )
377
381
}
378
382
0 commit comments