smegmesh/pkg/robin/responder.go

35 lines
719 B
Go
Raw Normal View History

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
)
type WgRpc struct {
2023-09-29 16:00:20 +02:00
rpc.UnimplementedMeshCtrlServerServer
Server *ctrlserver.MeshCtrlServer
2023-09-20 00:50:44 +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
}
func (m *WgRpc) JoinMesh(ctx context.Context, request *rpc.JoinMeshRequest) (*rpc.JoinMeshReply, error) {
2023-10-06 12:52:51 +02:00
return &rpc.JoinMeshReply{Success: true}, nil
2023-09-20 00:50:44 +02:00
}