From 480362b02fd4db62fc2605223c527351050a6407 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 23 Sep 2020 16:31:51 +0300 Subject: [PATCH] [#43] cmd/neofs-node: Make cfg provide network address source interface Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 1ab9f28b5..ec1589c36 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -12,6 +12,7 @@ import ( crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/misc" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + "github.com/nspcc-dev/neofs-node/pkg/network" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/spf13/viper" @@ -75,6 +76,8 @@ type cfg struct { privateTokenStore *tokenStorage.TokenStore cfgNodeInfo cfgNodeInfo + + localAddr *network.Address } type cfgGRPC struct { @@ -139,6 +142,19 @@ func initCfg(path string) *cfg { log, err := logger.NewLogger(viperCfg) fatalOnErr(err) + viperCfg.GetString(cfgListenAddress) + + endpoint, port, err := net.SplitHostPort(viperCfg.GetString(cfgListenAddress)) + fatalOnErr(err) + + netAddr, err := network.AddressFromString(strings.Join([]string{ + "/ip4", + endpoint, + "tcp", + port, + }, "/")) + fatalOnErr(err) + return &cfg{ ctx: context.Background(), viper: viperCfg, @@ -161,6 +177,7 @@ func initCfg(path string) *cfg { bootType: StorageNode, attributes: parseAttributes(viperCfg), }, + localAddr: netAddr, } } @@ -208,3 +225,7 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgLogInitSampling, 1000) v.SetDefault(cfgLogThereafterSampling, 1000) } + +func (c *cfg) LocalAddress() *network.Address { + return c.localAddr +}