forked from TrueCloudLab/frostfs-node
[#645] core/client: Implement helper functions to fill NodeInfo
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4ec7e24b85
commit
3d3d30560a
1 changed files with 42 additions and 0 deletions
42
pkg/core/client/util.go
Normal file
42
pkg/core/client/util.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||
)
|
||||
|
||||
func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a network.AddressGroup) {
|
||||
dst.SetPublicKey(k)
|
||||
dst.SetAddressGroup(a)
|
||||
}
|
||||
|
||||
// NodeInfoFromRawNetmapElement fills NodeInfo structure from the interface of raw netmap member's descriptor.
|
||||
//
|
||||
// Args must not be nil.
|
||||
func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
|
||||
PublicKey() []byte
|
||||
IterateAddresses(func(string) bool)
|
||||
NumberOfAddresses() int
|
||||
}) error {
|
||||
var a network.AddressGroup
|
||||
|
||||
err := a.FromIterator(info)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse network address: %w", err)
|
||||
}
|
||||
|
||||
nodeInfoFromKeyAddr(dst, info.PublicKey(), a)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NodeInfoFromNetmapElement fills NodeInfo structure from the interface of parsed netmap member's descriptor.
|
||||
//
|
||||
// Args must not be nil.
|
||||
func NodeInfoFromNetmapElement(dst *NodeInfo, info interface {
|
||||
PublicKey() []byte
|
||||
Addresses() network.AddressGroup
|
||||
}) {
|
||||
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses())
|
||||
}
|
Loading…
Reference in a new issue