rpc: use gRPC status and error codes instead of our own

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-08-24 04:12:16 +02:00
parent 1395ee25f7
commit c6df0dc0f3
16 changed files with 127 additions and 188 deletions

View File

@@ -22,7 +22,7 @@ func init() {
}
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 {
logger.Fatal("Failed to retrieve status from daemon", zap.Error(err))
}

View File

@@ -21,10 +21,8 @@ func init() {
func stop(cmd *cobra.Command, args []string) error {
// 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)
} else if !rerr.Ok() {
return fmt.Errorf("received RPC error: %w", rerr)
}
return nil

View File

@@ -23,12 +23,9 @@ func init() {
}
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 {
return fmt.Errorf("failed RPC request: %w", err)
} else if !rerr.Ok() {
return fmt.Errorf("received RPC error: %w", rerr)
}
return nil
}

View File

@@ -87,7 +87,7 @@ func wgPubKey(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 {
return fmt.Errorf("failed RPC request: %w", err)
}

View File

@@ -8,37 +8,6 @@ import (
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 {
return Time(time.Now())
}

View File

@@ -3,7 +3,7 @@ syntax = "proto3";
package wice;
option go_package = "riasc.eu/wice/pkg/pb";
message Void {}
message Empty {}
enum ConnectionState {
// ICE Connection state from pion/ice/ice.go
@@ -27,26 +27,3 @@ message Timestamp {
int64 seconds = 1;
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;
}

View File

@@ -52,31 +52,31 @@ message PutSignalingMessageParams {
service Socket {
rpc StreamEvents(StreamEventsParams) returns (stream Event) {}
rpc UnWait(UnWaitParams) returns (Error) {}
rpc Stop(StopParams) returns (Error) {}
rpc UnWait(UnWaitParams) returns (Empty) {}
rpc Stop(StopParams) returns (Empty) {}
}
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 AddInterfaceConfig(InterfaceConfigParams) returns (Error) {}
rpc SetInterfaceConfig(InterfaceConfigParams) returns (Error) {}
rpc SyncInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
rpc AddInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
rpc SetInterfaceConfig(InterfaceConfigParams) returns (Empty) {}
// For manual signaling backend
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Error) {}
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Empty) {}
}
service EndpointDiscoverySocket {
rpc RestartPeer(RestartPeerParams) returns (Error) {}
rpc RestartPeer(RestartPeerParams) returns (Empty) {}
}
service SignalingSocket {
rpc GetSignalingMessage(GetSignalingMessageParams) returns (GetSignalingMessageResp) {}
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Error) {}
rpc PutSignalingMessage(PutSignalingMessageParams) returns (Empty) {}
}

View File

@@ -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.
type SocketClient interface {
StreamEvents(ctx context.Context, in *StreamEventsParams, opts ...grpc.CallOption) (Socket_StreamEventsClient, error)
UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Error, error)
Stop(ctx context.Context, in *StopParams, 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) (*Empty, error)
}
type socketClient struct {
@@ -67,8 +67,8 @@ func (x *socketStreamEventsClient) Recv() (*Event, error) {
return m, nil
}
func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Socket/UnWait", in, out, opts...)
if err != nil {
return nil, err
@@ -76,8 +76,8 @@ func (c *socketClient) UnWait(ctx context.Context, in *UnWaitParams, opts ...grp
return out, nil
}
func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Socket/Stop", in, out, opts...)
if err != nil {
return nil, err
@@ -90,8 +90,8 @@ func (c *socketClient) Stop(ctx context.Context, in *StopParams, opts ...grpc.Ca
// for forward compatibility
type SocketServer interface {
StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error
UnWait(context.Context, *UnWaitParams) (*Error, error)
Stop(context.Context, *StopParams) (*Error, error)
UnWait(context.Context, *UnWaitParams) (*Empty, error)
Stop(context.Context, *StopParams) (*Empty, error)
mustEmbedUnimplementedSocketServer()
}
@@ -102,10 +102,10 @@ type UnimplementedSocketServer struct {
func (UnimplementedSocketServer) StreamEvents(*StreamEventsParams, Socket_StreamEventsServer) error {
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")
}
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")
}
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.
type WatcherClient interface {
Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Error, error)
GetStatus(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Status, error)
RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Error, error)
SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error)
Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Empty, error)
GetStatus(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Status, error)
RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Empty, error)
SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error)
// For manual signaling backend
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 {
@@ -227,8 +227,8 @@ func NewWatcherClient(cc grpc.ClientConnInterface) WatcherClient {
return &watcherClient{cc}
}
func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/Sync", in, out, opts...)
if err != nil {
return nil, err
@@ -236,7 +236,7 @@ func (c *watcherClient) Sync(ctx context.Context, in *SyncParams, opts ...grpc.C
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)
err := c.cc.Invoke(ctx, "/wice.Watcher/GetStatus", in, out, opts...)
if err != nil {
@@ -245,8 +245,8 @@ func (c *watcherClient) GetStatus(ctx context.Context, in *Void, opts ...grpc.Ca
return out, nil
}
func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterfaceParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/RemoveInterface", in, out, opts...)
if err != nil {
return nil, err
@@ -254,8 +254,8 @@ func (c *watcherClient) RemoveInterface(ctx context.Context, in *RemoveInterface
return out, nil
}
func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/SyncInterfaceConfig", in, out, opts...)
if err != nil {
return nil, err
@@ -263,8 +263,8 @@ func (c *watcherClient) SyncInterfaceConfig(ctx context.Context, in *InterfaceCo
return out, nil
}
func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/AddInterfaceConfig", in, out, opts...)
if err != nil {
return nil, err
@@ -272,8 +272,8 @@ func (c *watcherClient) AddInterfaceConfig(ctx context.Context, in *InterfaceCon
return out, nil
}
func (c *watcherClient) SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) SetInterfaceConfig(ctx context.Context, in *InterfaceConfigParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/SetInterfaceConfig", in, out, opts...)
if err != nil {
return nil, err
@@ -290,8 +290,8 @@ func (c *watcherClient) GetSignalingMessage(ctx context.Context, in *GetSignalin
return out, nil
}
func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Watcher/PutSignalingMessage", in, out, opts...)
if err != nil {
return nil, err
@@ -303,15 +303,15 @@ func (c *watcherClient) PutSignalingMessage(ctx context.Context, in *PutSignalin
// All implementations must embed UnimplementedWatcherServer
// for forward compatibility
type WatcherServer interface {
Sync(context.Context, *SyncParams) (*Error, error)
GetStatus(context.Context, *Void) (*Status, error)
RemoveInterface(context.Context, *RemoveInterfaceParams) (*Error, error)
SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Error, error)
Sync(context.Context, *SyncParams) (*Empty, error)
GetStatus(context.Context, *Empty) (*Status, error)
RemoveInterface(context.Context, *RemoveInterfaceParams) (*Empty, error)
SyncInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
AddInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
SetInterfaceConfig(context.Context, *InterfaceConfigParams) (*Empty, error)
// For manual signaling backend
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error)
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error)
mustEmbedUnimplementedWatcherServer()
}
@@ -319,28 +319,28 @@ type WatcherServer interface {
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")
}
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")
}
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")
}
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")
}
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")
}
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")
}
func (UnimplementedWatcherServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
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")
}
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) {
in := new(Void)
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
@@ -387,7 +387,7 @@ func _Watcher_GetStatus_Handler(srv interface{}, ctx context.Context, dec func(i
FullMethod: "/wice.Watcher/GetStatus",
}
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)
}
@@ -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.
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 {
@@ -559,8 +559,8 @@ func NewEndpointDiscoverySocketClient(cc grpc.ClientConnInterface) EndpointDisco
return &endpointDiscoverySocketClient{cc}
}
func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *RestartPeerParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.EndpointDiscoverySocket/RestartPeer", in, out, opts...)
if err != nil {
return nil, err
@@ -572,7 +572,7 @@ func (c *endpointDiscoverySocketClient) RestartPeer(ctx context.Context, in *Res
// All implementations must embed UnimplementedEndpointDiscoverySocketServer
// for forward compatibility
type EndpointDiscoverySocketServer interface {
RestartPeer(context.Context, *RestartPeerParams) (*Error, error)
RestartPeer(context.Context, *RestartPeerParams) (*Empty, error)
mustEmbedUnimplementedEndpointDiscoverySocketServer()
}
@@ -580,7 +580,7 @@ type EndpointDiscoverySocketServer interface {
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")
}
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.
type SignalingSocketClient interface {
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 {
@@ -656,8 +656,8 @@ func (c *signalingSocketClient) GetSignalingMessage(ctx context.Context, in *Get
return out, nil
}
func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *PutSignalingMessageParams, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.SignalingSocket/PutSignalingMessage", in, out, opts...)
if err != nil {
return nil, err
@@ -670,7 +670,7 @@ func (c *signalingSocketClient) PutSignalingMessage(ctx context.Context, in *Put
// for forward compatibility
type SignalingSocketServer interface {
GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error)
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Error, error)
PutSignalingMessage(context.Context, *PutSignalingMessageParams) (*Empty, error)
mustEmbedUnimplementedSignalingSocketServer()
}
@@ -681,7 +681,7 @@ type UnimplementedSignalingSocketServer struct {
func (UnimplementedSignalingSocketServer) GetSignalingMessage(context.Context, *GetSignalingMessageParams) (*GetSignalingMessageResp, error) {
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")
}
func (UnimplementedSignalingSocketServer) mustEmbedUnimplementedSignalingSocketServer() {}

View File

@@ -36,5 +36,5 @@ message SubscribeParams {
service Signaling {
rpc Subscribe(SubscribeParams) returns (stream SignalingEnvelope) {}
rpc Publish(SignalingEnvelope) returns (Error) {}
rpc Publish(SignalingEnvelope) returns (Empty) {}
}

View File

@@ -1,4 +1,8 @@
// 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
@@ -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.
type SignalingClient interface {
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 {
@@ -62,8 +66,8 @@ func (x *signalingSubscribeClient) Recv() (*SignalingEnvelope, error) {
return m, nil
}
func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Error, error) {
out := new(Error)
func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := c.cc.Invoke(ctx, "/wice.Signaling/Publish", in, out, opts...)
if err != nil {
return nil, err
@@ -76,7 +80,7 @@ func (c *signalingClient) Publish(ctx context.Context, in *SignalingEnvelope, op
// for forward compatibility
type SignalingServer interface {
Subscribe(*SubscribeParams, Signaling_SubscribeServer) error
Publish(context.Context, *SignalingEnvelope) (*Error, error)
Publish(context.Context, *SignalingEnvelope) (*Empty, error)
mustEmbedUnimplementedSignalingServer()
}
@@ -87,7 +91,7 @@ type UnimplementedSignalingServer struct {
func (UnimplementedSignalingServer) Subscribe(*SubscribeParams, Signaling_SubscribeServer) error {
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")
}
func (UnimplementedSignalingServer) mustEmbedUnimplementedSignalingServer() {}

View File

@@ -79,11 +79,9 @@ func Connect(path string) (*Client, error) {
go client.streamEvents()
rerr, err := client.UnWait(context.Background(), &pb.UnWaitParams{})
if err != nil {
_, err = client.UnWait(context.Background(), &pb.UnWaitParams{})
if sts := status.Convert(err); sts != nil && sts.Code() != codes.AlreadyExists {
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

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"io"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
wice "riasc.eu/wice/pkg"
"riasc.eu/wice/pkg/pb"
)
@@ -55,25 +57,22 @@ out:
return nil
}
func (s *DaemonServer) UnWait(ctx context.Context, params *pb.UnWaitParams) (*pb.Error, error) {
var e = &pb.Error{
Code: pb.Error_EALREADY,
Message: "already unwaited",
}
func (s *DaemonServer) UnWait(ctx context.Context, params *pb.UnWaitParams) (*pb.Empty, error) {
err := status.Error(codes.AlreadyExists, "RPC socket has already been unwaited")
s.waitOnce.Do(func() {
s.logger.Info("Control socket un-waited")
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 {
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
}

View File

@@ -2,10 +2,11 @@ package rpc
import (
"context"
"fmt"
"io"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"riasc.eu/wice/pkg/crypto"
"riasc.eu/wice/pkg/feat/disc/epice"
icex "riasc.eu/wice/pkg/ice"
@@ -32,30 +33,28 @@ func NewEndpointDiscoveryServer(s *Server, ep *epice.EndpointDiscovery) *Endpoin
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)
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)
if p == nil {
err := fmt.Errorf("unknown peer %s/%s", params.Intf, pk.String())
return pb.NewError(err), nil
return &pb.Empty{}, status.Errorf(codes.NotFound, "unknown peer %s/%s", params.Intf, pk.String())
}
ip := s.Peers[p]
if ip == nil {
err := fmt.Errorf("unknown peer %s/%s", params.Intf, pk.String())
return pb.NewError(err), nil
return &pb.Empty{}, status.Errorf(codes.NotFound, "unknown peer %s/%s", params.Intf, pk.String())
}
err = ip.Restart()
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) {

View File

@@ -3,6 +3,8 @@ package rpc
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"riasc.eu/wice/pkg/pb"
"riasc.eu/wice/pkg/signaling"
"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) {
// peer, pbErr, err := s.findPeer(params.Intf, params.Peer)
// if pbErr != nil || err != nil {
// return nil, err
// }
return &pb.GetSignalingMessageResp{}, nil
return nil, status.Error(codes.Unimplemented, "not implemented yet")
}
func (s *SignalingServer) PutSignalingMessage(ctx context.Context, params *pb.PutSignalingMessageParams) (*pb.Error, error) {
return pb.Success, nil
func (s *SignalingServer) PutSignalingMessage(ctx context.Context, params *pb.PutSignalingMessageParams) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}
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) {
return pb.Success, nil
func (s *SignalingServer) Publish(context.Context, *signaling.Envelope) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}

View File

@@ -3,6 +3,8 @@ package rpc
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"riasc.eu/wice/pkg/pb"
"riasc.eu/wice/pkg/watcher"
)
@@ -27,7 +29,7 @@ func NewWatcherServer(s *Server, w *watcher.Watcher) *WatcherServer {
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()
defer s.InterfaceLock.Unlock()
@@ -41,26 +43,26 @@ func (s *WatcherServer) GetStatus(ctx context.Context, _ *pb.Void) (*pb.Status,
}, 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 {
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) {
return pb.ErrNotSupported, nil
func (s *WatcherServer) RemoveInterface(ctx context.Context, params *pb.RemoveInterfaceParams) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}
func (s *WatcherServer) SyncInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
return pb.ErrNotSupported, nil
func (s *WatcherServer) SyncInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}
func (s *WatcherServer) AddInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
return pb.ErrNotSupported, nil
func (s *WatcherServer) AddInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}
func (s *WatcherServer) SetInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Error, error) {
return pb.ErrNotSupported, nil
func (s *WatcherServer) SetInterfaceConfig(ctx context.Context, params *pb.InterfaceConfigParams) (*pb.Empty, error) {
return &pb.Empty{}, status.Error(codes.Unimplemented, "not implemented yet")
}

View File

@@ -91,16 +91,16 @@ out:
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 pkRecipient, pkSender crypto.Key
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 {
return nil, fmt.Errorf("invalid sender key: %w", err)
return &pb.Empty{}, fmt.Errorf("invalid sender key: %w", err)
}
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("sender", pkSender))
return pb.Success, nil
return &pb.Empty{}, nil
}
func (s *Server) GracefulStop() {