Skip to content

Commit

Permalink
[#607] node/control: Make group address in NodeInfo message
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Jun 28, 2021
1 parent 163c24a commit 1e52e86
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 48 deletions.
5 changes: 3 additions & 2 deletions cmd/neofs-cli/modules/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
"fmt"

"github.com/mr-tron/base58"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
Expand Down Expand Up @@ -194,10 +195,10 @@ func prettyPrintNetmap(cmd *cobra.Command, nm *control.Netmap, jsonEncoding bool
cmd.Println("Epoch:", nm.GetEpoch())

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()),
node.GetAddress(),
node.GetState(),
node.GetAddresses(),
)

for _, attr := range node.GetAttributes() {
Expand Down
7 changes: 6 additions & 1 deletion pkg/services/control/server/netmap_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func nodesFromAPI(apiNodes netmapAPI.Nodes) []*control.NodeInfo {
for _, apiNode := range apiNodes {
node := new(control.NodeInfo)
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.SetState(stateFromAPI(apiNode.State()))

Expand Down
10 changes: 5 additions & 5 deletions pkg/services/control/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func (x *NodeInfo) SetPublicKey(v []byte) {
}
}

// SetAddress sets ways to connect to a node.
func (x *NodeInfo) SetAddress(v string) {
// SetAddresses sets ways to connect to a node.
func (x *NodeInfo) SetAddresses(v []string) {
if x != nil {
x.Address = v
x.Addresses = v
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func (x *NodeInfo) StableMarshal(buf []byte) ([]byte, error) {

offset += n

n, err = proto.StringMarshal(nodeAddrFNum, buf[offset:], x.Address)
n, err = proto.RepeatedStringMarshal(nodeAddrFNum, buf[offset:], x.Addresses)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func (x *NodeInfo) StableSize() int {
size := 0

size += proto.BytesSize(nodePubKeyFNum, x.PublicKey)
size += proto.StringSize(nodeAddrFNum, x.Address)
size += proto.RepeatedStringSize(nodeAddrFNum, x.Addresses)

for i := range x.Attributes {
size += proto.NestedStructureSize(nodeAttrsFNum, x.Attributes[i])
Expand Down
74 changes: 37 additions & 37 deletions pkg/services/control/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/services/control/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ message NodeInfo {
bytes public_key = 1 [json_name = "publicKey"];

// 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.
//
Expand Down
15 changes: 13 additions & 2 deletions pkg/services/control/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func generateNetmap() *control.Netmap {
for i := 0; i < nodeCount; i++ {
n := new(control.NodeInfo)
n.SetPublicKey(testData(33))
n.SetAddress(testString())
n.SetAddresses([]string{testString(), testString()})
n.SetState(control.NetmapStatus_ONLINE)

const attrCount = 2
Expand Down Expand Up @@ -81,11 +81,22 @@ func equalNetmaps(nm1, nm2 *control.Netmap) bool {

func equalNodeInfos(n1, n2 *control.NodeInfo) bool {
if !bytes.Equal(n1.GetPublicKey(), n2.GetPublicKey()) ||
n1.GetAddress() != n2.GetAddress() ||
n1.GetState() != n2.GetState() {
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()

if len(a1) != len(a2) {
Expand Down

0 comments on commit 1e52e86

Please sign in to comment.