[#577] cmd/node: Use new config for node configuration

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-01 20:50:46 +03:00 committed by Alex Vanin
parent 42d18f1322
commit 6ab7efb358
2 changed files with 9 additions and 33 deletions

View file

@ -5,8 +5,9 @@ import (
"strconv" "strconv"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes" "github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"github.com/spf13/viper"
) )
const ( const (
@ -15,8 +16,8 @@ const (
defaultPrice = 0 defaultPrice = 0
) )
func parseAttributes(v *viper.Viper) []*netmap.NodeAttribute { func parseAttributes(c *config.Config) []*netmap.NodeAttribute {
stringAttributes := readAttributes(v) stringAttributes := nodeconfig.Attributes(c)
attrs, err := attributes.ParseV2Attributes(stringAttributes, nil) attrs, err := attributes.ParseV2Attributes(stringAttributes, nil)
if err != nil { if err != nil {
@ -26,21 +27,6 @@ func parseAttributes(v *viper.Viper) []*netmap.NodeAttribute {
return addWellKnownAttributes(attrs) return addWellKnownAttributes(attrs)
} }
func readAttributes(v *viper.Viper) (attrs []string) {
const maxAttributes = 100
for i := 0; i < maxAttributes; i++ {
attr := v.GetString(cfgNodeAttributePrefix + "_" + strconv.Itoa(i))
if attr == "" {
return
}
attrs = append(attrs, attr)
}
return attrs
}
type wellKnownNodeAttrDesc struct { type wellKnownNodeAttrDesc struct {
explicit bool explicit bool
defaultVal string defaultVal string

View file

@ -20,6 +20,7 @@ import (
shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard" shardconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard"
loggerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/logger" loggerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/logger"
metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics" metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"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"
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -52,12 +53,6 @@ import (
) )
const ( const (
// config keys for cfgNodeInfo
cfgNodeKey = "node.key"
cfgBootstrapAddress = "node.address"
cfgNodeAttributePrefix = "node.attribute"
cfgNodeRelay = "node.relay"
// config keys for cfgGRPC // config keys for cfgGRPC
cfgListenAddress = "grpc.endpoint" cfgListenAddress = "grpc.endpoint"
cfgTLSEnabled = "grpc.tls.enabled" cfgTLSEnabled = "grpc.tls.enabled"
@ -273,7 +268,7 @@ func initCfg(path string) *cfg {
viperCfg := initViper(path) viperCfg := initViper(path)
key, err := crypto.LoadPrivateKey(viperCfg.GetString(cfgNodeKey)) key, err := crypto.LoadPrivateKey(nodeconfig.Key(appCfg))
fatalOnErr(err) fatalOnErr(err)
u160Accounting, err := util.Uint160DecodeStringLE( u160Accounting, err := util.Uint160DecodeStringLE(
@ -302,8 +297,7 @@ func initCfg(path string) *cfg {
log, err := logger.NewLogger(logPrm) log, err := logger.NewLogger(logPrm)
fatalOnErr(err) fatalOnErr(err)
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress)) netAddr := nodeconfig.BootstrapAddress(appCfg)
fatalOnErr(err)
maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes
@ -335,7 +329,7 @@ func initCfg(path string) *cfg {
reputationWorkerPool, err := ants.NewPool(notificationHandlerPoolSize) reputationWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
fatalOnErr(err) fatalOnErr(err)
relayOnly := viperCfg.GetBool(cfgNodeRelay) relayOnly := nodeconfig.Relay(appCfg)
c := &cfg{ c := &cfg{
ctx: context.Background(), ctx: context.Background(),
@ -362,7 +356,7 @@ func initCfg(path string) *cfg {
}, },
cfgNodeInfo: cfgNodeInfo{ cfgNodeInfo: cfgNodeInfo{
bootType: StorageNode, bootType: StorageNode,
attributes: parseAttributes(viperCfg), attributes: parseAttributes(appCfg),
}, },
cfgGRPC: cfgGRPC{ cfgGRPC: cfgGRPC{
maxChunkSize: maxChunkSize, maxChunkSize: maxChunkSize,
@ -414,10 +408,6 @@ func initViper(path string) *viper.Viper {
} }
func defaultConfiguration(v *viper.Viper) { func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgNodeKey, "") // node key
v.SetDefault(cfgBootstrapAddress, "") // announced address of the node
v.SetDefault(cfgNodeRelay, false)
v.SetDefault(cfgMorphRPCAddress, []string{}) v.SetDefault(cfgMorphRPCAddress, []string{})
v.SetDefault(cfgMorphNotifyRPCAddress, []string{}) v.SetDefault(cfgMorphNotifyRPCAddress, []string{})
v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second) v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second)