@@ -289,12 +289,17 @@ func (r Parallel) forKey(key string) Parallel {
289
289
})
290
290
}
291
291
292
+ // PutValue puts the given key to all sub-routers in parallel. It succeeds as
293
+ // long as putting to at least one sub-router succeeds, but it waits for all
294
+ // puts to terminate.
292
295
func (r Parallel ) PutValue (ctx context.Context , key string , value []byte , opts ... routing.Option ) error {
293
296
return r .forKey (key ).put (func (ri routing.Routing ) error {
294
297
return ri .PutValue (ctx , key , value , opts ... )
295
298
})
296
299
}
297
300
301
+ // GetValue searches all sub-routers for the given key, returning the result
302
+ // from the first sub-router to complete the query.
298
303
func (r Parallel ) GetValue (ctx context.Context , key string , opts ... routing.Option ) ([]byte , error ) {
299
304
vInt , err := r .forKey (key ).get (ctx , func (ri routing.Routing ) (interface {}, error ) {
300
305
return ri .GetValue (ctx , key , opts ... )
@@ -303,6 +308,9 @@ func (r Parallel) GetValue(ctx context.Context, key string, opts ...routing.Opti
303
308
return val , err
304
309
}
305
310
311
+ // SearchValue searches all sub-routers for the given key in parallel,
312
+ // returning results in monotonically increasing "freshness" from all
313
+ // sub-routers.
306
314
func (r Parallel ) SearchValue (ctx context.Context , key string , opts ... routing.Option ) (<- chan []byte , error ) {
307
315
resCh , err := r .forKey (key ).search (ctx , func (ri routing.Routing ) (<- chan []byte , error ) {
308
316
return ri .SearchValue (ctx , key , opts ... )
@@ -342,6 +350,8 @@ func (r Parallel) SearchValue(ctx context.Context, key string, opts ...routing.O
342
350
return valid , err
343
351
}
344
352
353
+ // GetPublicKey retrieves the public key from all sub-routers in parallel,
354
+ // returning the first result.
345
355
func (r Parallel ) GetPublicKey (ctx context.Context , p peer.ID ) (ci.PubKey , error ) {
346
356
vInt , err := r .
347
357
forKey (routing .KeyForPublicKey (p )).
@@ -352,6 +362,8 @@ func (r Parallel) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error
352
362
return val , err
353
363
}
354
364
365
+ // FindPeer finds the given peer in all sub-routers in parallel, returning the
366
+ // first result.
355
367
func (r Parallel ) FindPeer (ctx context.Context , p peer.ID ) (peer.AddrInfo , error ) {
356
368
vInt , err := r .filter (func (ri routing.Routing ) bool {
357
369
return supportsPeer (ri )
@@ -362,6 +374,13 @@ func (r Parallel) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error
362
374
return pi , err
363
375
}
364
376
377
+ // Provide announces that this peer provides the content in question to all
378
+ // sub-routers in parallel. Provide returns success as long as a single
379
+ // sub-router succeeds, but still waits for all sub-routers to finish before
380
+ // returning.
381
+ //
382
+ // If count > 0, it returns at most count providers. If count == 0, it returns
383
+ // an unbounded number of providers.
365
384
func (r Parallel ) Provide (ctx context.Context , c cid.Cid , local bool ) error {
366
385
return r .filter (func (ri routing.Routing ) bool {
367
386
return supportsContent (ri )
@@ -370,6 +389,11 @@ func (r Parallel) Provide(ctx context.Context, c cid.Cid, local bool) error {
370
389
})
371
390
}
372
391
392
+ // FindProvidersAsync searches all sub-routers in parallel for peers who are
393
+ // able to provide a given key.
394
+ //
395
+ // If count > 0, it returns at most count providers. If count == 0, it returns
396
+ // an unbounded number of providers.
373
397
func (r Parallel ) FindProvidersAsync (ctx context.Context , c cid.Cid , count int ) <- chan peer.AddrInfo {
374
398
routers := r .filter (func (ri routing.Routing ) bool {
375
399
return supportsContent (ri )
@@ -507,6 +531,7 @@ func fewProviders(ctx context.Context, out chan<- peer.AddrInfo, in []<-chan pee
507
531
}
508
532
}
509
533
534
+ // Bootstrap signals all the sub-routers to bootstrap.
510
535
func (r Parallel ) Bootstrap (ctx context.Context ) error {
511
536
var me multierror.Error
512
537
for _ , b := range r .Routers {
@@ -517,6 +542,7 @@ func (r Parallel) Bootstrap(ctx context.Context) error {
517
542
return me .ErrorOrNil ()
518
543
}
519
544
545
+ // Close closes all sub-routers that implement the io.Closer interface.
520
546
func (r Parallel ) Close () error {
521
547
var me multierror.Error
522
548
for _ , router := range r .Routers {
0 commit comments