2020-10-08 13:13:28 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
|
|
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
2021-03-15 10:53:08 +00:00
|
|
|
netmapsvc "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
|
2020-10-08 13:13:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server wraps NeoFS API Netmap service and
|
|
|
|
// provides gRPC Netmap service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv netmapsvc.Server
|
2020-10-08 13:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2021-03-15 10:53:08 +00:00
|
|
|
func New(c netmapsvc.Server) *Server {
|
2020-10-08 13:13:28 +00:00
|
|
|
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
|
|
|
|
}
|
2021-02-19 08:01:37 +00:00
|
|
|
|
|
|
|
// NetworkInfo converts gRPC request message and passes it to internal netmap service.
|
|
|
|
func (s *Server) NetworkInfo(ctx context.Context, req *netmapGRPC.NetworkInfoRequest) (*netmapGRPC.NetworkInfoResponse, error) {
|
|
|
|
resp, err := s.srv.NetworkInfo(ctx, netmap.NetworkInfoRequestFromGRPCMessage(req))
|
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return netmap.NetworkInfoResponseToGRPCMessage(resp), nil
|
|
|
|
}
|