forked from extern/smegmesh
Merge pull request #82 from tim-beatham/bugfix-node-not-leving
bugfix-node-not-leaving
This commit is contained in:
commit
9818645299
@ -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))))
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user