Skip to content

Commit b7c5f16

Browse files
committed
providerQueryManager: when max == 0 in FindProvidersAsync, use maxProviders option.
1 parent f7da578 commit b7c5f16

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

routing/providerquerymanager/providerquerymanager.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ func WithMaxInProcessRequests(count int) Option {
116116
}
117117
}
118118

119-
// WithMaxProviders is the maximum number of providers that will be looked up per query
119+
// WithMaxProviders is the maximum number of providers that will be looked up
120+
// per query. We only return providers that we can connect to. Defaults to 0,
121+
// which means unbounded.
120122
func WithMaxProviders(count int) Option {
121123
return func(mgr *ProviderQueryManager) error {
122124
mgr.maxProviders = count
@@ -168,11 +170,10 @@ func (pqm *ProviderQueryManager) setFindProviderTimeout(findProviderTimeout time
168170

169171
// FindProvidersAsync finds providers for the given block. The max parameter
170172
// controls how many will be returned at most. For a provider to be returned,
171-
// we must have successfully connected to it. Setting max to -1 will use the
172-
// configured MaxProviders. Setting max to 0 will return an unbounded number
173-
// of providers.
173+
// we must have successfully connected to it. Setting max to 0 will use the
174+
// configured MaxProviders which defaults to 0 (unbounded).
174175
func (pqm *ProviderQueryManager) FindProvidersAsync(sessionCtx context.Context, k cid.Cid, max int) <-chan peer.AddrInfo {
175-
if max < 0 {
176+
if max == 0 {
176177
max = pqm.maxProviders
177178
}
178179

routing/providerquerymanager/providerquerymanager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func TestLimitedProviders(t *testing.T) {
400400
providerQueryManager.setFindProviderTimeout(100 * time.Millisecond)
401401
keys := random.Cids(1)
402402

403-
providersChan := providerQueryManager.FindProvidersAsync(ctx, keys[0], -1)
403+
providersChan := providerQueryManager.FindProvidersAsync(ctx, keys[0], 0)
404404
total := 0
405405
for range providersChan {
406406
total++

0 commit comments

Comments
 (0)