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
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-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 {
|
2022-06-08 23:18:26 +00:00
|
|
|
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.
|
2022-06-08 23:18:26 +00:00
|
|
|
func (a *AddPeerPrm) SetNodeInfo(nodeInfo netmap.NodeInfo) {
|
2022-01-31 11:58:55 +00:00
|
|
|
a.nodeInfo = nodeInfo
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// AddPeer registers peer in FrostFS network through
|
2022-01-31 11:58:55 +00:00
|
|
|
// Netmap contract call.
|
|
|
|
func (c *Client) AddPeer(p AddPeerPrm) error {
|
2022-05-13 18:35:37 +00:00
|
|
|
var method = addPeerMethod
|
|
|
|
|
|
|
|
if c.client.WithNotary() && c.client.IsAlpha() {
|
|
|
|
// In notary environments Alphabet must calls AddPeerIR method instead of AddPeer.
|
|
|
|
// It differs from AddPeer only by name, so we can do this in the same form.
|
2022-12-23 17:35:35 +00:00
|
|
|
// See https://github.com/nspcc-dev/frostfs-contract/issues/154.
|
2022-05-13 18:35:37 +00:00
|
|
|
method += "IR"
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:58:55 +00:00
|
|
|
prm := client.InvokePrm{}
|
2022-05-13 18:35:37 +00:00
|
|
|
prm.SetMethod(method)
|
2022-06-08 23:18:26 +00:00
|
|
|
prm.SetArgs(p.nodeInfo.Marshal())
|
2022-01-31 11:58:55 +00:00
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
if err := c.client.Invoke(prm); err != nil {
|
2022-05-13 18:35:37 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", method, err)
|
2021-05-18 08:12:51 +00:00
|
|
|
}
|
|
|
|
return nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
2023-05-03 13:19:46 +00:00
|
|
|
|
|
|
|
// ForceRemovePeer marks the given peer as offline via a notary control transaction.
|
|
|
|
func (c *Client) ForceRemovePeer(nodeInfo netmap.NodeInfo) error {
|
|
|
|
if !c.client.WithNotary() {
|
|
|
|
return fmt.Errorf("peer can be forcefully removed only in notary environment")
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := UpdatePeerPrm{}
|
|
|
|
prm.SetKey(nodeInfo.PublicKey())
|
|
|
|
prm.SetControlTX(true)
|
|
|
|
|
|
|
|
if err := c.UpdatePeerState(prm); err != nil {
|
|
|
|
return fmt.Errorf("updating peer state: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|