1
0
forked from extern/smegmesh

Merge pull request #82 from tim-beatham/bugfix-node-not-leving

bugfix-node-not-leaving
This commit is contained in:
Tim Beatham 2024-01-04 00:24:58 +00:00 committed by GitHub
commit 9818645299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -23,9 +23,10 @@ func binarySearch(global []string, selfId string, groupSize int) (int, int) {
lower := 0
higher := len(global) - 1
mid := (lower + higher) / 2
for (higher+1)-lower > groupSize {
mid := (lower + higher) / 2
if global[mid] < selfId {
lower = mid + 1
} else if global[mid] > selfId {
@ -33,8 +34,6 @@ func binarySearch(global []string, selfId string, groupSize int) (int, int) {
} else {
break
}
mid = (lower + higher) / 2
}
return lower, int(math.Min(float64(lower+groupSize), float64(len(global))))

View File

@ -10,6 +10,7 @@ import (
"github.com/tim-beatham/smegmesh/pkg/conf"
"github.com/tim-beatham/smegmesh/pkg/ip"
"github.com/tim-beatham/smegmesh/pkg/lib"
logging "github.com/tim-beatham/smegmesh/pkg/log"
"github.com/tim-beatham/smegmesh/pkg/wg"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
@ -355,7 +356,7 @@ func (s *MeshManagerImpl) LeaveMesh(meshId string) error {
err := mesh.RemoveNode(s.HostParameters.GetPublicKey())
if err != nil {
return err
logging.Log.WriteErrorf(err.Error())
}
if s.OnDelete != nil {

View File

@ -28,6 +28,7 @@ type SyncerImpl struct {
cluster conn.ConnCluster
conf *conf.DaemonConfiguration
lastSync map[string]int64
lock sync.RWMutex
}
// Sync: Sync with random nodes
@ -134,7 +135,9 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) error {
correspondingMesh.SaveChanges()
s.lock.Lock()
s.lastSync[correspondingMesh.GetMeshId()] = time.Now().Unix()
s.lock.Unlock()
return nil
}