From 82c233366ce60224d2f8741659f0e2143cf47a25 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Thu, 9 Apr 2020 21:11:16 +0530 Subject: [PATCH] fix bug in periodic peer pinging --- dht.go | 8 ++++---- dht_bootstrap.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dht.go b/dht.go index c5676d39b..358190c7e 100644 --- a/dht.go +++ b/dht.go @@ -108,10 +108,9 @@ type IpfsDHT struct { // networks). enableProviders, enableValues bool - // maxLastSuccessfulOutboundThreshold is the max threshold/upper limit for the value of "lastSuccessfulOutboundQuery" - // of the peer in the bucket above which we will evict it to make place for a new peer if the bucket - // is full - maxLastSuccessfulOutboundThreshold time.Duration + // maxLastSuccessfulOutboundThreshold is the max threshold/upper limit on the time duration + // between the current time and the last time a peer was useful to us. + maxLastSuccessfulOutboundThreshold float64 fixLowPeersChan chan struct{} } @@ -294,6 +293,7 @@ func makeRoutingTable(dht *IpfsDHT, cfg config) (*kb.RoutingTable, error) { self := kb.ConvertPeerID(dht.host.ID()) rt, err := kb.NewRoutingTable(cfg.bucketSize, self, time.Minute, dht.host.Peerstore(), maxLastSuccessfulOutboundThreshold) + dht.maxLastSuccessfulOutboundThreshold = maxLastSuccessfulOutboundThreshold cmgr := dht.host.ConnManager() rt.PeerAdded = func(p peer.ID) { diff --git a/dht_bootstrap.go b/dht_bootstrap.go index fb3961dc9..c6c29cff6 100644 --- a/dht_bootstrap.go +++ b/dht_bootstrap.go @@ -128,7 +128,7 @@ func (dht *IpfsDHT) startRefreshing() { // ping Routing Table peers that haven't been hear of/from in the interval they should have been. for _, ps := range dht.routingTable.GetPeerInfos() { // ping the peer if it's due for a ping and evict it if the ping fails - if time.Since(ps.LastSuccessfulOutboundQuery) > dht.maxLastSuccessfulOutboundThreshold { + if float64(time.Since(ps.LastSuccessfulOutboundQuery)) > dht.maxLastSuccessfulOutboundThreshold { livelinessCtx, cancel := context.WithTimeout(ctx, peerPingTimeout) if err := dht.host.Connect(livelinessCtx, peer.AddrInfo{ID: ps.Id}); err != nil { logger.Debugw("evicting peer after failed ping", "peer", ps.Id, "error", err)