[#1817] network: Allow to use network addresses from the iterator

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-26 15:34:01 +03:00 committed by fyrchik
parent 76893bdc50
commit 236414df49
21 changed files with 203 additions and 17 deletions

View file

@ -8,9 +8,10 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/client"
)
func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a network.AddressGroup) {
func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a, external network.AddressGroup) {
dst.SetPublicKey(k)
dst.SetAddressGroup(a)
dst.SetExternalAddressGroup(external)
}
// NodeInfoFromRawNetmapElement fills NodeInfo structure from the interface of raw netmap member's descriptor.
@ -20,6 +21,7 @@ func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
PublicKey() []byte
IterateAddresses(func(string) bool)
NumberOfAddresses() int
ExternalAddresses() []string
}) error {
var a network.AddressGroup
@ -28,7 +30,14 @@ func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
return fmt.Errorf("parse network address: %w", err)
}
nodeInfoFromKeyAddr(dst, info.PublicKey(), a)
var external network.AddressGroup
ext := info.ExternalAddresses()
if len(ext) > 0 {
_ = external.FromStringSlice(ext)
}
nodeInfoFromKeyAddr(dst, info.PublicKey(), a, external)
return nil
}
@ -39,8 +48,9 @@ func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
func NodeInfoFromNetmapElement(dst *NodeInfo, info interface {
PublicKey() []byte
Addresses() network.AddressGroup
ExternalAddresses() network.AddressGroup
}) {
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses())
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses(), info.ExternalAddresses())
}
// AssertKeyResponseCallback returns client response callback which checks if the response was signed by the expected key.