diff --git a/cmix/clockSkew/timeTracker.go b/cmix/clockSkew/timeTracker.go index 08457637951f3726c36a9e30cd3b2f809295437b..04f8924dc197d07e99a7699aae0026aca2c29462 100644 --- a/cmix/clockSkew/timeTracker.go +++ b/cmix/clockSkew/timeTracker.go @@ -9,6 +9,7 @@ package clockSkew import ( + jww "github.com/spf13/jwalterweatherman" "sync" "time" @@ -82,6 +83,12 @@ func New(clamp time.Duration) Tracker { // Add implements the Add method of the Tracker interface. func (t *timeOffsetTracker) Add(gwID *id.ID, startTime, rTs time.Time, rtt, gwD time.Duration) { + if abs(startTime.Sub(rTs)) > time.Hour { + jww.WARN.Printf("Time data from %s dropped, more than an hour off from"+ + " local time; local: %s, remote: %s", startTime, rTs) + return + } + delay := (rtt - gwD) / 2 delays, _ := t.gatewayClockDelays.LoadOrStore(*gwID, newGatewayDelays()) @@ -94,6 +101,13 @@ func (t *timeOffsetTracker) Add(gwID *id.ID, startTime, rTs time.Time, rtt, gwD t.addOffset(offset) } +func abs(duration time.Duration) time.Duration { + if duration < 0 { + return -duration + } + return duration +} + func (t *timeOffsetTracker) addOffset(offset time.Duration) { t.lock.Lock() defer t.lock.Unlock()