mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-01-07 05:49:05 +01:00
bugfix-node-not-leaving
- Add lock when perform synchronisation on concurrent access
This commit is contained in:
parent
27e00196cd
commit
1f0914e2df
@ -23,9 +23,10 @@ func binarySearch(global []string, selfId string, groupSize int) (int, int) {
|
|||||||
|
|
||||||
lower := 0
|
lower := 0
|
||||||
higher := len(global) - 1
|
higher := len(global) - 1
|
||||||
mid := (lower + higher) / 2
|
|
||||||
|
|
||||||
for (higher+1)-lower > groupSize {
|
for (higher+1)-lower > groupSize {
|
||||||
|
mid := (lower + higher) / 2
|
||||||
|
|
||||||
if global[mid] < selfId {
|
if global[mid] < selfId {
|
||||||
lower = mid + 1
|
lower = mid + 1
|
||||||
} else if global[mid] > selfId {
|
} else if global[mid] > selfId {
|
||||||
@ -33,8 +34,6 @@ func binarySearch(global []string, selfId string, groupSize int) (int, int) {
|
|||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
mid = (lower + higher) / 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lower, int(math.Min(float64(lower+groupSize), float64(len(global))))
|
return lower, int(math.Min(float64(lower+groupSize), float64(len(global))))
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/tim-beatham/smegmesh/pkg/conf"
|
"github.com/tim-beatham/smegmesh/pkg/conf"
|
||||||
"github.com/tim-beatham/smegmesh/pkg/ip"
|
"github.com/tim-beatham/smegmesh/pkg/ip"
|
||||||
"github.com/tim-beatham/smegmesh/pkg/lib"
|
"github.com/tim-beatham/smegmesh/pkg/lib"
|
||||||
|
logging "github.com/tim-beatham/smegmesh/pkg/log"
|
||||||
"github.com/tim-beatham/smegmesh/pkg/wg"
|
"github.com/tim-beatham/smegmesh/pkg/wg"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
@ -355,7 +356,7 @@ func (s *MeshManagerImpl) LeaveMesh(meshId string) error {
|
|||||||
err := mesh.RemoveNode(s.HostParameters.GetPublicKey())
|
err := mesh.RemoveNode(s.HostParameters.GetPublicKey())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
logging.Log.WriteErrorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.OnDelete != nil {
|
if s.OnDelete != nil {
|
||||||
|
@ -28,6 +28,7 @@ type SyncerImpl struct {
|
|||||||
cluster conn.ConnCluster
|
cluster conn.ConnCluster
|
||||||
conf *conf.DaemonConfiguration
|
conf *conf.DaemonConfiguration
|
||||||
lastSync map[string]int64
|
lastSync map[string]int64
|
||||||
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync: Sync with random nodes
|
// Sync: Sync with random nodes
|
||||||
@ -134,7 +135,9 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) error {
|
|||||||
|
|
||||||
correspondingMesh.SaveChanges()
|
correspondingMesh.SaveChanges()
|
||||||
|
|
||||||
|
s.lock.Lock()
|
||||||
s.lastSync[correspondingMesh.GetMeshId()] = time.Now().Unix()
|
s.lastSync[correspondingMesh.GetMeshId()] = time.Now().Unix()
|
||||||
|
s.lock.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user