From 119031c8c758a7bd4dbfd23baf52c7f8e21c938e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 23 Jun 2021 12:50:40 +0300 Subject: [PATCH] [#607] network: Make `AddressGroup.WriteToNodeInfo` method a function Method implementation doesn't use any private logic. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/netmap.go | 3 ++- pkg/network/group.go | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 6d6106cbb..c5d3504ad 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" + "github.com/nspcc-dev/neofs-node/pkg/network" netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc" "github.com/nspcc-dev/neofs-node/pkg/services/control" netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap" @@ -77,7 +78,7 @@ func (c *cfg) addressNum() int { } func initNetmapService(c *cfg) { - c.localAddr.WriteToNodeInfo(&c.cfgNodeInfo.localInfo) + network.WriteToNodeInfo(c.localAddr, &c.cfgNodeInfo.localInfo) c.cfgNodeInfo.localInfo.SetPublicKey(c.key.PublicKey().Bytes()) c.cfgNodeInfo.localInfo.SetAttributes(parseAttributes(c.appCfg)...) c.cfgNodeInfo.localInfo.SetState(netmapSDK.NodeStateOffline) diff --git a/pkg/network/group.go b/pkg/network/group.go index 0feb3a0b1..43c5c6641 100644 --- a/pkg/network/group.go +++ b/pkg/network/group.go @@ -107,12 +107,14 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) { } // WriteToNodeInfo writes AddressGroup to netmap.NodeInfo structure. -func (x AddressGroup) WriteToNodeInfo(ni *netmap.NodeInfo) { - addrs := make([]string, len(x)) +func WriteToNodeInfo(g AddressGroup, ni *netmap.NodeInfo) { + num := g.Len() + addrs := make([]string, 0, num) - for i := range x { - addrs[i] = x[i].String() - } + g.IterateAddresses(func(addr Address) bool { + addrs = append(addrs, addr.String()) + return false + }) ni.SetAddresses(addrs...) }