Skip to content
Snippets Groups Projects
Commit 9cccfb7a authored by benjamin's avatar benjamin
Browse files

made the add function ignore inputs that are too out of sync

parent 29d53701
No related branches found
No related tags found
3 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!340Project/channels
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package clockSkew package clockSkew
import ( import (
jww "github.com/spf13/jwalterweatherman"
"sync" "sync"
"time" "time"
...@@ -82,6 +83,12 @@ func New(clamp time.Duration) Tracker { ...@@ -82,6 +83,12 @@ func New(clamp time.Duration) Tracker {
// Add implements the Add method of the Tracker interface. // Add implements the Add method of the Tracker interface.
func (t *timeOffsetTracker) Add(gwID *id.ID, startTime, rTs time.Time, rtt, gwD time.Duration) { 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 delay := (rtt - gwD) / 2
delays, _ := t.gatewayClockDelays.LoadOrStore(*gwID, newGatewayDelays()) delays, _ := t.gatewayClockDelays.LoadOrStore(*gwID, newGatewayDelays())
...@@ -94,6 +101,13 @@ func (t *timeOffsetTracker) Add(gwID *id.ID, startTime, rTs time.Time, rtt, gwD ...@@ -94,6 +101,13 @@ func (t *timeOffsetTracker) Add(gwID *id.ID, startTime, rTs time.Time, rtt, gwD
t.addOffset(offset) t.addOffset(offset)
} }
func abs(duration time.Duration) time.Duration {
if duration < 0 {
return -duration
}
return duration
}
func (t *timeOffsetTracker) addOffset(offset time.Duration) { func (t *timeOffsetTracker) addOffset(offset time.Duration) {
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment