mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-06-26 06:51:26 +02:00
81-seperate-synchronisation
- More code comments
This commit is contained in:
parent
02dfd73e08
commit
59d8ae4334
@ -7,7 +7,9 @@ import (
|
|||||||
"github.com/tim-beatham/smegmesh/pkg/lib"
|
"github.com/tim-beatham/smegmesh/pkg/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RouteManager: manager that leaks routes between meshes
|
||||||
type RouteManager interface {
|
type RouteManager interface {
|
||||||
|
// UpdateRoutes: leak all routes in each mesh
|
||||||
UpdateRoutes() error
|
UpdateRoutes() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,20 +17,24 @@ type Querier interface {
|
|||||||
Query(meshId string, queryParams string) ([]byte, error)
|
Query(meshId string, queryParams string) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JmesQuerier: queries the datstore in JMESPath syntax
|
||||||
type JmesQuerier struct {
|
type JmesQuerier struct {
|
||||||
manager mesh.MeshManager
|
manager mesh.MeshManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryError: query error if something went wrong
|
||||||
type QueryError struct {
|
type QueryError struct {
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QuerRoute: represents a route in the query
|
||||||
type QueryRoute struct {
|
type QueryRoute struct {
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination"`
|
||||||
HopCount int `json:"hopCount"`
|
HopCount int `json:"hopCount"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryNode: represents a single node in the query
|
||||||
type QueryNode struct {
|
type QueryNode struct {
|
||||||
HostEndpoint string `json:"hostEndpoint"`
|
HostEndpoint string `json:"hostEndpoint"`
|
||||||
PublicKey string `json:"publicKey"`
|
PublicKey string `json:"publicKey"`
|
||||||
@ -48,7 +52,7 @@ func (m *QueryError) Error() string {
|
|||||||
return m.msg
|
return m.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query: queries the data
|
// Query: queries the the datastore at the given meshid
|
||||||
func (j *JmesQuerier) Query(meshId, queryParams string) ([]byte, error) {
|
func (j *JmesQuerier) Query(meshId, queryParams string) ([]byte, error) {
|
||||||
mesh, ok := j.manager.GetMeshes()[meshId]
|
mesh, ok := j.manager.GetMeshes()[meshId]
|
||||||
|
|
||||||
@ -74,6 +78,7 @@ func (j *JmesQuerier) Query(meshId, queryParams string) ([]byte, error) {
|
|||||||
return bytes, err
|
return bytes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MeshNodeToQuerynode: convert the mesh node into a query abstraction
|
||||||
func MeshNodeToQueryNode(node mesh.MeshNode) *QueryNode {
|
func MeshNodeToQueryNode(node mesh.MeshNode) *QueryNode {
|
||||||
queryNode := new(QueryNode)
|
queryNode := new(QueryNode)
|
||||||
queryNode.HostEndpoint = node.GetHostEndpoint()
|
queryNode.HostEndpoint = node.GetHostEndpoint()
|
||||||
|
@ -14,10 +14,12 @@ import (
|
|||||||
"github.com/tim-beatham/smegmesh/pkg/rpc"
|
"github.com/tim-beatham/smegmesh/pkg/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IpcHandler: represents a handler for ipc calls
|
||||||
type IpcHandler struct {
|
type IpcHandler struct {
|
||||||
Server ctrlserver.CtrlServer
|
Server ctrlserver.CtrlServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getOverrideConfiguration: override any specific WireGuard configuration
|
||||||
func getOverrideConfiguration(args *ipc.WireGuardArgs) conf.WgConfiguration {
|
func getOverrideConfiguration(args *ipc.WireGuardArgs) conf.WgConfiguration {
|
||||||
overrideConf := conf.WgConfiguration{}
|
overrideConf := conf.WgConfiguration{}
|
||||||
|
|
||||||
@ -40,6 +42,7 @@ func getOverrideConfiguration(args *ipc.WireGuardArgs) conf.WgConfiguration {
|
|||||||
return overrideConf
|
return overrideConf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateMesh: create a new mesh network
|
||||||
func (n *IpcHandler) CreateMesh(args *ipc.NewMeshArgs, reply *string) error {
|
func (n *IpcHandler) CreateMesh(args *ipc.NewMeshArgs, reply *string) error {
|
||||||
overrideConf := getOverrideConfiguration(&args.WgArgs)
|
overrideConf := getOverrideConfiguration(&args.WgArgs)
|
||||||
|
|
||||||
@ -66,6 +69,7 @@ func (n *IpcHandler) CreateMesh(args *ipc.NewMeshArgs, reply *string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMeshes: list mesh networks
|
||||||
func (n *IpcHandler) ListMeshes(_ string, reply *ipc.ListMeshReply) error {
|
func (n *IpcHandler) ListMeshes(_ string, reply *ipc.ListMeshReply) error {
|
||||||
meshNames := make([]string, len(n.Server.GetMeshManager().GetMeshes()))
|
meshNames := make([]string, len(n.Server.GetMeshManager().GetMeshes()))
|
||||||
|
|
||||||
@ -79,6 +83,7 @@ func (n *IpcHandler) ListMeshes(_ string, reply *ipc.ListMeshReply) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JoinMesh: join a mesh network
|
||||||
func (n *IpcHandler) JoinMesh(args *ipc.JoinMeshArgs, reply *string) error {
|
func (n *IpcHandler) JoinMesh(args *ipc.JoinMeshArgs, reply *string) error {
|
||||||
overrideConf := getOverrideConfiguration(&args.WgArgs)
|
overrideConf := getOverrideConfiguration(&args.WgArgs)
|
||||||
|
|
||||||
@ -140,7 +145,7 @@ func (n *IpcHandler) JoinMesh(args *ipc.JoinMeshArgs, reply *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaveMesh leaves a mesh network
|
// LeaveMesh: leaves a mesh network
|
||||||
func (n *IpcHandler) LeaveMesh(meshId string, reply *string) error {
|
func (n *IpcHandler) LeaveMesh(meshId string, reply *string) error {
|
||||||
err := n.Server.GetMeshManager().LeaveMesh(meshId)
|
err := n.Server.GetMeshManager().LeaveMesh(meshId)
|
||||||
|
|
||||||
@ -150,6 +155,7 @@ func (n *IpcHandler) LeaveMesh(meshId string, reply *string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMesh: get a mesh network at the given meshid
|
||||||
func (n *IpcHandler) GetMesh(meshId string, reply *ipc.GetMeshReply) error {
|
func (n *IpcHandler) GetMesh(meshId string, reply *ipc.GetMeshReply) error {
|
||||||
theMesh := n.Server.GetMeshManager().GetMesh(meshId)
|
theMesh := n.Server.GetMeshManager().GetMesh(meshId)
|
||||||
|
|
||||||
@ -181,6 +187,7 @@ func (n *IpcHandler) GetMesh(meshId string, reply *ipc.GetMeshReply) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query: perform a jmespath query
|
||||||
func (n *IpcHandler) Query(params ipc.QueryMesh, reply *string) error {
|
func (n *IpcHandler) Query(params ipc.QueryMesh, reply *string) error {
|
||||||
queryResponse, err := n.Server.GetQuerier().Query(params.MeshId, params.Query)
|
queryResponse, err := n.Server.GetQuerier().Query(params.MeshId, params.Query)
|
||||||
|
|
||||||
@ -192,6 +199,7 @@ func (n *IpcHandler) Query(params ipc.QueryMesh, reply *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutDescription: change your description in the mesh
|
||||||
func (n *IpcHandler) PutDescription(args ipc.PutDescriptionArgs, reply *string) error {
|
func (n *IpcHandler) PutDescription(args ipc.PutDescriptionArgs, reply *string) error {
|
||||||
err := n.Server.GetMeshManager().SetDescription(args.MeshId, args.Description)
|
err := n.Server.GetMeshManager().SetDescription(args.MeshId, args.Description)
|
||||||
|
|
||||||
@ -203,6 +211,7 @@ func (n *IpcHandler) PutDescription(args ipc.PutDescriptionArgs, reply *string)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutAlias: put your aliasin the mesh
|
||||||
func (n *IpcHandler) PutAlias(args ipc.PutAliasArgs, reply *string) error {
|
func (n *IpcHandler) PutAlias(args ipc.PutAliasArgs, reply *string) error {
|
||||||
if args.Alias == "" {
|
if args.Alias == "" {
|
||||||
return fmt.Errorf("alias not provided")
|
return fmt.Errorf("alias not provided")
|
||||||
@ -218,6 +227,7 @@ func (n *IpcHandler) PutAlias(args ipc.PutAliasArgs, reply *string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutService: place a service in the mesh
|
||||||
func (n *IpcHandler) PutService(service ipc.PutServiceArgs, reply *string) error {
|
func (n *IpcHandler) PutService(service ipc.PutServiceArgs, reply *string) error {
|
||||||
err := n.Server.GetMeshManager().SetService(service.MeshId, service.Service, service.Value)
|
err := n.Server.GetMeshManager().SetService(service.MeshId, service.Service, service.Value)
|
||||||
|
|
||||||
@ -229,6 +239,7 @@ func (n *IpcHandler) PutService(service ipc.PutServiceArgs, reply *string) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteService: withtract a service in the mesh
|
||||||
func (n *IpcHandler) DeleteService(service ipc.DeleteServiceArgs, reply *string) error {
|
func (n *IpcHandler) DeleteService(service ipc.DeleteServiceArgs, reply *string) error {
|
||||||
err := n.Server.GetMeshManager().RemoveService(service.MeshId, service.Service)
|
err := n.Server.GetMeshManager().RemoveService(service.MeshId, service.Service)
|
||||||
|
|
||||||
@ -240,6 +251,7 @@ func (n *IpcHandler) DeleteService(service ipc.DeleteServiceArgs, reply *string)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RobinIpcParams: parameters required to construct a new mesh network
|
||||||
type RobinIpcParams struct {
|
type RobinIpcParams struct {
|
||||||
CtrlServer ctrlserver.CtrlServer
|
CtrlServer ctrlserver.CtrlServer
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,13 @@ import (
|
|||||||
"github.com/tim-beatham/smegmesh/pkg/rpc"
|
"github.com/tim-beatham/smegmesh/pkg/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WgRpc: represents a WireGuard rpc call
|
||||||
type WgRpc struct {
|
type WgRpc struct {
|
||||||
rpc.UnimplementedMeshCtrlServerServer
|
rpc.UnimplementedMeshCtrlServerServer
|
||||||
Server *ctrlserver.MeshCtrlServer
|
Server *ctrlserver.MeshCtrlServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMesh: serialise the mesh network into bytes
|
||||||
func (m *WgRpc) GetMesh(ctx context.Context, request *rpc.GetMeshRequest) (*rpc.GetMeshReply, error) {
|
func (m *WgRpc) GetMesh(ctx context.Context, request *rpc.GetMeshRequest) (*rpc.GetMeshReply, error) {
|
||||||
mesh := m.Server.MeshManager.GetMesh(request.MeshId)
|
mesh := m.Server.MeshManager.GetMesh(request.MeshId)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RouteInstaller: install the routes to the given interface
|
||||||
type RouteInstaller interface {
|
type RouteInstaller interface {
|
||||||
InstallRoutes(devName string, routes ...lib.Route) error
|
InstallRoutes(devName string, routes ...lib.Route) error
|
||||||
}
|
}
|
||||||
@ -19,6 +20,8 @@ func (r *RouteInstallerImpl) InstallRoutes(devName string, routes ...lib.Route)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer rtnl.Close()
|
||||||
|
|
||||||
err = rtnl.DeleteRoutes(devName, unix.AF_INET6, routes...)
|
err = rtnl.DeleteRoutes(devName, unix.AF_INET6, routes...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package timer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/tim-beatham/smegmesh/pkg/ctrlserver"
|
|
||||||
"github.com/tim-beatham/smegmesh/pkg/lib"
|
|
||||||
logging "github.com/tim-beatham/smegmesh/pkg/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewTimestampScheduler(ctrlServer *ctrlserver.MeshCtrlServer) lib.Timer {
|
|
||||||
timerFunc := func() error {
|
|
||||||
logging.Log.WriteInfof("Updated Timestamp")
|
|
||||||
return ctrlServer.MeshManager.UpdateTimeStamp()
|
|
||||||
}
|
|
||||||
return *lib.NewTimer(timerFunc, ctrlServer.Conf.HeartBeat)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user