From 1e52e86bbc5a179bd8a77c4011885aa2611516cb Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Jun 2021 22:48:33 +0300 Subject: [PATCH] [#607] node/control: Make group address in NodeInfo message Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/netmap.go | 5 +++-- .../control/server/netmap_snapshot.go | 7 ++++++- pkg/services/control/types.go | 10 +++++----- pkg/services/control/types.pb.go | Bin 20076 -> 20115 bytes pkg/services/control/types.proto | 2 +- pkg/services/control/types_test.go | 15 +++++++++++++-- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cmd/neofs-cli/modules/netmap.go b/cmd/neofs-cli/modules/netmap.go index 7e095c09..4cb7a3ac 100644 --- a/cmd/neofs-cli/modules/netmap.go +++ b/cmd/neofs-cli/modules/netmap.go @@ -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" @@ -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() { diff --git a/pkg/services/control/server/netmap_snapshot.go b/pkg/services/control/server/netmap_snapshot.go index d7252b33..4c55cf1e 100644 --- a/pkg/services/control/server/netmap_snapshot.go +++ b/pkg/services/control/server/netmap_snapshot.go @@ -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())) diff --git a/pkg/services/control/types.go b/pkg/services/control/types.go index d19275fe..ed563337 100644 --- a/pkg/services/control/types.go +++ b/pkg/services/control/types.go @@ -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 } } @@ -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 } @@ -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]) diff --git a/pkg/services/control/types.pb.go b/pkg/services/control/types.pb.go index 528de009a7aa39ef0f954b66d4c8ba52d0844625..17c2f0806ad124412e5d0d92e4636d63807c4829 100644 GIT binary patch delta 754 zcmYjO&ubGw7-dUq(qdCnn@((!nynFISncj)XZA;a5iR5(h|r@1iOni1CLvoS9>t>w zg?I5_{sAwI$Ba=?`^1QaZr$9%Y9-iBmG0#pT>nGAni{^;B z5g|`Tk3@5v;kA8cZfOzUSPl=IO~hCMrk~VqM>RTzF#cdf z84J9GqC;X)D;rHp@RS>}_Jk8q?*e{uUBaY8aGkHC;ZO;G*&9gEOL*g?am`JlOE;mp ziki?2Zn!&2<>oMTuWZOT+>#SHDhOxt&c%#a@mh+u6k*vaXS5O_!oX|ArQ3{vj?bQZ zLOoEV**P?QS2o%%Z{wA3u1codJyv56mRA%R3MtV*vd24ECjL~f;-GR;))-d^+O<=7 zUr{ChRfv`cskS6{t17`L0&f-g6al?PM1g{E7O-1MY80h<7KgR6N@c4&%##yYv%eRq z{??+;n7 z1P8@$a8Zj>Rw1(v-2{IYCqdA`K@hB)UBr9Os~B7^=kNQ@Ip4W>n)?1E^sIE3|bi!u4z252ft844Mjh;PcTn!1xGlh57k&Iu}C)g&p{-qX8a_rU!hLEnQ zBA&DV>JvE3V_XWdI+a=-Nrjt14L@8Rv0cG?ey$`D|KSverAjCH0xr4+E_iuOsK5g^ zMquXgEJ$O|jmBgpx6pDc=z11*dGUZODqA&t@ruy=tZu7O+?K*li5Rb}BKEvVIN}5b zVp^*CQWO-1`P29&Z0rc4aQzs^67#V%ANmyiCCx48D1M7^g}EHW`-@~SV~6&>;?F|VEBL&urAZ-1nwbpG!y@k21+ItG=2JaZJdDIlq-KAmmTjZuB%RzU zX+YO=xmt63G;Mln7KhS~N(|nm{*aF)$Z2SAHk#HVU|BW{3GRw=;hL DJdn;J diff --git a/pkg/services/control/types.proto b/pkg/services/control/types.proto index d9cc9d77..4a53824f 100644 --- a/pkg/services/control/types.proto +++ b/pkg/services/control/types.proto @@ -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. // diff --git a/pkg/services/control/types_test.go b/pkg/services/control/types_test.go index faed9ba7..64143975 100644 --- a/pkg/services/control/types_test.go +++ b/pkg/services/control/types_test.go @@ -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 @@ -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) {