From a619838e9e2327cc5a014b5e84ebee812999cea6 Mon Sep 17 00:00:00 2001 From: Tim Beatham Date: Thu, 18 Jan 2024 16:08:41 +0000 Subject: [PATCH] main - DONE :) --- cmd/smegctl/main.go | 10 +++++----- pkg/mesh/config.go | 11 +++++++++-- pkg/robin/requester.go | 2 +- pkg/sync/syncer.go | 5 ++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/smegctl/main.go b/cmd/smegctl/main.go index 4cea7cc..21dd8cb 100644 --- a/cmd/smegctl/main.go +++ b/cmd/smegctl/main.go @@ -55,7 +55,7 @@ func joinMesh(client *ipc.SmegmeshIpc, args ipc.JoinMeshArgs) { err := client.JoinMesh(args, &reply) if err != nil { - fmt.Println(err.Error()) + fmt.Print(err.Error()) } fmt.Println(reply) @@ -67,7 +67,7 @@ func leaveMesh(client *ipc.SmegmeshIpc, meshId string) { err := client.LeaveMesh(meshId, &reply) if err != nil { - fmt.Println(err.Error()) + fmt.Print(err.Error()) return } @@ -80,7 +80,7 @@ func getGraph(client *ipc.SmegmeshIpc) { err := client.ListMeshes(listMeshesReply) if err != nil { - fmt.Println(err.Error()) + fmt.Print(err.Error()) return } @@ -154,7 +154,7 @@ func putAlias(client *ipc.SmegmeshIpc, meshid, alias string) { }, &reply) if err != nil { - fmt.Println(err.Error()) + fmt.Print(err.Error()) return } @@ -171,7 +171,7 @@ func setService(client *ipc.SmegmeshIpc, meshId, service, value string) { }, &reply) if err != nil { - fmt.Println(err.Error()) + fmt.Print(err.Error()) return } diff --git a/pkg/mesh/config.go b/pkg/mesh/config.go index 8cf5c99..248b210 100644 --- a/pkg/mesh/config.go +++ b/pkg/mesh/config.go @@ -293,7 +293,10 @@ func (m *WgMeshConfigApplyer) getClientConfig(params *GetConfigParams) (*wgtypes Peers: peerCfgs, } - m.routeInstaller.InstallRoutes(params.dev.Name, installedRoutes...) + if params.dev != nil { + m.routeInstaller.InstallRoutes(params.dev.Name, installedRoutes...) + } + return &cfg, err } @@ -400,7 +403,11 @@ func (m *WgMeshConfigApplyer) updateWgConf(mesh MeshProvider, routes map[string] } nodes := lib.MapValues(snap.GetNodes()) - dev, _ := mesh.GetDevice() + dev, err := mesh.GetDevice() + + if err != nil { + return err + } slices.SortFunc(nodes, func(a, b MeshNode) int { return strings.Compare(string(a.GetType()), string(b.GetType())) diff --git a/pkg/robin/requester.go b/pkg/robin/requester.go index 775ac2e..1042a75 100644 --- a/pkg/robin/requester.go +++ b/pkg/robin/requester.go @@ -202,7 +202,7 @@ func (n *IpcHandler) Query(params ipc.QueryMesh, reply *string) error { // PutDescription: change your description in the mesh func (n *IpcHandler) PutDescription(args ipc.PutDescriptionArgs, reply *string) error { - err := n.Server.GetMeshManager().SetDescription(args.MeshId, args.Description) + err := n.Server.GetMeshManager().SetDescription(args.MeshId, args.Description)z if err != nil { return err diff --git a/pkg/sync/syncer.go b/pkg/sync/syncer.go index 227d06c..7404bb6 100644 --- a/pkg/sync/syncer.go +++ b/pkg/sync/syncer.go @@ -82,7 +82,7 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) (bool, error) { return false, nil } - // Peer with 2 nodes so that there is redundnacy in + // Peer with 2 nodes so that there is redundancy in // the situation the node leaves pre-emptively redundancyLength := min(len(neighbours), 2) gossipNodes = neighbours[:redundancyLength] @@ -126,13 +126,12 @@ func (s *SyncerImpl) Sync(correspondingMesh mesh.MeshProvider) (bool, error) { s.infectionCount++ } - changes := correspondingMesh.HasChanges() correspondingMesh.SaveChanges() s.lastSyncLock.Lock() s.lastSync[correspondingMesh.GetMeshId()] = time.Now().Unix() s.lastSyncLock.Unlock() - return changes, nil + return true, nil } // Pull one node in the cluster, if there has not been message dissemination