[#607] network: Make AddressGroup.WriteToNodeInfo method a function

Method implementation doesn't use any private logic.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-23 12:50:40 +03:00 committed by Leonard Lyubich
parent 359bbe319a
commit 119031c8c7
2 changed files with 9 additions and 6 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" 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" netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
"github.com/nspcc-dev/neofs-node/pkg/services/control" "github.com/nspcc-dev/neofs-node/pkg/services/control"
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap" netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
@ -77,7 +78,7 @@ func (c *cfg) addressNum() int {
} }
func initNetmapService(c *cfg) { 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.SetPublicKey(c.key.PublicKey().Bytes())
c.cfgNodeInfo.localInfo.SetAttributes(parseAttributes(c.appCfg)...) c.cfgNodeInfo.localInfo.SetAttributes(parseAttributes(c.appCfg)...)
c.cfgNodeInfo.localInfo.SetState(netmapSDK.NodeStateOffline) c.cfgNodeInfo.localInfo.SetState(netmapSDK.NodeStateOffline)

View file

@ -107,12 +107,14 @@ func (x *AddressGroup) FromIterator(iter MultiAddressIterator) (err error) {
} }
// WriteToNodeInfo writes AddressGroup to netmap.NodeInfo structure. // WriteToNodeInfo writes AddressGroup to netmap.NodeInfo structure.
func (x AddressGroup) WriteToNodeInfo(ni *netmap.NodeInfo) { func WriteToNodeInfo(g AddressGroup, ni *netmap.NodeInfo) {
addrs := make([]string, len(x)) num := g.Len()
addrs := make([]string, 0, num)
for i := range x { g.IterateAddresses(func(addr Address) bool {
addrs[i] = x[i].String() addrs = append(addrs, addr.String())
} return false
})
ni.SetAddresses(addrs...) ni.SetAddresses(addrs...)
} }