2020-10-08 13:14:19 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type signService struct {
|
|
|
|
sigSvc *util.SignService
|
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
svc Server
|
2020-10-08 13:14:19 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
func NewSignService(key *ecdsa.PrivateKey, svc Server) Server {
|
2020-10-08 13:14:19 +00:00
|
|
|
return &signService{
|
|
|
|
sigSvc: util.NewUnarySignService(key),
|
|
|
|
svc: svc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) LocalNodeInfo(
|
|
|
|
ctx context.Context,
|
|
|
|
req *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
|
|
|
|
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
2020-10-22 08:03:34 +00:00
|
|
|
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
|
2020-10-08 13:14:19 +00:00
|
|
|
return s.svc.LocalNodeInfo(ctx, req.(*netmap.LocalNodeInfoRequest))
|
|
|
|
},
|
2021-11-06 11:13:04 +00:00
|
|
|
func() util.ResponseMessage {
|
|
|
|
return new(netmap.LocalNodeInfoResponse)
|
|
|
|
},
|
2020-10-08 13:14:19 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.(*netmap.LocalNodeInfoResponse), nil
|
|
|
|
}
|
2021-02-19 08:01:37 +00:00
|
|
|
|
|
|
|
func (s *signService) NetworkInfo(ctx context.Context, req *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
|
|
|
|
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
|
|
|
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
|
|
|
|
return s.svc.NetworkInfo(ctx, req.(*netmap.NetworkInfoRequest))
|
|
|
|
},
|
2021-11-06 11:13:04 +00:00
|
|
|
func() util.ResponseMessage {
|
|
|
|
return new(netmap.NetworkInfoResponse)
|
|
|
|
},
|
2021-02-19 08:01:37 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.(*netmap.NetworkInfoResponse), nil
|
|
|
|
}
|