frostfs-node/pkg/morph/client/netmap/add_peer.go

44 lines
1,010 B
Go
Raw Normal View History

2020-07-24 13:54:03 +00:00
package netmap
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
2020-07-24 13:54:03 +00:00
)
// AddPeerPrm groups parameters of AddPeer operation.
type AddPeerPrm struct {
nodeInfo *netmap.NodeInfo
client.InvokePrmOptional
2020-07-24 13:54:03 +00:00
}
// SetNodeInfo sets new peer NodeInfo.
func (a *AddPeerPrm) SetNodeInfo(nodeInfo *netmap.NodeInfo) {
a.nodeInfo = nodeInfo
2020-07-24 13:54:03 +00:00
}
// AddPeer registers peer in NeoFS network through
// Netmap contract call.
func (c *Client) AddPeer(p AddPeerPrm) error {
if p.nodeInfo == nil {
return fmt.Errorf("nil node info (%s)", addPeerMethod)
}
rawNodeInfo, err := p.nodeInfo.Marshal()
if err != nil {
return fmt.Errorf("can't marshal node info (%s): %w", addPeerMethod, err)
}
prm := client.InvokePrm{}
prm.SetMethod(addPeerMethod)
prm.SetArgs(rawNodeInfo)
prm.InvokePrmOptional = p.InvokePrmOptional
if err := c.client.Invoke(prm); err != nil {
return fmt.Errorf("could not invoke method (%s): %w", addPeerMethod, err)
}
return nil
2020-07-24 13:54:03 +00:00
}