From 3f9c8f2f5913a61e0ed48d3447d3aed3478d3fbf Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 24 Mar 2021 12:55:07 +0300 Subject: [PATCH] [#444] reputation: Implement sign and response servers Signed-off-by: Leonard Lyubich --- pkg/services/reputation/rpc/response.go | 37 +++++++++++++++++++++++++ pkg/services/reputation/rpc/sign.go | 35 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 pkg/services/reputation/rpc/response.go create mode 100644 pkg/services/reputation/rpc/sign.go diff --git a/pkg/services/reputation/rpc/response.go b/pkg/services/reputation/rpc/response.go new file mode 100644 index 000000000..a1633cf14 --- /dev/null +++ b/pkg/services/reputation/rpc/response.go @@ -0,0 +1,37 @@ +package reputationrpc + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/reputation" + "github.com/nspcc-dev/neofs-node/pkg/services/util" + "github.com/nspcc-dev/neofs-node/pkg/services/util/response" +) + +type responseService struct { + respSvc *response.Service + + svc Server +} + +// NewResponseService returns reputation service server instance that passes +// internal service call to response service. +func NewResponseService(cnrSvc Server, respSvc *response.Service) Server { + return &responseService{ + respSvc: respSvc, + svc: cnrSvc, + } +} + +func (s *responseService) SendLocalTrust(ctx context.Context, req *reputation.SendLocalTrustRequest) (*reputation.SendLocalTrustResponse, error) { + resp, err := s.respSvc.HandleUnaryRequest(ctx, req, + func(ctx context.Context, req interface{}) (util.ResponseMessage, error) { + return s.svc.SendLocalTrust(ctx, req.(*reputation.SendLocalTrustRequest)) + }, + ) + if err != nil { + return nil, err + } + + return resp.(*reputation.SendLocalTrustResponse), nil +} diff --git a/pkg/services/reputation/rpc/sign.go b/pkg/services/reputation/rpc/sign.go new file mode 100644 index 000000000..4903a33dc --- /dev/null +++ b/pkg/services/reputation/rpc/sign.go @@ -0,0 +1,35 @@ +package reputationrpc + +import ( + "context" + "crypto/ecdsa" + + "github.com/nspcc-dev/neofs-api-go/v2/reputation" + "github.com/nspcc-dev/neofs-node/pkg/services/util" +) + +type signService struct { + sigSvc *util.SignService + + svc Server +} + +func NewSignService(key *ecdsa.PrivateKey, svc Server) Server { + return &signService{ + sigSvc: util.NewUnarySignService(key), + svc: svc, + } +} + +func (s *signService) SendLocalTrust(ctx context.Context, req *reputation.SendLocalTrustRequest) (*reputation.SendLocalTrustResponse, error) { + resp, err := s.sigSvc.HandleUnaryRequest(ctx, req, + func(ctx context.Context, req interface{}) (util.ResponseMessage, error) { + return s.svc.SendLocalTrust(ctx, req.(*reputation.SendLocalTrustRequest)) + }, + ) + if err != nil { + return nil, err + } + + return resp.(*reputation.SendLocalTrustResponse), nil +}