diff --git a/go.mod b/go.mod index a8867de..7d5c5f0 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ module github.com/atc0005/ntpt go 1.20 -require github.com/beevik/ntp v1.4.1 +require github.com/beevik/ntp v1.4.2 require ( golang.org/x/net v0.25.0 // indirect diff --git a/go.sum b/go.sum index 5691ed6..7259776 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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 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 8e3d929..42ac601 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 # golang.org/x/net v0.25.0