2023-10-10 21:14:40 +02:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
|
2023-11-06 14:37:28 +01:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/lib"
|
2023-10-10 21:14:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// SyncScheduler: Loops through all nodes in the mesh and runs a schedule to
|
|
|
|
// sync each event
|
|
|
|
type SyncScheduler interface {
|
|
|
|
Run() error
|
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
2023-10-24 17:00:46 +02:00
|
|
|
// SyncSchedulerImpl scheduler for sync scheduling
|
2023-10-10 21:14:40 +02:00
|
|
|
type SyncSchedulerImpl struct {
|
2023-11-03 16:24:18 +01:00
|
|
|
quit chan struct{}
|
|
|
|
server *ctrlserver.MeshCtrlServer
|
|
|
|
syncer Syncer
|
2023-10-10 21:14:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements SyncScheduler.
|
2023-11-06 14:37:28 +01:00
|
|
|
func syncFunction(syncer Syncer) lib.TimerFunc {
|
|
|
|
return func() error {
|
|
|
|
return syncer.SyncMeshes()
|
2023-10-10 21:14:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-06 14:37:28 +01:00
|
|
|
func NewSyncScheduler(s *ctrlserver.MeshCtrlServer, syncRequester SyncRequester) *lib.Timer {
|
2023-11-03 16:24:18 +01:00
|
|
|
syncer := NewSyncer(s.MeshManager, s.Conf, syncRequester)
|
2023-11-06 14:37:28 +01:00
|
|
|
return lib.NewTimer(syncFunction(syncer), int(s.Conf.SyncRate))
|
2023-10-10 21:14:40 +02:00
|
|
|
}
|