From b37b60815028ce38fbee79e4c26f3a4f5274af8f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 24 Mar 2021 12:54:19 +0300 Subject: [PATCH] [#444] reputation/grpc: Implement gRPC ReputationServiceServer Implement gRPC ReputationServiceServer on structure that forwards requests to underlying NeoFS API v2 ReputationService `Server`. Signed-off-by: Leonard Lyubich --- .../transport/reputation/grpc/service.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/network/transport/reputation/grpc/service.go diff --git a/pkg/network/transport/reputation/grpc/service.go b/pkg/network/transport/reputation/grpc/service.go new file mode 100644 index 000000000..41e28fa07 --- /dev/null +++ b/pkg/network/transport/reputation/grpc/service.go @@ -0,0 +1,37 @@ +package grpcreputation + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/reputation" + reputation2 "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc" + reputationrpc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/rpc" +) + +// Server wraps NeoFS API v2 Container service server +// and provides gRPC Container service server interface. +type Server struct { + srv reputationrpc.Server +} + +// New creates, initializes and returns Server instance. +func New(srv reputationrpc.Server) *Server { + return &Server{ + srv: srv, + } +} + +func (s *Server) SendLocalTrust(ctx context.Context, r *reputation2.SendLocalTrustRequest) (*reputation2.SendLocalTrustResponse, error) { + req := new(reputation.SendLocalTrustRequest) + if err := req.FromGRPCMessage(r); err != nil { + return nil, err + } + + resp, err := s.srv.SendLocalTrust(ctx, req) + if err != nil { + // TODO: think about how we transport errors through gRPC + return nil, err + } + + return resp.ToGRPCMessage().(*reputation2.SendLocalTrustResponse), nil +}