Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New SDK #3103

Merged
merged 4 commits into from
Feb 3, 2025
Merged

New SDK #3103

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Changelog for NeoFS Node
- Drop creating new eacl tables with public keys (#3096)

### 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 @@
"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 @@
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 {

Check warning on line 62 in cmd/neofs-cli/internal/client/sdk.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/internal/client/sdk.go#L62

Added line #L62 was not covered by tests
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 @@
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])) {

Check warning on line 212 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L211-L212

Added lines #L211 - L212 were not covered by tests
return errors.New("invalid action (expected 'allow' or 'deny')")
}

Expand Down Expand Up @@ -348,8 +348,8 @@

// 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)) {

Check warning on line 352 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L351-L352

Added lines #L351 - L352 were not covered by tests
return r, fmt.Errorf("unexpected role %s", s)
}

Expand Down Expand Up @@ -377,10 +377,9 @@
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])) {

Check warning on line 382 in cmd/neofs-cli/modules/util/acl.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/util/acl.go#L382

Added line #L382 was not covered by tests
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 @@
server := accountingService.New(&c.key.PrivateKey, c.networkState, balanceMorphWrapper)

for _, srv := range c.cfgGRPC.servers {
accountingGRPC.RegisterAccountingServiceServer(srv, server)
protoaccounting.RegisterAccountingServiceServer(srv, server)

Check warning on line 20 in cmd/neofs-node/accounting.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/accounting.go#L20

Added line #L20 was not covered by tests
}
}
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 @@
"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 @@
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) 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(),

Check warning on line 520 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L520

Added line #L520 was not covered by tests
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

Check warning on line 526 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L525-L526

Added lines #L525 - L526 were not covered by tests
}

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 {

Check warning on line 534 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L534

Added line #L534 was not covered by tests
return c.makeStatusResponse(util.ToRequestSignatureVerificationError(err))
}

Expand All @@ -566,11 +557,7 @@
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)

Check warning on line 560 in cmd/neofs-node/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/container.go#L560

Added line #L560 was not covered by tests
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 @@
"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 @@
"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 @@
server := netmapService.New(&c.key.PrivateKey, c)

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

Check warning on line 174 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L174

Added line #L174 was not covered by tests
}

addNewEpochNotificationHandler(c, func(ev event.Event) {
Expand Down Expand Up @@ -446,33 +445,22 @@
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()

Check warning on line 448 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L448

Added line #L448 was not covered by tests

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

Check warning on line 450 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L450

Added line #L450 was not covered by tests

ni2.SetAttributes(nil)

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

err = writeSystemAttributes(c)
err := writeSystemAttributes(c)

Check warning on line 452 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L452

Added line #L452 was not covered by tests
if err != nil {
c.cfgNodeInfo.localInfoLock.Unlock()
return err
}
parseAttributes(c)

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

Check warning on line 459 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L459

Added line #L459 was not covered by tests

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

if nodeAttrsEqual(nodeAttrsToSlice(oldAttrs), nodeAttrsToSlice(newAttrs)) {
if nodeAttrsEqual(oldAttrs, newAttrs) {

Check warning on line 463 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L463

Added line #L463 was not covered by tests
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 @@

"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 @@
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 @@
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)

Check warning on line 312 in cmd/neofs-node/object.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/object.go#L312

Added line #L312 was not covered by tests
}
}

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 @@
"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 @@
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 @@
}

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(),

Check warning on line 260 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L260

Added line #L260 was not covered by tests
Epoch: s.networkState.CurrentEpoch(),
Status: st,
}
Expand All @@ -273,15 +267,12 @@
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

Check warning on line 271 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L270-L271

Added lines #L270 - L271 were not covered by tests
}

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 {

Check warning on line 275 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L275

Added line #L275 was not covered by tests
return s.makeLocalResponse(util.ToRequestSignatureVerificationError(err))
}

Expand Down Expand Up @@ -314,15 +305,12 @@
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

Check warning on line 309 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L308-L309

Added lines #L308 - L309 were not covered by tests
}

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 {

Check warning on line 313 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L313

Added line #L313 was not covered by tests
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 @@
"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 @@
server := sessionSvc.New(&c.key.PrivateKey, c, c.privateTokenStore)

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

Check warning on line 53 in cmd/neofs-node/session.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/session.go#L53

Added line #L53 was not covered by tests
}
}
Loading
Loading