2021-03-24 09:54:19 +00:00
|
|
|
package grpcreputation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/reputation"
|
|
|
|
reputation2 "github.com/TrueCloudLab/frostfs-api-go/v2/reputation/grpc"
|
|
|
|
reputationrpc "github.com/TrueCloudLab/frostfs-node/pkg/services/reputation/rpc"
|
2021-03-24 09:54:19 +00:00
|
|
|
)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Server wraps FrostFS API v2 Reputation service server
|
2021-04-02 16:21:05 +00:00
|
|
|
// and provides gRPC Reputation service server interface.
|
2021-03-24 09:54:19 +00:00
|
|
|
type Server struct {
|
|
|
|
srv reputationrpc.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
|
|
|
func New(srv reputationrpc.Server) *Server {
|
|
|
|
return &Server{
|
|
|
|
srv: srv,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *Server) AnnounceLocalTrust(ctx context.Context, r *reputation2.AnnounceLocalTrustRequest) (*reputation2.AnnounceLocalTrustResponse, error) {
|
|
|
|
req := new(reputation.AnnounceLocalTrustRequest)
|
2021-03-24 09:54:19 +00:00
|
|
|
if err := req.FromGRPCMessage(r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp, err := s.srv.AnnounceLocalTrust(ctx, req)
|
2021-03-24 09:54:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
return resp.ToGRPCMessage().(*reputation2.AnnounceLocalTrustResponse), nil
|
2021-03-24 09:54:19 +00:00
|
|
|
}
|
2021-04-05 09:27:58 +00:00
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
func (s *Server) AnnounceIntermediateResult(ctx context.Context, r *reputation2.AnnounceIntermediateResultRequest) (*reputation2.AnnounceIntermediateResultResponse, error) {
|
|
|
|
req := new(reputation.AnnounceIntermediateResultRequest)
|
2021-04-05 09:27:58 +00:00
|
|
|
if err := req.FromGRPCMessage(r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
resp, err := s.srv.AnnounceIntermediateResult(ctx, req)
|
2021-04-05 09:27:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:13:11 +00:00
|
|
|
return resp.ToGRPCMessage().(*reputation2.AnnounceIntermediateResultResponse), nil
|
2021-04-05 09:27:58 +00:00
|
|
|
}
|