Commit 8741e6ec authored by Aarsh Shah's avatar Aarsh Shah

changes as per review

parent 616ef868
......@@ -108,9 +108,10 @@ type IpfsDHT struct {
// networks).
enableProviders, enableValues bool
// maxLastSuccessfulOutboundThreshold is the max threshold/upper limit on the time duration
// between the current time and the last time we successfully queried a peer.
maxLastSuccessfulOutboundThreshold float64
// successfulOutboundQueryGracePeriod is the maximum grace period we will give to a peer
// to between two successful query responses from it, failing which,
// we will ping it to see if it's alive.
successfulOutboundQueryGracePeriod float64
fixLowPeersChan chan struct{}
}
......@@ -293,7 +294,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
dht.successfulOutboundQueryGracePeriod = maxLastSuccessfulOutboundThreshold
cmgr := dht.host.ConnManager()
rt.PeerAdded = func(p peer.ID) {
......
......@@ -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 float64(time.Since(ps.LastSuccessfulOutboundQueryAt)) > dht.maxLastSuccessfulOutboundThreshold {
if float64(time.Since(ps.LastSuccessfulOutboundQueryAt)) > dht.successfulOutboundQueryGracePeriod {
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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment