diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 74716fb36..c3d72a38f 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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), ), diff --git a/cmd/neofs-node/config/node/config.go b/cmd/neofs-node/config/node/config.go index 1e1f0bf85..c22fb239a 100644 --- a/cmd/neofs-node/config/node/config.go +++ b/cmd/neofs-node/config/node/config.go @@ -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 diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index d20c1b09f..00b67e424 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -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) diff --git a/config/example/node.env b/config/example/node.env index d979f5c59..42e395c4d 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -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 diff --git a/config/example/node.json b/config/example/node.json index 9b78d9d5a..bd6baceee 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -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 diff --git a/config/example/node.yaml b/config/example/node.yaml index bc79e9735..c7c576f3d 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -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