From 348cb0f1ad4643043d477c781a2792b74bd1daaf Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Fri, 9 Jun 2023 10:32:45 +0200 Subject: [PATCH] Revalidate loop fix (#60) * Sets lower limit in revalidation loop timeout. * Moves up RevalidateMin --- libp2pdht/private/eth/p2p/discoveryv5/protocol.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libp2pdht/private/eth/p2p/discoveryv5/protocol.nim b/libp2pdht/private/eth/p2p/discoveryv5/protocol.nim index fb0dd2b..9987c52 100644 --- a/libp2pdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/libp2pdht/private/eth/p2p/discoveryv5/protocol.nim @@ -121,7 +121,8 @@ const MaxNodesPerMessage = 3 ## Maximum amount of SPRs per individual Nodes message RefreshInterval = 5.minutes ## Interval of launching a random query to ## refresh the routing table. - RevalidateMax = 10000 ## Revalidation of a peer is done between 0 and this + RevalidateMin = 5000 + RevalidateMax = 10000 ## Revalidation of a peer is done between min and max milliseconds. ## value in milliseconds IpMajorityInterval = 5.minutes ## Interval for checking the latest IP:Port ## majority and updating this when SPR auto update is set. @@ -937,7 +938,8 @@ proc revalidateLoop(d: Protocol) {.async.} = ## message. try: while true: - await sleepAsync(milliseconds(d.rng[].rand(RevalidateMax))) + let revalidateTimeout = RevalidateMin + d.rng[].rand(RevalidateMax - RevalidateMin) + await sleepAsync(milliseconds(revalidateTimeout)) let n = d.routingTable.nodeToRevalidate() if not n.isNil: traceAsyncErrors d.revalidateNode(n)