2020-07-24 13:54:03 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2022-01-31 11:58:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
// AddPeerPrm groups parameters of AddPeer operation.
|
|
|
|
type AddPeerPrm struct {
|
|
|
|
nodeInfo *netmap.NodeInfo
|
2021-11-10 10:44:19 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +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
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +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)
|
|
|
|
}
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
rawNodeInfo, err := p.nodeInfo.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't marshal node info (%s): %w", addPeerMethod, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := client.InvokePrm{}
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(addPeerMethod)
|
2022-01-31 11:58:55 +00:00
|
|
|
prm.SetArgs(rawNodeInfo)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
if err := c.client.Invoke(prm); err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", addPeerMethod, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|