[#174] Use Marshal(JSON)/Unmarshal(JSON) methods for encoding/decoding
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
3de8febe57
commit
58fcb35fb0
22 changed files with 91 additions and 140 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
|
@ -21,11 +20,9 @@ import (
|
|||
"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/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/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -275,15 +272,10 @@ var getContainerInfoCmd = &cobra.Command{
|
|||
return fmt.Errorf("can't read file: %w", err)
|
||||
}
|
||||
|
||||
// todo: make more user friendly way to parse raw data
|
||||
msg := new(grpccontainer.Container)
|
||||
if proto.Unmarshal(data, msg) != nil {
|
||||
return errors.New("can't unmarshal container")
|
||||
cnr = container.New()
|
||||
if err := cnr.Unmarshal(data); err != nil {
|
||||
return errors.Wrap(err, "can't unmarshal container")
|
||||
}
|
||||
|
||||
v2cnr := v2container.ContainerFromGRPCMessage(msg)
|
||||
|
||||
cnr = container.NewContainerFromV2(v2cnr)
|
||||
} else {
|
||||
cli, err := getSDKClient()
|
||||
if err != nil {
|
||||
|
@ -315,7 +307,7 @@ var getContainerInfoCmd = &cobra.Command{
|
|||
return fmt.Errorf("can't JSON encode container: %w", err)
|
||||
}
|
||||
} else {
|
||||
data, err = cnr.ToV2().StableMarshal(nil)
|
||||
data, err = cnr.Marshal()
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
data, err = eaclTable.ToV2().StableMarshal(nil)
|
||||
data, err = eaclTable.Marshal()
|
||||
if err != nil {
|
||||
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 {
|
||||
exp, err := eaclTable.ToV2().StableMarshal(nil)
|
||||
exp, err := eaclTable.Marshal()
|
||||
if err != nil {
|
||||
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()))
|
||||
if err == nil {
|
||||
// compare binary values because EACL could have been set already
|
||||
got, err := table.ToV2().StableMarshal(nil)
|
||||
got, err := table.Marshal()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cmd
|
|||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -628,9 +627,9 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
|
|||
case toJson && toProto:
|
||||
return nil, errors.New("'--json' and '--proto' flags are mutually exclusive")
|
||||
case toJson:
|
||||
return json.Marshal(hdr) // TODO currently not supported by neofs-api-go
|
||||
return hdr.MarshalJSON()
|
||||
case toProto:
|
||||
return hdr.ToV2().StableMarshal(nil)
|
||||
return hdr.Marshal()
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) error {
|
|||
return fmt.Errorf("can't JSON encode bearer token: %w", err)
|
||||
}
|
||||
} else {
|
||||
data, err = btok.ToV2().StableMarshal(nil)
|
||||
data, err = btok.Marshal()
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
data, err = table.ToV2().StableMarshal(nil)
|
||||
data, err = table.Marshal()
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't binary encode extended ACL table: %w", err)
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@ package main
|
|||
import (
|
||||
"strconv"
|
||||
|
||||
sdk "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
"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/util/attributes"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -15,7 +14,7 @@ const (
|
|||
defaultPrice = 0
|
||||
)
|
||||
|
||||
func parseAttributes(v *viper.Viper) []*netmap.Attribute {
|
||||
func parseAttributes(v *viper.Viper) []*netmap.NodeAttribute {
|
||||
stringAttributes := readAttributes(v)
|
||||
|
||||
attrs, err := attributes.ParseV2Attributes(stringAttributes, nil)
|
||||
|
@ -41,14 +40,14 @@ func readAttributes(v *viper.Viper) (attrs []string) {
|
|||
return attrs
|
||||
}
|
||||
|
||||
func addWellKnownAttributes(attrs []*netmap.Attribute) []*netmap.Attribute {
|
||||
func addWellKnownAttributes(attrs []*netmap.NodeAttribute) []*netmap.NodeAttribute {
|
||||
var hasCapacity, hasPrice bool
|
||||
|
||||
// check if user defined capacity and price attributes
|
||||
for i := range attrs {
|
||||
if !hasPrice && attrs[i].GetKey() == sdk.PriceAttr {
|
||||
if !hasPrice && attrs[i].Key() == netmap.PriceAttr {
|
||||
hasPrice = true
|
||||
} else if !hasCapacity && attrs[i].GetKey() == sdk.CapacityAttr {
|
||||
} else if !hasCapacity && attrs[i].Key() == netmap.CapacityAttr {
|
||||
hasCapacity = true
|
||||
}
|
||||
}
|
||||
|
@ -56,15 +55,15 @@ func addWellKnownAttributes(attrs []*netmap.Attribute) []*netmap.Attribute {
|
|||
// do not override user defined capacity and price attributes
|
||||
|
||||
if !hasCapacity {
|
||||
capacity := new(netmap.Attribute)
|
||||
capacity.SetKey(sdk.CapacityAttr)
|
||||
capacity := netmap.NewNodeAttribute()
|
||||
capacity.SetKey(netmap.CapacityAttr)
|
||||
capacity.SetValue(strconv.FormatUint(defaultCapacity, 10))
|
||||
attrs = append(attrs, capacity)
|
||||
}
|
||||
|
||||
if !hasPrice {
|
||||
price := new(netmap.Attribute)
|
||||
price.SetKey(sdk.PriceAttr)
|
||||
price := netmap.NewNodeAttribute()
|
||||
price.SetKey(netmap.PriceAttr)
|
||||
price.SetValue(strconv.FormatUint(defaultPrice, 10))
|
||||
attrs = append(attrs, price)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"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"
|
||||
"github.com/nspcc-dev/neofs-node/misc"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
|
@ -194,7 +194,7 @@ type BootstrapType uint32
|
|||
type cfgNodeInfo struct {
|
||||
// values from config
|
||||
bootType BootstrapType
|
||||
attributes []*netmap.Attribute
|
||||
attributes []*netmap.NodeAttribute
|
||||
|
||||
// values at runtime
|
||||
info *netmap.NodeInfo
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
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"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
|
@ -36,7 +36,7 @@ func initNetmapService(c *cfg) {
|
|||
peerInfo := new(netmap.NodeInfo)
|
||||
peerInfo.SetAddress(c.localAddr.String())
|
||||
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
||||
peerInfo.SetAttributes(c.cfgNodeInfo.attributes)
|
||||
peerInfo.SetAttributes(c.cfgNodeInfo.attributes...)
|
||||
|
||||
c.cfgNodeInfo.info = peerInfo
|
||||
|
||||
|
@ -46,7 +46,7 @@ func initNetmapService(c *cfg) {
|
|||
c.key,
|
||||
netmapService.NewResponseService(
|
||||
netmapService.NewExecutionService(
|
||||
c.cfgNodeInfo.info,
|
||||
c.cfgNodeInfo.info.ToV2(),
|
||||
c.apiVersion,
|
||||
),
|
||||
c.respSvc,
|
||||
|
|
|
@ -5,17 +5,14 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"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/pkg/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type (
|
||||
UpdatePeerArgs struct {
|
||||
Key *keys.PublicKey
|
||||
Status uint32
|
||||
Status netmap.NodeState
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
result = append(result, *netmap.NewNodeInfoFromV2(nodeInfo))
|
||||
result = append(result, *nodeInfo)
|
||||
}
|
||||
|
||||
return netmap.NewNetmap(netmap.NodesFromInfo(result))
|
||||
}
|
||||
|
||||
func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) {
|
||||
node := new(netmapgrpc.NodeInfo)
|
||||
func peerInfoFromStackItem(prm stackitem.Item) (*netmap.NodeInfo, error) {
|
||||
node := netmap.NewNodeInfo()
|
||||
|
||||
subItems, err := client.ArrayFromStackItem(prm)
|
||||
if err != nil {
|
||||
|
@ -156,9 +153,9 @@ func peerInfoFromStackItem(prm stackitem.Item) (*netmapv2.NodeInfo, error) {
|
|||
return nil, errors.New("invalid RPC response")
|
||||
} else if rawNodeInfo, err := client.BytesFromStackItem(subItems[0]); err != nil {
|
||||
return nil, err
|
||||
} else if err = proto.Unmarshal(rawNodeInfo, node); err != nil {
|
||||
} else if err = node.Unmarshal(rawNodeInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return netmapv2.NodeInfoFromGRPCMessage(node), nil
|
||||
return node, nil
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
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/innerring/invoke"
|
||||
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()
|
||||
|
||||
// unmarshal container structure
|
||||
// FIXME: temp solution, replace after neofs-api-go#168
|
||||
cnrProto := new(containerGRPC.Container)
|
||||
if err := proto.Unmarshal(cnrData, cnrProto); err != nil {
|
||||
cnr := containerSDK.New()
|
||||
if err := cnr.Unmarshal(cnrData); err != nil {
|
||||
cp.log.Info("could not unmarshal container structure",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
|
@ -32,10 +28,6 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) {
|
|||
return
|
||||
}
|
||||
|
||||
cnr := containerSDK.NewContainerFromV2(
|
||||
v2container.ContainerFromGRPCMessage(cnrProto),
|
||||
)
|
||||
|
||||
// perform format check
|
||||
if err := container.CheckFormat(cnr); err != nil {
|
||||
cp.log.Info("container with incorrect format detected",
|
||||
|
|
|
@ -2,7 +2,7 @@ package netmap
|
|||
|
||||
import (
|
||||
"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"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -27,7 +27,7 @@ func (np *Processor) processNetmapCleanupTick(epoch uint64) {
|
|||
|
||||
err = invoke.UpdatePeerState(np.morphClient, np.netmapContract, &invoke.UpdatePeerArgs{
|
||||
Key: key,
|
||||
Status: uint32(netmap.Offline),
|
||||
Status: netmap.NodeStateOffline,
|
||||
})
|
||||
if err != nil {
|
||||
np.log.Error("can't invoke netmap.UpdateState", zap.Error(err))
|
||||
|
|
|
@ -3,11 +3,10 @@ package netmap
|
|||
import (
|
||||
"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"
|
||||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Process add peer notification by sanity check of new node
|
||||
|
@ -18,25 +17,22 @@ func (np *Processor) processAddPeer(node []byte) {
|
|||
return
|
||||
}
|
||||
|
||||
// unmarshal grpc (any transport) version of node info from API v2
|
||||
nodeInfo := new(netmap.NodeInfo)
|
||||
|
||||
err := proto.Unmarshal(node, nodeInfo)
|
||||
if err != nil {
|
||||
// unmarshal node info
|
||||
nodeInfo := netmap.NewNodeInfo()
|
||||
if err := nodeInfo.Unmarshal(node); err != nil {
|
||||
// it will be nice to have tx id at event structure to log it
|
||||
np.log.Warn("can't parse network map candidate")
|
||||
return
|
||||
}
|
||||
|
||||
keyString := hex.EncodeToString(nodeInfo.PublicKey)
|
||||
keyString := hex.EncodeToString(nodeInfo.PublicKey())
|
||||
|
||||
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
|
||||
if !exists {
|
||||
np.log.Info("approving network map candidate",
|
||||
zap.String("key", keyString))
|
||||
|
||||
err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node)
|
||||
if err != nil {
|
||||
if err := invoke.ApprovePeer(np.morphClient, np.netmapContract, node); err != nil {
|
||||
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
|
||||
if ev.Status() != uint32(netmap.NodeInfo_OFFLINE) {
|
||||
if ev.Status() != netmap.NodeStateOffline {
|
||||
np.log.Warn("node proposes unknown state",
|
||||
zap.String("key", hex.EncodeToString(ev.PublicKey().Bytes())),
|
||||
zap.Uint32("status", ev.Status()),
|
||||
zap.Stringer("status", ev.Status()),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
)
|
||||
|
||||
func addressBytes(a *objectSDK.Address) ([]byte, error) {
|
||||
return a.ToV2().StableMarshal(nil)
|
||||
return a.Marshal()
|
||||
}
|
||||
|
||||
func objectBytes(o *object.Object) ([]byte, error) {
|
||||
return o.ToV2().StableMarshal(nil)
|
||||
return o.Marshal()
|
||||
}
|
||||
|
||||
func (s *Storage) Put(obj *object.Object) error {
|
||||
|
|
|
@ -31,7 +31,7 @@ func (db *DB) Put(obj *object.Object) error {
|
|||
return errors.Wrapf(err, "(%T) could not create primary bucket", db)
|
||||
}
|
||||
|
||||
data, err := obj.ToV2().StableMarshal(nil)
|
||||
data, err := obj.Marshal()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "(%T) could not marshal the object", db)
|
||||
}
|
||||
|
|
|
@ -5,13 +5,10 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"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"
|
||||
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
client "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -33,19 +30,15 @@ func (w *Wrapper) Put(cnr *container.Container, pubKey, signature []byte) (*cont
|
|||
args.SetPublicKey(pubKey)
|
||||
args.SetSignature(signature)
|
||||
|
||||
id := new(container.ID)
|
||||
id := container.NewID()
|
||||
|
||||
if v2 := cnr.ToV2(); v2 == nil {
|
||||
return nil, errUnsupported // use other major version if there any
|
||||
} else {
|
||||
data, err := v2.StableMarshal(nil)
|
||||
data, err := cnr.Marshal()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "can't marshal container")
|
||||
}
|
||||
|
||||
id.SetSHA256(sha256.Sum256(data))
|
||||
args.SetContainer(data)
|
||||
}
|
||||
|
||||
return id, w.client.Put(args)
|
||||
}
|
||||
|
@ -81,18 +74,14 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) {
|
|||
return nil, core.ErrNotFound
|
||||
}
|
||||
|
||||
// convert serialized bytes into GRPC structure
|
||||
grpcMsg := new(msgContainer.Container)
|
||||
err = proto.Unmarshal(rpcAnswer.Container(), grpcMsg)
|
||||
if err != nil {
|
||||
// unmarshal container
|
||||
cnr := container.New()
|
||||
if err := cnr.Unmarshal(rpcAnswer.Container()); err != nil {
|
||||
// use other major version if there any
|
||||
return nil, errors.Wrap(err, "can't unmarshal container")
|
||||
}
|
||||
|
||||
// convert GRPC structure into SDK structure, used in the code
|
||||
v2Cnr := v2container.ContainerFromGRPCMessage(grpcMsg)
|
||||
|
||||
return container.NewContainerFromV2(v2Cnr), nil
|
||||
return cnr, nil
|
||||
}
|
||||
|
||||
// Delete removes the container from NeoFS system
|
||||
|
|
|
@ -3,11 +3,8 @@ package wrapper
|
|||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
||||
"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"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
grpcMsg := new(msgACL.EACLTable)
|
||||
err = proto.Unmarshal(rpcAnswer.EACL(), grpcMsg)
|
||||
if err != nil {
|
||||
table := eacl.NewTable()
|
||||
if err = table.Unmarshal(rpcAnswer.EACL()); err != nil {
|
||||
// use other major version if there any
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
v2table := v2ACL.TableFromGRPCMessage(grpcMsg)
|
||||
|
||||
return eacl.NewTableFromV2(v2table), rpcAnswer.Signature(), nil
|
||||
return table, rpcAnswer.Signature(), nil
|
||||
}
|
||||
|
||||
// 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.SetSignature(signature)
|
||||
|
||||
if v2 := table.ToV2(); v2 == nil {
|
||||
return errUnsupported // use other major version if there any
|
||||
} else {
|
||||
data, err := v2.StableMarshal(nil)
|
||||
data, err := table.Marshal()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "can't marshal eacl table")
|
||||
}
|
||||
|
||||
args.SetEACL(data)
|
||||
}
|
||||
|
||||
return w.client.SetEACL(args)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package netmap
|
|||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error {
|
|||
return errors.New("nil node info")
|
||||
}
|
||||
|
||||
rawNodeInfo, err := nodeInfo.StableMarshal(nil)
|
||||
rawNodeInfo, err := nodeInfo.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,11 +2,8 @@ package wrapper
|
|||
|
||||
import (
|
||||
"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"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// 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))
|
||||
|
||||
for _, peer := range rawPeers {
|
||||
grpcNodeInfo := new(grpcNetmap.NodeInfo) // transport representation of struct
|
||||
err = proto.Unmarshal(peer, grpcNodeInfo)
|
||||
if err != nil {
|
||||
// consider unmarshalling into different major versions
|
||||
// of NodeInfo structure, if there any
|
||||
nodeInfo := netmap.NewNodeInfo()
|
||||
if err := nodeInfo.Unmarshal(peer); err != nil {
|
||||
return nil, errors.Wrap(err, "can't unmarshal peer info")
|
||||
}
|
||||
|
||||
v2 := v2netmap.NodeInfoFromGRPCMessage(grpcNodeInfo)
|
||||
infos = append(infos, *netmap.NewNodeInfoFromV2(v2))
|
||||
infos = append(infos, *nodeInfo)
|
||||
}
|
||||
|
||||
nodes := netmap.NodesFromInfo(infos)
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"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/event"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -12,13 +14,13 @@ import (
|
|||
|
||||
type UpdatePeer struct {
|
||||
publicKey *keys.PublicKey
|
||||
status uint32
|
||||
status netmap.NodeState
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (UpdatePeer) MorphEvent() {}
|
||||
|
||||
func (s UpdatePeer) Status() uint32 {
|
||||
func (s UpdatePeer) Status() netmap.NodeState {
|
||||
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")
|
||||
}
|
||||
|
||||
ev.status = uint32(st)
|
||||
ev.status = netmap.NodeStateFromV2(v2netmap.NodeState(st))
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"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"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
|
@ -16,7 +17,7 @@ import (
|
|||
func TestParseUpdatePeer(t *testing.T) {
|
||||
var (
|
||||
publicKey = &test.DecodeKey(-1).PublicKey
|
||||
state int64 = 1
|
||||
state = netmap.NodeStateOffline
|
||||
)
|
||||
|
||||
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) {
|
||||
ev, err := ParseUpdatePeer([]stackitem.Item{
|
||||
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)
|
||||
|
||||
|
@ -57,7 +58,7 @@ func TestParseUpdatePeer(t *testing.T) {
|
|||
|
||||
require.Equal(t, UpdatePeer{
|
||||
publicKey: expectedKey,
|
||||
status: uint32(state),
|
||||
status: state,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,13 +8,14 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func New() *TokenStore {
|
|||
//
|
||||
// Returns nil is there is no element in storage.
|
||||
func (s *TokenStore) Get(ownerID *owner.ID, tokenID []byte) *PrivateToken {
|
||||
ownerBytes, err := ownerID.ToV2().StableMarshal(nil)
|
||||
ownerBytes, err := ownerID.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -21,13 +21,13 @@ var (
|
|||
|
||||
// ParseV2Attributes parses strings like "K1:V1/K2:V2/K3:V3" into netmap
|
||||
// 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))
|
||||
for i := range excl {
|
||||
restricted[excl[i]] = struct{}{}
|
||||
}
|
||||
|
||||
cache := make(map[string]*netmap.Attribute, len(attrs))
|
||||
cache := make(map[string]*netmap.NodeAttribute, len(attrs))
|
||||
|
||||
for i := range attrs {
|
||||
line := strings.Trim(attrs[i], pairSeparator)
|
||||
|
@ -47,7 +47,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, erro
|
|||
key := pair[0]
|
||||
value := pair[1]
|
||||
|
||||
if at, ok := cache[key]; ok && at.GetValue() != value {
|
||||
if at, ok := cache[key]; ok && at.Value() != value {
|
||||
return nil, errNonUniqueBucket
|
||||
}
|
||||
|
||||
|
@ -55,12 +55,12 @@ func ParseV2Attributes(attrs []string, excl []string) ([]*netmap.Attribute, erro
|
|||
return nil, errUnexpectedKey
|
||||
}
|
||||
|
||||
attribute := new(netmap.Attribute)
|
||||
attribute := netmap.NewNodeAttribute()
|
||||
attribute.SetKey(key)
|
||||
attribute.SetValue(value)
|
||||
|
||||
if parentKey != "" {
|
||||
attribute.SetParents([]string{parentKey})
|
||||
attribute.SetParentKeys(parentKey)
|
||||
}
|
||||
|
||||
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 {
|
||||
result = append(result, v)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue