mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2024-12-04 21:50:49 +01:00
81-seperate-synchronisation-into-independent-process
- nil dereference due to concurrency issues (the method shouldn't be concurrent)
This commit is contained in:
parent
a0e7a4a644
commit
1f8d229076
@ -22,7 +22,7 @@ type Route struct {
|
|||||||
// Destination the route is advertising
|
// Destination the route is advertising
|
||||||
Destination string
|
Destination string
|
||||||
// Path to the destination
|
// Path to the destination
|
||||||
Path []string
|
Path []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDestination implements mesh.Route.
|
// GetDestination implements mesh.Route.
|
||||||
@ -316,7 +316,7 @@ func (m *TwoPhaseStoreMeshManager) AddRoutes(nodeId string, routes ...mesh.Route
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add nodes on changes. Otherwise the node will advertise new
|
// Only add nodes on changes. Otherwise the node will advertise new
|
||||||
// information whenever they get new routes
|
// information whenever they get new routes
|
||||||
if changes {
|
if changes {
|
||||||
m.store.Put(nodeId, node)
|
m.store.Put(nodeId, node)
|
||||||
@ -466,7 +466,7 @@ func (m *TwoPhaseStoreMeshManager) getRoutes(targetNode string) (map[string]Rout
|
|||||||
return node.Routes, nil
|
return node.Routes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoutes: Get all unique routes the target node is advertising.
|
// GetRoutes: Get all unique routes the target node is advertising.
|
||||||
// on conflicts the route with the least hop count is chosen
|
// on conflicts the route with the least hop count is chosen
|
||||||
func (m *TwoPhaseStoreMeshManager) GetRoutes(targetNode string) (map[string]mesh.Route, error) {
|
func (m *TwoPhaseStoreMeshManager) GetRoutes(targetNode string) (map[string]mesh.Route, error) {
|
||||||
node, err := m.GetNode(targetNode)
|
node, err := m.GetNode(targetNode)
|
||||||
@ -521,7 +521,7 @@ func (m *TwoPhaseStoreMeshManager) RemoveNode(nodeId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfiguration gets the WireGuard configuration to use for this
|
// GetConfiguration gets the WireGuard configuration to use for this
|
||||||
// network
|
// network
|
||||||
func (m *TwoPhaseStoreMeshManager) GetConfiguration() *conf.WgConfiguration {
|
func (m *TwoPhaseStoreMeshManager) GetConfiguration() *conf.WgConfiguration {
|
||||||
return m.Conf
|
return m.Conf
|
||||||
|
@ -107,7 +107,7 @@ func NewCtrlServer(params *NewCtrlServerParams) (*MeshCtrlServer, error) {
|
|||||||
logging.Log.WriteErrorf(err.Error())
|
logging.Log.WriteErrorf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}, 1)
|
}, 1)
|
||||||
|
|
||||||
heartbeatTimer := lib.NewTimer(func() error {
|
heartbeatTimer := lib.NewTimer(func() error {
|
||||||
|
@ -120,7 +120,12 @@ func (m *WgMeshConfigApplyer) convertMeshNode(params convertMeshNodeParams) (*wg
|
|||||||
// getRoutes: finds the routes with the least hop distance. If more than one route exists
|
// getRoutes: finds the routes with the least hop distance. If more than one route exists
|
||||||
// consistently hash to evenly spread the distribution of traffic
|
// consistently hash to evenly spread the distribution of traffic
|
||||||
func (m *WgMeshConfigApplyer) getRoutes(meshProvider MeshProvider) (map[string][]routeNode, error) {
|
func (m *WgMeshConfigApplyer) getRoutes(meshProvider MeshProvider) (map[string][]routeNode, error) {
|
||||||
mesh, _ := meshProvider.GetMesh()
|
mesh, err := meshProvider.GetMesh()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
routes := make(map[string][]routeNode)
|
routes := make(map[string][]routeNode)
|
||||||
|
|
||||||
peers := lib.Filter(lib.MapValues(mesh.GetNodes()), func(p MeshNode) bool {
|
peers := lib.Filter(lib.MapValues(mesh.GetNodes()), func(p MeshNode) bool {
|
||||||
|
@ -63,11 +63,6 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
err := s.meshManager.GetRouteManager().UpdateRoutes()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
logging.Log.WriteErrorf(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
publicKey := s.meshManager.GetPublicKey()
|
publicKey := s.meshManager.GetPublicKey()
|
||||||
nodeNames := correspondingMesh.GetPeers()
|
nodeNames := correspondingMesh.GetPeers()
|
||||||
@ -231,12 +226,19 @@ func (s *SyncerImpl) SyncMeshes() error {
|
|||||||
if hasChanges {
|
if hasChanges {
|
||||||
logging.Log.WriteInfof("updating the WireGuard configuration")
|
logging.Log.WriteInfof("updating the WireGuard configuration")
|
||||||
err = s.meshManager.ApplyConfig()
|
err = s.meshManager.ApplyConfig()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logging.Log.WriteErrorf("failed to update config %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.meshManager.GetRouteManager().UpdateRoutes()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logging.Log.WriteErrorf("update routes failed %s", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
return err
|
||||||
logging.Log.WriteInfof("failed to update config %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewSyncerParams struct {
|
type NewSyncerParams struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user