Skip to content

Commit

Permalink
New SDK (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Feb 3, 2025
2 parents c44b367 + 2528406 commit 5279df2
Show file tree
Hide file tree
Showing 48 changed files with 624 additions and 1,015 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Changelog for NeoFS Node
- BoltDB from write-cache (#3091)

### Updated
- SDK to the post-api-go version (#3103)

### Updating from v0.44.2
Using public keys as a rule target in eACL tables was deprecated, and
Expand Down
17 changes: 1 addition & 16 deletions cmd/neofs-cli/internal/client/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/spf13/viper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var errInvalidEndpoint = errors.New("provided RPC endpoint is incorrect")
Expand Down Expand Up @@ -61,20 +59,7 @@ func GetSDKClient(ctx context.Context, addr network.Address) (*client.Client, er
return nil, fmt.Errorf("can't create SDK client: %w", err)
}

if err := c.Dial(prmDial); err != nil { //nolint:contextcheck // SetContext is used above.
// Here is a hack helping IR healthcheck to work. Current API client revision
// calls NetmapService.EndpointInfo RPC which is a part of the NeoFS API
// protocol. Inner ring nodes don't serve NeoFS API services, so they respond
// with Unimplemented code. We ignore this error here:
// - if nodes responds, then dial was successful
// - even if we connect to storage node which MUST provide NeoFS API services,
// subsequent EndpointInfo method will return Unimplemented error anyway
// This behavior is going to be fixed on SDK side.
//
// Track https://github.com/nspcc-dev/neofs-node/issues/2477
if status.Code(err) == codes.Unimplemented {
return c, nil
}
if err := c.Dial(prmDial); err != nil {
return nil, fmt.Errorf("can't init SDK client: %w", err)
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/neofs-cli/modules/util/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ func parseEACLTable(tb *eacl.Table, args []string) error {
return errors.New("at least 2 arguments must be provided")
}

action, ok := eacl.ActionFromString(strings.ToUpper(args[0]))
if !ok {
var action eacl.Action
if !action.DecodeString(strings.ToUpper(args[0])) {
return errors.New("invalid action (expected 'allow' or 'deny')")
}

Expand Down Expand Up @@ -348,8 +348,8 @@ func validateDecimal(s string) bool {

// eaclRoleFromString parses eacl.Role from string.
func eaclRoleFromString(s string) (eacl.Role, error) {
r, ok := eacl.RoleFromString(strings.ToUpper(s))
if !ok {
var r eacl.Role
if !r.DecodeString(strings.ToUpper(s)) {
return r, fmt.Errorf("unexpected role %s", s)
}

Expand Down Expand Up @@ -377,10 +377,9 @@ func parseAccountList(s string) ([]user.ID, error) {
func eaclOperationsFromString(s string) ([]eacl.Operation, error) {
ss := strings.Split(s, ",")
ops := make([]eacl.Operation, len(ss))
var ok bool

for i := range ss {
if ops[i], ok = eacl.OperationFromString(strings.ToUpper(ss[i])); !ok {
if !ops[i].DecodeString(strings.ToUpper(ss[i])) {
return nil, fmt.Errorf("invalid operation: %s", ss[i])
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/accounting.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
protoaccounting "github.com/nspcc-dev/neofs-sdk-go/proto/accounting"
)

func initAccountingService(c *cfg) {
Expand All @@ -17,6 +17,6 @@ func initAccountingService(c *cfg) {
server := accountingService.New(&c.key.PrivateKey, c.networkState, balanceMorphWrapper)

for _, srv := range c.cfgGRPC.servers {
accountingGRPC.RegisterAccountingServiceServer(srv, server)
protoaccounting.RegisterAccountingServiceServer(srv, server)
}
}
9 changes: 0 additions & 9 deletions cmd/neofs-node/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/nspcc-dev/locode-db/pkg/locodedb"
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"go.uber.org/zap"
Expand Down Expand Up @@ -118,11 +117,3 @@ func nodeAttrsEqual(arr1, arr2 [][2]string) bool {

return true
}

func nodeAttrsToSlice(attrs []netmapV2.Attribute) [][2]string {
res := make([][2]string, len(attrs))
for i := range attrs {
res[i] = [2]string{attrs[i].GetKey(), attrs[i].GetValue()}
}
return res
}
31 changes: 9 additions & 22 deletions cmd/neofs-node/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import (
"errors"
"fmt"

apicontainer "github.com/nspcc-dev/neofs-api-go/v2/container"
protocontainer "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
apirefs "github.com/nspcc-dev/neofs-api-go/v2/refs"
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
protosession "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/signature"
protostatus "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
containerrpc "github.com/nspcc-dev/neofs-contract/rpc/container"
"github.com/nspcc-dev/neofs-node/pkg/core/client"
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
Expand All @@ -33,9 +26,13 @@ import (
apiClient "github.com/nspcc-dev/neofs-sdk-go/client"
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
"github.com/nspcc-dev/neofs-sdk-go/eacl"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
protocontainer "github.com/nspcc-dev/neofs-sdk-go/proto/container"
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
protostatus "github.com/nspcc-dev/neofs-sdk-go/proto/status"
"github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/nspcc-dev/neofs-sdk-go/version"
Expand Down Expand Up @@ -517,30 +514,24 @@ func (c *usedSpaceService) ExternalAddresses() []string {
}

func (c *usedSpaceService) makeResponse(body *protocontainer.AnnounceUsedSpaceResponse_Body, st *protostatus.Status) (*protocontainer.AnnounceUsedSpaceResponse, error) {
v := version.Current()
var v2 apirefs.Version
v.WriteToV2(&v2)
resp := &protocontainer.AnnounceUsedSpaceResponse{
Body: body,
MetaHeader: &protosession.ResponseMetaHeader{
Version: v2.ToGRPCMessage().(*refs.Version),
Version: version.Current().ProtoMessage(),
Epoch: c.cfg.networkState.CurrentEpoch(),
Status: st,
},
}
return util.SignResponse(&c.cfg.key.PrivateKey, resp, apicontainer.AnnounceUsedSpaceResponse{}), nil
resp.VerifyHeader = util.SignResponse(&c.cfg.key.PrivateKey, resp)
return resp, nil
}

func (c *usedSpaceService) makeStatusResponse(err error) (*protocontainer.AnnounceUsedSpaceResponse, error) {
return c.makeResponse(nil, util.ToStatus(err))
}

func (c *usedSpaceService) AnnounceUsedSpace(ctx context.Context, req *protocontainer.AnnounceUsedSpaceRequest) (*protocontainer.AnnounceUsedSpaceResponse, error) {
putReq := new(apicontainer.AnnounceUsedSpaceRequest)
if err := putReq.FromGRPCMessage(req); err != nil {
return nil, err
}
if err := signature.VerifyServiceMessage(putReq); err != nil {
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
return c.makeStatusResponse(util.ToRequestSignatureVerificationError(err))
}

Expand All @@ -566,11 +557,7 @@ func (c *usedSpaceService) AnnounceUsedSpace(ctx context.Context, req *protocont
var est containerSDK.SizeEstimation

for _, a := range req.GetBody().GetAnnouncements() {
var a2 apicontainer.UsedSpaceAnnouncement
if err := a2.FromGRPCMessage(a); err != nil {
panic(err)
}
err = est.ReadFromV2(a2)
err = est.FromProtoMessage(a)
if err != nil {
return c.makeStatusResponse(fmt.Errorf("invalid size announcement: %w", err))
}
Expand Down
26 changes: 7 additions & 19 deletions cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"sync/atomic"

netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
"github.com/nspcc-dev/neofs-node/pkg/metrics"
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
Expand All @@ -16,6 +14,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/services/control"
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap"
protonetmap "github.com/nspcc-dev/neofs-sdk-go/proto/netmap"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -172,7 +171,7 @@ func initNetmapService(c *cfg) {
server := netmapService.New(&c.key.PrivateKey, c)

for _, srv := range c.cfgGRPC.servers {
netmapGRPC.RegisterNetmapServiceServer(srv, server)
protonetmap.RegisterNetmapServiceServer(srv, server)
}

addNewEpochNotificationHandler(c, func(ev event.Event) {
Expand Down Expand Up @@ -446,33 +445,22 @@ func (c *cfg) GetNetworkInfo() (netmapSDK.NetworkInfo, error) {
func (c *cfg) reloadNodeAttributes() error {
c.cfgNodeInfo.localInfoLock.Lock()

// TODO(@End-rey): after updating SDK, rewrite with w/o api netmap. See #3005, neofs-sdk-go#635.
var ni2 netmapV2.NodeInfo
c.cfgNodeInfo.localInfo.WriteToV2(&ni2)
oldAttrs := c.cfgNodeInfo.localInfo.GetAttributes()

oldAttrs := ni2.GetAttributes()
c.cfgNodeInfo.localInfo.SetAttributes(nil)

ni2.SetAttributes(nil)

err := c.cfgNodeInfo.localInfo.ReadFromV2(ni2)
if err != nil {
c.cfgNodeInfo.localInfoLock.Unlock()
return err
}

err = writeSystemAttributes(c)
err := writeSystemAttributes(c)
if err != nil {
c.cfgNodeInfo.localInfoLock.Unlock()
return err
}
parseAttributes(c)

c.cfgNodeInfo.localInfo.WriteToV2(&ni2)
newAttrs := c.cfgNodeInfo.localInfo.GetAttributes()

newAttrs := ni2.GetAttributes()
c.cfgNodeInfo.localInfoLock.Unlock()

if nodeAttrsEqual(nodeAttrsToSlice(oldAttrs), nodeAttrsToSlice(newAttrs)) {
if nodeAttrsEqual(oldAttrs, newAttrs) {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/google/uuid"
lru "github.com/hashicorp/golang-lru/v2"
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
replicatorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/replicator"
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
containercore "github.com/nspcc-dev/neofs-node/pkg/core/container"
Expand Down Expand Up @@ -39,6 +38,7 @@ import (
netmapsdk "github.com/nspcc-dev/neofs-sdk-go/netmap"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
protoobject "github.com/nspcc-dev/neofs-sdk-go/proto/object"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
Expand Down Expand Up @@ -309,7 +309,7 @@ func initObjectService(c *cfg) {
server := objectService.New(objSvc, mNumber, fsChain, storage, c.shared.basics.key.PrivateKey, c.metricsCollector, aclChecker, aclSvc)

for _, srv := range c.cfgGRPC.servers {
objectGRPC.RegisterObjectServiceServer(srv, server)
protoobject.RegisterObjectServiceServer(srv, server)
}
}

Expand Down
34 changes: 11 additions & 23 deletions cmd/neofs-node/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
"context"
"fmt"

apirefs "github.com/nspcc-dev/neofs-api-go/v2/refs"
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
protoreputation "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
protosession "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/signature"
protostatus "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
Expand All @@ -31,6 +24,10 @@ import (
localroutes "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/routes"
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
"github.com/nspcc-dev/neofs-node/pkg/services/util"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
protoreputation "github.com/nspcc-dev/neofs-sdk-go/proto/reputation"
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
protostatus "github.com/nspcc-dev/neofs-sdk-go/proto/status"
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
"github.com/nspcc-dev/neofs-sdk-go/version"
"go.uber.org/zap"
Expand Down Expand Up @@ -259,11 +256,8 @@ type reputationServer struct {
}

func (s *reputationServer) makeResponseMetaHeader(st *protostatus.Status) *protosession.ResponseMetaHeader {
v := version.Current()
var v2 apirefs.Version
v.WriteToV2(&v2)
return &protosession.ResponseMetaHeader{
Version: v2.ToGRPCMessage().(*refs.Version),
Version: version.Current().ProtoMessage(),
Epoch: s.networkState.CurrentEpoch(),
Status: st,
}
Expand All @@ -273,15 +267,12 @@ func (s *reputationServer) makeLocalResponse(err error) (*protoreputation.Announ
resp := &protoreputation.AnnounceLocalTrustResponse{
MetaHeader: s.makeResponseMetaHeader(util.ToStatus(err)),
}
return util.SignResponse(&s.key.PrivateKey, resp, v2reputation.AnnounceLocalTrustResponse{}), nil
resp.VerifyHeader = util.SignResponse(&s.key.PrivateKey, resp)
return resp, nil
}

func (s *reputationServer) AnnounceLocalTrust(ctx context.Context, req *protoreputation.AnnounceLocalTrustRequest) (*protoreputation.AnnounceLocalTrustResponse, error) {
req2 := new(v2reputation.AnnounceLocalTrustRequest)
if err := req2.FromGRPCMessage(req); err != nil {
return nil, err
}
if err := signature.VerifyServiceMessage(req2); err != nil {
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
return s.makeLocalResponse(util.ToRequestSignatureVerificationError(err))
}

Expand Down Expand Up @@ -314,15 +305,12 @@ func (s *reputationServer) makeIntermediateResponse(err error) (*protoreputation
resp := &protoreputation.AnnounceIntermediateResultResponse{
MetaHeader: s.makeResponseMetaHeader(util.ToStatus(err)),
}
return util.SignResponse(&s.key.PrivateKey, resp, v2reputation.AnnounceIntermediateResultResponse{}), nil
resp.VerifyHeader = util.SignResponse(&s.key.PrivateKey, resp)
return resp, nil
}

func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req *protoreputation.AnnounceIntermediateResultRequest) (*protoreputation.AnnounceIntermediateResultResponse, error) {
req2 := new(v2reputation.AnnounceIntermediateResultRequest)
if err := req2.FromGRPCMessage(req); err != nil {
return nil, err
}
if err := signature.VerifyServiceMessage(req2); err != nil {
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
return s.makeIntermediateResponse(util.ToRequestSignatureVerificationError(err))
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-node/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"fmt"
"time"

sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
sessionSvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage/persistent"
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage/temporary"
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
"github.com/nspcc-dev/neofs-sdk-go/user"
)

Expand Down Expand Up @@ -50,6 +50,6 @@ func initSessionService(c *cfg) {
server := sessionSvc.New(&c.key.PrivateKey, c, c.privateTokenStore)

for _, srv := range c.cfgGRPC.servers {
sessionGRPC.RegisterSessionServiceServer(srv, server)
protosession.RegisterSessionServiceServer(srv, server)
}
}
Loading

0 comments on commit 5279df2

Please sign in to comment.