frostfs-node/pkg/core/client/util.go
Evgenii Stratonikov 2d1232ce6d
All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m25s
Build / Build Components (push) Successful in 1m57s
Pre-commit hooks / Pre-commit (push) Successful in 1m58s
Tests and linters / Run gofumpt (push) Successful in 3m50s
Tests and linters / Staticcheck (push) Successful in 4m21s
Tests and linters / Lint (push) Successful in 4m25s
Tests and linters / gopls check (push) Successful in 4m27s
Tests and linters / Tests (push) Successful in 4m44s
OCI image / Build container images (push) Successful in 5m19s
Tests and linters / Tests with -race (push) Successful in 5m32s
[#1689] network,core/netmap: Replace Iterate*() functions with iterators
Change-Id: I4842a3160d74c56d99ea9465d4be2f0662080605
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2025-04-15 14:47:32 +00:00

69 lines
1.8 KiB
Go

package client
import (
"bytes"
"fmt"
"iter"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
)
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.
//
// Args must not be nil.
func NodeInfoFromRawNetmapElement(dst *NodeInfo, info interface {
PublicKey() []byte
Addresses() iter.Seq[string]
NumberOfAddresses() int
ExternalAddresses() []string
},
) error {
var a network.AddressGroup
err := a.FromIterator(info)
if err != nil {
return fmt.Errorf("parse network address: %w", err)
}
var external network.AddressGroup
ext := info.ExternalAddresses()
if len(ext) > 0 {
_ = external.FromStringSlice(ext)
}
nodeInfoFromKeyAddr(dst, info.PublicKey(), a, external)
return nil
}
// NodeInfoFromNetmapElement fills NodeInfo structure from the interface of the parsed netmap member's descriptor.
//
// Args must not be nil.
func NodeInfoFromNetmapElement(dst *NodeInfo, info interface {
PublicKey() []byte
Addresses() network.AddressGroup
ExternalAddresses() network.AddressGroup
},
) {
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses(), info.ExternalAddresses())
}
// AssertKeyResponseCallback returns client response callback which checks if the response was signed by the expected key.
// Returns ErrWrongPublicKey in case of key mismatch.
func AssertKeyResponseCallback(expectedKey []byte) func(client.ResponseMetaInfo) error {
return func(info client.ResponseMetaInfo) error {
if !bytes.Equal(info.ResponderKey(), expectedKey) {
return ErrWrongPublicKey
}
return nil
}
}