@@ -137,17 +137,13 @@ impl Iroh {
137
137
Ok ( Some ( join_rx) )
138
138
}
139
139
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 < ( ) > {
142
142
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 ( ) ) ?;
146
144
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] ) ) ;
151
147
}
152
148
Ok ( ( ) )
153
149
}
@@ -315,6 +311,14 @@ impl Context {
315
311
}
316
312
}
317
313
}
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
+ }
318
322
}
319
323
320
324
/// Cache a peers [NodeId] for one topic.
@@ -335,6 +339,7 @@ pub(crate) async fn iroh_add_peer_for_topic(
335
339
}
336
340
337
341
/// 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.
338
343
pub async fn add_gossip_peer_from_header (
339
344
context : & Context ,
340
345
instance_id : MsgId ,
@@ -370,8 +375,7 @@ pub async fn add_gossip_peer_from_header(
370
375
let relay_server = node_addr. relay_url ( ) . map ( |relay| relay. as_str ( ) ) ;
371
376
iroh_add_peer_for_topic ( context, instance_id, topic, node_id, relay_server) . await ?;
372
377
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 ?;
375
379
Ok ( ( ) )
376
380
}
377
381
0 commit comments