1
0
forked from extern/smegmesh

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

bugfix node not leaving
This commit is contained in:
Tim Beatham 2024-01-02 19:43:04 +00:00 committed by GitHub
commit 8a5673e303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 15 deletions

View File

@ -235,9 +235,19 @@ func NewSmegServer(conf ApiServerConf) (ApiServer, error) {
words: words, words: words,
} }
router.GET("/meshes", smegServer.GetMeshes) v1 := router.Group("/api/v1")
router.GET("/mesh/:meshid", smegServer.GetMesh) {
router.POST("/mesh/create", smegServer.CreateMesh) meshes := v1.Group("/meshes")
router.POST("/mesh/join", smegServer.JoinMesh) {
meshes.GET("/", smegServer.GetMeshes)
}
mesh := v1.Group("/mesh")
{
mesh.GET("/:meshid", smegServer.GetMesh)
mesh.POST("/create", smegServer.CreateMesh)
mesh.POST("/join", smegServer.JoinMesh)
}
}
return smegServer, nil return smegServer, nil
} }

View File

@ -38,11 +38,10 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) error {
// Self can be nil if the node is removed // Self can be nil if the node is removed
selfID := s.manager.GetPublicKey() selfID := s.manager.GetPublicKey()
self, _ := correspondingMesh.GetNode(selfID.String()) self, err := correspondingMesh.GetNode(selfID.String())
// Mesh has been removed if err != nil {
if self == nil { logging.Log.WriteErrorf(err.Error())
return fmt.Errorf("mesh %s does not exist", correspondingMesh.GetMeshId())
} }
correspondingMesh.Prune() correspondingMesh.Prune()
@ -51,7 +50,8 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) error {
logging.Log.WriteInfof("meshes %s has changes", correspondingMesh.GetMeshId()) logging.Log.WriteInfof("meshes %s has changes", correspondingMesh.GetMeshId())
} }
if self.GetType() == conf.PEER_ROLE && !correspondingMesh.HasChanges() && s.infectionCount == 0 { // If removed sync with other nodes to gossip the node is removed
if self != nil && self.GetType() == conf.PEER_ROLE && !correspondingMesh.HasChanges() && s.infectionCount == 0 {
logging.Log.WriteInfof("no changes for %s", correspondingMesh.GetMeshId()) logging.Log.WriteInfof("no changes for %s", correspondingMesh.GetMeshId())
// If not synchronised in certain time pull from random neighbour // If not synchronised in certain time pull from random neighbour
@ -63,16 +63,19 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) error {
} }
before := time.Now() before := time.Now()
s.manager.GetRouteManager().UpdateRoutes() err = s.manager.GetRouteManager().UpdateRoutes()
if err != nil {
logging.Log.WriteErrorf(err.Error())
}
publicKey := s.manager.GetPublicKey() publicKey := s.manager.GetPublicKey()
nodeNames := correspondingMesh.GetPeers() nodeNames := correspondingMesh.GetPeers()
if self != nil { nodeNames = lib.Filter(nodeNames, func(s string) bool {
nodeNames = lib.Filter(nodeNames, func(s string) bool { // Filter our only public key out so we dont sync with ourself
return s != mesh.NodeID(self) return s != publicKey.String()
}) })
}
var gossipNodes []string var gossipNodes []string