-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control: add network management via ir control
New `neofs-cli control notary` with `list`, `request` and `sign` commands. - `list` - get list of all notary requests from notary pool. - `request` - send a notary request with one of the following methods: `newEpoch`, `setConfig` and `removeNode`. - `sign` - sign the notary request using a hash. Closes #2088, #1866. Signed-off-by: Andrey Butusov <[email protected]>
- Loading branch information
Showing
23 changed files
with
2,595 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package control | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var notaryCmd = &cobra.Command{ | ||
Use: "notary", | ||
Short: "Commands with notary request with alphabet key of inner ring node", | ||
} | ||
|
||
func initControlNotaryCmd() { | ||
notaryCmd.AddCommand(listNotaryCmd) | ||
notaryCmd.AddCommand(notaryRequestCmd) | ||
notaryCmd.AddCommand(notarySignCmd) | ||
|
||
initControlNotaryListCmd() | ||
initControlNotaryRequestCmd() | ||
initControlNotarySignCmd() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package control | ||
|
||
import ( | ||
"fmt" | ||
|
||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" | ||
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" | ||
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listNotaryCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "Get list of all notary requests in network", | ||
Long: "Get list of all notary requests in network", | ||
Args: cobra.NoArgs, | ||
RunE: listNotary, | ||
} | ||
|
||
func initControlNotaryListCmd() { | ||
initControlFlags(listNotaryCmd) | ||
} | ||
|
||
func listNotary(cmd *cobra.Command, _ []string) error { | ||
ctx, cancel := commonflags.GetCommandContext(cmd) | ||
defer cancel() | ||
|
||
pk, err := key.Get(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli, err := getClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := new(ircontrol.NotaryListRequest) | ||
|
||
req.SetBody(new(ircontrol.NotaryListRequest_Body)) | ||
|
||
err = ircontrolsrv.SignMessage(pk, req) | ||
if err != nil { | ||
return fmt.Errorf("could not sign request: %w", err) | ||
} | ||
|
||
var resp *ircontrol.NotaryListResponse | ||
err = cli.ExecRaw(func(client *rawclient.Client) error { | ||
resp, err = ircontrol.NotaryList(client, req) | ||
return err | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("rpc error: %w", err) | ||
} | ||
|
||
err = verifyResponse(resp.GetSignature(), resp.GetBody()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
hashes := resp.GetBody().GetTransactions() | ||
|
||
cmd.Printf("Hashes: %s\n", hashes) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package control | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" | ||
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" | ||
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
netmapEpochKey = "EpochDuration" | ||
netmapMaxObjectSizeKey = "MaxObjectSize" | ||
netmapAuditFeeKey = "AuditFee" | ||
netmapContainerFeeKey = "ContainerFee" | ||
netmapContainerAliasFeeKey = "ContainerAliasFee" | ||
netmapEigenTrustIterationsKey = "EigenTrustIterations" | ||
netmapEigenTrustAlphaKey = "EigenTrustAlpha" | ||
netmapBasicIncomeRateKey = "BasicIncomeRate" | ||
netmapInnerRingCandidateFeeKey = "InnerRingCandidateFee" | ||
netmapWithdrawFeeKey = "WithdrawFee" | ||
netmapHomomorphicHashDisabledKey = "HomomorphicHashingDisabled" | ||
netmapMaintenanceAllowedKey = "MaintenanceModeAllowed" | ||
|
||
notaryMethodFlag = "method" | ||
notaryForceConfigSetFlag = "force" | ||
) | ||
|
||
var notaryRequestCmd = &cobra.Command{ | ||
Use: "request", | ||
Short: "Create and send a notary request", | ||
Long: "Create and send a notary request with one of the following methods:\n" + | ||
"- newEpoch, transaction for creating of new NeoFS epoch event in FS chain, no args\n" + | ||
"- setConfig, transaction to add/update global config value in the NeoFS network, args in the form key1=val1\n" + | ||
"- removeNode, transaction to move nodes to the Offline state in the candidates list, args are the public keys of the nodes", | ||
RunE: notaryRequest, | ||
} | ||
|
||
func initControlNotaryRequestCmd() { | ||
initControlFlags(notaryRequestCmd) | ||
|
||
flags := notaryRequestCmd.Flags() | ||
flags.String(notaryMethodFlag, "", "Requested method") | ||
flags.Bool(notaryForceConfigSetFlag, false, "Only for 'setConfig' method. Force setting not well-known configuration key.") | ||
} | ||
|
||
func notaryRequest(cmd *cobra.Command, args []string) error { | ||
ctx, cancel := commonflags.GetCommandContext(cmd) | ||
defer cancel() | ||
|
||
pk, err := key.Get(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli, err := getClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := new(ircontrol.NotaryRequestRequest) | ||
body := new(ircontrol.NotaryRequestRequest_Body) | ||
req.SetBody(body) | ||
|
||
method, _ := cmd.Flags().GetString(notaryMethodFlag) | ||
body.SetMethod(method) | ||
|
||
switch method { | ||
case "newEpoch": | ||
if len(args) > 0 { | ||
cmd.Println("method 'newEpoch', but the args provided, they will be ignored") | ||
} | ||
case "setConfig": | ||
forceFlag, _ := cmd.Flags().GetBool(notaryForceConfigSetFlag) | ||
|
||
if len(args) == 0 { | ||
return fmt.Errorf("no arguments provided for 'setConfig'") | ||
} | ||
|
||
bodyArgs := make([]string, 0, len(args)*2) | ||
for _, arg := range args { | ||
k, v, err := parseConfigPair(arg, forceFlag) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bodyArgs = append(bodyArgs, k, fmt.Sprint(v)) | ||
} | ||
body.SetArgs(bodyArgs) | ||
case "removeNode": | ||
if len(args) == 0 { | ||
return errors.New("method 'removeNode', at least 1 argument must be provided - the public key of the node") | ||
} | ||
body.SetArgs(args) | ||
} | ||
|
||
err = ircontrolsrv.SignMessage(pk, req) | ||
if err != nil { | ||
return fmt.Errorf("could not sign request: %w", err) | ||
} | ||
|
||
var resp *ircontrol.NotaryRequestResponse | ||
err = cli.ExecRaw(func(client *rawclient.Client) error { | ||
resp, err = ircontrol.NotaryRequest(client, req) | ||
return err | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("rpc error: %w", err) | ||
} | ||
|
||
err = verifyResponse(resp.GetSignature(), resp.GetBody()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
hashes := resp.GetBody().GetHash() | ||
|
||
cmd.Printf("Tx Hash: %s\n", hashes) | ||
return nil | ||
} | ||
|
||
func parseConfigPair(kvStr string, force bool) (key string, val any, err error) { | ||
kv := strings.SplitN(kvStr, "=", 2) | ||
if len(kv) != 2 { | ||
return "", nil, fmt.Errorf("invalid parameter format: must be 'key=val', got: %s", kvStr) | ||
} | ||
|
||
key = kv[0] | ||
valRaw := kv[1] | ||
|
||
switch key { | ||
case netmapAuditFeeKey, netmapBasicIncomeRateKey, | ||
netmapContainerFeeKey, netmapContainerAliasFeeKey, | ||
netmapEigenTrustIterationsKey, | ||
netmapEpochKey, netmapInnerRingCandidateFeeKey, | ||
netmapMaxObjectSizeKey, netmapWithdrawFeeKey: | ||
val, err = strconv.ParseInt(valRaw, 10, 64) | ||
if err != nil { | ||
err = fmt.Errorf("invalid value for %s key, expected int, got '%s'", key, valRaw) | ||
} | ||
case netmapEigenTrustAlphaKey: | ||
// just check that it could | ||
// be parsed correctly | ||
_, err = strconv.ParseFloat(kv[1], 64) | ||
if err != nil { | ||
err = fmt.Errorf("invalid value for %s key, expected float, got '%s'", key, valRaw) | ||
} | ||
|
||
val = valRaw | ||
case netmapHomomorphicHashDisabledKey, netmapMaintenanceAllowedKey: | ||
val, err = strconv.ParseBool(valRaw) | ||
if err != nil { | ||
err = fmt.Errorf("invalid value for %s key, expected bool, got '%s'", key, valRaw) | ||
} | ||
|
||
default: | ||
if !force { | ||
return "", nil, fmt.Errorf( | ||
"'%s' key is not well-known, use '--%s' flag if want to set it anyway", | ||
key, notaryForceConfigSetFlag) | ||
} | ||
|
||
val = valRaw | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package control | ||
|
||
import ( | ||
"fmt" | ||
|
||
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" | ||
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" | ||
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" | ||
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var notarySignHashFlag string | ||
|
||
var notarySignCmd = &cobra.Command{ | ||
Use: "sign", | ||
Short: "Sign notary request with it hash", | ||
Long: "Sign notary request with it hash", | ||
Args: cobra.NoArgs, | ||
RunE: notarySign, | ||
} | ||
|
||
func initControlNotarySignCmd() { | ||
initControlFlags(notarySignCmd) | ||
|
||
flags := notarySignCmd.Flags() | ||
flags.StringVar(¬arySignHashFlag, "hash", "", "hash of the notary request") | ||
} | ||
|
||
func notarySign(cmd *cobra.Command, _ []string) error { | ||
ctx, cancel := commonflags.GetCommandContext(cmd) | ||
defer cancel() | ||
|
||
pk, err := key.Get(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli, err := getClient(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req := new(ircontrol.NotarySignRequest) | ||
body := new(ircontrol.NotarySignRequest_Body) | ||
req.SetBody(body) | ||
body.SetHash(notarySignHashFlag) | ||
|
||
err = ircontrolsrv.SignMessage(pk, req) | ||
if err != nil { | ||
return fmt.Errorf("could not sign request: %w", err) | ||
} | ||
|
||
var resp *ircontrol.NotarySignResponse | ||
err = cli.ExecRaw(func(client *rawclient.Client) error { | ||
resp, err = ircontrol.NotarySign(client, req) | ||
return err | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("rpc error: %w", err) | ||
} | ||
|
||
err = verifyResponse(resp.GetSignature(), resp.GetBody()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd.Printf("Hashes: %s\n", notarySignHashFlag) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.