diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-02-19 22:18:55 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-02-24 18:16:28 +0800 |
commit | ac954f48bd9f9897f3118782ff2e68eeb3e1ed4e (patch) | |
tree | 17c97278b6419699ed0384df1c5f1c1ebe1105bc /p2p/discover/ntp.go | |
parent | b1908f6a16e712d4059195db3f22a0b856907bdb (diff) | |
download | dexon-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/ntp.go')
-rw-r--r-- | p2p/discover/ntp.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/p2p/discover/ntp.go b/p2p/discover/ntp.go index a87ee1fbe..c1a4b3af1 100644 --- a/p2p/discover/ntp.go +++ b/p2p/discover/ntp.go @@ -20,13 +20,20 @@ package discover import ( + "fmt" "net" "sort" + "strings" "time" + + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger/glog" ) -// ntpPool is the NTP server to query for the current time -const ntpPool = "pool.ntp.org" +const ( + ntpPool = "pool.ntp.org" // ntpPool is the NTP server to query for the current time + ntpChecks = 3 // Number of measurements to do against the NTP server +) // durationSlice attaches the methods of sort.Interface to []time.Duration, // sorting in increasing order. @@ -36,6 +43,27 @@ func (s durationSlice) Len() int { return len(s) } func (s durationSlice) Less(i, j int) bool { return s[i] < s[j] } func (s durationSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// checkClockDrift queries an NTP server for clock drifts and warns the user if +// one large enough is detected. +func checkClockDrift() { + drift, err := sntpDrift(ntpChecks) + if err != nil { + return + } + if drift < -driftThreshold || drift > driftThreshold { + warning := fmt.Sprintf("System clock seems off by %v, which can prevent network connectivity", drift) + howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings") + separator := strings.Repeat("-", len(warning)) + + glog.V(logger.Warn).Info(separator) + glog.V(logger.Warn).Info(warning) + glog.V(logger.Warn).Info(howtofix) + glog.V(logger.Warn).Info(separator) + } else { + glog.V(logger.Debug).Infof("Sanity NTP check reported %v drift, all ok", drift) + } +} + // sntpDrift does a naive time resolution against an NTP server and returns the // measured drift. This method uses the simple version of NTP. It's not precise // but should be fine for these purposes. |