Skip to content

Commit 8741e6e

Browse files
changes as per review
1 parent 616ef86 commit 8741e6e

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

dht.go

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

111-
// maxLastSuccessfulOutboundThreshold is the max threshold/upper limit on the time duration
112-
// between the current time and the last time we successfully queried a peer.
113-
maxLastSuccessfulOutboundThreshold float64
111+
// successfulOutboundQueryGracePeriod is the maximum grace period we will give to a peer
112+
// to between two successful query responses from it, failing which,
113+
// we will ping it to see if it's alive.
114+
successfulOutboundQueryGracePeriod float64
114115

115116
fixLowPeersChan chan struct{}
116117
}
@@ -293,7 +294,7 @@ func makeRoutingTable(dht *IpfsDHT, cfg config) (*kb.RoutingTable, error) {
293294
self := kb.ConvertPeerID(dht.host.ID())
294295

295296
rt, err := kb.NewRoutingTable(cfg.bucketSize, self, time.Minute, dht.host.Peerstore(), maxLastSuccessfulOutboundThreshold)
296-
dht.maxLastSuccessfulOutboundThreshold = maxLastSuccessfulOutboundThreshold
297+
dht.successfulOutboundQueryGracePeriod = maxLastSuccessfulOutboundThreshold
297298
cmgr := dht.host.ConnManager()
298299

299300
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 float64(time.Since(ps.LastSuccessfulOutboundQueryAt)) > dht.maxLastSuccessfulOutboundThreshold {
131+
if float64(time.Since(ps.LastSuccessfulOutboundQueryAt)) > dht.successfulOutboundQueryGracePeriod {
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)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/libp2p/go-eventbus v0.1.0
1919
github.com/libp2p/go-libp2p v0.7.4
2020
github.com/libp2p/go-libp2p-core v0.5.1
21-
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409173621-ac6d9f25cfc5
21+
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409175716-8ee3433d2070
2222
github.com/libp2p/go-libp2p-peerstore v0.2.2
2323
github.com/libp2p/go-libp2p-record v0.1.2
2424
github.com/libp2p/go-libp2p-swarm v0.2.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ github.com/libp2p/go-libp2p-kbucket v0.3.3 h1:V2Zwv6QnCK6Who0iiJW2eUKwdlTYGJ2HnL
234234
github.com/libp2p/go-libp2p-kbucket v0.3.3/go.mod h1:IWFdYRBOYzaLEHnvrfzEkr+UcuveCXIoeO8QeFZSI6A=
235235
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409173621-ac6d9f25cfc5 h1:WKHaqIIF9mHebRjTtsOCGPY32Wr2TKOyKnF6KQ9LV8Q=
236236
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409173621-ac6d9f25cfc5/go.mod h1:sDQeCkD6yf/Yq8O+HPTNLyGa0TsJi+CURa6ELp1ppkk=
237+
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409175716-8ee3433d2070 h1:RjsANEFzVYo0424kmZ7ykm2/fd0iem2r7cm45YFfALY=
238+
github.com/libp2p/go-libp2p-kbucket v0.3.4-0.20200409175716-8ee3433d2070/go.mod h1:sDQeCkD6yf/Yq8O+HPTNLyGa0TsJi+CURa6ELp1ppkk=
237239
github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8=
238240
github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90=
239241
github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo=

0 commit comments

Comments
 (0)