smegmesh/pkg/ipc/ipc.go
Tim Beatham 360f9d3c54 Few refactorings of managing the mesh and a graph
visualisation tool for seeing the state of a mesh.
2023-10-22 13:34:49 +01:00

53 lines
944 B
Go

package ipc
import (
"errors"
"net"
"net/http"
"net/rpc"
"os"
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
)
type JoinMeshArgs struct {
MeshId string
IpAdress string
}
type GetMeshReply struct {
Nodes []ctrlserver.MeshNode
}
type ListMeshReply struct {
Meshes []string
}
type MeshIpc interface {
CreateMesh(name string, reply *string) error
ListMeshes(name string, reply *ListMeshReply) error
JoinMesh(args JoinMeshArgs, reply *string) error
GetMesh(meshId string, reply *GetMeshReply) error
EnableInterface(meshId string, reply *string) error
GetDOT(meshId string, reply *string) error
}
const SockAddr = "/tmp/wgmesh_ipc.sock"
func RunIpcHandler(server MeshIpc) error {
if err := os.RemoveAll(SockAddr); err != nil {
return errors.New("Could not find to address")
}
rpc.Register(server)
rpc.HandleHTTP()
l, e := net.Listen("unix", SockAddr)
if e != nil {
return e
}
http.Serve(l, nil)
return nil
}