Browse Source

use time.Since

pull/1292/head
Anton Kaliaev 7 years ago
parent
commit
fc5b0471d9
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      p2p/pex/pex_reactor.go

+ 2
- 2
p2p/pex/pex_reactor.go View File

@ -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


Loading…
Cancel
Save