good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
ac954f48
Commit
ac954f48
authored
Feb 19, 2016
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
p2p/discover: emphasize warning, add 10 min cooldown
parent
b1908f6a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
p2p/discover/ntp.go
+30
-2
30 additions, 2 deletions
p2p/discover/ntp.go
p2p/discover/udp.go
+9
-16
9 additions, 16 deletions
p2p/discover/udp.go
with
39 additions
and
18 deletions
p2p/discover/ntp.go
+
30
−
2
View file @
ac954f48
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
p2p/discover/udp.go
+
9
−
16
View file @
ac954f48
...
...
@@ -52,7 +52,8 @@ const (
sendTimeout
=
500
*
time
.
Millisecond
expiration
=
20
*
time
.
Second
ntpThreshold
=
32
// Continuous timeouts after which to check NTP
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
)
...
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment