forked from TrueCloudLab/frostfs-node
[#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
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue