Skip to content

Commit

Permalink
ns: Only time sync on absolute time:
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualguy committed Jun 9, 2024
1 parent 2db068a commit 8e00527
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pkg/gatewayserver/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ func (c *Connection) ScheduleDown(path *ttnpb.DownlinkPath, msg *ttnpb.DownlinkM
settings.Time = request.AbsoluteTime
case ttnpb.Class_CLASS_C:
if request.AbsoluteTime != nil {
if !c.scheduler.IsGatewayTimeSynced() {
rxErrs = append(rxErrs, errNoGPSSync.New())
continue
}

f = c.scheduler.ScheduleAt
settings.Time = request.AbsoluteTime
} else {
Expand Down
14 changes: 9 additions & 5 deletions pkg/gatewayserver/scheduling/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ type Clock interface {

// RolloverClock is a Clock that takes roll-over of a uint32 microsecond concentrator time into account.
type RolloverClock struct {
synced bool
relative uint32
absolute ConcentratorTime
server *time.Time
gateway *time.Time
synced bool
relative uint32
absolute ConcentratorTime
server *time.Time
gateway *time.Time
absoluteSynced bool
}

// IsSynced implements Clock.
func (c *RolloverClock) IsSynced() bool { return c.synced }

func (c *RolloverClock) IsAbsoluteSynced() bool { return c.absoluteSynced }

Check warning on line 52 in pkg/gatewayserver/scheduling/clock.go

View workflow job for this annotation

GitHub Actions / Code Quality

exported: exported method RolloverClock.IsAbsoluteSynced should have comment or be unexported (revive)

// SyncTime implements Clock.
func (c *RolloverClock) SyncTime() (time.Time, bool) {
if !c.synced {
Expand Down Expand Up @@ -82,6 +85,7 @@ func (c *RolloverClock) Sync(timestamp uint32, server time.Time) ConcentratorTim
func (c *RolloverClock) SyncWithGatewayAbsolute(timestamp uint32, server, gateway time.Time) ConcentratorTime {
ct := c.Sync(timestamp, server)
c.gateway = &gateway
c.absoluteSynced = true
return ct
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gatewayserver/scheduling/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (s *Scheduler) ScheduleAt(ctx context.Context, opts Options) (res Emission,
if opts.UplinkToken != nil {
s.syncWithUplinkToken(opts.UplinkToken)
}
if !s.clock.IsSynced() {
if !s.clock.IsAbsoluteSynced() {
return Emission{}, 0, errNoClockSync.New()
}
minScheduleTime := ScheduleTimeShort
Expand Down Expand Up @@ -477,7 +477,7 @@ func (s *Scheduler) SyncWithGatewayConcentrator(timestamp uint32, server time.Ti
func (s *Scheduler) IsGatewayTimeSynced() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.clock.IsSynced() && s.clock.gateway != nil
return s.clock.IsAbsoluteSynced() && s.clock.gateway != nil
}

// Now returns an indication of the current concentrator time.
Expand Down

0 comments on commit 8e00527

Please sign in to comment.