From 9cccfb7af3f849f6dcbb2b71c7fb26170dbedc29 Mon Sep 17 00:00:00 2001 From: benjamin <ben@elixxir.io> Date: Tue, 11 Oct 2022 16:26:09 -0700 Subject: [PATCH] made the add function ignore inputs that are too out of sync --- cmix/clockSkew/timeTracker.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmix/clockSkew/timeTracker.go b/cmix/clockSkew/timeTracker.go index 084576379..04f8924dc 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() -- GitLab