Tidied up code, made changes for benchmarking.

This commit is contained in:
Tim Beatham 2023-10-30 16:49:02 +00:00
parent 928f6af9ac
commit 579426e32d
4 changed files with 38 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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 {