forked from TrueCloudLab/frostfs-node
[#15] Use api-go definition of NodeInfo in node
Signed-off-by: Alex Vanin <alexey@nspcc.ru>support/v0.27
parent
f0ee275ce6
commit
ee9551992c
|
@ -25,13 +25,16 @@ func bootstrapNode(c *cfg) {
|
|||
cli, err := netmap.New(staticClient)
|
||||
fatalOnErr(err)
|
||||
|
||||
peerInfo := new(netmap.PeerInfo)
|
||||
peerInfo := new(netmap.NodeInfo)
|
||||
peerInfo.SetAddress(c.cfgNodeInfo.address)
|
||||
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
|
||||
// todo: add attributes as opts
|
||||
|
||||
rawInfo, err := peerInfo.StableMarshal(nil)
|
||||
fatalOnErr(err)
|
||||
|
||||
args := new(netmap.AddPeerArgs)
|
||||
args.SetInfo(*peerInfo)
|
||||
args.SetInfo(rawInfo)
|
||||
err = cli.AddPeer(*args)
|
||||
fatalOnErr(err)
|
||||
}
|
||||
|
|
|
@ -4,80 +4,14 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PeerInfo groups the parameters of
|
||||
// new NeoFS peer.
|
||||
type PeerInfo struct {
|
||||
address []byte // peer network address in a binary format
|
||||
|
||||
key []byte // peer public key
|
||||
|
||||
opts [][]byte // binary peer options
|
||||
}
|
||||
|
||||
// AddPeerArgs groups the arguments
|
||||
// of add peer invocation call.
|
||||
type AddPeerArgs struct {
|
||||
info PeerInfo // peer information
|
||||
}
|
||||
|
||||
const addPeerFixedArgNumber = 2
|
||||
|
||||
// Address returns the peer network address
|
||||
// in a binary format.
|
||||
//
|
||||
// Address format is dictated by application
|
||||
// architecture.
|
||||
func (a PeerInfo) Address() []byte {
|
||||
return a.address
|
||||
}
|
||||
|
||||
// SetAddress sets the peer network address
|
||||
// in a binary format.
|
||||
//
|
||||
// Address format is dictated by application
|
||||
// architecture.
|
||||
func (a *PeerInfo) SetAddress(v []byte) {
|
||||
a.address = v
|
||||
}
|
||||
|
||||
// PublicKey returns the peer public key
|
||||
// in a binary format.
|
||||
//
|
||||
// Key format is dictated by application
|
||||
// architecture.
|
||||
func (a PeerInfo) PublicKey() []byte {
|
||||
return a.key
|
||||
}
|
||||
|
||||
// SetPublicKey sets the peer public key
|
||||
// in a binary format.
|
||||
//
|
||||
// Key format is dictated by application
|
||||
// architecture.
|
||||
func (a *PeerInfo) SetPublicKey(v []byte) {
|
||||
a.key = v
|
||||
}
|
||||
|
||||
// Options returns the peer options
|
||||
// in a binary format.
|
||||
//
|
||||
// Option format is dictated by application
|
||||
// architecture.
|
||||
func (a PeerInfo) Options() [][]byte {
|
||||
return a.opts
|
||||
}
|
||||
|
||||
// SetOptions sets the peer options
|
||||
// in a binary format.
|
||||
//
|
||||
// Option format is dictated by application
|
||||
// architecture.
|
||||
func (a *PeerInfo) SetOptions(v [][]byte) {
|
||||
a.opts = v
|
||||
info []byte
|
||||
}
|
||||
|
||||
// SetInfo sets the peer information.
|
||||
func (a *AddPeerArgs) SetInfo(v PeerInfo) {
|
||||
func (a *AddPeerArgs) SetInfo(v []byte) {
|
||||
a.info = v
|
||||
}
|
||||
|
||||
|
@ -86,19 +20,8 @@ func (a *AddPeerArgs) SetInfo(v PeerInfo) {
|
|||
func (c *Client) AddPeer(args AddPeerArgs) error {
|
||||
info := args.info
|
||||
|
||||
invokeArgs := make([]interface{}, 0, addPeerFixedArgNumber+len(info.opts))
|
||||
|
||||
invokeArgs = append(invokeArgs,
|
||||
info.address,
|
||||
info.key,
|
||||
)
|
||||
|
||||
for i := range info.opts {
|
||||
invokeArgs = append(invokeArgs, info.opts[i])
|
||||
}
|
||||
|
||||
return errors.Wrapf(c.client.Invoke(
|
||||
c.addPeerMethod,
|
||||
invokeArgs...,
|
||||
info,
|
||||
), "could not invoke method (%s)", c.addPeerMethod)
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ package netmap
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
type NodeInfo = netmap.NodeInfo
|
||||
|
||||
// Client is a wrapper over StaticClient
|
||||
// which makes calls with the names and arguments
|
||||
// of the NeoFS Netmap contract.
|
||||
|
|
|
@ -14,20 +14,20 @@ type GetNetMapArgs struct {
|
|||
// GetNetMapValues groups the stack parameters
|
||||
// returned by get network map test invoke.
|
||||
type GetNetMapValues struct {
|
||||
peers []PeerInfo // peer list in a binary format
|
||||
peers [][]byte
|
||||
}
|
||||
|
||||
const nodeInfoFixedPrmNumber = 3
|
||||
const nodeInfoFixedPrmNumber = 1
|
||||
|
||||
// Peers return the list of peers from
|
||||
// network map in a binary format.
|
||||
func (g GetNetMapValues) Peers() []PeerInfo {
|
||||
func (g GetNetMapValues) Peers() [][]byte {
|
||||
return g.peers
|
||||
}
|
||||
|
||||
// NetMap performs the test invoke of get network map
|
||||
// method of NeoFS Netmap contract.
|
||||
func (c *Client) NetMap(args GetNetMapArgs) (*GetNetMapValues, error) {
|
||||
func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) {
|
||||
prms, err := c.client.TestInvoke(
|
||||
c.netMapMethod,
|
||||
)
|
||||
|
@ -43,7 +43,7 @@ func (c *Client) NetMap(args GetNetMapArgs) (*GetNetMapValues, error) {
|
|||
}
|
||||
|
||||
res := &GetNetMapValues{
|
||||
peers: make([]PeerInfo, 0, len(prms)),
|
||||
peers: make([][]byte, 0, len(prms)),
|
||||
}
|
||||
|
||||
for i := range prms {
|
||||
|
@ -52,48 +52,19 @@ func (c *Client) NetMap(args GetNetMapArgs) (*GetNetMapValues, error) {
|
|||
return nil, errors.Wrapf(err, "could not parse stack item (Peer #%d)", i)
|
||||
}
|
||||
|
||||
res.peers = append(res.peers, *peer)
|
||||
res.peers = append(res.peers, peer)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func peerInfoFromStackItem(prm stackitem.Item) (*PeerInfo, error) {
|
||||
func peerInfoFromStackItem(prm stackitem.Item) ([]byte, error) {
|
||||
prms, err := client.ArrayFromStackItem(prm)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not get stack item array (PeerInfo)")
|
||||
} else if ln := len(prms); ln != nodeInfoFixedPrmNumber {
|
||||
return nil, errors.Errorf("unexpected stack item count (PeerInfo): expected %d, has %d", 3, ln)
|
||||
return nil, errors.Errorf("unexpected stack item count (PeerInfo): expected %d, has %d", 1, ln)
|
||||
}
|
||||
|
||||
res := new(PeerInfo)
|
||||
|
||||
// Address
|
||||
res.address, err = client.BytesFromStackItem(prms[0])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get byte array from stack item (Address)")
|
||||
}
|
||||
|
||||
// Public key
|
||||
if res.key, err = client.BytesFromStackItem(prms[1]); err != nil {
|
||||
return nil, errors.Wrap(err, "could not get byte array from stack item (Public key)")
|
||||
}
|
||||
|
||||
// Options
|
||||
if prms, err = client.ArrayFromStackItem(prms[2]); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not get stack item array (Options)")
|
||||
}
|
||||
|
||||
res.opts = make([][]byte, 0, len(prms))
|
||||
|
||||
for i := range prms {
|
||||
opt, err := client.BytesFromStackItem(prms[i])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not get byte array from stack item (Option #%d)", i)
|
||||
}
|
||||
|
||||
res.opts = append(res.opts, opt)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
return client.BytesFromStackItem(prms[0])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue