forked from extern/smegmesh
Merge pull request #2 from tim-beatham/1-log-key-events-in-the-mesh
1 log key events in the mesh
This commit is contained in:
commit
a1caf2e8ae
@ -144,6 +144,19 @@ func getGraph(client *ipcRpc.Client, meshId string) {
|
|||||||
fmt.Println(reply)
|
fmt.Println(reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func queryMesh(client *ipcRpc.Client, meshId, query string) {
|
||||||
|
var reply string
|
||||||
|
|
||||||
|
err := client.Call("IpcHandler.Query", &ipc.QueryMesh{MeshId: meshId, Query: query}, &reply)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(reply)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parser := argparse.NewParser("wg-mesh",
|
parser := argparse.NewParser("wg-mesh",
|
||||||
"wg-mesh Manipulate WireGuard meshes")
|
"wg-mesh Manipulate WireGuard meshes")
|
||||||
@ -155,6 +168,7 @@ func main() {
|
|||||||
enableInterfaceCmd := parser.NewCommand("enable-interface", "Enable A Specific Mesh Interface")
|
enableInterfaceCmd := parser.NewCommand("enable-interface", "Enable A Specific Mesh Interface")
|
||||||
getGraphCmd := parser.NewCommand("get-graph", "Convert a mesh into DOT format")
|
getGraphCmd := parser.NewCommand("get-graph", "Convert a mesh into DOT format")
|
||||||
leaveMeshCmd := parser.NewCommand("leave-mesh", "Leave a mesh network")
|
leaveMeshCmd := parser.NewCommand("leave-mesh", "Leave a mesh network")
|
||||||
|
queryMeshCmd := parser.NewCommand("query-mesh", "Query a mesh network using JMESPath")
|
||||||
|
|
||||||
var newMeshIfName *string = newMeshCmd.String("f", "ifname", &argparse.Options{Required: true})
|
var newMeshIfName *string = newMeshCmd.String("f", "ifname", &argparse.Options{Required: true})
|
||||||
var newMeshPort *int = newMeshCmd.Int("p", "wgport", &argparse.Options{Required: true})
|
var newMeshPort *int = newMeshCmd.Int("p", "wgport", &argparse.Options{Required: true})
|
||||||
@ -172,6 +186,9 @@ func main() {
|
|||||||
|
|
||||||
var leaveMeshMeshId *string = leaveMeshCmd.String("m", "mesh", &argparse.Options{Required: true})
|
var leaveMeshMeshId *string = leaveMeshCmd.String("m", "mesh", &argparse.Options{Required: true})
|
||||||
|
|
||||||
|
var queryMeshMeshId *string = queryMeshCmd.String("m", "mesh", &argparse.Options{Required: true})
|
||||||
|
var queryMeshQuery *string = queryMeshCmd.String("q", "query", &argparse.Options{Required: true})
|
||||||
|
|
||||||
err := parser.Parse(os.Args)
|
err := parser.Parse(os.Args)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -224,4 +241,8 @@ func main() {
|
|||||||
if leaveMeshCmd.Happened() {
|
if leaveMeshCmd.Happened() {
|
||||||
leaveMesh(client, *leaveMeshMeshId)
|
leaveMesh(client, *leaveMeshMeshId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if queryMeshCmd.Happened() {
|
||||||
|
queryMesh(client, *queryMeshMeshId, *queryMeshQuery)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,4 +3,4 @@ privateKeyPath: "/wgmesh/cert/priv.pem"
|
|||||||
caCertificatePath: "/wgmesh/cert/cacert.pem"
|
caCertificatePath: "/wgmesh/cert/cacert.pem"
|
||||||
skipCertVerification: true
|
skipCertVerification: true
|
||||||
gRPCPort: "8080"
|
gRPCPort: "8080"
|
||||||
advertiseRoutes: true
|
advertiseRoutes: true
|
1
go.mod
1
go.mod
@ -16,6 +16,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/josharian/native v1.1.0 // indirect
|
github.com/josharian/native v1.1.0 // indirect
|
||||||
github.com/mdlayher/genetlink v1.3.2 // indirect
|
github.com/mdlayher/genetlink v1.3.2 // indirect
|
||||||
github.com/mdlayher/netlink v1.7.2 // indirect
|
github.com/mdlayher/netlink v1.7.2 // indirect
|
||||||
|
@ -139,10 +139,6 @@ func (m *CrdtMeshManager) HasChanges() bool {
|
|||||||
return len(changes) > 0
|
return len(changes) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CrdtMeshManager) HasFailed(endpoint string) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *CrdtMeshManager) SaveChanges() {
|
func (m *CrdtMeshManager) SaveChanges() {
|
||||||
hashes := m.doc.Heads()
|
hashes := m.doc.Heads()
|
||||||
hash := hashes[len(hashes)-1]
|
hash := hashes[len(hashes)-1]
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/tim-beatham/wgmesh/pkg/ip"
|
"github.com/tim-beatham/wgmesh/pkg/ip"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/lib"
|
"github.com/tim-beatham/wgmesh/pkg/lib"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/mesh"
|
"github.com/tim-beatham/wgmesh/pkg/mesh"
|
||||||
|
"github.com/tim-beatham/wgmesh/pkg/query"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/rpc"
|
"github.com/tim-beatham/wgmesh/pkg/rpc"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/wg"
|
"github.com/tim-beatham/wgmesh/pkg/wg"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
@ -19,6 +20,7 @@ type NewCtrlServerParams struct {
|
|||||||
AuthProvider rpc.AuthenticationServer
|
AuthProvider rpc.AuthenticationServer
|
||||||
CtrlProvider rpc.MeshCtrlServerServer
|
CtrlProvider rpc.MeshCtrlServerServer
|
||||||
SyncProvider rpc.SyncServiceServer
|
SyncProvider rpc.SyncServiceServer
|
||||||
|
Querier query.Querier
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new instance of the MeshCtrlServer or error if the
|
// Create a new instance of the MeshCtrlServer or error if the
|
||||||
@ -73,7 +75,9 @@ func NewCtrlServer(params *NewCtrlServerParams) (*MeshCtrlServer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctrlServer.Querier = query.NewJmesQuerier(ctrlServer.MeshManager)
|
||||||
ctrlServer.ConnectionServer = connServer
|
ctrlServer.ConnectionServer = connServer
|
||||||
|
|
||||||
return ctrlServer, nil
|
return ctrlServer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,13 +4,12 @@ import (
|
|||||||
"github.com/tim-beatham/wgmesh/pkg/conf"
|
"github.com/tim-beatham/wgmesh/pkg/conf"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/conn"
|
"github.com/tim-beatham/wgmesh/pkg/conn"
|
||||||
"github.com/tim-beatham/wgmesh/pkg/mesh"
|
"github.com/tim-beatham/wgmesh/pkg/mesh"
|
||||||
|
"github.com/tim-beatham/wgmesh/pkg/query"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
// Represents a WireGuard MeshNode
|
||||||
* Represents a WireGuard node
|
|
||||||
*/
|
|
||||||
type MeshNode struct {
|
type MeshNode struct {
|
||||||
HostEndpoint string
|
HostEndpoint string
|
||||||
WgEndpoint string
|
WgEndpoint string
|
||||||
@ -20,19 +19,18 @@ type MeshNode struct {
|
|||||||
Routes []string
|
Routes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Represents a WireGuard Mesh
|
||||||
type Mesh struct {
|
type Mesh struct {
|
||||||
SharedKey *wgtypes.Key
|
SharedKey *wgtypes.Key
|
||||||
Nodes map[string]MeshNode
|
Nodes map[string]MeshNode
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Represents a ctrlserver to be used in WireGuard
|
||||||
* Defines the mesh control server this node
|
|
||||||
* is running
|
|
||||||
*/
|
|
||||||
type MeshCtrlServer struct {
|
type MeshCtrlServer struct {
|
||||||
Client *wgctrl.Client
|
Client *wgctrl.Client
|
||||||
MeshManager *mesh.MeshManager
|
MeshManager *mesh.MeshManager
|
||||||
ConnectionManager conn.ConnectionManager
|
ConnectionManager conn.ConnectionManager
|
||||||
ConnectionServer *conn.ConnectionServer
|
ConnectionServer *conn.ConnectionServer
|
||||||
Conf *conf.WgMeshConfiguration
|
Conf *conf.WgMeshConfiguration
|
||||||
|
Querier query.Querier
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,11 @@ type ListMeshReply struct {
|
|||||||
Meshes []string
|
Meshes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryMesh struct {
|
||||||
|
MeshId string
|
||||||
|
Query string
|
||||||
|
}
|
||||||
|
|
||||||
type MeshIpc interface {
|
type MeshIpc interface {
|
||||||
CreateMesh(args *NewMeshArgs, reply *string) error
|
CreateMesh(args *NewMeshArgs, reply *string) error
|
||||||
ListMeshes(name string, reply *ListMeshReply) error
|
ListMeshes(name string, reply *ListMeshReply) error
|
||||||
@ -50,6 +55,7 @@ type MeshIpc interface {
|
|||||||
GetMesh(meshId string, reply *GetMeshReply) error
|
GetMesh(meshId string, reply *GetMeshReply) error
|
||||||
EnableInterface(meshId string, reply *string) error
|
EnableInterface(meshId string, reply *string) error
|
||||||
GetDOT(meshId string, reply *string) error
|
GetDOT(meshId string, reply *string) error
|
||||||
|
Query(query QueryMesh, reply *string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
const SockAddr = "/tmp/wgmesh_ipc.sock"
|
const SockAddr = "/tmp/wgmesh_ipc.sock"
|
||||||
|
@ -43,3 +43,15 @@ func MapKeys[K comparable, V any](m map[K]V) []K {
|
|||||||
|
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type convert[V1 any, V2 any] func(V1) V2
|
||||||
|
|
||||||
|
func Map[V1 any, V2 any](list []V1, f convert[V1, V2]) []V2 {
|
||||||
|
newList := make([]V2, len(list))
|
||||||
|
|
||||||
|
for i, elem := range list {
|
||||||
|
newList[i] = f(elem)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newList
|
||||||
|
}
|
||||||
|
@ -176,6 +176,17 @@ func (n *IpcHandler) GetDOT(meshId string, reply *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *IpcHandler) Query(params ipc.QueryMesh, reply *string) error {
|
||||||
|
queryResponse, err := n.Server.Querier.Query(params.MeshId, params.Query)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*reply = string(queryResponse)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type RobinIpcParams struct {
|
type RobinIpcParams struct {
|
||||||
CtrlServer *ctrlserver.MeshCtrlServer
|
CtrlServer *ctrlserver.MeshCtrlServer
|
||||||
}
|
}
|
||||||
|
@ -87,10 +87,12 @@ func (s *SyncServiceImpl) SyncMesh(stream rpc.SyncService_SyncMeshServer) error
|
|||||||
if syncer != nil {
|
if syncer != nil {
|
||||||
syncer.Complete()
|
syncer.Complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSyncService(server *ctrlserver.MeshCtrlServer) *SyncServiceImpl {
|
func NewSyncService(server *ctrlserver.MeshCtrlServer) *SyncServiceImpl {
|
||||||
return &SyncServiceImpl{Server: server}
|
return &SyncServiceImpl{Server: server}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user