2023-09-29 16:00:20 +02:00
|
|
|
package ipc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/rpc"
|
|
|
|
"os"
|
|
|
|
|
2023-10-20 18:35:02 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
|
2023-09-29 16:00:20 +02:00
|
|
|
)
|
|
|
|
|
2023-10-24 17:00:46 +02:00
|
|
|
type NewMeshArgs struct {
|
|
|
|
IfName string
|
|
|
|
WgPort int
|
|
|
|
}
|
|
|
|
|
2023-09-29 16:00:20 +02:00
|
|
|
type JoinMeshArgs struct {
|
|
|
|
MeshId string
|
|
|
|
IpAdress string
|
2023-10-24 17:00:46 +02:00
|
|
|
IfName string
|
|
|
|
Port int
|
2023-09-29 16:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetMeshReply struct {
|
2023-10-20 18:35:02 +02:00
|
|
|
Nodes []ctrlserver.MeshNode
|
2023-09-29 16:00:20 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 19:25:38 +02:00
|
|
|
type ListMeshReply struct {
|
|
|
|
Meshes []string
|
|
|
|
}
|
|
|
|
|
2023-09-29 16:00:20 +02:00
|
|
|
type MeshIpc interface {
|
2023-10-24 17:00:46 +02:00
|
|
|
CreateMesh(args *NewMeshArgs, reply *string) error
|
2023-10-06 19:25:38 +02:00
|
|
|
ListMeshes(name string, reply *ListMeshReply) error
|
2023-09-29 16:00:20 +02:00
|
|
|
JoinMesh(args JoinMeshArgs, reply *string) error
|
|
|
|
GetMesh(meshId string, reply *GetMeshReply) error
|
|
|
|
EnableInterface(meshId string, reply *string) error
|
2023-10-22 14:34:49 +02:00
|
|
|
GetDOT(meshId string, reply *string) error
|
2023-09-29 16:00:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|