forked from TrueCloudLab/frostfs-node
[#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:
parent
8060735732
commit
163c24a2d2
6 changed files with 42 additions and 27 deletions
|
@ -215,7 +215,7 @@ func initCfg(path string) *cfg {
|
||||||
log, err := logger.NewLogger(logPrm)
|
log, err := logger.NewLogger(logPrm)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
netAddr := nodeconfig.BootstrapAddress(appCfg)
|
netAddr := nodeconfig.BootstrapAddresses(appCfg)
|
||||||
|
|
||||||
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
|
||||||
|
@ -259,7 +259,7 @@ func initCfg(path string) *cfg {
|
||||||
maxChunkSize: maxChunkSize,
|
maxChunkSize: maxChunkSize,
|
||||||
maxAddrAmount: maxAddrAmount,
|
maxAddrAmount: maxAddrAmount,
|
||||||
},
|
},
|
||||||
localAddr: network.GroupFromAddress(netAddr),
|
localAddr: netAddr,
|
||||||
respSvc: response.NewService(
|
respSvc: response.NewService(
|
||||||
response.WithNetworkState(state),
|
response.WithNetworkState(state),
|
||||||
),
|
),
|
||||||
|
|
|
@ -18,10 +18,7 @@ const (
|
||||||
attributePrefix = "attribute"
|
attributePrefix = "attribute"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
|
||||||
errKeyNotSet = errors.New("empty/not set key address, see `node.key` section")
|
|
||||||
errAddressNotSet = errors.New("empty/not set bootstrap address, see `node.address` section")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Key returns value of "key" config parameter
|
// Key returns value of "key" config parameter
|
||||||
// from "node" section.
|
// from "node" section.
|
||||||
|
@ -63,19 +60,30 @@ func Wallet(c *config.Config) *keys.PrivateKey {
|
||||||
return acc.PrivateKey()
|
return acc.PrivateKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
// BootstrapAddress returns value of "address" config parameter
|
type stringAddressGroup []string
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
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
|
return addr
|
||||||
|
|
|
@ -22,11 +22,10 @@ func TestNodeSection(t *testing.T) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
require.PanicsWithError(
|
require.Panics(
|
||||||
t,
|
t,
|
||||||
errAddressNotSet.Error(),
|
|
||||||
func() {
|
func() {
|
||||||
BootstrapAddress(empty)
|
BootstrapAddresses(empty)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,18 +40,21 @@ func TestNodeSection(t *testing.T) {
|
||||||
|
|
||||||
var fileConfigTest = func(c *config.Config) {
|
var fileConfigTest = func(c *config.Config) {
|
||||||
key := Key(c)
|
key := Key(c)
|
||||||
addr := BootstrapAddress(c)
|
addr := BootstrapAddresses(c)
|
||||||
attributes := Attributes(c)
|
attributes := Attributes(c)
|
||||||
relay := Relay(c)
|
relay := Relay(c)
|
||||||
wKey := Wallet(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.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
|
require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address())
|
||||||
require.Equal(t, true, addr.Equal(expectedAddr))
|
require.Equal(t, expectedAddr, addr)
|
||||||
require.Equal(t, true, relay)
|
require.Equal(t, true, relay)
|
||||||
|
|
||||||
require.Len(t, attributes, 2)
|
require.Len(t, attributes, 2)
|
||||||
|
|
|
@ -11,7 +11,7 @@ NEOFS_NODE_KEY=./wallet.key
|
||||||
NEOFS_NODE_WALLET_PATH=./wallet.json
|
NEOFS_NODE_WALLET_PATH=./wallet.json
|
||||||
NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz
|
NEOFS_NODE_WALLET_ADDRESS=NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz
|
||||||
NEOFS_NODE_WALLET_PASSWORD=password
|
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_0=Price:11
|
||||||
NEOFS_NODE_ATTRIBUTE_1=UN-LOCODE:RU MSK
|
NEOFS_NODE_ATTRIBUTE_1=UN-LOCODE:RU MSK
|
||||||
NEOFS_NODE_RELAY=true
|
NEOFS_NODE_RELAY=true
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
|
"address": "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz",
|
||||||
"password": "password"
|
"password": "password"
|
||||||
},
|
},
|
||||||
"address": "s01.neofs.devenv:8080",
|
"addresses": [
|
||||||
|
"s01.neofs.devenv:8080",
|
||||||
|
"s02.neofs.devenv:8081"
|
||||||
|
],
|
||||||
"attribute_0": "Price:11",
|
"attribute_0": "Price:11",
|
||||||
"attribute_1": "UN-LOCODE:RU MSK",
|
"attribute_1": "UN-LOCODE:RU MSK",
|
||||||
"relay": true
|
"relay": true
|
||||||
|
|
|
@ -15,7 +15,9 @@ node:
|
||||||
path: "./wallet.json"
|
path: "./wallet.json"
|
||||||
address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"
|
address: "NcpJzXcSDrh5CCizf4K9Ro6w4t59J5LKzz"
|
||||||
password: "password"
|
password: "password"
|
||||||
address: s01.neofs.devenv:8080
|
addresses:
|
||||||
|
- s01.neofs.devenv:8080
|
||||||
|
- s02.neofs.devenv:8081
|
||||||
attribute_0: "Price:11"
|
attribute_0: "Price:11"
|
||||||
attribute_1: UN-LOCODE:RU MSK
|
attribute_1: UN-LOCODE:RU MSK
|
||||||
relay: true
|
relay: true
|
||||||
|
|
Loading…
Reference in a new issue