2023-09-29 16:00:20 +02:00
|
|
|
package robin
|
2023-09-20 00:50:44 +02:00
|
|
|
|
|
|
|
import (
|
2023-09-29 16:00:20 +02:00
|
|
|
"context"
|
2023-09-20 00:50:44 +02:00
|
|
|
"errors"
|
|
|
|
|
2024-01-02 00:55:50 +01:00
|
|
|
"github.com/tim-beatham/smegmesh/pkg/ctrlserver"
|
|
|
|
"github.com/tim-beatham/smegmesh/pkg/rpc"
|
2023-09-20 00:50:44 +02:00
|
|
|
)
|
|
|
|
|
2024-01-04 14:12:07 +01:00
|
|
|
// WgRpc: represents a WireGuard rpc call
|
2023-10-26 17:53:12 +02:00
|
|
|
type WgRpc struct {
|
2023-09-29 16:00:20 +02:00
|
|
|
rpc.UnimplementedMeshCtrlServerServer
|
2023-10-02 17:03:41 +02:00
|
|
|
Server *ctrlserver.MeshCtrlServer
|
2023-09-20 00:50:44 +02:00
|
|
|
}
|
|
|
|
|
2024-01-04 14:12:07 +01:00
|
|
|
// GetMesh: serialise the mesh network into bytes
|
2023-10-26 17:53:12 +02:00
|
|
|
func (m *WgRpc) GetMesh(ctx context.Context, request *rpc.GetMeshRequest) (*rpc.GetMeshReply, error) {
|
2023-10-06 12:52:51 +02:00
|
|
|
mesh := m.Server.MeshManager.GetMesh(request.MeshId)
|
2023-09-20 00:50:44 +02:00
|
|
|
|
2023-10-06 12:52:51 +02:00
|
|
|
if mesh == nil {
|
|
|
|
return nil, errors.New("mesh does not exist")
|
2023-09-20 00:50:44 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 12:52:51 +02:00
|
|
|
meshBytes := mesh.Save()
|
|
|
|
|
2023-09-29 16:00:20 +02:00
|
|
|
reply := rpc.GetMeshReply{
|
2023-10-06 12:52:51 +02:00
|
|
|
Mesh: meshBytes,
|
2023-09-20 00:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return &reply, nil
|
|
|
|
}
|