[#1609] config: Allow to prioritize N3 endpoints

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-18 16:41:35 +03:00 committed by fyrchik
parent aed83d1660
commit 7410827db8
15 changed files with 123 additions and 85 deletions

View file

@ -2,9 +2,11 @@ package morphconfig
import (
"fmt"
"strconv"
"time"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
const (
@ -28,13 +30,27 @@ const (
// from "morph" section.
//
// Throws panic if list is empty.
func RPCEndpoint(c *config.Config) []string {
v := config.StringSliceSafe(c.Sub(subsection), "rpc_endpoint")
if len(v) == 0 {
panic(fmt.Errorf("no morph chain RPC endpoints, see `morph.rpc_endpoint` section"))
func RPCEndpoint(c *config.Config) []client.Endpoint {
var es []client.Endpoint
sub := c.Sub(subsection).Sub("rpc_endpoint")
for i := 0; ; i++ {
s := sub.Sub(strconv.FormatInt(int64(i), 10))
addr := config.StringSafe(s, "address")
if addr == "" {
break
}
es = append(es, client.Endpoint{
Address: addr,
Priority: int(config.IntSafe(s, "priority")),
})
}
return v
if len(es) == 0 {
panic(fmt.Errorf("no morph chain RPC endpoints, see `morph.rpc_endpoint` section"))
}
return es
}
// DialTimeout returns the value of "dial_timeout" config parameter

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
morphconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/morph"
configtest "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/test"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/stretchr/testify/require"
)
@ -22,9 +23,9 @@ func TestMorphSection(t *testing.T) {
const path = "../../../../config/example/node"
var (
rpcs = []string{
"wss://rpc1.morph.fs.neo.org:40341/ws",
"wss://rpc2.morph.fs.neo.org:40341/ws",
rpcs = []client.Endpoint{
{"wss://rpc1.morph.fs.neo.org:40341/ws", 2},
{"wss://rpc2.morph.fs.neo.org:40341/ws", 1},
}
)