2021-09-28 05:06:54 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2021-09-28 06:02:02 +00:00
|
|
|
"bytes"
|
2021-09-28 05:06:54 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2021-09-28 05:06:54 +00:00
|
|
|
)
|
|
|
|
|
2022-09-26 12:34:01 +00:00
|
|
|
func nodeInfoFromKeyAddr(dst *NodeInfo, k []byte, a, external network.AddressGroup) {
|
2021-09-28 05:06:54 +00:00
|
|
|
dst.SetPublicKey(k)
|
|
|
|
dst.SetAddressGroup(a)
|
2022-09-26 12:34:01 +00:00
|
|
|
dst.SetExternalAddressGroup(external)
|
2021-09-28 05:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2022-09-26 12:34:01 +00:00
|
|
|
ExternalAddresses() []string
|
2023-10-31 11:56:55 +00:00
|
|
|
},
|
|
|
|
) error {
|
2021-09-28 05:06:54 +00:00
|
|
|
var a network.AddressGroup
|
|
|
|
|
|
|
|
err := a.FromIterator(info)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("parse network address: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-09-26 12:34:01 +00:00
|
|
|
var external network.AddressGroup
|
|
|
|
|
|
|
|
ext := info.ExternalAddresses()
|
|
|
|
if len(ext) > 0 {
|
|
|
|
_ = external.FromStringSlice(ext)
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeInfoFromKeyAddr(dst, info.PublicKey(), a, external)
|
2021-09-28 05:06:54 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// NodeInfoFromNetmapElement fills NodeInfo structure from the interface of the parsed netmap member's descriptor.
|
2021-09-28 05:06:54 +00:00
|
|
|
//
|
|
|
|
// Args must not be nil.
|
|
|
|
func NodeInfoFromNetmapElement(dst *NodeInfo, info interface {
|
|
|
|
PublicKey() []byte
|
|
|
|
Addresses() network.AddressGroup
|
2022-09-26 12:34:01 +00:00
|
|
|
ExternalAddresses() network.AddressGroup
|
2023-10-31 11:56:55 +00:00
|
|
|
},
|
|
|
|
) {
|
2022-09-26 12:34:01 +00:00
|
|
|
nodeInfoFromKeyAddr(dst, info.PublicKey(), info.Addresses(), info.ExternalAddresses())
|
2021-09-28 05:06:54 +00:00
|
|
|
}
|
2021-09-28 06:02:02 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// AssertKeyResponseCallback returns client response callback which checks if the response was signed by the expected key.
|
2021-09-28 06:02:02 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|