From f92dc5b27cbd20ff6501ec1edfa1a95394a59886 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 8 Oct 2020 16:13:28 +0300 Subject: [PATCH] [#84] Add GRPC layer of netmap service Signed-off-by: Alex Vanin --- pkg/network/transport/netmap/grpc/service.go | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pkg/network/transport/netmap/grpc/service.go diff --git a/pkg/network/transport/netmap/grpc/service.go b/pkg/network/transport/netmap/grpc/service.go new file mode 100644 index 00000000..82d87201 --- /dev/null +++ b/pkg/network/transport/netmap/grpc/service.go @@ -0,0 +1,35 @@ +package grpc + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/netmap" + netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" +) + +// Server wraps NeoFS API Netmap service and +// provides gRPC Netmap service server interface. +type Server struct { + srv netmap.Service +} + +// New creates, initializes and returns Server instance. +func New(c netmap.Service) *Server { + return &Server{ + srv: c, + } +} + +// LocalNodeInfo converts gRPC request message and passes it to internal netmap service. +func (s *Server) LocalNodeInfo( + ctx context.Context, + req *netmapGRPC.LocalNodeInfoRequest) (*netmapGRPC.LocalNodeInfoResponse, error) { + + resp, err := s.srv.LocalNodeInfo(ctx, netmap.LocalNodeInfoRequestFromGRPCMessage(req)) + if err != nil { + // TODO: think about how we transport errors through gRPC + return nil, err + } + + return netmap.LocalNodeInfoResponseToGRPCMessage(resp), nil +}