[#174] Use Marshal(JSON)/Unmarshal(JSON) methods for encoding/decoding

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-16 13:26:35 +03:00 committed by Alex Vanin
parent 3de8febe57
commit 58fcb35fb0
22 changed files with 91 additions and 140 deletions

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math" "math"
@ -21,11 +20,9 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
v2container "github.com/nspcc-dev/neofs-api-go/v2/container"
grpccontainer "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"github.com/nspcc-dev/neofs-node/pkg/policy" "github.com/nspcc-dev/neofs-node/pkg/policy"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
) )
const ( const (
@ -275,15 +272,10 @@ var getContainerInfoCmd = &cobra.Command{
return fmt.Errorf("can't read file: %w", err) return fmt.Errorf("can't read file: %w", err)
} }
// todo: make more user friendly way to parse raw data cnr = container.New()
msg := new(grpccontainer.Container) if err := cnr.Unmarshal(data); err != nil {
if proto.Unmarshal(data, msg) != nil { return errors.Wrap(err, "can't unmarshal container")
return errors.New("can't unmarshal container")
} }
v2cnr := v2container.ContainerFromGRPCMessage(msg)
cnr = container.NewContainerFromV2(v2cnr)
} else { } else {
cli, err := getSDKClient() cli, err := getSDKClient()
if err != nil { if err != nil {
@ -315,7 +307,7 @@ var getContainerInfoCmd = &cobra.Command{
return fmt.Errorf("can't JSON encode container: %w", err) return fmt.Errorf("can't JSON encode container: %w", err)
} }
} else { } else {
data, err = cnr.ToV2().StableMarshal(nil) data, err = cnr.Marshal()
if err != nil { if err != nil {
return fmt.Errorf("can't binary encode container: %w", err) return fmt.Errorf("can't binary encode container: %w", err)
} }
@ -372,7 +364,7 @@ var getExtendedACLCmd = &cobra.Command{
return fmt.Errorf("can't enode to JSON: %w", err) return fmt.Errorf("can't enode to JSON: %w", err)
} }
} else { } else {
data, err = eaclTable.ToV2().StableMarshal(nil) data, err = eaclTable.Marshal()
if err != nil { if err != nil {
return fmt.Errorf("can't enode to binary: %w", err) return fmt.Errorf("can't enode to binary: %w", err)
} }
@ -415,7 +407,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
} }
if containerAwait { if containerAwait {
exp, err := eaclTable.ToV2().StableMarshal(nil) exp, err := eaclTable.Marshal()
if err != nil { if err != nil {
return errors.New("broken EACL table") return errors.New("broken EACL table")
} }
@ -428,7 +420,7 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
table, err := cli.GetEACL(ctx, id, client.WithTTL(getTTL())) table, err := cli.GetEACL(ctx, id, client.WithTTL(getTTL()))
if err == nil { if err == nil {
// compare binary values because EACL could have been set already // compare binary values because EACL could have been set already
got, err := table.ToV2().StableMarshal(nil) got, err := table.Marshal()
if err != nil { if err != nil {
continue continue
} }

View file

@ -3,7 +3,6 @@ package cmd
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -628,9 +627,9 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
case toJson && toProto: case toJson && toProto:
return nil, errors.New("'--json' and '--proto' flags are mutually exclusive") return nil, errors.New("'--json' and '--proto' flags are mutually exclusive")
case toJson: case toJson:
return json.Marshal(hdr) // TODO currently not supported by neofs-api-go return hdr.MarshalJSON()
case toProto: case toProto:
return hdr.ToV2().StableMarshal(nil) return hdr.Marshal()
default: default:
return nil, nil return nil, nil
} }

View file

@ -112,7 +112,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't JSON encode bearer token: %w", err) return fmt.Errorf("can't JSON encode bearer token: %w", err)
} }
} else { } else {
data, err = btok.ToV2().StableMarshal(nil) data, err = btok.Marshal()
if err != nil { if err != nil {
return fmt.Errorf("can't binary encode bearer token: %w", err) return fmt.Errorf("can't binary encode bearer token: %w", err)
} }
@ -151,7 +151,7 @@ func convertEACLTable(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't JSON encode extended ACL table: %w", err) return fmt.Errorf("can't JSON encode extended ACL table: %w", err)
} }
} else { } else {
data, err = table.ToV2().StableMarshal(nil) data, err = table.Marshal()
if err != nil { if err != nil {
return fmt.Errorf("can't binary encode extended ACL table: %w", err) return fmt.Errorf("can't binary encode extended ACL table: %w", err)
} }

View file

@ -3,8 +3,7 @@ package main
import ( import (
"strconv" "strconv"
sdk "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes" "github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -15,7 +14,7 @@ const (
defaultPrice = 0 defaultPrice = 0
) )
func parseAttributes(v *viper.Viper) []*netmap.Attribute { func parseAttributes(v *viper.Viper) []*netmap.NodeAttribute {
stringAttributes := readAttributes(v) stringAttributes := readAttributes(v)
attrs, err := attributes.ParseV2Attributes(stringAttributes, nil) attrs, err := attributes.ParseV2Attributes(stringAttributes, nil)
@ -41,14 +40,14 @@ func readAttributes(v *viper.Viper) (attrs []string) {
return attrs return attrs
} }
func addWellKnownAttributes(attrs []*netmap.Attribute) []*netmap.Attribute { func addWellKnownAttributes(attrs []*netmap.NodeAttribute) []*netmap.NodeAttribute {
var hasCapacity, hasPrice bool var hasCapacity, hasPrice bool
// check if user defined capacity and price attributes // check if user defined capacity and price attributes
for i := range attrs { for i := range attrs {
if !hasPrice && attrs[i].GetKey() == sdk.PriceAttr { if !hasPrice && attrs[i].Key() == netmap.PriceAttr {
hasPrice = true hasPrice = true
} else if !hasCapacity && attrs[i].GetKey() == sdk.CapacityAttr { } else if !hasCapacity && attrs[i].Key() == netmap.CapacityAttr {
hasCapacity = true hasCapacity = true
} }
} }
@ -56,15 +55,15 @@ func addWellKnownAttributes(attrs []*netmap.Attribute) []*netmap.Attribute {
// do not override user defined capacity and price attributes // do not override user defined capacity and price attributes
if !hasCapacity { if !hasCapacity {
capacity := new(netmap.Attribute) capacity := netmap.NewNodeAttribute()
capacity.SetKey(sdk.CapacityAttr) capacity.SetKey(netmap.CapacityAttr)
capacity.SetValue(strconv.FormatUint(defaultCapacity, 10)) capacity.SetValue(strconv.FormatUint(defaultCapacity, 10))
attrs = append(attrs, capacity) attrs = append(attrs, capacity)
} }
if !hasPrice { if !hasPrice {
price := new(netmap.Attribute) price := netmap.NewNodeAttribute()
price.SetKey(sdk.PriceAttr) price.SetKey(netmap.PriceAttr)
price.SetValue(strconv.FormatUint(defaultPrice, 10)) price.SetValue(strconv.FormatUint(defaultPrice, 10))
attrs = append(attrs, price) attrs = append(attrs, price)
} }

View file

@ -11,7 +11,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/misc" "github.com/nspcc-dev/neofs-node/misc"
"github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/container"
@ -194,7 +194,7 @@ type BootstrapType uint32
type cfgNodeInfo struct { type cfgNodeInfo struct {
// values from config // values from config
bootType BootstrapType bootType BootstrapType
attributes []*netmap.Attribute attributes []*netmap.NodeAttribute
// values at runtime // values at runtime
info *netmap.NodeInfo info *netmap.NodeInfo

View file

@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -36,7 +36,7 @@ func initNetmapService(c *cfg) {
peerInfo := new(netmap.NodeInfo) peerInfo := new(netmap.NodeInfo)
peerInfo.SetAddress(c.localAddr.String()) peerInfo.SetAddress(c.localAddr.String())
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey)) peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
peerInfo.SetAttributes(c.cfgNodeInfo.attributes) peerInfo.SetAttributes(c.cfgNodeInfo.attributes...)
c.cfgNodeInfo.info = peerInfo c.cfgNodeInfo.info = peerInfo
@ -46,7 +46,7 @@ func initNetmapService(c *cfg) {
c.key, c.key,
netmapService.NewResponseService( netmapService.NewResponseService(
netmapService.NewExecutionService( netmapService.NewExecutionService(
c.cfgNodeInfo.info, c.cfgNodeInfo.info.ToV2(),
c.apiVersion, c.apiVersion,
), ),
c.respSvc, c.respSvc,

View file

@ -5,17 +5,14 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
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/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/protobuf/proto"
) )
type ( type (
UpdatePeerArgs struct { UpdatePeerArgs struct {
Key *keys.PublicKey Key *keys.PublicKey
Status uint32 Status netmap.NodeState
} }
SetConfigArgs struct { SetConfigArgs struct {
@ -140,14 +137,14 @@ func NetmapSnapshot(cli *client.Client, con util.Uint160) (*netmap.Netmap, error
return nil, errors.Wrap(err, "invalid RPC response") return nil, errors.Wrap(err, "invalid RPC response")
} }
result = append(result, *netmap.NewNodeInfoFromV2(nodeInfo)) result = append(result, *nodeInfo)
} }
return netmap.NewNetmap(netmap.NodesFromInfo(result)) return netmap.NewNetmap(netmap.NodesFromInfo(result))
} }
func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) { func peerInfoFromStackItem(prm stackitem.Item) (*netmap.NodeInfo, error) {
node := new(netmapgrpc.NodeInfo) node := netmap.NewNodeInfo()
subItems, err := client.ArrayFromStackItem(prm) subItems, err := client.ArrayFromStackItem(prm)
if err != nil { if err != nil {
@ -156,9 +153,9 @@ func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) {
return nil, errors.New("invalid RPC response") return nil, errors.New("invalid RPC response")
} else if rawNodeInfo, err := client.BytesFromStackItem(subItems[0]); err != nil { } else if rawNodeInfo, err := client.BytesFromStackItem(subItems[0]); err != nil {
return nil, err return nil, err
} else if err = proto.Unmarshal(rawNodeInfo, node); err != nil { } else if err = node.Unmarshal(rawNodeInfo); err != nil {
return nil, err return nil, err
} }
return netmapv2.NodeInfoFromGRPCMessage(node), nil return node, nil
} }

View file

@ -1,10 +1,7 @@
package container package container
import ( import (
"github.com/golang/protobuf/proto"
containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container"
v2container "github.com/nspcc-dev/neofs-api-go/v2/container"
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
@ -22,9 +19,8 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) {
cnrData := put.Container() cnrData := put.Container()
// unmarshal container structure // unmarshal container structure
// FIXME: temp solution, replace after neofs-api-go#168 cnr := containerSDK.New()
cnrProto := new(containerGRPC.Container) if err := cnr.Unmarshal(cnrData); err != nil {
if err := proto.Unmarshal(cnrData, cnrProto); err != nil {
cp.log.Info("could not unmarshal container structure", cp.log.Info("could not unmarshal container structure",
zap.String("error", err.Error()), zap.String("error", err.Error()),
) )
@ -32,10 +28,6 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) {
return return
} }
cnr := containerSDK.NewContainerFromV2(
v2container.ContainerFromGRPCMessage(cnrProto),
)
// perform format check // perform format check
if err := container.CheckFormat(cnr); err != nil { if err := container.CheckFormat(cnr); err != nil {
cp.log.Info("container with incorrect format detected", cp.log.Info("container with incorrect format detected",

View file

@ -2,7 +2,7 @@ package netmap
import ( import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -27,7 +27,7 @@ func (np *Processor) processNetmapCleanupTick(epoch uint64) {
err = invoke.UpdatePeerState(np.morphClient, np.netmapContract, &invoke.UpdatePeerArgs{ err = invoke.UpdatePeerState(np.morphClient, np.netmapContract, &invoke.UpdatePeerArgs{
Key: key, Key: key,
Status: uint32(netmap.Offline), Status: netmap.NodeStateOffline,
}) })
if err != nil { if err != nil {
np.log.Error("can't invoke netmap.UpdateState", zap.Error(err)) np.log.Error("can't invoke netmap.UpdateState", zap.Error(err))

View file

@ -3,11 +3,10 @@ package netmap
import ( import (
"encoding/hex" "encoding/hex"
"github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/protobuf/proto"
) )
// Process add peer notification by sanity check of new node // Process add peer notification by sanity check of new node
@ -18,25 +17,22 @@ func (np *Processor) processAddPeer(node []byte) {
return return
} }
// unmarshal grpc (any transport) version of node info from API v2 // unmarshal node info
nodeInfo := new(netmap.NodeInfo) nodeInfo := netmap.NewNodeInfo()
if err := nodeInfo.Unmarshal(node); err != nil {
err := proto.Unmarshal(node, nodeInfo)
if err != nil {
// it will be nice to have tx id at event structure to log it // it will be nice to have tx id at event structure to log it
np.log.Warn("can't parse network map candidate") np.log.Warn("can't parse network map candidate")
return return
} }
keyString := hex.EncodeToString(nodeInfo.PublicKey) keyString := hex.EncodeToString(nodeInfo.PublicKey())
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter()) exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
if !exists { if !exists {
np.log.Info("approving network map candidate", np.log.Info("approving network map candidate",
zap.String("key", keyString)) zap.String("key", keyString))
err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node) if err := invoke.ApprovePeer(np.morphClient, np.netmapContract, node); err != nil {
if err != nil {
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err)) np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
} }
} }
@ -50,10 +46,10 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
} }
// better use unified enum from neofs-api-go/v2/netmap package // better use unified enum from neofs-api-go/v2/netmap package
if ev.Status() != uint32(netmap.NodeInfo_OFFLINE) { if ev.Status() != netmap.NodeStateOffline {
np.log.Warn("node proposes unknown state", np.log.Warn("node proposes unknown state",
zap.String("key", hex.EncodeToString(ev.PublicKey().Bytes())), zap.String("key", hex.EncodeToString(ev.PublicKey().Bytes())),
zap.Uint32("status", ev.Status()), zap.Stringer("status", ev.Status()),
) )
return return
} }

View file

@ -8,11 +8,11 @@ import (
) )
func addressBytes(a *objectSDK.Address) ([]byte, error) { func addressBytes(a *objectSDK.Address) ([]byte, error) {
return a.ToV2().StableMarshal(nil) return a.Marshal()
} }
func objectBytes(o *object.Object) ([]byte, error) { func objectBytes(o *object.Object) ([]byte, error) {
return o.ToV2().StableMarshal(nil) return o.Marshal()
} }
func (s *Storage) Put(obj *object.Object) error { func (s *Storage) Put(obj *object.Object) error {

View file

@ -31,7 +31,7 @@ func (db *DB) Put(obj *object.Object) error {
return errors.Wrapf(err, "(%T) could not create primary bucket", db) return errors.Wrapf(err, "(%T) could not create primary bucket", db)
} }
data, err := obj.ToV2().StableMarshal(nil) data, err := obj.Marshal()
if err != nil { if err != nil {
return errors.Wrapf(err, "(%T) could not marshal the object", db) return errors.Wrapf(err, "(%T) could not marshal the object", db)
} }

View file

@ -5,13 +5,10 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
v2container "github.com/nspcc-dev/neofs-api-go/v2/container"
msgContainer "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs" v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
core "github.com/nspcc-dev/neofs-node/pkg/core/container" core "github.com/nspcc-dev/neofs-node/pkg/core/container"
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/protobuf/proto"
) )
var ( var (
@ -33,19 +30,15 @@ func (w *Wrapper) Put(cnr *container.Container, pubKey, signature []byte) (*cont
args.SetPublicKey(pubKey) args.SetPublicKey(pubKey)
args.SetSignature(signature) args.SetSignature(signature)
id := new(container.ID) id := container.NewID()
if v2 := cnr.ToV2(); v2 == nil { data, err := cnr.Marshal()
return nil, errUnsupported // use other major version if there any
} else {
data, err := v2.StableMarshal(nil)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "can't marshal container") return nil, errors.Wrap(err, "can't marshal container")
} }
id.SetSHA256(sha256.Sum256(data)) id.SetSHA256(sha256.Sum256(data))
args.SetContainer(data) args.SetContainer(data)
}
return id, w.client.Put(args) return id, w.client.Put(args)
} }
@ -81,18 +74,14 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) {
return nil, core.ErrNotFound return nil, core.ErrNotFound
} }
// convert serialized bytes into GRPC structure // unmarshal container
grpcMsg := new(msgContainer.Container) cnr := container.New()
err = proto.Unmarshal(rpcAnswer.Container(), grpcMsg) if err := cnr.Unmarshal(rpcAnswer.Container()); err != nil {
if err != nil {
// use other major version if there any // use other major version if there any
return nil, errors.Wrap(err, "can't unmarshal container") return nil, errors.Wrap(err, "can't unmarshal container")
} }
// convert GRPC structure into SDK structure, used in the code return cnr, nil
v2Cnr := v2container.ContainerFromGRPCMessage(grpcMsg)
return container.NewContainerFromV2(v2Cnr), nil
} }
// Delete removes the container from NeoFS system // Delete removes the container from NeoFS system

View file

@ -3,11 +3,8 @@ package wrapper
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
v2ACL "github.com/nspcc-dev/neofs-api-go/v2/acl"
msgACL "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc"
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/protobuf/proto"
) )
// GetEACL reads the extended ACL table from NeoFS system // GetEACL reads the extended ACL table from NeoFS system
@ -30,16 +27,13 @@ func (w *Wrapper) GetEACL(cid *container.ID) (*eacl.Table, []byte, error) {
return nil, nil, err return nil, nil, err
} }
grpcMsg := new(msgACL.EACLTable) table := eacl.NewTable()
err = proto.Unmarshal(rpcAnswer.EACL(), grpcMsg) if err = table.Unmarshal(rpcAnswer.EACL()); err != nil {
if err != nil {
// use other major version if there any // use other major version if there any
return nil, nil, err return nil, nil, err
} }
v2table := v2ACL.TableFromGRPCMessage(grpcMsg) return table, rpcAnswer.Signature(), nil
return eacl.NewTableFromV2(v2table), rpcAnswer.Signature(), nil
} }
// PutEACL saves the extended ACL table in NeoFS system // PutEACL saves the extended ACL table in NeoFS system
@ -54,16 +48,12 @@ func (w *Wrapper) PutEACL(table *eacl.Table, signature []byte) error {
args := client.SetEACLArgs{} args := client.SetEACLArgs{}
args.SetSignature(signature) args.SetSignature(signature)
if v2 := table.ToV2(); v2 == nil { data, err := table.Marshal()
return errUnsupported // use other major version if there any
} else {
data, err := v2.StableMarshal(nil)
if err != nil { if err != nil {
return errors.Wrap(err, "can't marshal eacl table") return errors.Wrap(err, "can't marshal eacl table")
} }
args.SetEACL(data) args.SetEACL(data)
}
return w.client.SetEACL(args) return w.client.SetEACL(args)
} }

View file

@ -3,7 +3,7 @@ package netmap
import ( import (
"errors" "errors"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
) )

View file

@ -12,7 +12,7 @@ func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error {
return errors.New("nil node info") return errors.New("nil node info")
} }
rawNodeInfo, err := nodeInfo.StableMarshal(nil) rawNodeInfo, err := nodeInfo.Marshal()
if err != nil { if err != nil {
return err return err
} }

View file

@ -2,11 +2,8 @@ package wrapper
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
grpcNetmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" client "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/pkg/errors" "github.com/pkg/errors"
"google.golang.org/protobuf/proto"
) )
// GetNetMap receives information list about storage nodes // GetNetMap receives information list about storage nodes
@ -26,16 +23,12 @@ func (w Wrapper) GetNetMap(diff uint64) (*netmap.Netmap, error) {
infos := make([]netmap.NodeInfo, 0, len(rawPeers)) infos := make([]netmap.NodeInfo, 0, len(rawPeers))
for _, peer := range rawPeers { for _, peer := range rawPeers {
grpcNodeInfo := new(grpcNetmap.NodeInfo) // transport representation of struct nodeInfo := netmap.NewNodeInfo()
err = proto.Unmarshal(peer, grpcNodeInfo) if err := nodeInfo.Unmarshal(peer); err != nil {
if err != nil {
// consider unmarshalling into different major versions
// of NodeInfo structure, if there any
return nil, errors.Wrap(err, "can't unmarshal peer info") return nil, errors.Wrap(err, "can't unmarshal peer info")
} }
v2 := v2netmap.NodeInfoFromGRPCMessage(grpcNodeInfo) infos = append(infos, *nodeInfo)
infos = append(infos, *netmap.NewNodeInfoFromV2(v2))
} }
nodes := netmap.NodesFromInfo(infos) nodes := netmap.NodesFromInfo(infos)

View file

@ -5,6 +5,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -12,13 +14,13 @@ import (
type UpdatePeer struct { type UpdatePeer struct {
publicKey *keys.PublicKey publicKey *keys.PublicKey
status uint32 status netmap.NodeState
} }
// MorphEvent implements Neo:Morph Event interface. // MorphEvent implements Neo:Morph Event interface.
func (UpdatePeer) MorphEvent() {} func (UpdatePeer) MorphEvent() {}
func (s UpdatePeer) Status() uint32 { func (s UpdatePeer) Status() netmap.NodeState {
return s.status return s.status
} }
@ -53,7 +55,7 @@ func ParseUpdatePeer(prms []stackitem.Item) (event.Event, error) {
return nil, errors.Wrap(err, "could not get node status") return nil, errors.Wrap(err, "could not get node status")
} }
ev.status = uint32(st) ev.status = netmap.NodeStateFromV2(v2netmap.NodeState(st))
return ev, nil return ev, nil
} }

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test" "github.com/nspcc-dev/neofs-crypto/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -16,7 +17,7 @@ import (
func TestParseUpdatePeer(t *testing.T) { func TestParseUpdatePeer(t *testing.T) {
var ( var (
publicKey = &test.DecodeKey(-1).PublicKey publicKey = &test.DecodeKey(-1).PublicKey
state int64 = 1 state = netmap.NodeStateOffline
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
@ -48,7 +49,7 @@ func TestParseUpdatePeer(t *testing.T) {
t.Run("correct behavior", func(t *testing.T) { t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseUpdatePeer([]stackitem.Item{ ev, err := ParseUpdatePeer([]stackitem.Item{
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)), stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)),
stackitem.NewBigInteger(new(big.Int).SetInt64(state)), stackitem.NewBigInteger(new(big.Int).SetInt64(int64(state.ToV2()))),
}) })
require.NoError(t, err) require.NoError(t, err)
@ -57,7 +58,7 @@ func TestParseUpdatePeer(t *testing.T) {
require.Equal(t, UpdatePeer{ require.Equal(t, UpdatePeer{
publicKey: expectedKey, publicKey: expectedKey,
status: uint32(state), status: state,
}, ev) }, ev)
}) })
} }

View file

@ -8,13 +8,14 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
crypto "github.com/nspcc-dev/neofs-crypto" crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) { func (s *TokenStore) Create(ctx context.Context, body *session.CreateRequestBody) (*session.CreateResponseBody, error) {
ownerBytes, err := body.GetOwnerID().StableMarshal(nil) ownerBytes, err := owner.NewIDFromV2(body.GetOwnerID()).Marshal()
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -35,7 +35,7 @@ func New() *TokenStore {
// //
// Returns nil is there is no element in storage. // Returns nil is there is no element in storage.
func (s *TokenStore) Get(ownerID *owner.ID, tokenID []byte) *PrivateToken { func (s *TokenStore) Get(ownerID *owner.ID, tokenID []byte) *PrivateToken {
ownerBytes, err := ownerID.ToV2().StableMarshal(nil) ownerBytes, err := ownerID.Marshal()
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
) )
const ( const (
@ -21,13 +21,13 @@ var (
// ParseV2Attributes parses strings like "K1:V1/K2:V2/K3:V3" into netmap // ParseV2Attributes parses strings like "K1:V1/K2:V2/K3:V3" into netmap
// attributes. // attributes.
func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, error) { func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.NodeAttribute, error) {
restricted := make(map[string]struct{}, len(excl)) restricted := make(map[string]struct{}, len(excl))
for i := range excl { for i := range excl {
restricted[excl[i]] = struct{}{} restricted[excl[i]] = struct{}{}
} }
cache := make(map[string]*netmap.Attribute, len(attrs)) cache := make(map[string]*netmap.NodeAttribute, len(attrs))
for i := range attrs { for i := range attrs {
line := strings.Trim(attrs[i], pairSeparator) line := strings.Trim(attrs[i], pairSeparator)
@ -47,7 +47,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, erro
key := pair[0] key := pair[0]
value := pair[1] value := pair[1]
if at, ok := cache[key]; ok && at.GetValue() != value { if at, ok := cache[key]; ok && at.Value() != value {
return nil, errNonUniqueBucket return nil, errNonUniqueBucket
} }
@ -55,12 +55,12 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, erro
return nil, errUnexpectedKey return nil, errUnexpectedKey
} }
attribute := new(netmap.Attribute) attribute := netmap.NewNodeAttribute()
attribute.SetKey(key) attribute.SetKey(key)
attribute.SetValue(value) attribute.SetValue(value)
if parentKey != "" { if parentKey != "" {
attribute.SetParents([]string{parentKey}) attribute.SetParentKeys(parentKey)
} }
parentKey = key parentKey = key
@ -68,7 +68,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, erro
} }
} }
result := make([]*netmap.Attribute, 0, len(cache)) result := make([]*netmap.NodeAttribute, 0, len(cache))
for _, v := range cache { for _, v := range cache {
result = append(result, v) result = append(result, v)
} }