Skip to content

Commit

Permalink
providerQueryManager: when max == 0 in FindProvidersAsync, use maxPro…
Browse files Browse the repository at this point in the history
…viders option.
  • Loading branch information
hsanjuan committed Nov 21, 2024
1 parent f7da578 commit b7c5f16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions routing/providerquerymanager/providerquerymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion routing/providerquerymanager/providerquerymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down

0 comments on commit b7c5f16

Please sign in to comment.