Skip to content

Commit

Permalink
[#1195] Adopt recent changes in NeoFS SDK
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Feb 28, 2022
1 parent a8d1070 commit e0dce10
Show file tree
Hide file tree
Showing 25 changed files with 856 additions and 395 deletions.
471 changes: 360 additions & 111 deletions cmd/neofs-cli/internal/client/client.go

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions cmd/neofs-cli/internal/client/prm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ type commonObjectPrm struct {
sessionTokenPrm
bearerTokenPrm

opts []client.CallOption
local bool
}

// SetTTL sets request TTL value.
func (x *commonObjectPrm) SetTTL(ttl uint32) {
x.opts = append(x.opts, client.WithTTL(ttl))
x.local = ttl < 2
}

// SetXHeaders sets request X-Headers.
func (x *commonObjectPrm) SetXHeaders(xhdrs []*session.XHeader) {
for _, xhdr := range xhdrs {
x.opts = append(x.opts, client.WithXHeader(xhdr))
}
func (x *commonObjectPrm) SetXHeaders(_ []*session.XHeader) {
// FIXME: (neofs-node#1194) not supported by client
}
12 changes: 2 additions & 10 deletions cmd/neofs-cli/modules/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ It will be stored in sidechain when inner ring will accepts it.`,
prepareAPIClientWithKey(cmd, key, &putPrm, &getPrm)
putPrm.SetContainer(*cnr)

if tok != nil {
putPrm.SetSessionToken(*tok)
}

res, err := internalclient.PutContainer(putPrm)
exitOnErr(cmd, errf("rpc error: %w", err))

Expand Down Expand Up @@ -423,10 +419,6 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
prepareAPIClient(cmd, &setEACLPrm, &getEACLPrm)
setEACLPrm.SetTable(*eaclTable)

if tok != nil {
setEACLPrm.SetSessionToken(*tok)
}

_, err = internalclient.SetEACL(setEACLPrm)
exitOnErr(cmd, errf("rpc error: %w", err))

Expand Down Expand Up @@ -754,8 +746,8 @@ func prettyPrintContainer(cmd *cobra.Command, cnr *container.Container, jsonEnco
id := container.CalculateID(cnr)
cmd.Println("container ID:", id)

version := cnr.Version()
cmd.Printf("version: %d.%d\n", version.Major(), version.Minor())
v := cnr.Version()
cmd.Printf("version: %d.%d\n", v.Major(), v.Minor())

cmd.Println("owner ID:", cnr.OwnerID())

Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-node/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ func (r *remoteLoadAnnounceWriter) Put(a containerSDK.UsedSpaceAnnouncement) err
}

func (r *remoteLoadAnnounceWriter) Close() error {
var cliPrm apiClient.AnnounceSpacePrm
var cliPrm apiClient.PrmAnnounceSpace

cliPrm.SetValues(r.buf)

_, err := r.client.AnnounceContainerUsedSpace(r.ctx, cliPrm)
_, err := r.client.ContainerAnnounceUsedSpace(r.ctx, cliPrm)
return err
}

Expand Down Expand Up @@ -515,7 +515,7 @@ func (l *loadPlacementBuilder) isNodeFromContainerKey(epoch uint64, cid *cid.ID,
return false, nil
}

func (c *usedSpaceService) processLoadValue(ctx context.Context, a containerSDK.UsedSpaceAnnouncement,
func (c *usedSpaceService) processLoadValue(_ context.Context, a containerSDK.UsedSpaceAnnouncement,
route []loadroute.ServerInfo, w loadcontroller.Writer) error {
fromCnr, err := c.loadPlacementBuilder.isNodeFromContainerKey(a.Epoch(), a.ContainerID(), route[0].PublicKey())
if err != nil {
Expand Down
43 changes: 21 additions & 22 deletions cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/nspcc-dev/neofs-sdk-go/client"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
Expand Down Expand Up @@ -449,57 +450,55 @@ func (c *reputationClient) submitResult(err error) {
c.cons.trustStorage.Update(prm)
}

func (c *reputationClient) PutObject(ctx context.Context, prm *client.PutObjectParams, opts ...client.CallOption) (*client.ObjectPutRes, error) {
res, err := c.MultiAddressClient.PutObject(ctx, prm, opts...)
func (c *reputationClient) ObjectPutInit(ctx context.Context, prm client.PrmObjectPutInit) (*client.ObjectWriter, error) {
res, err := c.MultiAddressClient.ObjectPutInit(ctx, prm)

// FIXME: (neofs-node#1193) here we submit only initialization errors, writing errors are not processed
c.submitResult(err)

return res, err
}

func (c *reputationClient) DeleteObject(ctx context.Context, prm *client.DeleteObjectParams, opts ...client.CallOption) (*client.ObjectDeleteRes, error) {
res, err := c.MultiAddressClient.DeleteObject(ctx, prm, opts...)

c.submitResult(err)

return res, err
}

func (c *reputationClient) GetObject(ctx context.Context, prm *client.GetObjectParams, opts ...client.CallOption) (*client.ObjectGetRes, error) {
res, err := c.MultiAddressClient.GetObject(ctx, prm, opts...)

c.submitResult(err)
func (c *reputationClient) ObjectDelete(ctx context.Context, prm client.PrmObjectDelete) (*client.ResObjectDelete, error) {
res, err := c.MultiAddressClient.ObjectDelete(ctx, prm)
if err != nil {
c.submitResult(err)
} else {
c.submitResult(apistatus.ErrFromStatus(res.Status()))
}

return res, err
}

func (c *reputationClient) HeadObject(ctx context.Context, prm *client.ObjectHeaderParams, opts ...client.CallOption) (*client.ObjectHeadRes, error) {
res, err := c.MultiAddressClient.HeadObject(ctx, prm, opts...)
func (c *reputationClient) GetObjectInit(ctx context.Context, prm client.PrmObjectGet) (*client.ObjectReader, error) {
res, err := c.MultiAddressClient.ObjectGetInit(ctx, prm)

// FIXME: (neofs-node#1193) here we submit only initialization errors, reading errors are not processed
c.submitResult(err)

return res, err
}

func (c *reputationClient) ObjectPayloadRangeData(ctx context.Context, prm *client.RangeDataParams, opts ...client.CallOption) (*client.ObjectRangeRes, error) {
res, err := c.MultiAddressClient.ObjectPayloadRangeData(ctx, prm, opts...)
func (c *reputationClient) ObjectHead(ctx context.Context, prm client.PrmObjectHead) (*client.ResObjectHead, error) {
res, err := c.MultiAddressClient.ObjectHead(ctx, prm)

c.submitResult(err)

return res, err
}

func (c *reputationClient) HashObjectPayloadRanges(ctx context.Context, prm *client.RangeChecksumParams, opts ...client.CallOption) (*client.ObjectRangeHashRes, error) {
res, err := c.MultiAddressClient.HashObjectPayloadRanges(ctx, prm, opts...)
func (c *reputationClient) ObjectHash(ctx context.Context, prm client.PrmObjectHash) (*client.ResObjectHash, error) {
res, err := c.MultiAddressClient.ObjectHash(ctx, prm)

c.submitResult(err)

return res, err
}

func (c *reputationClient) SearchObjects(ctx context.Context, prm *client.SearchObjectParams, opts ...client.CallOption) (*client.ObjectSearchRes, error) {
res, err := c.MultiAddressClient.SearchObjects(ctx, prm, opts...)
func (c *reputationClient) ObjectSearchInit(ctx context.Context, prm client.PrmObjectSearch) (*client.ObjectListReader, error) {
res, err := c.MultiAddressClient.ObjectSearchInit(ctx, prm)

// FIXME: (neofs-node#1193) here we submit only initialization errors, reading errors are not processed
c.submitResult(err)

return res, err
Expand Down
1 change: 0 additions & 1 deletion cmd/neofs-node/reputation/intermediate/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (rtp *RemoteTrustWriter) Write(t reputation.Trust) error {

p.SetContext(rtp.eiCtx)
p.SetClient(rtp.client)
p.SetPrivateKey(rtp.key)
p.SetEpoch(rtp.eiCtx.Epoch())
p.SetIteration(rtp.eiCtx.I())
p.SetTrust(*apiPeerToPeerTrust)
Expand Down
18 changes: 4 additions & 14 deletions cmd/neofs-node/reputation/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"context"
"crypto/ecdsa"

coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
"github.com/nspcc-dev/neofs-sdk-go/client"
Expand All @@ -14,8 +13,6 @@ type commonPrm struct {
cli coreclient.Client

ctx context.Context

opts []client.CallOption
}

// SetClient sets base client for NeoFS API communication.
Expand All @@ -32,18 +29,11 @@ func (x *commonPrm) SetContext(ctx context.Context) {
x.ctx = ctx
}

// SetPrivateKey sets private key to sign the request(s).
//
// Required parameter.
func (x *commonPrm) SetPrivateKey(key *ecdsa.PrivateKey) {
x.opts = append(x.opts, client.WithKey(key))
}

// AnnounceLocalPrm groups parameters of AnnounceLocal operation.
type AnnounceLocalPrm struct {
commonPrm

cliPrm client.AnnounceLocalTrustPrm
cliPrm client.PrmAnnounceLocalTrust
}

// SetEpoch sets epoch in which the trust was assessed.
Expand All @@ -65,7 +55,7 @@ type AnnounceLocalRes struct{}
//
// Returns any error prevented the operation from completing correctly in error return.
func AnnounceLocal(prm AnnounceLocalPrm) (res AnnounceLocalRes, err error) {
var cliRes *client.AnnounceLocalTrustRes
var cliRes *client.ResAnnounceLocalTrust

cliRes, err = prm.cli.AnnounceLocalTrust(prm.ctx, prm.cliPrm)
if err == nil {
Expand All @@ -80,7 +70,7 @@ func AnnounceLocal(prm AnnounceLocalPrm) (res AnnounceLocalRes, err error) {
type AnnounceIntermediatePrm struct {
commonPrm

cliPrm client.AnnounceIntermediateTrustPrm
cliPrm client.PrmAnnounceIntermediateTrust
}

// SetEpoch sets number of the epoch when the trust calculation's iteration was executed.
Expand Down Expand Up @@ -108,7 +98,7 @@ type AnnounceIntermediateRes struct{}
//
// Returns any error prevented the operation from completing correctly in error return.
func AnnounceIntermediate(prm AnnounceIntermediatePrm) (res AnnounceIntermediateRes, err error) {
var cliRes *client.AnnounceIntermediateTrustRes
var cliRes *client.ResAnnounceIntermediateTrust

cliRes, err = prm.cli.AnnounceIntermediateTrust(prm.ctx, prm.cliPrm)
if err == nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/neofs-node/reputation/local/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func (rtp *RemoteTrustWriter) Close() error {

prm.SetContext(rtp.ctx)
prm.SetClient(rtp.client)
prm.SetPrivateKey(rtp.key)
prm.SetEpoch(rtp.ctx.Epoch())
prm.SetTrusts(rtp.buf)

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ require (
github.com/multiformats/go-multiaddr v0.4.0
github.com/nspcc-dev/hrw v1.0.9
github.com/nspcc-dev/neo-go v0.98.0
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220127135316-32dd0bb3f9c5
github.com/nspcc-dev/neofs-api-go/v2 v2.12.0
github.com/nspcc-dev/neofs-contract v0.14.2
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220201141054-6a7ba33b59ef
github.com/nspcc-dev/tzhash v1.5.1
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.1.0.20220225083115-4fba1af6aa08
github.com/nspcc-dev/tzhash v1.5.2
github.com/panjf2000/ants/v2 v2.4.0
github.com/paulmach/orb v0.2.2
github.com/prometheus/client_golang v1.11.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,22 @@ github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:
github.com/nspcc-dev/neo-go v0.98.0 h1:yyW4sgY88/pLf0949qmgfkQXzRKC3CI/WyhqXNnwMd8=
github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220127135316-32dd0bb3f9c5 h1:y9tbmUYhcr052QXsa4/IfUKAi2cx3TGDsEZUAow3P/Y=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.2-0.20220127135316-32dd0bb3f9c5/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.0 h1:xWqXzorDk9WFMTtWP7cwwlyJDL1X6Z4HT1e5zqkq7xY=
github.com/nspcc-dev/neofs-api-go/v2 v2.12.0/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-contract v0.14.2 h1:m3Wx5LO9QMKt0w7iVVqrsU4SPs67RfTCS6QSyhqCkCA=
github.com/nspcc-dev/neofs-contract v0.14.2/go.mod h1:wSA0lmDqERsb0LsSPxOzkYULrTCaOc9JZG609uNNBzc=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220201141054-6a7ba33b59ef h1:0DuR21CIuOIPfVIyThWATulCkemdqHmmEqKdt22EHXk=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220201141054-6a7ba33b59ef/go.mod h1:dPvrJlIgoF1hLJlOWgbNmxQwANsQI/8dTe/wfjxwy04=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.1.0.20220225083115-4fba1af6aa08 h1:pYPSLxuyG77BPzqVN34CVh7aR8//1h5PRlNrFSnpyEw=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.1.0.20220225083115-4fba1af6aa08/go.mod h1:/WV31AQHs6YLTjMgMjMZw8Z3/Q7b6kMjNgJVsRab5AU=
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/tzhash v1.5.1 h1:eiPfipjS/7/jVJIkQYQgr7O3VL2NBsuROJGwC3g2GUk=
github.com/nspcc-dev/tzhash v1.5.1/go.mod h1:gwAx6mcsbkfY+JVp+PovoP2Gvw6y57W8dj7zDHKOhzI=
github.com/nspcc-dev/tzhash v1.5.2 h1:GuIQPOY2xpl5ZE1pbUbz+QdKXVOTyzbbxSVv0nBfa98=
github.com/nspcc-dev/tzhash v1.5.2/go.mod h1:gwAx6mcsbkfY+JVp+PovoP2Gvw6y57W8dj7zDHKOhzI=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down
20 changes: 10 additions & 10 deletions pkg/core/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (
// Client is an interface of NeoFS storage
// node's client.
type Client interface {
AnnounceContainerUsedSpace(context.Context, client.AnnounceSpacePrm) (*client.AnnounceSpaceRes, error)
ContainerAnnounceUsedSpace(context.Context, client.PrmAnnounceSpace) (*client.ResAnnounceSpace, error)

PutObject(context.Context, *client.PutObjectParams, ...client.CallOption) (*client.ObjectPutRes, error)
DeleteObject(context.Context, *client.DeleteObjectParams, ...client.CallOption) (*client.ObjectDeleteRes, error)
GetObject(context.Context, *client.GetObjectParams, ...client.CallOption) (*client.ObjectGetRes, error)
HeadObject(context.Context, *client.ObjectHeaderParams, ...client.CallOption) (*client.ObjectHeadRes, error)
SearchObjects(context.Context, *client.SearchObjectParams, ...client.CallOption) (*client.ObjectSearchRes, error)
ObjectPayloadRangeData(context.Context, *client.RangeDataParams, ...client.CallOption) (*client.ObjectRangeRes, error)
HashObjectPayloadRanges(context.Context, *client.RangeChecksumParams, ...client.CallOption) (*client.ObjectRangeHashRes, error)
ObjectPutInit(context.Context, client.PrmObjectPutInit) (*client.ObjectWriter, error)
ObjectDelete(context.Context, client.PrmObjectDelete) (*client.ResObjectDelete, error)
ObjectGetInit(context.Context, client.PrmObjectGet) (*client.ObjectReader, error)
ObjectHead(context.Context, client.PrmObjectHead) (*client.ResObjectHead, error)
ObjectSearchInit(context.Context, client.PrmObjectSearch) (*client.ObjectListReader, error)
ObjectRangeInit(context.Context, client.PrmObjectRange) (*client.ObjectRangeReader, error)
ObjectHash(context.Context, client.PrmObjectHash) (*client.ResObjectHash, error)

AnnounceLocalTrust(context.Context, client.AnnounceLocalTrustPrm) (*client.AnnounceLocalTrustRes, error)
AnnounceIntermediateTrust(context.Context, client.AnnounceIntermediateTrustPrm) (*client.AnnounceIntermediateTrustRes, error)
AnnounceLocalTrust(context.Context, client.PrmAnnounceLocalTrust) (*client.ResAnnounceLocalTrust, error)
AnnounceIntermediateTrust(context.Context, client.PrmAnnounceIntermediateTrust) (*client.ResAnnounceIntermediateTrust, error)

Raw() *rawclient.Client

Expand Down
Loading

0 comments on commit e0dce10

Please sign in to comment.