2023-10-24 17:00:46 +02:00
|
|
|
package timestamp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
|
|
|
|
logging "github.com/tim-beatham/wgmesh/pkg/log"
|
|
|
|
"github.com/tim-beatham/wgmesh/pkg/mesh"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TimestampScheduler interface {
|
|
|
|
Run() error
|
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type TimeStampSchedulerImpl struct {
|
2023-10-26 17:53:12 +02:00
|
|
|
meshManager *mesh.MeshManager
|
2023-10-24 17:00:46 +02:00
|
|
|
updateRate int
|
|
|
|
quit chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TimeStampSchedulerImpl) Run() error {
|
|
|
|
ticker := time.NewTicker(time.Duration(s.updateRate) * time.Second)
|
|
|
|
|
|
|
|
s.quit = make(chan struct{})
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
err := s.meshManager.UpdateTimeStamp()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logging.Log.WriteErrorf("Update Timestamp Error: %s", err.Error())
|
|
|
|
}
|
|
|
|
case <-s.quit:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-03 16:24:18 +01:00
|
|
|
func NewTimestampScheduler(ctrlServer *ctrlserver.MeshCtrlServer) TimestampScheduler {
|
2023-11-05 13:08:20 +01:00
|
|
|
return &TimeStampSchedulerImpl{
|
|
|
|
meshManager: ctrlServer.MeshManager,
|
|
|
|
updateRate: ctrlServer.Conf.KeepAliveRate,
|
|
|
|
}
|
2023-10-24 17:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TimeStampSchedulerImpl) Stop() error {
|
|
|
|
close(s.quit)
|
|
|
|
return nil
|
|
|
|
}
|