[#607] node/control: Make group address in NodeInfo message

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-22 22:48:33 +03:00 committed by Leonard Lyubich
parent 163c24a2d2
commit 1e52e86bbc
6 changed files with 28 additions and 11 deletions

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
"github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
@ -194,10 +195,10 @@ func prettyPrintNetmap(cmd *cobra.Command, nm *control.Netmap, jsonEncoding bool
cmd.Println("Epoch:", nm.GetEpoch()) cmd.Println("Epoch:", nm.GetEpoch())
for i, node := range nm.GetNodes() { for i, node := range nm.GetNodes() {
cmd.Printf("Node %d: %s %s %s\n", i+1, cmd.Printf("Node %d: %s %s %v\n", i+1,
base58.Encode(node.GetPublicKey()), base58.Encode(node.GetPublicKey()),
node.GetAddress(),
node.GetState(), node.GetState(),
node.GetAddresses(),
) )
for _, attr := range node.GetAttributes() { for _, attr := range node.GetAttributes() {

View file

@ -53,7 +53,12 @@ func nodesFromAPI(apiNodes netmapAPI.Nodes) []*control.NodeInfo {
for _, apiNode := range apiNodes { for _, apiNode := range apiNodes {
node := new(control.NodeInfo) node := new(control.NodeInfo)
node.SetPublicKey(apiNode.PublicKey()) node.SetPublicKey(apiNode.PublicKey())
node.SetAddress(apiNode.Address())
addrs := make([]string, apiNode.NumberOfAddresses())
netmapAPI.IterateAllAddresses(apiNode.NodeInfo, func(s string) {
addrs = append(addrs, s)
})
node.SetAddresses(addrs)
node.SetAttributes(attributesFromAPI(apiNode.Attributes())) node.SetAttributes(attributesFromAPI(apiNode.Attributes()))
node.SetState(stateFromAPI(apiNode.State())) node.SetState(stateFromAPI(apiNode.State()))

View file

@ -125,10 +125,10 @@ func (x *NodeInfo) SetPublicKey(v []byte) {
} }
} }
// SetAddress sets ways to connect to a node. // SetAddresses sets ways to connect to a node.
func (x *NodeInfo) SetAddress(v string) { func (x *NodeInfo) SetAddresses(v []string) {
if x != nil { if x != nil {
x.Address = v x.Addresses = v
} }
} }
@ -184,7 +184,7 @@ func (x *NodeInfo) StableMarshal(buf []byte) ([]byte, error) {
offset += n offset += n
n, err = proto.StringMarshal(nodeAddrFNum, buf[offset:], x.Address) n, err = proto.RepeatedStringMarshal(nodeAddrFNum, buf[offset:], x.Addresses)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -220,7 +220,7 @@ func (x *NodeInfo) StableSize() int {
size := 0 size := 0
size += proto.BytesSize(nodePubKeyFNum, x.PublicKey) size += proto.BytesSize(nodePubKeyFNum, x.PublicKey)
size += proto.StringSize(nodeAddrFNum, x.Address) size += proto.RepeatedStringSize(nodeAddrFNum, x.Addresses)
for i := range x.Attributes { for i := range x.Attributes {
size += proto.NestedStructureSize(nodeAttrsFNum, x.Attributes[i]) size += proto.NestedStructureSize(nodeAttrsFNum, x.Attributes[i])

Binary file not shown.

View file

@ -31,7 +31,7 @@ message NodeInfo {
bytes public_key = 1 [json_name = "publicKey"]; bytes public_key = 1 [json_name = "publicKey"];
// Ways to connect to a node. // Ways to connect to a node.
string address = 2 [json_name = "address"]; repeated string addresses = 2 [json_name = "addresses"];
// Administrator-defined Attributes of the NeoFS Storage Node. // Administrator-defined Attributes of the NeoFS Storage Node.
// //

View file

@ -24,7 +24,7 @@ func generateNetmap() *control.Netmap {
for i := 0; i < nodeCount; i++ { for i := 0; i < nodeCount; i++ {
n := new(control.NodeInfo) n := new(control.NodeInfo)
n.SetPublicKey(testData(33)) n.SetPublicKey(testData(33))
n.SetAddress(testString()) n.SetAddresses([]string{testString(), testString()})
n.SetState(control.NetmapStatus_ONLINE) n.SetState(control.NetmapStatus_ONLINE)
const attrCount = 2 const attrCount = 2
@ -81,11 +81,22 @@ func equalNetmaps(nm1, nm2 *control.Netmap) bool {
func equalNodeInfos(n1, n2 *control.NodeInfo) bool { func equalNodeInfos(n1, n2 *control.NodeInfo) bool {
if !bytes.Equal(n1.GetPublicKey(), n2.GetPublicKey()) || if !bytes.Equal(n1.GetPublicKey(), n2.GetPublicKey()) ||
n1.GetAddress() != n2.GetAddress() ||
n1.GetState() != n2.GetState() { n1.GetState() != n2.GetState() {
return false return false
} }
na1, na2 := n1.GetAddresses(), n2.GetAddresses()
if len(na1) != len(na2) {
return false
}
for i := range na1 {
if na1[i] != na2[i] {
return false
}
}
a1, a2 := n1.GetAttributes(), n2.GetAttributes() a1, a2 := n1.GetAttributes(), n2.GetAttributes()
if len(a1) != len(a2) { if len(a1) != len(a2) {