aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/udp.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-19 22:18:55 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-24 18:16:28 +0800
commitac954f48bd9f9897f3118782ff2e68eeb3e1ed4e (patch)
tree17c97278b6419699ed0384df1c5f1c1ebe1105bc /p2p/discover/udp.go
parentb1908f6a16e712d4059195db3f22a0b856907bdb (diff)
downloaddexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar.gz
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar.bz2
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar.lz
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar.xz
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.tar.zst
dexon-ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e.zip
p2p/discover: emphasize warning, add 10 min cooldown
Diffstat (limited to 'p2p/discover/udp.go')
-rw-r--r--p2p/discover/udp.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index fa4bc07dc..03fa0c348 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -52,8 +52,9 @@ const (
sendTimeout = 500 * time.Millisecond
expiration = 20 * time.Second
- ntpThreshold = 32 // Continuous timeouts after which to check NTP
- driftThreshold = 10 * time.Second // Allowed clock drift before warning user
+ ntpFailureThreshold = 32 // Continuous timeouts after which to check NTP
+ ntpWarningCooldown = 10 * time.Minute // Minimum amount of time to pass before repeating NTP warning
+ driftThreshold = 10 * time.Second // Allowed clock drift before warning user
)
// RPC packet types
@@ -327,6 +328,7 @@ func (t *udp) loop() {
timeout = time.NewTimer(0)
nextTimeout *pending // head of plist when timeout was last reset
contTimeouts = 0 // number of continuous timeouts to do NTP checks
+ ntpWarnTime = time.Unix(0, 0)
)
<-timeout.C // ignore first timeout
defer timeout.Stop()
@@ -400,20 +402,11 @@ func (t *udp) loop() {
}
}
// If we've accumulated too many timeouts, do an NTP time sync check
- if contTimeouts > ntpThreshold {
- go func() {
- drift, err := sntpDrift(3)
- switch {
- case err != nil:
- glog.V(logger.Warn).Infof("No UDP connectivity, maybe blocked by firewall? (%v)", err)
-
- case drift < -driftThreshold || drift > driftThreshold:
- glog.V(logger.Warn).Infof("System clock seems off by %v, which can prevent network connectivity", drift)
-
- default:
- glog.V(logger.Debug).Infof("Sanity NTP check reported %v drift, all ok", drift)
- }
- }()
+ if contTimeouts > ntpFailureThreshold {
+ if time.Since(ntpWarnTime) >= ntpWarningCooldown {
+ ntpWarnTime = time.Now()
+ go checkClockDrift()
+ }
contTimeouts = 0
}
}