diff --git a/go.mod b/go.mod index d7065bc..e143ab9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/sapcc/ntp_exporter go 1.22 require ( - github.com/beevik/ntp v1.4.1 + github.com/beevik/ntp v1.4.2 github.com/prometheus/client_golang v1.19.1 github.com/sapcc/go-api-declarations v1.11.2 github.com/sapcc/go-bits v0.0.0-20240516084938-1c041b7a84ce diff --git a/go.sum b/go.sum index f35d9da..9160a06 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/beevik/ntp v1.4.1 h1:wbs1dC82GEcSk7LjDog3kMEZuiOk8M7tePUsZaTCvXY= -github.com/beevik/ntp v1.4.1/go.mod h1:zkATLTt8VUZuOfYX2KgOnir4yvtAxWbnUUA24umXFnc= +github.com/beevik/ntp v1.4.2 h1:cjYhZqczanf6br/ocViahE75ipj7CmKQAh7fSBaCNK4= +github.com/beevik/ntp v1.4.2/go.mod h1:zkATLTt8VUZuOfYX2KgOnir4yvtAxWbnUUA24umXFnc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/vendor/github.com/beevik/ntp/CONTRIBUTORS b/vendor/github.com/beevik/ntp/CONTRIBUTORS index 714817a..f984471 100644 --- a/vendor/github.com/beevik/ntp/CONTRIBUTORS +++ b/vendor/github.com/beevik/ntp/CONTRIBUTORS @@ -7,3 +7,4 @@ Leonid Evdokimov (darkk) Ask Bjørn Hansen (abh) Al Cutter (AlCutter) Silves-Xiang (silves-xiang) +Andrey Smirnov (smira) diff --git a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md index c696225..f53ad47 100644 --- a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md +++ b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md @@ -1,3 +1,10 @@ +Release v1.4.2 +============== + +**Fixes** + +* Fixed a bug in clock offset calculation. + Release v1.4.1 ============== diff --git a/vendor/github.com/beevik/ntp/ntp.go b/vendor/github.com/beevik/ntp/ntp.go index 0d25544..8306ffa 100644 --- a/vendor/github.com/beevik/ntp/ntp.go +++ b/vendor/github.com/beevik/ntp/ntp.go @@ -749,9 +749,18 @@ func rtt(org, rec, xmt, dst ntpTime) time.Duration { func offset(org, rec, xmt, dst ntpTime) time.Duration { // local clock offset // offset = ((rec-org) + (xmt-dst)) / 2 - a := rec.Time().Sub(org.Time()) - b := xmt.Time().Sub(dst.Time()) - return (a + b) / time.Duration(2) + // The inputs are 64-bit unsigned ints. The output is a 63-bit signed int. + // Need to handle conversions with care. See: + // https://www.eecis.udel.edu/~mills/time.html + a := int64(rec) - int64(org) + b := int64(xmt) - int64(dst) + d := (a + b) / 2 + + if d > 0 { + return ntpTime(d).Duration() + } else { + return -ntpTime(-d).Duration() + } } func minError(org, rec, xmt, dst ntpTime) time.Duration { diff --git a/vendor/modules.txt b/vendor/modules.txt index d4ea0a9..8d77672 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/beevik/ntp v1.4.1 +# github.com/beevik/ntp v1.4.2 ## explicit; go 1.17 github.com/beevik/ntp # github.com/beorn7/perks v1.0.1