cmd/uplink: experimental environment variable to change piece hash algorithm
Change-Id: I7420919146c64d29ff1023f7498867d3d30892d0
This commit is contained in:
parent
98fb4c4f32
commit
1646a0ac9e
@ -8,12 +8,15 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/spacemonkeygo/monkit/v3"
|
"github.com/spacemonkeygo/monkit/v3"
|
||||||
"github.com/zeebo/clingy"
|
"github.com/zeebo/clingy"
|
||||||
|
|
||||||
|
"storj.io/common/pb"
|
||||||
_ "storj.io/common/rpc/quic" // include quic connector
|
_ "storj.io/common/rpc/quic" // include quic connector
|
||||||
"storj.io/storj/cmd/uplink/ulext"
|
"storj.io/storj/cmd/uplink/ulext"
|
||||||
|
"storj.io/uplink/private/piecestore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mon = monkit.Package()
|
var mon = monkit.Package()
|
||||||
@ -21,12 +24,15 @@ var mon = monkit.Package()
|
|||||||
func main() {
|
func main() {
|
||||||
ex := newExternal()
|
ex := newExternal()
|
||||||
raiseUlimits()
|
raiseUlimits()
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = withPieceHashAlgorithm(ctx)
|
||||||
|
|
||||||
ok, err := clingy.Environment{
|
ok, err := clingy.Environment{
|
||||||
Name: "uplink",
|
Name: "uplink",
|
||||||
Args: os.Args[1:],
|
Args: os.Args[1:],
|
||||||
Dynamic: ex.Dynamic,
|
Dynamic: ex.Dynamic,
|
||||||
Wrap: ex.Wrap,
|
Wrap: ex.Wrap,
|
||||||
}.Run(context.Background(), func(cmds clingy.Commands) {
|
}.Run(ctx, func(cmds clingy.Commands) {
|
||||||
ex.Setup(cmds) // setup ex first so that stdlib flags can consult config
|
ex.Setup(cmds) // setup ex first so that stdlib flags can consult config
|
||||||
newStdlibFlags(flag.CommandLine).Setup(cmds)
|
newStdlibFlags(flag.CommandLine).Setup(cmds)
|
||||||
commands(cmds, ex)
|
commands(cmds, ex)
|
||||||
@ -39,6 +45,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withPieceHashAlgorithm(ctx context.Context) context.Context {
|
||||||
|
customHashAlgo := os.Getenv("STORJ_PIECE_HASH_ALGORITHM_EXPERIMENTAL")
|
||||||
|
if customHashAlgo != "" {
|
||||||
|
var available []string
|
||||||
|
for value, name := range pb.PieceHashAlgorithm_name {
|
||||||
|
available = append(available, name)
|
||||||
|
if name == customHashAlgo {
|
||||||
|
return piecestore.WithPieceHashAlgo(ctx, pb.PieceHashAlgorithm(value))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("Piece hash algorithm is invalid. Available options: " + strings.Join(available, ","))
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
func commands(cmds clingy.Commands, ex ulext.External) {
|
func commands(cmds clingy.Commands, ex ulext.External) {
|
||||||
cmds.Group("access", "Access related commands", func() {
|
cmds.Group("access", "Access related commands", func() {
|
||||||
cmds.New("create", "Create an access from the satellite UI", newCmdAccessCreate(ex))
|
cmds.New("create", "Create an access from the satellite UI", newCmdAccessCreate(ex))
|
||||||
|
Loading…
Reference in New Issue
Block a user