From 579426e32df8bf16088d6f320233ddc4c4db1e45 Mon Sep 17 00:00:00 2001 From: Tim Beatham Date: Mon, 30 Oct 2023 16:49:02 +0000 Subject: [PATCH] Tidied up code, made changes for benchmarking. --- cmd/wgmeshd/configuration.yaml | 6 +++--- cmd/wgmeshd/main.go | 11 +++++++++-- pkg/mesh/manager.go | 23 ++++++++++++++++++++--- pkg/robin/requester.go | 7 ++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cmd/wgmeshd/configuration.yaml b/cmd/wgmeshd/configuration.yaml index 9c6bf0e..96a5c94 100644 --- a/cmd/wgmeshd/configuration.yaml +++ b/cmd/wgmeshd/configuration.yaml @@ -1,6 +1,6 @@ -certificatePath: "../../cert/cert.pem" -privateKeyPath: "../../cert/priv.pem" -caCertificatePath: "../../cert/cacert.pem" +certificatePath: "/wgmesh/cert/cert.pem" +privateKeyPath: "/wgmesh/cert/priv.pem" +caCertificatePath: "/wgmesh/cert/cacert.pem" skipCertVerification: true gRPCPort: "8080" advertiseRoutes: true diff --git a/cmd/wgmeshd/main.go b/cmd/wgmeshd/main.go index 0f2f5f8..b4c8a16 100644 --- a/cmd/wgmeshd/main.go +++ b/cmd/wgmeshd/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "os" "github.com/tim-beatham/wgmesh/pkg/conf" ctrlserver "github.com/tim-beatham/wgmesh/pkg/ctrlserver" @@ -15,9 +16,15 @@ import ( ) func main() { - conf, err := conf.ParseConfiguration("./configuration.yaml") + if len(os.Args) != 2 { + logging.Log.WriteErrorf("Need to provide configuration.yaml") + return + } + + conf, err := conf.ParseConfiguration(os.Args[1]) if err != nil { - log.Fatalln("Could not parse configuration") + logging.Log.WriteInfof("Could not parse configuration") + return } client, err := wgctrl.New() diff --git a/pkg/mesh/manager.go b/pkg/mesh/manager.go index 7ae5025..165fb62 100644 --- a/pkg/mesh/manager.go +++ b/pkg/mesh/manager.go @@ -50,7 +50,10 @@ func (m *MeshManager) CreateMesh(devName string, port int) (string, error) { } m.Meshes[meshId] = nodeManager - return meshId, err + return meshId, m.interfaceManipulator.CreateInterface(&wg.CreateInterfaceParams{ + IfName: devName, + Port: port, + }) } type AddMeshParams struct { @@ -81,7 +84,11 @@ func (m *MeshManager) AddMesh(params *AddMeshParams) error { } m.Meshes[params.MeshId] = meshProvider - return err + + return m.interfaceManipulator.CreateInterface(&wg.CreateInterfaceParams{ + IfName: params.DevName, + Port: params.WgPort, + }) } // HasChanges returns true if the mesh has changes @@ -214,11 +221,21 @@ func (s *MeshManager) GetSelf(meshId string) (MeshNode, error) { // UpdateTimeStamp updates the timestamp of this node in all meshes func (s *MeshManager) UpdateTimeStamp() error { for _, mesh := range s.Meshes { - err := mesh.UpdateTimeStamp(s.HostParameters.HostEndpoint) + snapshot, err := mesh.GetMesh() if err != nil { return err } + + _, exists := snapshot.GetNodes()[s.HostParameters.HostEndpoint] + + if exists { + err = mesh.UpdateTimeStamp(s.HostParameters.HostEndpoint) + + if err != nil { + return err + } + } } return nil diff --git a/pkg/robin/requester.go b/pkg/robin/requester.go index 33ba779..eb14aa2 100644 --- a/pkg/robin/requester.go +++ b/pkg/robin/requester.go @@ -31,8 +31,9 @@ func (n *IpcHandler) CreateMesh(args *ipc.NewMeshArgs, reply *string) error { WgPort: args.WgPort, Endpoint: args.Endpoint, }) + *reply = meshId - return nil + return err } func (n *IpcHandler) ListMeshes(_ string, reply *ipc.ListMeshReply) error { @@ -51,6 +52,10 @@ func (n *IpcHandler) ListMeshes(_ string, reply *ipc.ListMeshReply) error { func (n *IpcHandler) JoinMesh(args ipc.JoinMeshArgs, reply *string) error { peerConnection, err := n.Server.ConnectionManager.GetConnection(args.IpAdress) + if err != nil { + return err + } + client, err := peerConnection.GetClient() if err != nil {