2021-11-28 12:56:11 +00:00
|
|
|
package morphsubnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-11-28 12:56:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NodeAllowedPrm groups parameters of NodeAllowed method of Subnet contract.
|
|
|
|
type NodeAllowedPrm struct {
|
|
|
|
cliPrm client.TestInvokePrm
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
args [2]any
|
2021-11-28 12:56:11 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetID sets identifier of the subnet of the node in a binary FrostFS API protocol format.
|
2021-11-28 12:56:11 +00:00
|
|
|
func (x *NodeAllowedPrm) SetID(id []byte) {
|
|
|
|
x.args[0] = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNode sets public key of the node that is being checked.
|
|
|
|
func (x *NodeAllowedPrm) SetNode(id []byte) {
|
|
|
|
x.args[1] = id
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// NodeAllowedRes groups the resulting values of NodeAllowed method of Subnet contract.
|
2021-11-28 12:56:11 +00:00
|
|
|
type NodeAllowedRes struct {
|
|
|
|
result bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed returns true iff the node is allowed to enter the subnet.
|
|
|
|
func (x NodeAllowedRes) Allowed() bool {
|
|
|
|
return x.result
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeAllowed checks if the node is included in the subnetwork.
|
|
|
|
func (x *Client) NodeAllowed(prm NodeAllowedPrm) (*NodeAllowedRes, error) {
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.cliPrm.SetMethod(nodeAllowedMethod)
|
2021-11-28 12:56:11 +00:00
|
|
|
prm.cliPrm.SetArgs(prm.args[:]...)
|
|
|
|
|
|
|
|
res, err := x.client.TestInvoke(prm.cliPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not make test invoke: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(res) == 0 {
|
|
|
|
return nil, errEmptyResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := client.BoolFromStackItem(res[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &NodeAllowedRes{
|
|
|
|
result: result,
|
|
|
|
}, nil
|
|
|
|
}
|