Skip to content

Commit 82c2333

Browse files
fix bug in periodic peer pinging
1 parent 0d1a917 commit 82c2333

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

dht.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ type IpfsDHT struct {
108108
// networks).
109109
enableProviders, enableValues bool
110110

111-
// maxLastSuccessfulOutboundThreshold is the max threshold/upper limit for the value of "lastSuccessfulOutboundQuery"
112-
// of the peer in the bucket above which we will evict it to make place for a new peer if the bucket
113-
// is full
114-
maxLastSuccessfulOutboundThreshold time.Duration
111+
// maxLastSuccessfulOutboundThreshold is the max threshold/upper limit on the time duration
112+
// between the current time and the last time a peer was useful to us.
113+
maxLastSuccessfulOutboundThreshold float64
115114

116115
fixLowPeersChan chan struct{}
117116
}
@@ -294,6 +293,7 @@ func makeRoutingTable(dht *IpfsDHT, cfg config) (*kb.RoutingTable, error) {
294293
self := kb.ConvertPeerID(dht.host.ID())
295294

296295
rt, err := kb.NewRoutingTable(cfg.bucketSize, self, time.Minute, dht.host.Peerstore(), maxLastSuccessfulOutboundThreshold)
296+
dht.maxLastSuccessfulOutboundThreshold = maxLastSuccessfulOutboundThreshold
297297
cmgr := dht.host.ConnManager()
298298

299299
rt.PeerAdded = func(p peer.ID) {

dht_bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (dht *IpfsDHT) startRefreshing() {
128128
// ping Routing Table peers that haven't been hear of/from in the interval they should have been.
129129
for _, ps := range dht.routingTable.GetPeerInfos() {
130130
// ping the peer if it's due for a ping and evict it if the ping fails
131-
if time.Since(ps.LastSuccessfulOutboundQuery) > dht.maxLastSuccessfulOutboundThreshold {
131+
if float64(time.Since(ps.LastSuccessfulOutboundQuery)) > dht.maxLastSuccessfulOutboundThreshold {
132132
livelinessCtx, cancel := context.WithTimeout(ctx, peerPingTimeout)
133133
if err := dht.host.Connect(livelinessCtx, peer.AddrInfo{ID: ps.Id}); err != nil {
134134
logger.Debugw("evicting peer after failed ping", "peer", ps.Id, "error", err)

0 commit comments

Comments
 (0)