From 46c639732c78137bcec39a519425211c4ceeae50 Mon Sep 17 00:00:00 2001 From: Guillaume Michel Date: Wed, 31 Jul 2024 23:16:36 +0200 Subject: [PATCH] allow findpeers limit to be 0 (#2894) --- p2p/discovery/routing/routing.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/p2p/discovery/routing/routing.go b/p2p/discovery/routing/routing.go index 6fee75096e..e550bc304f 100644 --- a/p2p/discovery/routing/routing.go +++ b/p2p/discovery/routing/routing.go @@ -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) {