diff --git a/routing/providerquerymanager/providerquerymanager.go b/routing/providerquerymanager/providerquerymanager.go index 2d66a153d..e0de10163 100644 --- a/routing/providerquerymanager/providerquerymanager.go +++ b/routing/providerquerymanager/providerquerymanager.go @@ -116,7 +116,9 @@ func WithMaxInProcessRequests(count int) Option { } } -// WithMaxProviders is the maximum number of providers that will be looked up per query +// WithMaxProviders is the maximum number of providers that will be looked up +// per query. We only return providers that we can connect to. Defaults to 0, +// which means unbounded. func WithMaxProviders(count int) Option { return func(mgr *ProviderQueryManager) error { mgr.maxProviders = count @@ -168,11 +170,10 @@ func (pqm *ProviderQueryManager) setFindProviderTimeout(findProviderTimeout time // FindProvidersAsync finds providers for the given block. The max parameter // controls how many will be returned at most. For a provider to be returned, -// we must have successfully connected to it. Setting max to -1 will use the -// configured MaxProviders. Setting max to 0 will return an unbounded number -// of providers. +// we must have successfully connected to it. Setting max to 0 will use the +// configured MaxProviders which defaults to 0 (unbounded). func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context, k cid.Cid, max int) <-chan peer.AddrInfo { - if max < 0 { + if max == 0 { max = pqm.maxProviders } diff --git a/routing/providerquerymanager/providerquerymanager_test.go b/routing/providerquerymanager/providerquerymanager_test.go index 9d8ac8ed4..b55c1debc 100644 --- a/routing/providerquerymanager/providerquerymanager_test.go +++ b/routing/providerquerymanager/providerquerymanager_test.go @@ -400,7 +400,7 @@ func TestLimitedProviders(t *testing.T) { providerQueryManager.setFindProviderTimeout(100 * time.Millisecond) keys := random.Cids(1) - providersChan := providerQueryManager.FindProvidersAsync(ctx, keys[0], -1) + providersChan := providerQueryManager.FindProvidersAsync(ctx, keys[0], 0) total := 0 for range providersChan { total++