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

made edits to how the clock skew clap is implemented

parent fa4a0f5f
Branches
Tags
4 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!408made the cfollower regualrly update the clock skew,!340Project/channels
......@@ -113,7 +113,7 @@ func NewClient(params Params, comms *commClient.Comms, session storage.Session,
rng: rng,
comms: comms,
maxMsgLen: tmpMsg.ContentsSize(),
skewTracker: clockSkew.New(),
skewTracker: clockSkew.New(params.ClockSkewClamp),
}
if params.VerboseRoundTracking {
......
......@@ -66,10 +66,11 @@ type timeOffsetTracker struct {
lock sync.RWMutex
offsets []*time.Duration
currentIndex int
clamp time.Duration
}
// New returns an implementation of Tracker.
func New() Tracker {
func New(clamp time.Duration) Tracker {
t := &timeOffsetTracker{
gatewayClockDelays: new(sync.Map),
offsets: make([]*time.Duration, maxHistogramSize),
......@@ -108,7 +109,13 @@ func (t *timeOffsetTracker) Aggregate() time.Duration {
t.lock.RLock()
defer t.lock.RUnlock()
return average(t.offsets)
avg := average(t.offsets)
if avg < (-t.clamp) || avg > t.clamp {
return avg
} else {
return 0
}
}
func average(durations []*time.Duration) time.Duration {
......
......@@ -20,7 +20,7 @@ import (
)
func TestTimeTrackerSmokeTest(t *testing.T) {
tracker := New()
tracker := New(0)
gwID := &id.ID{}
_, err := rand.Read(gwID[:])
require.NoError(t, err)
......
......@@ -127,11 +127,7 @@ func (c *client) followNetwork(report ClientErrorReport,
//update clock skew
estimatedSkew := c.skewTracker.Aggregate()
if estimatedSkew < (-c.param.ClockSkewClamp) || estimatedSkew > c.param.ClockSkewClamp {
netTime.SetOffset(estimatedSkew)
} else {
netTime.SetOffset(0)
}
if err != nil {
jww.ERROR.Printf("failed to operate on identities to "+
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment