Skip to content

Commit

Permalink
allow findpeers limit to be 0 (#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel authored Jul 31, 2024
1 parent afc6a07 commit 46c6397
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions p2p/discovery/routing/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,20 @@ func (d *RoutingDiscovery) Advertise(ctx context.Context, ns string, opts ...dis
}

func (d *RoutingDiscovery) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error) {
var options discovery.Options
options := discovery.Options{
Limit: 100, // default limit if not specified in options
}
err := options.Apply(opts...)
if err != nil {
return nil, err
}

limit := options.Limit
if limit == 0 {
limit = 100 // that's just arbitrary, but FindProvidersAsync needs a count
}

cid, err := nsToCid(ns)
if err != nil {
return nil, err
}

return d.FindProvidersAsync(ctx, cid, limit), nil
return d.FindProvidersAsync(ctx, cid, options.Limit), nil
}

func nsToCid(ns string) (cid.Cid, error) {
Expand Down

0 comments on commit 46c6397

Please sign in to comment.