Skip to content

Commit 19cd67f

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

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

bitswap/client/internal/session/session.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@ func (s *Session) findMorePeers(ctx context.Context, c cid.Cid) {
410410
go func(k cid.Cid) {
411411
ctx, span := internal.StartSpan(ctx, "Session.FindMorePeers")
412412
defer span.End()
413-
// Max is set to -1. This means "use the default limit" in the
414-
// provider query manager.
415-
for p := range s.providerFinder.FindProvidersAsync(ctx, k, -1) {
413+
for p := range s.providerFinder.FindProvidersAsync(ctx, k, 0) {
416414
// When a provider indicates that it has a cid, it's equivalent to
417415
// the providing peer sending a HAVE
418416
span.AddEvent("FoundPeer")

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)