@@ -21,11 +21,8 @@ use iroh_net::{
21
21
relay:: RelayMode ,
22
22
Endpoint ,
23
23
} ;
24
- use quic_rpc:: {
25
- transport:: {
26
- flume:: FlumeServerEndpoint , misc:: DummyServerEndpoint , quinn:: QuinnServerEndpoint ,
27
- } ,
28
- ServiceEndpoint ,
24
+ use quic_rpc:: transport:: {
25
+ boxed:: BoxableServerEndpoint , flume:: FlumeServerEndpoint , quinn:: QuinnServerEndpoint ,
29
26
} ;
30
27
use serde:: { Deserialize , Serialize } ;
31
28
use tokio_util:: { sync:: CancellationToken , task:: LocalPoolHandle } ;
@@ -56,6 +53,11 @@ const DEFAULT_GC_INTERVAL: Duration = Duration::from_secs(60 * 5);
56
53
const MAX_CONNECTIONS : u32 = 1024 ;
57
54
const MAX_STREAMS : u64 = 10 ;
58
55
56
+ type BoxedServerEndpoint = quic_rpc:: transport:: boxed:: ServerEndpoint <
57
+ crate :: rpc_protocol:: Request ,
58
+ crate :: rpc_protocol:: Response ,
59
+ > ;
60
+
59
61
/// Storage backend for documents.
60
62
#[ derive( Debug , Clone ) ]
61
63
pub enum DocsStorage {
@@ -81,15 +83,14 @@ pub enum DocsStorage {
81
83
/// The returned [`Node`] is awaitable to know when it finishes. It can be terminated
82
84
/// using [`Node::shutdown`].
83
85
#[ derive( derive_more:: Debug ) ]
84
- pub struct Builder < D , E = DummyServerEndpoint >
86
+ pub struct Builder < D >
85
87
where
86
88
D : Map ,
87
- E : ServiceEndpoint < RpcService > ,
88
89
{
89
90
storage : StorageConfig ,
90
91
bind_port : Option < u16 > ,
91
92
secret_key : SecretKey ,
92
- rpc_endpoint : E ,
93
+ rpc_endpoint : BoxedServerEndpoint ,
93
94
rpc_port : Option < u16 > ,
94
95
blobs_store : D ,
95
96
keylog : bool ,
@@ -146,6 +147,40 @@ impl From<Box<ConcurrentDiscovery>> for DiscoveryConfig {
146
147
}
147
148
}
148
149
150
+ /// A server endpoint that does nothing. Accept will never resolve.
151
+ ///
152
+ /// This is used unless an external rpc endpoint is configured.
153
+ #[ derive( Debug , Default ) ]
154
+ struct DummyServerEndpoint ;
155
+
156
+ impl BoxableServerEndpoint < crate :: rpc_protocol:: Request , crate :: rpc_protocol:: Response >
157
+ for DummyServerEndpoint
158
+ {
159
+ fn clone_box (
160
+ & self ,
161
+ ) -> Box < dyn BoxableServerEndpoint < crate :: rpc_protocol:: Request , crate :: rpc_protocol:: Response > >
162
+ {
163
+ Box :: new ( DummyServerEndpoint )
164
+ }
165
+
166
+ fn accept_bi_boxed (
167
+ & self ,
168
+ ) -> quic_rpc:: transport:: boxed:: AcceptFuture <
169
+ crate :: rpc_protocol:: Request ,
170
+ crate :: rpc_protocol:: Response ,
171
+ > {
172
+ quic_rpc:: transport:: boxed:: AcceptFuture :: boxed ( futures_lite:: future:: pending ( ) )
173
+ }
174
+
175
+ fn local_addr ( & self ) -> & [ quic_rpc:: transport:: LocalAddr ] {
176
+ & [ ]
177
+ }
178
+ }
179
+
180
+ fn mk_external_rpc ( ) -> BoxedServerEndpoint {
181
+ quic_rpc:: transport:: boxed:: ServerEndpoint :: new ( DummyServerEndpoint )
182
+ }
183
+
149
184
impl Default for Builder < iroh_blobs:: store:: mem:: Store > {
150
185
fn default ( ) -> Self {
151
186
Self {
@@ -156,7 +191,7 @@ impl Default for Builder<iroh_blobs::store::mem::Store> {
156
191
keylog : false ,
157
192
relay_mode : RelayMode :: Default ,
158
193
dns_resolver : None ,
159
- rpc_endpoint : Default :: default ( ) ,
194
+ rpc_endpoint : mk_external_rpc ( ) ,
160
195
rpc_port : None ,
161
196
gc_policy : GcPolicy :: Disabled ,
162
197
docs_storage : DocsStorage :: Memory ,
@@ -183,7 +218,7 @@ impl<D: Map> Builder<D> {
183
218
keylog : false ,
184
219
relay_mode : RelayMode :: Default ,
185
220
dns_resolver : None ,
186
- rpc_endpoint : Default :: default ( ) ,
221
+ rpc_endpoint : mk_external_rpc ( ) ,
187
222
rpc_port : None ,
188
223
gc_policy : GcPolicy :: Disabled ,
189
224
docs_storage,
@@ -195,16 +230,15 @@ impl<D: Map> Builder<D> {
195
230
}
196
231
}
197
232
198
- impl < D , E > Builder < D , E >
233
+ impl < D > Builder < D >
199
234
where
200
235
D : BaoStore ,
201
- E : ServiceEndpoint < RpcService > ,
202
236
{
203
237
/// Persist all node data in the provided directory.
204
238
pub async fn persist (
205
239
self ,
206
240
root : impl AsRef < Path > ,
207
- ) -> Result < Builder < iroh_blobs:: store:: fs:: Store , E > > {
241
+ ) -> Result < Builder < iroh_blobs:: store:: fs:: Store > > {
208
242
let root = root. as_ref ( ) ;
209
243
let blob_dir = IrohPaths :: BaoStoreDir . with_root ( root) ;
210
244
@@ -260,11 +294,7 @@ where
260
294
}
261
295
262
296
/// Configure rpc endpoint, changing the type of the builder to the new endpoint type.
263
- pub fn rpc_endpoint < E2 : ServiceEndpoint < RpcService > > (
264
- self ,
265
- value : E2 ,
266
- port : Option < u16 > ,
267
- ) -> Builder < D , E2 > {
297
+ pub fn rpc_endpoint ( self , value : BoxedServerEndpoint , port : Option < u16 > ) -> Builder < D > {
268
298
// we can't use ..self here because the return type is different
269
299
Builder {
270
300
storage : self . storage ,
@@ -286,8 +316,9 @@ where
286
316
}
287
317
288
318
/// Configure the default iroh rpc endpoint.
289
- pub async fn enable_rpc ( self ) -> Result < Builder < D , QuinnServerEndpoint < RpcService > > > {
319
+ pub async fn enable_rpc ( self ) -> Result < Builder < D > > {
290
320
let ( ep, actual_rpc_port) = make_rpc_endpoint ( & self . secret_key , DEFAULT_RPC_PORT ) ?;
321
+ let ep = quic_rpc:: transport:: boxed:: ServerEndpoint :: new ( ep) ;
291
322
if let StorageConfig :: Persistent ( ref root) = self . storage {
292
323
// store rpc endpoint
293
324
RpcStatus :: store ( root, actual_rpc_port) . await ?;
@@ -416,7 +447,7 @@ where
416
447
///
417
448
/// Returns an [`ProtocolBuilder`], on which custom protocols can be registered with
418
449
/// [`ProtocolBuilder::accept`]. To spawn the node, call [`ProtocolBuilder::spawn`].
419
- pub async fn build ( self ) -> Result < ProtocolBuilder < D , E > > {
450
+ pub async fn build ( self ) -> Result < ProtocolBuilder < D > > {
420
451
// Clone the blob store to shutdown in case of error.
421
452
let blobs_store = self . blobs_store . clone ( ) ;
422
453
match self . build_inner ( ) . await {
@@ -428,7 +459,7 @@ where
428
459
}
429
460
}
430
461
431
- async fn build_inner ( self ) -> Result < ProtocolBuilder < D , E > > {
462
+ async fn build_inner ( self ) -> Result < ProtocolBuilder < D > > {
432
463
trace ! ( "building node" ) ;
433
464
let lp = LocalPoolHandle :: new ( num_cpus:: get ( ) ) ;
434
465
let endpoint = {
@@ -547,17 +578,18 @@ where
547
578
/// Note that RPC calls performed with client returned from [`Self::client`] will not complete
548
579
/// until the node is spawned.
549
580
#[ derive( derive_more:: Debug ) ]
550
- pub struct ProtocolBuilder < D , E > {
581
+ pub struct ProtocolBuilder < D > {
551
582
inner : Arc < NodeInner < D > > ,
552
583
internal_rpc : FlumeServerEndpoint < RpcService > ,
553
- external_rpc : E ,
584
+ #[ debug( "external rpc" ) ]
585
+ external_rpc : BoxedServerEndpoint ,
554
586
protocols : ProtocolMap ,
555
587
#[ debug( "callback" ) ]
556
588
gc_done_callback : Option < Box < dyn Fn ( ) + Send > > ,
557
589
gc_policy : GcPolicy ,
558
590
}
559
591
560
- impl < D : iroh_blobs:: store:: Store , E : ServiceEndpoint < RpcService > > ProtocolBuilder < D , E > {
592
+ impl < D : iroh_blobs:: store:: Store > ProtocolBuilder < D > {
561
593
/// Registers a protocol handler for incoming connections.
562
594
///
563
595
/// Use this to register custom protocols onto the iroh node. Whenever a new connection for
0 commit comments