Skip to content

Commit 5279df2

Browse files
authored
New SDK (#3103)
2 parents c44b367 + 2528406 commit 5279df2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+624
-1015
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Changelog for NeoFS Node
2929
- BoltDB from write-cache (#3091)
3030

3131
### Updated
32+
- SDK to the post-api-go version (#3103)
3233

3334
### Updating from v0.44.2
3435
Using public keys as a rule target in eACL tables was deprecated, and

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/nspcc-dev/neofs-node/pkg/network"
1010
"github.com/nspcc-dev/neofs-sdk-go/client"
1111
"github.com/spf13/viper"
12-
"google.golang.org/grpc/codes"
13-
"google.golang.org/grpc/status"
1412
)
1513

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

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

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ func parseEACLTable(tb *eacl.Table, args []string) error {
208208
return errors.New("at least 2 arguments must be provided")
209209
}
210210

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

@@ -348,8 +348,8 @@ func validateDecimal(s string) bool {
348348

349349
// eaclRoleFromString parses eacl.Role from string.
350350
func eaclRoleFromString(s string) (eacl.Role, error) {
351-
r, ok := eacl.RoleFromString(strings.ToUpper(s))
352-
if !ok {
351+
var r eacl.Role
352+
if !r.DecodeString(strings.ToUpper(s)) {
353353
return r, fmt.Errorf("unexpected role %s", s)
354354
}
355355

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

382381
for i := range ss {
383-
if ops[i], ok = eacl.OperationFromString(strings.ToUpper(ss[i])); !ok {
382+
if !ops[i].DecodeString(strings.ToUpper(ss[i])) {
384383
return nil, fmt.Errorf("invalid operation: %s", ss[i])
385384
}
386385
}

cmd/neofs-node/accounting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package main
22

33
import (
4-
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
54
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
65
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
6+
protoaccounting "github.com/nspcc-dev/neofs-sdk-go/proto/accounting"
77
)
88

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

1919
for _, srv := range c.cfgGRPC.servers {
20-
accountingGRPC.RegisterAccountingServiceServer(srv, server)
20+
protoaccounting.RegisterAccountingServiceServer(srv, server)
2121
}
2222
}

cmd/neofs-node/attributes.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

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

119118
return true
120119
}
121-
122-
func nodeAttrsToSlice(attrs []netmapV2.Attribute) [][2]string {
123-
res := make([][2]string, len(attrs))
124-
for i := range attrs {
125-
res[i] = [2]string{attrs[i].GetKey(), attrs[i].GetValue()}
126-
}
127-
return res
128-
}

cmd/neofs-node/container.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import (
88
"errors"
99
"fmt"
1010

11-
apicontainer "github.com/nspcc-dev/neofs-api-go/v2/container"
12-
protocontainer "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
13-
apirefs "github.com/nspcc-dev/neofs-api-go/v2/refs"
14-
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
15-
protosession "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
16-
"github.com/nspcc-dev/neofs-api-go/v2/signature"
17-
protostatus "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
1811
containerrpc "github.com/nspcc-dev/neofs-contract/rpc/container"
1912
"github.com/nspcc-dev/neofs-node/pkg/core/client"
2013
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
@@ -33,9 +26,13 @@ import (
3326
apiClient "github.com/nspcc-dev/neofs-sdk-go/client"
3427
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
3528
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
29+
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
3630
"github.com/nspcc-dev/neofs-sdk-go/eacl"
3731
"github.com/nspcc-dev/neofs-sdk-go/netmap"
3832
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
33+
protocontainer "github.com/nspcc-dev/neofs-sdk-go/proto/container"
34+
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
35+
protostatus "github.com/nspcc-dev/neofs-sdk-go/proto/status"
3936
"github.com/nspcc-dev/neofs-sdk-go/session"
4037
"github.com/nspcc-dev/neofs-sdk-go/user"
4138
"github.com/nspcc-dev/neofs-sdk-go/version"
@@ -517,30 +514,24 @@ func (c *usedSpaceService) ExternalAddresses() []string {
517514
}
518515

519516
func (c *usedSpaceService) makeResponse(body *protocontainer.AnnounceUsedSpaceResponse_Body, st *protostatus.Status) (*protocontainer.AnnounceUsedSpaceResponse, error) {
520-
v := version.Current()
521-
var v2 apirefs.Version
522-
v.WriteToV2(&v2)
523517
resp := &protocontainer.AnnounceUsedSpaceResponse{
524518
Body: body,
525519
MetaHeader: &protosession.ResponseMetaHeader{
526-
Version: v2.ToGRPCMessage().(*refs.Version),
520+
Version: version.Current().ProtoMessage(),
527521
Epoch: c.cfg.networkState.CurrentEpoch(),
528522
Status: st,
529523
},
530524
}
531-
return util.SignResponse(&c.cfg.key.PrivateKey, resp, apicontainer.AnnounceUsedSpaceResponse{}), nil
525+
resp.VerifyHeader = util.SignResponse(&c.cfg.key.PrivateKey, resp)
526+
return resp, nil
532527
}
533528

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

538533
func (c *usedSpaceService) AnnounceUsedSpace(ctx context.Context, req *protocontainer.AnnounceUsedSpaceRequest) (*protocontainer.AnnounceUsedSpaceResponse, error) {
539-
putReq := new(apicontainer.AnnounceUsedSpaceRequest)
540-
if err := putReq.FromGRPCMessage(req); err != nil {
541-
return nil, err
542-
}
543-
if err := signature.VerifyServiceMessage(putReq); err != nil {
534+
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
544535
return c.makeStatusResponse(util.ToRequestSignatureVerificationError(err))
545536
}
546537

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

568559
for _, a := range req.GetBody().GetAnnouncements() {
569-
var a2 apicontainer.UsedSpaceAnnouncement
570-
if err := a2.FromGRPCMessage(a); err != nil {
571-
panic(err)
572-
}
573-
err = est.ReadFromV2(a2)
560+
err = est.FromProtoMessage(a)
574561
if err != nil {
575562
return c.makeStatusResponse(fmt.Errorf("invalid size announcement: %w", err))
576563
}

cmd/neofs-node/netmap.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"fmt"
77
"sync/atomic"
88

9-
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
10-
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
119
"github.com/nspcc-dev/neofs-node/pkg/metrics"
1210
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
1311
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
@@ -16,6 +14,7 @@ import (
1614
"github.com/nspcc-dev/neofs-node/pkg/services/control"
1715
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
1816
netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap"
17+
protonetmap "github.com/nspcc-dev/neofs-sdk-go/proto/netmap"
1918
"go.uber.org/zap"
2019
)
2120

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

174173
for _, srv := range c.cfgGRPC.servers {
175-
netmapGRPC.RegisterNetmapServiceServer(srv, server)
174+
protonetmap.RegisterNetmapServiceServer(srv, server)
176175
}
177176

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

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

453-
oldAttrs := ni2.GetAttributes()
450+
c.cfgNodeInfo.localInfo.SetAttributes(nil)
454451

455-
ni2.SetAttributes(nil)
456-
457-
err := c.cfgNodeInfo.localInfo.ReadFromV2(ni2)
458-
if err != nil {
459-
c.cfgNodeInfo.localInfoLock.Unlock()
460-
return err
461-
}
462-
463-
err = writeSystemAttributes(c)
452+
err := writeSystemAttributes(c)
464453
if err != nil {
465454
c.cfgNodeInfo.localInfoLock.Unlock()
466455
return err
467456
}
468457
parseAttributes(c)
469458

470-
c.cfgNodeInfo.localInfo.WriteToV2(&ni2)
459+
newAttrs := c.cfgNodeInfo.localInfo.GetAttributes()
471460

472-
newAttrs := ni2.GetAttributes()
473461
c.cfgNodeInfo.localInfoLock.Unlock()
474462

475-
if nodeAttrsEqual(nodeAttrsToSlice(oldAttrs), nodeAttrsToSlice(newAttrs)) {
463+
if nodeAttrsEqual(oldAttrs, newAttrs) {
476464
return nil
477465
}
478466

cmd/neofs-node/object.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

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

311311
for _, srv := range c.cfgGRPC.servers {
312-
objectGRPC.RegisterObjectServiceServer(srv, server)
312+
protoobject.RegisterObjectServiceServer(srv, server)
313313
}
314314
}
315315

cmd/neofs-node/reputation.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
apirefs "github.com/nspcc-dev/neofs-api-go/v2/refs"
8-
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
9-
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
10-
protoreputation "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
11-
protosession "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
12-
"github.com/nspcc-dev/neofs-api-go/v2/signature"
13-
protostatus "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
147
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/common"
158
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
169
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
@@ -31,6 +24,10 @@ import (
3124
localroutes "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/routes"
3225
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
3326
"github.com/nspcc-dev/neofs-node/pkg/services/util"
27+
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
28+
protoreputation "github.com/nspcc-dev/neofs-sdk-go/proto/reputation"
29+
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
30+
protostatus "github.com/nspcc-dev/neofs-sdk-go/proto/status"
3431
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
3532
"github.com/nspcc-dev/neofs-sdk-go/version"
3633
"go.uber.org/zap"
@@ -259,11 +256,8 @@ type reputationServer struct {
259256
}
260257

261258
func (s *reputationServer) makeResponseMetaHeader(st *protostatus.Status) *protosession.ResponseMetaHeader {
262-
v := version.Current()
263-
var v2 apirefs.Version
264-
v.WriteToV2(&v2)
265259
return &protosession.ResponseMetaHeader{
266-
Version: v2.ToGRPCMessage().(*refs.Version),
260+
Version: version.Current().ProtoMessage(),
267261
Epoch: s.networkState.CurrentEpoch(),
268262
Status: st,
269263
}
@@ -273,15 +267,12 @@ func (s *reputationServer) makeLocalResponse(err error) (*protoreputation.Announ
273267
resp := &protoreputation.AnnounceLocalTrustResponse{
274268
MetaHeader: s.makeResponseMetaHeader(util.ToStatus(err)),
275269
}
276-
return util.SignResponse(&s.key.PrivateKey, resp, v2reputation.AnnounceLocalTrustResponse{}), nil
270+
resp.VerifyHeader = util.SignResponse(&s.key.PrivateKey, resp)
271+
return resp, nil
277272
}
278273

279274
func (s *reputationServer) AnnounceLocalTrust(ctx context.Context, req *protoreputation.AnnounceLocalTrustRequest) (*protoreputation.AnnounceLocalTrustResponse, error) {
280-
req2 := new(v2reputation.AnnounceLocalTrustRequest)
281-
if err := req2.FromGRPCMessage(req); err != nil {
282-
return nil, err
283-
}
284-
if err := signature.VerifyServiceMessage(req2); err != nil {
275+
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
285276
return s.makeLocalResponse(util.ToRequestSignatureVerificationError(err))
286277
}
287278

@@ -314,15 +305,12 @@ func (s *reputationServer) makeIntermediateResponse(err error) (*protoreputation
314305
resp := &protoreputation.AnnounceIntermediateResultResponse{
315306
MetaHeader: s.makeResponseMetaHeader(util.ToStatus(err)),
316307
}
317-
return util.SignResponse(&s.key.PrivateKey, resp, v2reputation.AnnounceIntermediateResultResponse{}), nil
308+
resp.VerifyHeader = util.SignResponse(&s.key.PrivateKey, resp)
309+
return resp, nil
318310
}
319311

320312
func (s *reputationServer) AnnounceIntermediateResult(ctx context.Context, req *protoreputation.AnnounceIntermediateResultRequest) (*protoreputation.AnnounceIntermediateResultResponse, error) {
321-
req2 := new(v2reputation.AnnounceIntermediateResultRequest)
322-
if err := req2.FromGRPCMessage(req); err != nil {
323-
return nil, err
324-
}
325-
if err := signature.VerifyServiceMessage(req2); err != nil {
313+
if err := neofscrypto.VerifyRequestWithBuffer(req, nil); err != nil {
326314
return s.makeIntermediateResponse(util.ToRequestSignatureVerificationError(err))
327315
}
328316

cmd/neofs-node/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"fmt"
55
"time"
66

7-
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
87
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
98
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
109
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
1110
sessionSvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
1211
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
1312
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage/persistent"
1413
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage/temporary"
14+
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
1515
"github.com/nspcc-dev/neofs-sdk-go/user"
1616
)
1717

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

5252
for _, srv := range c.cfgGRPC.servers {
53-
sessionGRPC.RegisterSessionServiceServer(srv, server)
53+
protosession.RegisterSessionServiceServer(srv, server)
5454
}
5555
}

0 commit comments

Comments
 (0)