mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-27 12:10:20 +08:00
rpc: use gRPC status and error codes instead of our own
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -22,7 +22,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func status(cmd *cobra.Command, args []string) {
|
func status(cmd *cobra.Command, args []string) {
|
||||||
sts, err := client.GetStatus(context.Background(), &pb.Void{})
|
sts, err := client.GetStatus(context.Background(), &pb.Empty{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal("Failed to retrieve status from daemon", zap.Error(err))
|
logger.Fatal("Failed to retrieve status from daemon", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ func init() {
|
|||||||
|
|
||||||
func stop(cmd *cobra.Command, args []string) error {
|
func stop(cmd *cobra.Command, args []string) error {
|
||||||
// TODO: Ignore errors caused by closed connection or gracefully shutdown the server
|
// TODO: Ignore errors caused by closed connection or gracefully shutdown the server
|
||||||
if rerr, err := client.Stop(context.Background(), &pb.StopParams{}); err != nil {
|
if _, err := client.Stop(context.Background(), &pb.StopParams{}); err != nil {
|
||||||
return fmt.Errorf("failed RPC request: %w", err)
|
return fmt.Errorf("failed RPC request: %w", err)
|
||||||
} else if !rerr.Ok() {
|
|
||||||
return fmt.Errorf("received RPC error: %w", rerr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -23,12 +23,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sync(cmd *cobra.Command, args []string) error {
|
func sync(cmd *cobra.Command, args []string) error {
|
||||||
rerr, err := client.Sync(context.Background(), &pb.SyncParams{})
|
_, err := client.Sync(context.Background(), &pb.SyncParams{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed RPC request: %w", err)
|
return fmt.Errorf("failed RPC request: %w", err)
|
||||||
} else if !rerr.Ok() {
|
|
||||||
return fmt.Errorf("received RPC error: %w", rerr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func wgPubKey(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func wgShow(cmd *cobra.Command, args []string) error {
|
func wgShow(cmd *cobra.Command, args []string) error {
|
||||||
sts, err := client.GetStatus(context.Background(), &pb.Void{})
|
sts, err := client.GetStatus(context.Background(), &pb.Empty{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed RPC request: %w", err)
|
return fmt.Errorf("failed RPC request: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,37 +8,6 @@ import (
|
|||||||
icex "riasc.eu/wice/pkg/ice"
|
icex "riasc.eu/wice/pkg/ice"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
Success = &Error{
|
|
||||||
Code: Error_SUCCESS,
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrNotSupported = &Error{
|
|
||||||
Code: Error_ENOTSUP,
|
|
||||||
Message: "not supported yet",
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrNotAuthorized = &Error{
|
|
||||||
Code: Error_EPERM,
|
|
||||||
Message: "not authorized",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewError(e error) *Error {
|
|
||||||
return &Error{
|
|
||||||
Code: Error_EUNKNOWN,
|
|
||||||
Message: e.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Error) Error() string {
|
|
||||||
return e.Message
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Error) Ok() bool {
|
|
||||||
return e.Code == Error_SUCCESS
|
|
||||||
}
|
|
||||||
|
|
||||||
func TimeNow() *Timestamp {
|
func TimeNow() *Timestamp {
|
||||||
return Time(time.Now())
|
return Time(time.Now())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ syntax = "proto3";
|
|||||||
package wice;
|
package wice;
|
||||||
option go_package = "riasc.eu/wice/pkg/pb";
|
option go_package = "riasc.eu/wice/pkg/pb";
|
||||||
|
|
||||||
message Void {}
|
message Empty {}
|
||||||
|
|
||||||
enum ConnectionState {
|
enum ConnectionState {
|
||||||
// ICE Connection state from pion/ice/ice.go
|
// ICE Connection state from pion/ice/ice.go
|
||||||
@@ -27,26 +27,3 @@ message Timestamp {
|
|||||||
int64 seconds = 1;
|
int64 seconds = 1;
|
||||||
int32 nanos = 2;
|
int32 nanos = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A common error type used as return value for gRPC calls
|
|
||||||
message Error {
|
|
||||||
// The Error code inspired by POSIX's errno
|
|
||||||
// See: https://pubs.opengroup.org/onlinepubs/009696899/functions/xsh_chap02_03.html
|
|
||||||
enum Code {
|
|
||||||
SUCCESS = 0;
|
|
||||||
EPERM = 1;
|
|
||||||
ENOENT = 2;
|
|
||||||
EEXIST = 17;
|
|
||||||
EALREADY = 18;
|
|
||||||
ENOTSUP = 10;
|
|
||||||
|
|
||||||
EUNKNOWN = 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The error code
|
|
||||||
Code code = 1;
|
|
||||||
|
|
||||||
// A human readable error message
|
|
||||||
string message = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,31 +52,31 @@ message PutSignalingMessageParams {
|
|||||||
|
|
||||||
service Socket {
|
service Socket {
|
||||||
rpc StreamEvents(StreamEventsParams) returns (stream Event) {}
|
rpc StreamEvents(StreamEventsParams) returns (stream Event) {}
|
||||||
rpc UnWait(UnWaitParams) returns (Error) {}
|
rpc UnWait(UnWaitParams) returns (Empty) {}
|
||||||
rpc Stop(StopParams) returns (Error) {}
|
rpc Stop(StopParams) returns (Empty) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
service Watcher {
|
service Watcher {
|
||||||
rpc Sync(SyncParams) returns (Error) {}
|
rpc Sync(SyncParams) returns (Empty) {}
|
||||||
|
|
||||||
rpc GetStatus(Void) returns (Status) {}
|
rpc GetStatus(Empty) returns (Status) {}
|
||||||
|
|
||||||
rpc RemoveInterface(RemoveInterfaceParams) returns (Error) {}
|
rpc RemoveInterface(RemoveInterfaceParams) returns (Empty) {}
|
||||||
|
|
||||||
rpc SyncInterfaceConfig(InterfaceConfigParams) returns (Error) {}
|
rpc SyncInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
|
||||||
rpc AddInterfaceConfig(InterfaceConfigParams) returns (Error) {}
|
rpc AddInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
|
||||||
rpc SetInterfaceConfig(InterfaceConfigParams) returns (Error) {}
|
rpc SetInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
|
||||||
|
|
||||||
// For manual signaling backend
|
// For manual signaling backend
|
||||||
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
|
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
|
||||||
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Error) {}
|
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Empty) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
service EndpointDiscoverySocket {
|
service EndpointDiscoverySocket {
|
||||||
rpc RestartPeer(RestartPeerParams) returns (Error) {}
|
rpc RestartPeer(RestartPeerParams) returns (Empty) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
service SignalingSocket {
|
service SignalingSocket {
|
||||||
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
|
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
|
||||||
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Error) {}
|
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Empty) {}
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,8 @@ const _ = grpc.SupportPackageIsVersion7
|
|||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
type SocketClient interface {
|
type SocketClient interface {
|
||||||
StreamEvents(ctx context.Context, in *StreamEventsParams, opts ...grpc.CallOption) (Socket_StreamEventsClient, error)
|
StreamEvents(ctx context.Context, in *StreamEventsParams, opts ...grpc.CallOption) (Socket_StreamEventsClient, error)
|
||||||
UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Error, error)
|
UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Error, error)
|
Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type socketClient struct {
|
type socketClient struct {
|
||||||
@@ -67,8 +67,8 @@ func (x *socketStreamEventsClient) Recv() (*Event, error) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Socket/UnWait", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Socket/UnWait", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -76,8 +76,8 @@ func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grp
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Socket/Stop", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Socket/Stop", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -90,8 +90,8 @@ func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.Ca
|
|||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type SocketServer interface {
|
type SocketServer interface {
|
||||||
StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error
|
StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error
|
||||||
UnWait(context.Context, *UnWaitParams) (*Error, error)
|
UnWait(context.Context, *UnWaitParams) (*Empty, error)
|
||||||
Stop(context.Context, *StopParams) (*Error, error)
|
Stop(context.Context, *StopParams) (*Empty, error)
|
||||||
mustEmbedUnimplementedSocketServer()
|
mustEmbedUnimplementedSocketServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,10 +102,10 @@ type UnimplementedSocketServer struct {
|
|||||||
func (UnimplementedSocketServer) StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error {
|
func (UnimplementedSocketServer) StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error {
|
||||||
return status.Errorf(codes.Unimplemented, "method StreamEvents not implemented")
|
return status.Errorf(codes.Unimplemented, "method StreamEvents not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSocketServer) UnWait(context.Context, *UnWaitParams) (*Error, error) {
|
func (UnimplementedSocketServer) UnWait(context.Context, *UnWaitParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method UnWait not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method UnWait not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSocketServer) Stop(context.Context, *StopParams) (*Error, error) {
|
func (UnimplementedSocketServer) Stop(context.Context, *StopParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Stop not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Stop not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSocketServer) mustEmbedUnimplementedSocketServer() {}
|
func (UnimplementedSocketServer) mustEmbedUnimplementedSocketServer() {}
|
||||||
@@ -208,15 +208,15 @@ var Socket_ServiceDesc = grpc.ServiceDesc{
|
|||||||
//
|
//
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
type WatcherClient interface {
|
type WatcherClient interface {
|
||||||
Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Error, error)
|
Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
GetStatus(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Status, error)
|
GetStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Status, error)
|
||||||
RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Error, error)
|
RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
|
SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
|
AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
|
SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
// For manual signaling backend
|
// For manual signaling backend
|
||||||
GetSignalingMessage(ctx context.Context, in *GetSignalingMessageParams, opts ...grpc.CallOption) (*GetSignalingMessageResp, error)
|
GetSignalingMessage(ctx context.Context, in *GetSignalingMessageParams, opts ...grpc.CallOption) (*GetSignalingMessageResp, error)
|
||||||
PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error)
|
PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type watcherClient struct {
|
type watcherClient struct {
|
||||||
@@ -227,8 +227,8 @@ func NewWatcherClient(cc grpc.ClientConnInterface) WatcherClient {
|
|||||||
return &watcherClient{cc}
|
return &watcherClient{cc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/Sync", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/Sync", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -236,7 +236,7 @@ func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.C
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) GetStatus(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Status, error) {
|
func (c *watcherClient) GetStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Status, error) {
|
||||||
out := new(Status)
|
out := new(Status)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/GetStatus", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/GetStatus", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -245,8 +245,8 @@ func (c *watcherClient) GetStatus(ctx context.Context, in *Void, opts ...grpc.Ca
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/RemoveInterface", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/RemoveInterface", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -254,8 +254,8 @@ func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterface
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/SyncInterfaceConfig", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/SyncInterfaceConfig", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -263,8 +263,8 @@ func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceCo
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/AddInterfaceConfig", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/AddInterfaceConfig", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -272,8 +272,8 @@ func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceCon
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/SetInterfaceConfig", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/SetInterfaceConfig", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -290,8 +290,8 @@ func (c *watcherClient) GetSignalingMessage(ctx context.Context, in *GetSignalin
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Watcher/PutSignalingMessage", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Watcher/PutSignalingMessage", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -303,15 +303,15 @@ func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalin
|
|||||||
// All implementations must embed UnimplementedWatcherServer
|
// All implementations must embed UnimplementedWatcherServer
|
||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type WatcherServer interface {
|
type WatcherServer interface {
|
||||||
Sync(context.Context, *SyncParams) (*Error, error)
|
Sync(context.Context, *SyncParams) (*Empty, error)
|
||||||
GetStatus(context.Context, *Void) (*Status, error)
|
GetStatus(context.Context, *Empty) (*Status, error)
|
||||||
RemoveInterface(context.Context, *RemoveInterfaceParams) (*Error, error)
|
RemoveInterface(context.Context, *RemoveInterfaceParams) (*Empty, error)
|
||||||
SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
|
SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
|
||||||
AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
|
AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
|
||||||
SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
|
SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
|
||||||
// For manual signaling backend
|
// For manual signaling backend
|
||||||
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
|
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
|
||||||
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error)
|
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error)
|
||||||
mustEmbedUnimplementedWatcherServer()
|
mustEmbedUnimplementedWatcherServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,28 +319,28 @@ type WatcherServer interface {
|
|||||||
type UnimplementedWatcherServer struct {
|
type UnimplementedWatcherServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UnimplementedWatcherServer) Sync(context.Context, *SyncParams) (*Error, error) {
|
func (UnimplementedWatcherServer) Sync(context.Context, *SyncParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Sync not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Sync not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) GetStatus(context.Context, *Void) (*Status, error) {
|
func (UnimplementedWatcherServer) GetStatus(context.Context, *Empty) (*Status, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetStatus not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetStatus not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) RemoveInterface(context.Context, *RemoveInterfaceParams) (*Error, error) {
|
func (UnimplementedWatcherServer) RemoveInterface(context.Context, *RemoveInterfaceParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method RemoveInterface not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method RemoveInterface not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error) {
|
func (UnimplementedWatcherServer) SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method SyncInterfaceConfig not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method SyncInterfaceConfig not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error) {
|
func (UnimplementedWatcherServer) AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method AddInterfaceConfig not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method AddInterfaceConfig not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error) {
|
func (UnimplementedWatcherServer) SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method SetInterfaceConfig not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method SetInterfaceConfig not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
|
func (UnimplementedWatcherServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetSignalingMessage not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetSignalingMessage not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error) {
|
func (UnimplementedWatcherServer) PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method PutSignalingMessage not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method PutSignalingMessage not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedWatcherServer) mustEmbedUnimplementedWatcherServer() {}
|
func (UnimplementedWatcherServer) mustEmbedUnimplementedWatcherServer() {}
|
||||||
@@ -375,7 +375,7 @@ func _Watcher_Sync_Handler(srv interface{}, ctx context.Context, dec func(interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func _Watcher_GetStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _Watcher_GetStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(Void)
|
in := new(Empty)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ func _Watcher_GetStatus_Handler(srv interface{}, ctx context.Context, dec func(i
|
|||||||
FullMethod: "/wice.Watcher/GetStatus",
|
FullMethod: "/wice.Watcher/GetStatus",
|
||||||
}
|
}
|
||||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return srv.(WatcherServer).GetStatus(ctx, req.(*Void))
|
return srv.(WatcherServer).GetStatus(ctx, req.(*Empty))
|
||||||
}
|
}
|
||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
@@ -548,7 +548,7 @@ var Watcher_ServiceDesc = grpc.ServiceDesc{
|
|||||||
//
|
//
|
||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
type EndpointDiscoverySocketClient interface {
|
type EndpointDiscoverySocketClient interface {
|
||||||
RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Error, error)
|
RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type endpointDiscoverySocketClient struct {
|
type endpointDiscoverySocketClient struct {
|
||||||
@@ -559,8 +559,8 @@ func NewEndpointDiscoverySocketClient(cc grpc.ClientConnInterface) EndpointDisco
|
|||||||
return &endpointDiscoverySocketClient{cc}
|
return &endpointDiscoverySocketClient{cc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.EndpointDiscoverySocket/RestartPeer", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.EndpointDiscoverySocket/RestartPeer", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -572,7 +572,7 @@ func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *Res
|
|||||||
// All implementations must embed UnimplementedEndpointDiscoverySocketServer
|
// All implementations must embed UnimplementedEndpointDiscoverySocketServer
|
||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type EndpointDiscoverySocketServer interface {
|
type EndpointDiscoverySocketServer interface {
|
||||||
RestartPeer(context.Context, *RestartPeerParams) (*Error, error)
|
RestartPeer(context.Context, *RestartPeerParams) (*Empty, error)
|
||||||
mustEmbedUnimplementedEndpointDiscoverySocketServer()
|
mustEmbedUnimplementedEndpointDiscoverySocketServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,7 +580,7 @@ type EndpointDiscoverySocketServer interface {
|
|||||||
type UnimplementedEndpointDiscoverySocketServer struct {
|
type UnimplementedEndpointDiscoverySocketServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UnimplementedEndpointDiscoverySocketServer) RestartPeer(context.Context, *RestartPeerParams) (*Error, error) {
|
func (UnimplementedEndpointDiscoverySocketServer) RestartPeer(context.Context, *RestartPeerParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method RestartPeer not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method RestartPeer not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedEndpointDiscoverySocketServer) mustEmbedUnimplementedEndpointDiscoverySocketServer() {
|
func (UnimplementedEndpointDiscoverySocketServer) mustEmbedUnimplementedEndpointDiscoverySocketServer() {
|
||||||
@@ -636,7 +636,7 @@ var EndpointDiscoverySocket_ServiceDesc = grpc.ServiceDesc{
|
|||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
type SignalingSocketClient interface {
|
type SignalingSocketClient interface {
|
||||||
GetSignalingMessage(ctx context.Context, in *GetSignalingMessageParams, opts ...grpc.CallOption) (*GetSignalingMessageResp, error)
|
GetSignalingMessage(ctx context.Context, in *GetSignalingMessageParams, opts ...grpc.CallOption) (*GetSignalingMessageResp, error)
|
||||||
PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error)
|
PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type signalingSocketClient struct {
|
type signalingSocketClient struct {
|
||||||
@@ -656,8 +656,8 @@ func (c *signalingSocketClient) GetSignalingMessage(ctx context.Context, in *Get
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error) {
|
func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.SignalingSocket/PutSignalingMessage", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.SignalingSocket/PutSignalingMessage", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -670,7 +670,7 @@ func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *Put
|
|||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type SignalingSocketServer interface {
|
type SignalingSocketServer interface {
|
||||||
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
|
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
|
||||||
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error)
|
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error)
|
||||||
mustEmbedUnimplementedSignalingSocketServer()
|
mustEmbedUnimplementedSignalingSocketServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,7 +681,7 @@ type UnimplementedSignalingSocketServer struct {
|
|||||||
func (UnimplementedSignalingSocketServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
|
func (UnimplementedSignalingSocketServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method GetSignalingMessage not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method GetSignalingMessage not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSignalingSocketServer) PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error) {
|
func (UnimplementedSignalingSocketServer) PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method PutSignalingMessage not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method PutSignalingMessage not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSignalingSocketServer) mustEmbedUnimplementedSignalingSocketServer() {}
|
func (UnimplementedSignalingSocketServer) mustEmbedUnimplementedSignalingSocketServer() {}
|
||||||
|
|||||||
@@ -36,5 +36,5 @@ message SubscribeParams {
|
|||||||
|
|
||||||
service Signaling {
|
service Signaling {
|
||||||
rpc Subscribe(SubscribeParams) returns (stream SignalingEnvelope) {}
|
rpc Subscribe(SubscribeParams) returns (stream SignalingEnvelope) {}
|
||||||
rpc Publish(SignalingEnvelope) returns (Error) {}
|
rpc Publish(SignalingEnvelope) returns (Empty) {}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.2.0
|
||||||
|
// - protoc v3.6.1
|
||||||
|
// source: signaling.proto
|
||||||
|
|
||||||
package pb
|
package pb
|
||||||
|
|
||||||
@@ -19,7 +23,7 @@ const _ = grpc.SupportPackageIsVersion7
|
|||||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||||
type SignalingClient interface {
|
type SignalingClient interface {
|
||||||
Subscribe(ctx context.Context, in *SubscribeParams, opts ...grpc.CallOption) (Signaling_SubscribeClient, error)
|
Subscribe(ctx context.Context, in *SubscribeParams, opts ...grpc.CallOption) (Signaling_SubscribeClient, error)
|
||||||
Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Error, error)
|
Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type signalingClient struct {
|
type signalingClient struct {
|
||||||
@@ -62,8 +66,8 @@ func (x *signalingSubscribeClient) Recv() (*SignalingEnvelope, error) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Error, error) {
|
func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
out := new(Error)
|
out := new(Empty)
|
||||||
err := c.cc.Invoke(ctx, "/wice.Signaling/Publish", in, out, opts...)
|
err := c.cc.Invoke(ctx, "/wice.Signaling/Publish", in, out, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -76,7 +80,7 @@ func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, op
|
|||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type SignalingServer interface {
|
type SignalingServer interface {
|
||||||
Subscribe(*SubscribeParams, Signaling_SubscribeServer) error
|
Subscribe(*SubscribeParams, Signaling_SubscribeServer) error
|
||||||
Publish(context.Context, *SignalingEnvelope) (*Error, error)
|
Publish(context.Context, *SignalingEnvelope) (*Empty, error)
|
||||||
mustEmbedUnimplementedSignalingServer()
|
mustEmbedUnimplementedSignalingServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +91,7 @@ type UnimplementedSignalingServer struct {
|
|||||||
func (UnimplementedSignalingServer) Subscribe(*SubscribeParams, Signaling_SubscribeServer) error {
|
func (UnimplementedSignalingServer) Subscribe(*SubscribeParams, Signaling_SubscribeServer) error {
|
||||||
return status.Errorf(codes.Unimplemented, "method Subscribe not implemented")
|
return status.Errorf(codes.Unimplemented, "method Subscribe not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSignalingServer) Publish(context.Context, *SignalingEnvelope) (*Error, error) {
|
func (UnimplementedSignalingServer) Publish(context.Context, *SignalingEnvelope) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented")
|
||||||
}
|
}
|
||||||
func (UnimplementedSignalingServer) mustEmbedUnimplementedSignalingServer() {}
|
func (UnimplementedSignalingServer) mustEmbedUnimplementedSignalingServer() {}
|
||||||
|
|||||||
@@ -79,11 +79,9 @@ func Connect(path string) (*Client, error) {
|
|||||||
|
|
||||||
go client.streamEvents()
|
go client.streamEvents()
|
||||||
|
|
||||||
rerr, err := client.UnWait(context.Background(), &pb.UnWaitParams{})
|
_, err = client.UnWait(context.Background(), &pb.UnWaitParams{})
|
||||||
if err != nil {
|
if sts := status.Convert(err); sts != nil && sts.Code() != codes.AlreadyExists {
|
||||||
return nil, fmt.Errorf("failed RPC request: %w", err)
|
return nil, fmt.Errorf("failed RPC request: %w", err)
|
||||||
} else if !rerr.Ok() && rerr.Code != pb.Error_EALREADY {
|
|
||||||
return nil, fmt.Errorf("received RPC error: %w", rerr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
wice "riasc.eu/wice/pkg"
|
wice "riasc.eu/wice/pkg"
|
||||||
"riasc.eu/wice/pkg/pb"
|
"riasc.eu/wice/pkg/pb"
|
||||||
)
|
)
|
||||||
@@ -55,25 +57,22 @@ out:
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DaemonServer) UnWait(ctx context.Context, params *pb.UnWaitParams) (*pb.Error, error) {
|
func (s *DaemonServer) UnWait(ctx context.Context, params *pb.UnWaitParams) (*pb.Empty, error) {
|
||||||
var e = &pb.Error{
|
err := status.Error(codes.AlreadyExists, "RPC socket has already been unwaited")
|
||||||
Code: pb.Error_EALREADY,
|
|
||||||
Message: "already unwaited",
|
|
||||||
}
|
|
||||||
|
|
||||||
s.waitOnce.Do(func() {
|
s.waitOnce.Do(func() {
|
||||||
s.logger.Info("Control socket un-waited")
|
s.logger.Info("Control socket un-waited")
|
||||||
s.waitGroup.Done()
|
s.waitGroup.Done()
|
||||||
e = pb.Success
|
err = nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return e, nil
|
return &pb.Empty{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DaemonServer) Stop(ctx context.Context, params *pb.StopParams) (*pb.Error, error) {
|
func (s *DaemonServer) Stop(ctx context.Context, params *pb.StopParams) (*pb.Empty, error) {
|
||||||
if err := s.Daemon.Close(); err != nil {
|
if err := s.Daemon.Close(); err != nil {
|
||||||
return pb.NewError(err), nil
|
return nil, status.Errorf(codes.Unknown, "failed to stop daemon: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pb.Success, nil
|
return &pb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package rpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"riasc.eu/wice/pkg/crypto"
|
"riasc.eu/wice/pkg/crypto"
|
||||||
"riasc.eu/wice/pkg/feat/disc/epice"
|
"riasc.eu/wice/pkg/feat/disc/epice"
|
||||||
icex "riasc.eu/wice/pkg/ice"
|
icex "riasc.eu/wice/pkg/ice"
|
||||||
@@ -32,30 +33,28 @@ func NewEndpointDiscoveryServer(s *Server, ep *epice.EndpointDiscovery) *Endpoin
|
|||||||
return eps
|
return eps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EndpointDiscoveryServer) RestartPeer(ctx context.Context, params *pb.RestartPeerParams) (*pb.Error, error) {
|
func (s *EndpointDiscoveryServer) RestartPeer(ctx context.Context, params *pb.RestartPeerParams) (*pb.Empty, error) {
|
||||||
pk, err := crypto.ParseKeyBytes(params.Peer)
|
pk, err := crypto.ParseKeyBytes(params.Peer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse key: %w", err)
|
return &pb.Empty{}, status.Errorf(codes.InvalidArgument, "failed to parse key: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := s.watcher.Peer(params.Intf, &pk)
|
p := s.watcher.Peer(params.Intf, &pk)
|
||||||
if p == nil {
|
if p == nil {
|
||||||
err := fmt.Errorf("unknown peer %s/%s", params.Intf, pk.String())
|
return &pb.Empty{}, status.Errorf(codes.NotFound, "unknown peer %s/%s", params.Intf, pk.String())
|
||||||
return pb.NewError(err), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := s.Peers[p]
|
ip := s.Peers[p]
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
err := fmt.Errorf("unknown peer %s/%s", params.Intf, pk.String())
|
return &pb.Empty{}, status.Errorf(codes.NotFound, "unknown peer %s/%s", params.Intf, pk.String())
|
||||||
return pb.NewError(err), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ip.Restart()
|
err = ip.Restart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pb.NewError(err), nil
|
return &pb.Empty{}, status.Errorf(codes.Unknown, "failed to restart peer session: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pb.Success, nil
|
return &pb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EndpointDiscoveryServer) SendConnectionStates(stream pb.Socket_StreamEventsServer) {
|
func (s *EndpointDiscoveryServer) SendConnectionStates(stream pb.Socket_StreamEventsServer) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"riasc.eu/wice/pkg/pb"
|
"riasc.eu/wice/pkg/pb"
|
||||||
"riasc.eu/wice/pkg/signaling"
|
"riasc.eu/wice/pkg/signaling"
|
||||||
"riasc.eu/wice/pkg/signaling/grpc"
|
"riasc.eu/wice/pkg/signaling/grpc"
|
||||||
@@ -31,23 +33,17 @@ func NewSignalingServer(s *Server, b *signaling.MultiBackend) *SignalingServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalingServer) GetSignalingMessage(ctx context.Context, params *pb.GetSignalingMessageParams) (*pb.GetSignalingMessageResp, error) {
|
func (s *SignalingServer) GetSignalingMessage(ctx context.Context, params *pb.GetSignalingMessageParams) (*pb.GetSignalingMessageResp, error) {
|
||||||
// peer, pbErr, err := s.findPeer(params.Intf, params.Peer)
|
return nil, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
// if pbErr != nil || err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
return &pb.GetSignalingMessageResp{}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalingServer) PutSignalingMessage(ctx context.Context, params *pb.PutSignalingMessageParams) (*pb.Error, error) {
|
func (s *SignalingServer) PutSignalingMessage(ctx context.Context, params *pb.PutSignalingMessageParams) (*pb.Empty, error) {
|
||||||
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
return pb.Success, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalingServer) Subscribe(*pb.SubscribeParams, pb.Signaling_SubscribeServer) error {
|
func (s *SignalingServer) Subscribe(*pb.SubscribeParams, pb.Signaling_SubscribeServer) error {
|
||||||
return nil
|
return status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalingServer) Publish(context.Context, *signaling.Envelope) (*pb.Error, error) {
|
func (s *SignalingServer) Publish(context.Context, *signaling.Envelope) (*pb.Empty, error) {
|
||||||
return pb.Success, nil
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"riasc.eu/wice/pkg/pb"
|
"riasc.eu/wice/pkg/pb"
|
||||||
"riasc.eu/wice/pkg/watcher"
|
"riasc.eu/wice/pkg/watcher"
|
||||||
)
|
)
|
||||||
@@ -27,7 +29,7 @@ func NewWatcherServer(s *Server, w *watcher.Watcher) *WatcherServer {
|
|||||||
return ws
|
return ws
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) GetStatus(ctx context.Context, _ *pb.Void) (*pb.Status, error) {
|
func (s *WatcherServer) GetStatus(ctx context.Context, _ *pb.Empty) (*pb.Status, error) {
|
||||||
s.InterfaceLock.Lock()
|
s.InterfaceLock.Lock()
|
||||||
defer s.InterfaceLock.Unlock()
|
defer s.InterfaceLock.Unlock()
|
||||||
|
|
||||||
@@ -41,26 +43,26 @@ func (s *WatcherServer) GetStatus(ctx context.Context, _ *pb.Void) (*pb.Status,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) Sync(ctx context.Context, params *pb.SyncParams) (*pb.Error, error) {
|
func (s *WatcherServer) Sync(ctx context.Context, params *pb.SyncParams) (*pb.Empty, error) {
|
||||||
if err := s.Watcher.Sync(); err != nil {
|
if err := s.Watcher.Sync(); err != nil {
|
||||||
return pb.NewError(err), nil
|
return &pb.Empty{}, status.Errorf(codes.Unknown, "failed to sync: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pb.Success, nil
|
return &pb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) RemoveInterface(ctx context.Context, params *pb.RemoveInterfaceParams) (*pb.Error, error) {
|
func (s *WatcherServer) RemoveInterface(ctx context.Context, params *pb.RemoveInterfaceParams) (*pb.Empty, error) {
|
||||||
return pb.ErrNotSupported, nil
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) SyncInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
|
func (s *WatcherServer) SyncInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
|
||||||
return pb.ErrNotSupported, nil
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) AddInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
|
func (s *WatcherServer) AddInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
|
||||||
return pb.ErrNotSupported, nil
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WatcherServer) SetInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
|
func (s *WatcherServer) SetInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
|
||||||
return pb.ErrNotSupported, nil
|
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,16 +91,16 @@ out:
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Publish(ctx context.Context, env *signaling.Envelope) (*pb.Error, error) {
|
func (s *Server) Publish(ctx context.Context, env *signaling.Envelope) (*pb.Empty, error) {
|
||||||
var err error
|
var err error
|
||||||
var pkRecipient, pkSender crypto.Key
|
var pkRecipient, pkSender crypto.Key
|
||||||
|
|
||||||
if pkRecipient, err = crypto.ParseKeyBytes(env.Recipient); err != nil {
|
if pkRecipient, err = crypto.ParseKeyBytes(env.Recipient); err != nil {
|
||||||
return nil, fmt.Errorf("invalid recipient key: %w", err)
|
return &pb.Empty{}, fmt.Errorf("invalid recipient key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkSender, err = crypto.ParseKeyBytes(env.Sender); err != nil {
|
if pkSender, err = crypto.ParseKeyBytes(env.Sender); err != nil {
|
||||||
return nil, fmt.Errorf("invalid sender key: %w", err)
|
return &pb.Empty{}, fmt.Errorf("invalid sender key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := s.getTopic(&pkRecipient)
|
t := s.getTopic(&pkRecipient)
|
||||||
@@ -111,7 +111,7 @@ func (s *Server) Publish(ctx context.Context, env *signaling.Envelope) (*pb.Erro
|
|||||||
zap.Any("recipient", pkRecipient),
|
zap.Any("recipient", pkRecipient),
|
||||||
zap.Any("sender", pkSender))
|
zap.Any("sender", pkSender))
|
||||||
|
|
||||||
return pb.Success, nil
|
return &pb.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GracefulStop() {
|
func (s *Server) GracefulStop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user