From fc5b0471d930d742fed138622462b6eb144f2663 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Sun, 11 Mar 2018 14:13:34 +0400 Subject: [PATCH] use time.Since --- p2p/pex/pex_reactor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 4a6eafee5..193efc88d 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -40,7 +40,7 @@ const ( defaultCrawlPeerInterval = 2 * time.Minute // dont redial for this. TODO: back-off defaultCrawlPeersPeriod = 30 * time.Second // check some peers every this - maxAttemptsToDial = 16 // ~ 35h in total (last attempt - 18h sleep) + maxAttemptsToDial = 16 // ~ 35h in total (last attempt - 18h) ) // PEXReactor handles PEX (peer exchange) and ensures that an @@ -389,7 +389,7 @@ func (r *PEXReactor) dialPeer(addr *p2p.NetAddress) { if attempts > 0 { jitterSeconds := time.Duration(rand.Float64() * float64(time.Second)) // 1s == (1e9 ns) backoffDuration := jitterSeconds + ((1 << uint(attempts)) * time.Second) - sinceLastDialed := time.Now().Sub(lastDialed) + sinceLastDialed := time.Since(lastDialed) if sinceLastDialed < backoffDuration { r.Logger.Debug("Too early to dial", "addr", addr, "backoff_duration", backoffDuration, "last_dialed", lastDialed, "time_since", sinceLastDialed) return