From 1646a0ac9e547f63a63bcb53265f56fe84ea9a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Thu, 11 Aug 2022 13:37:00 +0200 Subject: [PATCH] cmd/uplink: experimental environment variable to change piece hash algorithm Change-Id: I7420919146c64d29ff1023f7498867d3d30892d0 --- cmd/uplink/main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/uplink/main.go b/cmd/uplink/main.go index 043891c0a..8767b5859 100644 --- a/cmd/uplink/main.go +++ b/cmd/uplink/main.go @@ -8,12 +8,15 @@ import ( "flag" "fmt" "os" + "strings" "github.com/spacemonkeygo/monkit/v3" "github.com/zeebo/clingy" + "storj.io/common/pb" _ "storj.io/common/rpc/quic" // include quic connector "storj.io/storj/cmd/uplink/ulext" + "storj.io/uplink/private/piecestore" ) var mon = monkit.Package() @@ -21,12 +24,15 @@ var mon = monkit.Package() func main() { ex := newExternal() raiseUlimits() + ctx := context.Background() + ctx = withPieceHashAlgorithm(ctx) + ok, err := clingy.Environment{ Name: "uplink", Args: os.Args[1:], Dynamic: ex.Dynamic, 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 newStdlibFlags(flag.CommandLine).Setup(cmds) 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) { cmds.Group("access", "Access related commands", func() { cmds.New("create", "Create an access from the satellite UI", newCmdAccessCreate(ex))