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"
|
|
|
|
|
|
|
|
"github.com/tim-beatham/wgmesh/pkg/ctrlserver"
|
2023-09-29 16:00:20 +02:00
|
|
|
"github.com/tim-beatham/wgmesh/pkg/rpc"
|
2023-09-20 00:50:44 +02:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|