@@ -37,6 +37,7 @@ use iroh_net::derp::DerpUrl;
37
37
use iroh_net:: magic_endpoint:: get_alpn;
38
38
use iroh_net:: magicsock:: LocalEndpointsStream ;
39
39
use iroh_net:: util:: AbortingJoinHandle ;
40
+ use iroh_net:: magicsock:: Discovery ;
40
41
use iroh_net:: {
41
42
derp:: DerpMode ,
42
43
key:: { PublicKey , SecretKey } ,
@@ -135,6 +136,8 @@ where
135
136
docs : S ,
136
137
/// Path to store peer data. If `None`, peer data will not be persisted.
137
138
peers_data_path : Option < PathBuf > ,
139
+ /// Discovery service to retreive node dialing info.
140
+ node_discovery : Option < Box < dyn Discovery > > ,
138
141
}
139
142
140
143
const PROTOCOLS : [ & [ u8 ] ; 3 ] = [ & iroh_bytes:: protocol:: ALPN , GOSSIP_ALPN , SYNC_ALPN ] ;
@@ -153,6 +156,7 @@ impl<D: Map, S: DocStore> Builder<D, S> {
153
156
rt : None ,
154
157
docs,
155
158
peers_data_path : None ,
159
+ node_discovery : None ,
156
160
}
157
161
}
158
162
}
@@ -180,6 +184,7 @@ where
180
184
rt : self . rt ,
181
185
docs : self . docs ,
182
186
peers_data_path : self . peers_data_path ,
187
+ node_discovery : self . node_discovery ,
183
188
}
184
189
}
185
190
@@ -243,6 +248,14 @@ where
243
248
self
244
249
}
245
250
251
+ /// Sets the node discovery service.
252
+ ///
253
+ /// If not set, nodes without direct or derp addresses will not be dialable.
254
+ pub fn node_discovery ( mut self , discovery : Box < dyn Discovery > ) -> Self {
255
+ self . node_discovery = Some ( discovery) ;
256
+ self
257
+ }
258
+
246
259
/// Spawns the [`Node`] in a tokio task.
247
260
///
248
261
/// This will create the underlying network server and spawn a tokio task accepting
@@ -274,6 +287,10 @@ where
274
287
. transport_config ( transport_config)
275
288
. concurrent_connections ( MAX_CONNECTIONS )
276
289
. derp_mode ( self . derp_mode ) ;
290
+ let endpoint = match self . node_discovery {
291
+ Some ( discovery) => endpoint. discovery ( discovery) ,
292
+ None => endpoint
293
+ } ;
277
294
let endpoint = match self . peers_data_path {
278
295
Some ( path) => endpoint. peers_data_path ( path) ,
279
296
None => endpoint,
0 commit comments