Skip to content

Commit 8f175ae

Browse files
fix: netsize warning (#1077)
1 parent 7cc3df8 commit 8f175ae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lookup.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/libp2p/go-libp2p-kad-dht/internal"
99
"github.com/libp2p/go-libp2p-kad-dht/internal/metrics"
10+
"github.com/libp2p/go-libp2p-kad-dht/netsize"
1011
"github.com/libp2p/go-libp2p-kad-dht/qpeerset"
1112
kb "github.com/libp2p/go-libp2p-kbucket"
1213
"github.com/libp2p/go-libp2p/core/peer"
@@ -39,7 +40,11 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) ([]peer.ID,
3940

4041
// tracking lookup results for network size estimator
4142
if err = dht.nsEstimator.Track(key, lookupRes.closest); err != nil {
42-
logger.Warnf("network size estimator track peers: %s", err)
43+
if err != netsize.ErrWrongNumOfPeers || dht.routingTable.Size() > dht.bucketSize {
44+
// Don't warn if we have a wrong number of peers and the routing table is
45+
// small because the network may simply not have enough peers.
46+
logger.Warnf("network size estimator track peers: %s", err)
47+
}
4348
}
4449

4550
if ns, err := dht.nsEstimator.NetworkSize(); err == nil {

lookup_optim.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ func (dht *IpfsDHT) optimisticProvide(outerCtx context.Context, keyMH multihash.
169169

170170
// tracking lookup results for network size estimator as "completed" is true
171171
if err = dht.nsEstimator.Track(key, lookupRes.closest); err != nil {
172-
logger.Warnf("network size estimator track peers: %s", err)
172+
if err != netsize.ErrWrongNumOfPeers || dht.routingTable.Size() > dht.bucketSize {
173+
// Don't warn if we have a wrong number of peers and the routing table is
174+
// small because the network may simply not have enough peers.
175+
logger.Warnf("network size estimator track peers: %s", err)
176+
}
173177
}
174178

175179
if ns, err := dht.nsEstimator.NetworkSize(); err == nil {

0 commit comments

Comments
 (0)