[#607] cmd/node: Configure group of bootstrap addresses

There is a need to support multiple network addresses of the storage nodes.

Make `BootstrapAddress` to return `network.AddressGroup` (and rename).

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-22 20:35:56 +03:00 committed by Leonard Lyubich
parent 8060735732
commit 163c24a2d2
6 changed files with 42 additions and 27 deletions

View file

@ -215,7 +215,7 @@ func initCfg(path string) *cfg {
log, err := logger.NewLogger(logPrm)
fatalOnErr(err)
netAddr := nodeconfig.BootstrapAddress(appCfg)
netAddr := nodeconfig.BootstrapAddresses(appCfg)
maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes
@ -259,7 +259,7 @@ func initCfg(path string) *cfg {
maxChunkSize: maxChunkSize,
maxAddrAmount: maxAddrAmount,
},
localAddr: network.GroupFromAddress(netAddr),
localAddr: netAddr,
respSvc: response.NewService(
response.WithNetworkState(state),
),

View file

@ -18,10 +18,7 @@ const (
attributePrefix = "attribute"
)
var (
errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
errAddressNotSet = errors.New("empty/not set bootstrap address, see `node.address` section")
)
var errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
// Key returns value of "key" config parameter
// from "node" section.
@ -63,19 +60,30 @@ func Wallet(c *config.Config) *keys.PrivateKey {
return acc.PrivateKey()
}
// BootstrapAddress returns value of "address" config parameter
// from "node" section as network.Address.
//
// Panics if value is not a valid NeoFS network address
func BootstrapAddress(c *config.Config) (addr network.Address) {
v := config.StringSafe(c.Sub(subsection), "address")
if v == "" {
panic(errAddressNotSet)
}
type stringAddressGroup []string
err := addr.FromString(v)
func (x stringAddressGroup) IterateAddresses(f func(string) bool) {
for i := range x {
if f(x[i]) {
break
}
}
}
func (x stringAddressGroup) NumberOfAddresses() int {
return len(x)
}
// BootstrapAddresses returns value of "addresses" config parameter
// from "node" section as network.AddressGroup.
//
// Panics if value is not a string list of valid NeoFS network addresses.
func BootstrapAddresses(c *config.Config) (addr network.AddressGroup) {
v := config.StringSlice(c.Sub(subsection), "addresses")
err := addr.FromIterator(stringAddressGroup(v))
if err != nil {
panic(fmt.Errorf("could not convert bootstrap address %s to %T: %w", v, addr, err))
panic(fmt.Errorf("could not parse bootstrap addresses: %w", err))
}
return addr

View file

@ -22,11 +22,10 @@ func TestNodeSection(t *testing.T) {
},
)
require.PanicsWithError(
require.Panics(
t,
errAddressNotSet.Error(),
func() {
BootstrapAddress(empty)
BootstrapAddresses(empty)
},
)
@ -41,18 +40,21 @@ func TestNodeSection(t *testing.T) {
var fileConfigTest = func(c *config.Config) {
key := Key(c)
addr := BootstrapAddress(c)
addr := BootstrapAddresses(c)
attributes := Attributes(c)
relay := Relay(c)
wKey := Wallet(c)
var expectedAddr network.Address
var expectedAddr network.AddressGroup
err := expectedAddr.FromString("s01.neofs.devenv:8080")
err := expectedAddr.FromIterator(stringAddressGroup([]string{
"s01.neofs.devenv:8080",
"s02.neofs.devenv:8081",
}))
require.NoError(t, err)
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
require.Equal(t, true, addr.Equal(expectedAddr))
require.Equal(t, expectedAddr, addr)
require.Equal(t, true, relay)
require.Len(t, attributes, 2)

View file

@ -11,7 +11,7 @@ NEOFS_NODE_KEY=./wallet.key
NEOFS_NODE_WALLET_PATH=./wallet.json
NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz
NEOFS_NODE_WALLET_PASSWORD=password
NEOFS_NODE_ADDRESS=s01.neofs.devenv:8080
NEOFS_NODE_ADDRESSES=s01.neofs.devenv:8080 s02.neofs.devenv:8081
NEOFS_NODE_ATTRIBUTE_0=Price:11
NEOFS_NODE_ATTRIBUTE_1=UN-LOCODE:RU MSK
NEOFS_NODE_RELAY=true

View file

@ -17,7 +17,10 @@
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
"password": "password"
},
"address": "s01.neofs.devenv:8080",
"addresses": [
"s01.neofs.devenv:8080",
"s02.neofs.devenv:8081"
],
"attribute_0": "Price:11",
"attribute_1": "UN-LOCODE:RU MSK",
"relay": true

View file

@ -15,7 +15,9 @@ node:
path: "./wallet.json"
address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"
password: "password"
address: s01.neofs.devenv:8080
addresses:
- s01.neofs.devenv:8080
- s02.neofs.devenv:8081
attribute_0: "Price:11"
attribute_1: UN-LOCODE:RU MSK
relay: true