2020-10-08 13:14:19 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2020-10-08 13:14:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(netmap.LocalNodeInfoResponse)
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2020-10-08 13:14:19 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.LocalNodeInfo(ctx, req))
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2020-10-08 13:14:19 +00:00
|
|
|
}
|
2021-02-19 08:01:37 +00:00
|
|
|
|
|
|
|
func (s *signService) NetworkInfo(ctx context.Context, req *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(netmap.NetworkInfoResponse)
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.NetworkInfo(ctx, req))
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|
2022-09-17 12:37:01 +00:00
|
|
|
|
|
|
|
func (s *signService) Snapshot(ctx context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(netmap.SnapshotResponse)
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2022-09-17 12:37:01 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Snapshot(ctx, req))
|
2022-12-30 17:01:13 +00:00
|
|
|
return resp, s.sigSvc.SignResponse(util.IsStatusSupported(req), resp, err)
|
2022-09-17 12:37:01 +00:00
|
|
|
}
|