Bidirectional syncing

This commit is contained in:
Tim Beatham
2023-10-23 18:13:08 +01:00
parent 360f9d3c54
commit ef2b57047d
9 changed files with 231 additions and 91 deletions

View File

@@ -2,6 +2,7 @@ package sync
import (
"errors"
"sync"
crdt "github.com/tim-beatham/wgmesh/pkg/automerge"
"github.com/tim-beatham/wgmesh/pkg/lib"
@@ -54,14 +55,21 @@ func (s *SyncerImpl) Sync(meshId string) error {
meshNodes := lib.MapValuesWithExclude(snapshot.Nodes, excludedNodes)
randomSubset := lib.RandomSubsetOfLength(meshNodes, subSetLength)
for _, n := range randomSubset {
err := s.requester.SyncMesh(meshId, n.HostEndpoint)
var waitGroup sync.WaitGroup
if err != nil {
for _, n := range randomSubset {
waitGroup.Add(1)
syncMeshFunc := func() error {
defer waitGroup.Done()
err := s.requester.SyncMesh(meshId, n.HostEndpoint)
return err
}
go syncMeshFunc()
}
waitGroup.Wait()
return nil
}