cmd/swarm: rm merge conflicts

This commit is contained in:
Kiel barry 2018-07-09 12:55:49 -07:00
parent f02480d8bb
commit 5c6cb7e37c
3 changed files with 267 additions and 199 deletions

View file

@ -34,7 +34,7 @@ import (
func TestDumpConfig(t *testing.T) { func TestDumpConfig(t *testing.T) {
swarm := runSwarm(t, "dumpconfig") swarm := runSwarm(t, "dumpconfig")
defaultConf := api.NewDefaultConfig() defaultConf := api.NewConfig()
out, err := tomlSettings.Marshal(&defaultConf) out, err := tomlSettings.Marshal(&defaultConf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -43,7 +43,7 @@ func TestDumpConfig(t *testing.T) {
swarm.ExpectExit() swarm.ExpectExit()
} }
func TestFailsSwapEnabledNoSwapApi(t *testing.T) { func TestConfigFailsSwapEnabledNoSwapApi(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42", fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42",
fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545", fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545",
@ -55,7 +55,7 @@ func TestFailsSwapEnabledNoSwapApi(t *testing.T) {
swarm.ExpectExit() swarm.ExpectExit()
} }
func TestFailsNoBzzAccount(t *testing.T) { func TestConfigFailsNoBzzAccount(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42", fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42",
fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545", fmt.Sprintf("--%s", SwarmPortFlag.Name), "54545",
@ -66,7 +66,7 @@ func TestFailsNoBzzAccount(t *testing.T) {
swarm.ExpectExit() swarm.ExpectExit()
} }
func TestCmdLineOverrides(t *testing.T) { func TestConfigCmdLineOverrides(t *testing.T) {
dir, err := ioutil.TempDir("", "bzztest") dir, err := ioutil.TempDir("", "bzztest")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -85,9 +85,10 @@ func TestCmdLineOverrides(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42", fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "42",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), fmt.Sprintf("--%s", SwarmSyncDisabledFlag.Name),
fmt.Sprintf("--%s", CorsStringFlag.Name), "*", fmt.Sprintf("--%s", CorsStringFlag.Name), "*",
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
fmt.Sprintf("--%s", SwarmDeliverySkipCheckFlag.Name),
fmt.Sprintf("--%s", EnsAPIFlag.Name), "", fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
"--datadir", dir, "--datadir", dir,
"--ipcpath", conf.IPCPath, "--ipcpath", conf.IPCPath,
@ -120,12 +121,16 @@ func TestCmdLineOverrides(t *testing.T) {
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
} }
if info.NetworkId != 42 { if info.NetworkID != 42 {
t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", 42, info.NetworkID)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
}
if !info.DeliverySkipCheck {
t.Fatal("Expected DeliverySkipCheck to be enabled, but it is not")
} }
if info.Cors != "*" { if info.Cors != "*" {
@ -135,7 +140,7 @@ func TestCmdLineOverrides(t *testing.T) {
node.Shutdown() node.Shutdown()
} }
func TestFileOverrides(t *testing.T) { func TestConfigFileOverrides(t *testing.T) {
// assign ports // assign ports
httpPort, err := assignTCPPort() httpPort, err := assignTCPPort()
@ -145,16 +150,16 @@ func TestFileOverrides(t *testing.T) {
//create a config file //create a config file
//first, create a default conf //first, create a default conf
defaultConf := api.NewDefaultConfig() defaultConf := api.NewConfig()
//change some values in order to test if they have been loaded //change some values in order to test if they have been loaded
defaultConf.SyncEnabled = true defaultConf.SyncEnabled = false
defaultConf.NetworkId = 54 defaultConf.DeliverySkipCheck = true
defaultConf.NetworkID = 54
defaultConf.Port = httpPort defaultConf.Port = httpPort
defaultConf.StoreParams.DbCapacity = 9000000 defaultConf.DbCapacity = 9000000
defaultConf.ChunkerParams.Branches = 64 defaultConf.HiveParams.KeepAliveInterval = 6000000000
defaultConf.HiveParams.CallInterval = 6000000000
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
defaultConf.SyncParams.KeyBufferSize = 512 //defaultConf.SyncParams.KeyBufferSize = 512
//create a TOML string //create a TOML string
out, err := tomlSettings.Marshal(&defaultConf) out, err := tomlSettings.Marshal(&defaultConf)
if err != nil { if err != nil {
@ -215,38 +220,38 @@ func TestFileOverrides(t *testing.T) {
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
} }
if info.NetworkId != 54 { if info.NetworkID != 54 {
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
} }
if info.StoreParams.DbCapacity != 9000000 { if !info.DeliverySkipCheck {
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) t.Fatal("Expected DeliverySkipCheck to be enabled, but it is not")
} }
if info.ChunkerParams.Branches != 64 { if info.DbCapacity != 9000000 {
t.Fatalf("Expected chunker params branches to be %d, got %d", 64, info.ChunkerParams.Branches) t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkID)
} }
if info.HiveParams.CallInterval != 6000000000 { if info.HiveParams.KeepAliveInterval != 6000000000 {
t.Fatalf("Expected HiveParams CallInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.CallInterval)) t.Fatalf("Expected HiveParams KeepAliveInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.KeepAliveInterval))
} }
if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second { if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second {
t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval) t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval)
} }
if info.SyncParams.KeyBufferSize != 512 { // if info.SyncParams.KeyBufferSize != 512 {
t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize) // t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize)
} // }
node.Shutdown() node.Shutdown()
} }
func TestEnvVars(t *testing.T) { func TestConfigEnvVars(t *testing.T) {
// assign ports // assign ports
httpPort, err := assignTCPPort() httpPort, err := assignTCPPort()
if err != nil { if err != nil {
@ -257,7 +262,8 @@ func TestEnvVars(t *testing.T) {
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPortFlag.EnvVar, httpPort)) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmPortFlag.EnvVar, httpPort))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmNetworkIDFlag.EnvVar, "999")) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmNetworkIDFlag.EnvVar, "999"))
envVars = append(envVars, fmt.Sprintf("%s=%s", CorsStringFlag.EnvVar, "*")) envVars = append(envVars, fmt.Sprintf("%s=%s", CorsStringFlag.EnvVar, "*"))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmSyncEnabledFlag.EnvVar, "true")) envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmSyncDisabledFlag.EnvVar, "true"))
envVars = append(envVars, fmt.Sprintf("%s=%s", SwarmDeliverySkipCheckFlag.EnvVar, "true"))
dir, err := ioutil.TempDir("", "bzztest") dir, err := ioutil.TempDir("", "bzztest")
if err != nil { if err != nil {
@ -326,23 +332,27 @@ func TestEnvVars(t *testing.T) {
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
} }
if info.NetworkId != 999 { if info.NetworkID != 999 {
t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", 999, info.NetworkID)
} }
if info.Cors != "*" { if info.Cors != "*" {
t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors) t.Fatalf("Expected Cors flag to be set to %s, got %s", "*", info.Cors)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
}
if !info.DeliverySkipCheck {
t.Fatal("Expected DeliverySkipCheck to be enabled, but it is not")
} }
node.Shutdown() node.Shutdown()
cmd.Process.Kill() cmd.Process.Kill()
} }
func TestCmdLineOverridesFile(t *testing.T) { func TestConfigCmdLineOverridesFile(t *testing.T) {
// assign ports // assign ports
httpPort, err := assignTCPPort() httpPort, err := assignTCPPort()
@ -352,26 +362,27 @@ func TestCmdLineOverridesFile(t *testing.T) {
//create a config file //create a config file
//first, create a default conf //first, create a default conf
defaultConf := api.NewDefaultConfig() defaultConf := api.NewConfig()
//change some values in order to test if they have been loaded //change some values in order to test if they have been loaded
defaultConf.SyncEnabled = false defaultConf.SyncEnabled = true
defaultConf.NetworkId = 54 defaultConf.NetworkID = 54
defaultConf.Port = "8588" defaultConf.Port = "8588"
defaultConf.StoreParams.DbCapacity = 9000000 defaultConf.DbCapacity = 9000000
defaultConf.ChunkerParams.Branches = 64 defaultConf.HiveParams.KeepAliveInterval = 6000000000
defaultConf.HiveParams.CallInterval = 6000000000
defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second defaultConf.Swap.Params.Strategy.AutoCashInterval = 600 * time.Second
defaultConf.SyncParams.KeyBufferSize = 512 //defaultConf.SyncParams.KeyBufferSize = 512
//create a TOML file //create a TOML file
out, err := tomlSettings.Marshal(&defaultConf) out, err := tomlSettings.Marshal(&defaultConf)
if err != nil { if err != nil {
t.Fatalf("Error creating TOML file in TestFileOverride: %v", err) t.Fatalf("Error creating TOML file in TestFileOverride: %v", err)
} }
//write file //write file
f, err := ioutil.TempFile("", "testconfig.toml") fname := "testconfig.toml"
f, err := ioutil.TempFile("", fname)
if err != nil { if err != nil {
t.Fatalf("Error writing TOML file in TestFileOverride: %v", err) t.Fatalf("Error writing TOML file in TestFileOverride: %v", err)
} }
defer os.Remove(fname)
//write file //write file
_, err = f.WriteString(string(out)) _, err = f.WriteString(string(out))
if err != nil { if err != nil {
@ -392,7 +403,7 @@ func TestCmdLineOverridesFile(t *testing.T) {
flags := []string{ flags := []string{
fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "77", fmt.Sprintf("--%s", SwarmNetworkIDFlag.Name), "77",
fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort, fmt.Sprintf("--%s", SwarmPortFlag.Name), httpPort,
fmt.Sprintf("--%s", SwarmSyncEnabledFlag.Name), fmt.Sprintf("--%s", SwarmSyncDisabledFlag.Name),
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(), fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(), fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
"--ens-api", "", "--ens-api", "",
@ -427,33 +438,29 @@ func TestCmdLineOverridesFile(t *testing.T) {
t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port) t.Fatalf("Expected port to be %s, got %s", httpPort, info.Port)
} }
if info.NetworkId != expectNetworkID { if info.NetworkID != expectNetworkId {
t.Fatalf("Expected network ID to be %d, got %d", expectNetworkID, info.NetworkId) t.Fatalf("Expected network ID to be %d, got %d", expectNetworkId, info.NetworkID)
} }
if !info.SyncEnabled { if info.SyncEnabled {
t.Fatal("Expected Sync to be enabled, but is false") t.Fatal("Expected Sync to be disabled, but is true")
} }
if info.StoreParams.DbCapacity != 9000000 { if info.LocalStoreParams.DbCapacity != 9000000 {
t.Fatalf("Expected network ID to be %d, got %d", 54, info.NetworkId) t.Fatalf("Expected Capacity to be %d, got %d", 9000000, info.LocalStoreParams.DbCapacity)
} }
if info.ChunkerParams.Branches != 64 { if info.HiveParams.KeepAliveInterval != 6000000000 {
t.Fatalf("Expected chunker params branches to be %d, got %d", 64, info.ChunkerParams.Branches) t.Fatalf("Expected HiveParams KeepAliveInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.KeepAliveInterval))
}
if info.HiveParams.CallInterval != 6000000000 {
t.Fatalf("Expected HiveParams CallInterval to be %d, got %d", uint64(6000000000), uint64(info.HiveParams.CallInterval))
} }
if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second { if info.Swap.Params.Strategy.AutoCashInterval != 600*time.Second {
t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval) t.Fatalf("Expected SwapParams AutoCashInterval to be %ds, got %d", 600, info.Swap.Params.Strategy.AutoCashInterval)
} }
if info.SyncParams.KeyBufferSize != 512 { // if info.SyncParams.KeyBufferSize != 512 {
t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize) // t.Fatalf("Expected info.SyncParams.KeyBufferSize to be %d, got %d", 512, info.SyncParams.KeyBufferSize)
} // }
node.Shutdown() node.Shutdown()
} }

View file

@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
@ -49,6 +48,22 @@ import (
) )
const clientIdentifier = "swarm" const clientIdentifier = "swarm"
const helpTemplate = `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
CATEGORY:
{{.Category}}{{end}}{{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
var ( var (
gitCommit string // Git SHA1 commit hash of the release (set via linker flags) gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
@ -87,10 +102,6 @@ var (
Usage: "Network identifier (integer, default 3=swarm testnet)", Usage: "Network identifier (integer, default 3=swarm testnet)",
EnvVar: SWARM_ENV_NETWORK_ID, EnvVar: SWARM_ENV_NETWORK_ID,
} }
SwarmConfigPathFlag = cli.StringFlag{
Name: "bzzconfig",
Usage: "DEPRECATED: please use --config path/to/TOML-file",
}
SwarmSwapEnabledFlag = cli.BoolFlag{ SwarmSwapEnabledFlag = cli.BoolFlag{
Name: "swap", Name: "swap",
Usage: "Swarm SWAP enabled (default false)", Usage: "Swarm SWAP enabled (default false)",
@ -101,10 +112,20 @@ var (
Usage: "URL of the Ethereum API provider to use to settle SWAP payments", Usage: "URL of the Ethereum API provider to use to settle SWAP payments",
EnvVar: SWARM_ENV_SWAP_API, EnvVar: SWARM_ENV_SWAP_API,
} }
SwarmSyncEnabledFlag = cli.BoolTFlag{ SwarmSyncDisabledFlag = cli.BoolTFlag{
Name: "sync", Name: "nosync",
Usage: "Swarm Syncing enabled (default true)", Usage: "Disable swarm syncing",
EnvVar: SWARM_ENV_SYNC_ENABLE, EnvVar: SWARM_ENV_SYNC_DISABLE,
}
SwarmSyncUpdateDelay = cli.DurationFlag{
Name: "sync-update-delay",
Usage: "Duration for sync subscriptions update after no new peers are added (default 15s)",
EnvVar: SWARM_ENV_SYNC_UPDATE_DELAY,
}
SwarmDeliverySkipCheckFlag = cli.BoolFlag{
Name: "delivery-skip-check",
Usage: "Skip chunk delivery check (default false)",
EnvVar: SWARM_ENV_DELIVERY_SKIP_CHECK,
} }
EnsAPIFlag = cli.StringSliceFlag{ EnsAPIFlag = cli.StringSliceFlag{
Name: "ens-api", Name: "ens-api",
@ -116,13 +137,13 @@ var (
Usage: "Swarm HTTP endpoint", Usage: "Swarm HTTP endpoint",
Value: "http://127.0.0.1:8500", Value: "http://127.0.0.1:8500",
} }
SwarmRecursiveUploadFlag = cli.BoolFlag{ SwarmRecursiveFlag = cli.BoolFlag{
Name: "recursive", Name: "recursive",
Usage: "Upload directories recursively", Usage: "Upload directories recursively",
} }
SwarmWantManifestFlag = cli.BoolTFlag{ SwarmWantManifestFlag = cli.BoolTFlag{
Name: "manifest", Name: "manifest",
Usage: "Automatic manifest upload", Usage: "Automatic manifest upload (default true)",
} }
SwarmUploadDefaultPath = cli.StringFlag{ SwarmUploadDefaultPath = cli.StringFlag{
Name: "defaultpath", Name: "defaultpath",
@ -134,22 +155,31 @@ var (
} }
SwarmUploadMimeType = cli.StringFlag{ SwarmUploadMimeType = cli.StringFlag{
Name: "mime", Name: "mime",
Usage: "force mime type", Usage: "Manually specify MIME type",
}
SwarmEncryptedFlag = cli.BoolFlag{
Name: "encrypt",
Usage: "use encrypted upload",
} }
CorsStringFlag = cli.StringFlag{ CorsStringFlag = cli.StringFlag{
Name: "corsdomain", Name: "corsdomain",
Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')", Usage: "Domain on which to send Access-Control-Allow-Origin header (multiple domains can be supplied separated by a ',')",
EnvVar: SWARM_ENV_CORS, EnvVar: SWARM_ENV_CORS,
} }
SwarmStorePath = cli.StringFlag{
// the following flags are deprecated and should be removed in the future Name: "store.path",
DeprecatedEthAPIFlag = cli.StringFlag{ Usage: "Path to leveldb chunk DB (default <$GETH_ENV_DIR>/swarm/bzz-<$BZZ_KEY>/chunks)",
Name: "ethapi", EnvVar: SWARM_ENV_STORE_PATH,
Usage: "DEPRECATED: please use --ens-api and --swap-api",
} }
DeprecatedEnsAddrFlag = cli.StringFlag{ SwarmStoreCapacity = cli.Uint64Flag{
Name: "ens-addr", Name: "store.size",
Usage: "DEPRECATED: ENS contract address, please use --ens-api with contract address according to its format", Usage: "Number of chunks (5M is roughly 20-25GB) (default 5000000)",
EnvVar: SWARM_ENV_STORE_CAPACITY,
}
SwarmStoreCacheCapacity = cli.UintFlag{
Name: "store.cache.size",
Usage: "Number of recent chunks cached in memory (default 5000)",
EnvVar: SWARM_ENV_STORE_CACHE_CAPACITY,
} }
) )
@ -180,91 +210,130 @@ func init() {
app.Copyright = "Copyright 2013-2016 The go-ethereum Authors" app.Copyright = "Copyright 2013-2016 The go-ethereum Authors"
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {
Action: version, Action: version,
Name: "version", CustomHelpTemplate: helpTemplate,
Usage: "Print version numbers", Name: "version",
ArgsUsage: " ", Usage: "Print version numbers",
Description: ` Description: "The output of this command is supposed to be machine-readable",
The output of this command is supposed to be machine-readable.
`,
}, },
{ {
Action: upload, Action: upload,
Name: "up", CustomHelpTemplate: helpTemplate,
Usage: "upload a file or directory to swarm using the HTTP API", Name: "up",
ArgsUsage: " <file>", Usage: "uploads a file or directory to swarm using the HTTP API",
Description: ` ArgsUsage: "<file>",
"upload a file or directory to swarm using the HTTP API and prints the root hash", Flags: []cli.Flag{SwarmEncryptedFlag},
`, Description: "uploads a file or directory to swarm using the HTTP API and prints the root hash",
}, },
{ {
Action: list, Action: list,
Name: "ls", CustomHelpTemplate: helpTemplate,
Usage: "list files and directories contained in a manifest", Name: "ls",
ArgsUsage: " <manifest> [<prefix>]", Usage: "list files and directories contained in a manifest",
Description: ` ArgsUsage: "<manifest> [<prefix>]",
Lists files and directories contained in a manifest. Description: "Lists files and directories contained in a manifest",
`,
}, },
{ {
Action: hash, Action: hash,
Name: "hash", CustomHelpTemplate: helpTemplate,
Usage: "print the swarm hash of a file or directory", Name: "hash",
ArgsUsage: " <file>", Usage: "print the swarm hash of a file or directory",
Description: ` ArgsUsage: "<file>",
Prints the swarm hash of file or directory. Description: "Prints the swarm hash of file or directory",
`,
}, },
{ {
Name: "manifest", Action: download,
Usage: "update a MANIFEST", Name: "down",
ArgsUsage: "manifest COMMAND", Flags: []cli.Flag{SwarmRecursiveFlag},
Usage: "downloads a swarm manifest or a file inside a manifest",
ArgsUsage: " <uri> [<dir>]",
Description: ` Description: `
Updates a MANIFEST by adding/removing/updating the hash of a path. Downloads a swarm bzz uri to the given dir. When no dir is provided, working directory is assumed. --recursive flag is expected when downloading a manifest with multiple entries.
`, `,
},
{
Name: "manifest",
CustomHelpTemplate: helpTemplate,
Usage: "perform operations on swarm manifests",
ArgsUsage: "COMMAND",
Description: "Updates a MANIFEST by adding/removing/updating the hash of a path.\nCOMMAND could be: add, update, remove",
Subcommands: []cli.Command{ Subcommands: []cli.Command{
{ {
Action: add, Action: add,
Name: "add", CustomHelpTemplate: helpTemplate,
Usage: "add a new path to the manifest", Name: "add",
ArgsUsage: "<MANIFEST> <path> <hash> [<content-type>]", Usage: "add a new path to the manifest",
Description: ` ArgsUsage: "<MANIFEST> <path> <hash> [<content-type>]",
Adds a new path to the manifest Description: "Adds a new path to the manifest",
`,
}, },
{ {
Action: update, Action: update,
Name: "update", CustomHelpTemplate: helpTemplate,
Usage: "update the hash for an already existing path in the manifest", Name: "update",
ArgsUsage: "<MANIFEST> <path> <newhash> [<newcontent-type>]", Usage: "update the hash for an already existing path in the manifest",
Description: ` ArgsUsage: "<MANIFEST> <path> <newhash> [<newcontent-type>]",
Update the hash for an already existing path in the manifest Description: "Update the hash for an already existing path in the manifest",
`,
}, },
{ {
Action: remove, Action: remove,
Name: "remove", CustomHelpTemplate: helpTemplate,
Usage: "removes a path from the manifest", Name: "remove",
ArgsUsage: "<MANIFEST> <path>", Usage: "removes a path from the manifest",
Description: ` ArgsUsage: "<MANIFEST> <path>",
Removes a path from the manifest Description: "Removes a path from the manifest",
`,
}, },
}, },
}, },
{ {
Name: "db", Name: "fs",
Usage: "manage the local chunk database", CustomHelpTemplate: helpTemplate,
ArgsUsage: "db COMMAND", Usage: "perform FUSE operations",
Description: ` ArgsUsage: "fs COMMAND",
Manage the local chunk database. Description: "Performs FUSE operations by mounting/unmounting/listing mount points. This assumes you already have a Swarm node running locally. For all operation you must reference the correct path to bzzd.ipc in order to communicate with the node",
`,
Subcommands: []cli.Command{ Subcommands: []cli.Command{
{ {
Action: dbExport, Action: mount,
Name: "export", CustomHelpTemplate: helpTemplate,
Usage: "export a local chunk database as a tar archive (use - to send to stdout)", Name: "mount",
ArgsUsage: "<chunkdb> <file>", Flags: []cli.Flag{utils.IPCPathFlag},
Usage: "mount a swarm hash to a mount point",
ArgsUsage: "swarm fs mount --ipcpath <path to bzzd.ipc> <manifest hash> <mount point>",
Description: "Mounts a Swarm manifest hash to a given mount point. This assumes you already have a Swarm node running locally. You must reference the correct path to your bzzd.ipc file",
},
{
Action: unmount,
CustomHelpTemplate: helpTemplate,
Name: "unmount",
Flags: []cli.Flag{utils.IPCPathFlag},
Usage: "unmount a swarmfs mount",
ArgsUsage: "swarm fs unmount --ipcpath <path to bzzd.ipc> <mount point>",
Description: "Unmounts a swarmfs mount residing at <mount point>. This assumes you already have a Swarm node running locally. You must reference the correct path to your bzzd.ipc file",
},
{
Action: listMounts,
CustomHelpTemplate: helpTemplate,
Name: "list",
Flags: []cli.Flag{utils.IPCPathFlag},
Usage: "list swarmfs mounts",
ArgsUsage: "swarm fs list --ipcpath <path to bzzd.ipc>",
Description: "Lists all mounted swarmfs volumes. This assumes you already have a Swarm node running locally. You must reference the correct path to your bzzd.ipc file",
},
},
},
{
Name: "db",
CustomHelpTemplate: helpTemplate,
Usage: "manage the local chunk database",
ArgsUsage: "db COMMAND",
Description: "Manage the local chunk database",
Subcommands: []cli.Command{
{
Action: dbExport,
CustomHelpTemplate: helpTemplate,
Name: "export",
Usage: "export a local chunk database as a tar archive (use - to send to stdout)",
ArgsUsage: "<chunkdb> <file>",
Description: ` Description: `
Export a local chunk database as a tar archive (use - to send to stdout). Export a local chunk database as a tar archive (use - to send to stdout).
@ -277,10 +346,11 @@ pv(1) tool to get a progress bar:
`, `,
}, },
{ {
Action: dbImport, Action: dbImport,
Name: "import", CustomHelpTemplate: helpTemplate,
Usage: "import chunks from a tar archive into a local chunk database (use - to read from stdin)", Name: "import",
ArgsUsage: "<chunkdb> <file>", Usage: "import chunks from a tar archive into a local chunk database (use - to read from stdin)",
ArgsUsage: "<chunkdb> <file>",
Description: ` Description: `
Import chunks from a tar archive into a local chunk database (use - to read from stdin). Import chunks from a tar archive into a local chunk database (use - to read from stdin).
@ -293,27 +363,16 @@ pv(1) tool to get a progress bar:
`, `,
}, },
{ {
Action: dbClean, Action: dbClean,
Name: "clean", CustomHelpTemplate: helpTemplate,
Usage: "remove corrupt entries from a local chunk database", Name: "clean",
ArgsUsage: "<chunkdb>", Usage: "remove corrupt entries from a local chunk database",
Description: ` ArgsUsage: "<chunkdb>",
Remove corrupt entries from a local chunk database. Description: "Remove corrupt entries from a local chunk database",
`,
}, },
}, },
}, },
{
Action: func(ctx *cli.Context) {
utils.Fatalf("ERROR: 'swarm cleandb' has been removed, please use 'swarm db clean'.")
},
Name: "cleandb",
Usage: "DEPRECATED: use 'swarm db clean'",
ArgsUsage: " ",
Description: `
DEPRECATED: use 'swarm db clean'.
`,
},
// See config.go // See config.go
DumpConfigCommand, DumpConfigCommand,
} }
@ -339,26 +398,36 @@ DEPRECATED: use 'swarm db clean'.
CorsStringFlag, CorsStringFlag,
EnsAPIFlag, EnsAPIFlag,
SwarmTomlConfigPathFlag, SwarmTomlConfigPathFlag,
SwarmConfigPathFlag,
SwarmSwapEnabledFlag, SwarmSwapEnabledFlag,
SwarmSwapAPIFlag, SwarmSwapAPIFlag,
SwarmSyncEnabledFlag, SwarmSyncDisabledFlag,
SwarmSyncUpdateDelay,
SwarmDeliverySkipCheckFlag,
SwarmListenAddrFlag, SwarmListenAddrFlag,
SwarmPortFlag, SwarmPortFlag,
SwarmAccountFlag, SwarmAccountFlag,
SwarmNetworkIDFlag, SwarmNetworkIDFlag,
ChequebookAddrFlag, ChequebookAddrFlag,
// upload flags // upload flags
SwarmAPIFlag, SwarmApiFlag,
SwarmRecursiveUploadFlag, SwarmRecursiveFlag,
SwarmWantManifestFlag, SwarmWantManifestFlag,
SwarmUploadDefaultPath, SwarmUploadDefaultPath,
SwarmUpFromStdinFlag, SwarmUpFromStdinFlag,
SwarmUploadMimeType, SwarmUploadMimeType,
//deprecated flags // storage flags
DeprecatedEthAPIFlag, SwarmStorePath,
DeprecatedEnsAddrFlag, SwarmStoreCapacity,
SwarmStoreCacheCapacity,
} }
rpcFlags := []cli.Flag{
utils.WSEnabledFlag,
utils.WSListenAddrFlag,
utils.WSPortFlag,
utils.WSApiFlag,
utils.WSAllowedOriginsFlag,
}
app.Flags = append(app.Flags, rpcFlags...)
app.Flags = append(app.Flags, debug.Flags...) app.Flags = append(app.Flags, debug.Flags...)
app.Flags = append(app.Flags, swarmmetrics.Flags...) app.Flags = append(app.Flags, swarmmetrics.Flags...)
app.Before = func(ctx *cli.Context) error { app.Before = func(ctx *cli.Context) error {
@ -383,16 +452,13 @@ func main() {
} }
func version(ctx *cli.Context) error { func version(ctx *cli.Context) error {
fmt.Println(strings.Title(clientIdentifier)) fmt.Println("Version:", SWARM_VERSION)
fmt.Println("Version:", params.Version)
if gitCommit != "" { if gitCommit != "" {
fmt.Println("Git Commit:", gitCommit) fmt.Println("Git Commit:", gitCommit)
} }
fmt.Println("Network Id:", ctx.GlobalInt(utils.NetworkIDFlag.Name))
fmt.Println("Go Version:", runtime.Version()) fmt.Println("Go Version:", runtime.Version())
fmt.Println("OS:", runtime.GOOS) fmt.Println("OS:", runtime.GOOS)
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
return nil return nil
} }
@ -405,6 +471,10 @@ func bzzd(ctx *cli.Context) error {
} }
cfg := defaultNodeConfig cfg := defaultNodeConfig
//pss operates on ws
cfg.WSModules = append(cfg.WSModules, "pss")
//geth only supports --datadir via command line //geth only supports --datadir via command line
//in order to be consistent within swarm, if we pass --datadir via environment variable //in order to be consistent within swarm, if we pass --datadir via environment variable
//or via config file, we get the same directory for geth and swarm //or via config file, we get the same directory for geth and swarm
@ -421,7 +491,7 @@ func bzzd(ctx *cli.Context) error {
//due to overriding behavior //due to overriding behavior
initSwarmNode(bzzconfig, stack, ctx) initSwarmNode(bzzconfig, stack, ctx)
//register BZZ as node.Service in the ethereum node //register BZZ as node.Service in the ethereum node
registerBzzService(bzzconfig, ctx, stack) registerBzzService(bzzconfig, stack)
//start the node //start the node
utils.StartNode(stack) utils.StartNode(stack)
@ -439,7 +509,7 @@ func bzzd(ctx *cli.Context) error {
bootnodes := strings.Split(bzzconfig.BootNodes, ",") bootnodes := strings.Split(bzzconfig.BootNodes, ",")
injectBootnodes(stack.Server(), bootnodes) injectBootnodes(stack.Server(), bootnodes)
} else { } else {
if bzzconfig.NetworkId == 3 { if bzzconfig.NetworkID == 3 {
injectBootnodes(stack.Server(), testbetBootNodes) injectBootnodes(stack.Server(), testbetBootNodes)
} }
} }
@ -448,21 +518,11 @@ func bzzd(ctx *cli.Context) error {
return nil return nil
} }
func registerBzzService(bzzconfig *bzzapi.Config, ctx *cli.Context, stack *node.Node) { func registerBzzService(bzzconfig *bzzapi.Config, stack *node.Node) {
//define the swarm service boot function //define the swarm service boot function
boot := func(ctx *node.ServiceContext) (node.Service, error) { boot := func(_ *node.ServiceContext) (node.Service, error) {
var swapClient *ethclient.Client // In production, mockStore must be always nil.
var err error return swarm.NewSwarm(bzzconfig, nil)
if bzzconfig.SwapApi != "" {
log.Info("connecting to SWAP API", "url", bzzconfig.SwapApi)
swapClient, err = ethclient.Dial(bzzconfig.SwapApi)
if err != nil {
return nil, fmt.Errorf("error connecting to SWAP API %s: %s", bzzconfig.SwapApi, err)
}
}
return swarm.NewSwarm(ctx, swapClient, bzzconfig)
} }
//register within the ethereum node //register within the ethereum node
if err := stack.Register(boot); err != nil { if err := stack.Register(boot); err != nil {

View file

@ -39,13 +39,14 @@ func upload(ctx *cli.Context) {
args := ctx.Args() args := ctx.Args()
var ( var (
bzzapi = strings.TrimRight(ctx.GlobalString(SwarmAPIFlag.Name), "/") bzzapi = strings.TrimRight(ctx.GlobalString(SwarmApiFlag.Name), "/")
recursive = ctx.GlobalBool(SwarmRecursiveUploadFlag.Name) recursive = ctx.GlobalBool(SwarmRecursiveFlag.Name)
wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name) wantManifest = ctx.GlobalBoolT(SwarmWantManifestFlag.Name)
defaultPath = ctx.GlobalString(SwarmUploadDefaultPath.Name) defaultPath = ctx.GlobalString(SwarmUploadDefaultPath.Name)
fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name) fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name)
mimeType = ctx.GlobalString(SwarmUploadMimeType.Name) mimeType = ctx.GlobalString(SwarmUploadMimeType.Name)
client = swarm.NewClient(bzzapi) client = swarm.NewClient(bzzapi)
toEncrypt = ctx.Bool(SwarmEncryptedFlag.Name)
file string file string
) )
@ -76,7 +77,7 @@ func upload(ctx *cli.Context) {
utils.Fatalf("Error opening file: %s", err) utils.Fatalf("Error opening file: %s", err)
} }
defer f.Close() defer f.Close()
hash, err := client.UploadRaw(f, f.Size) hash, err := client.UploadRaw(f, f.Size, toEncrypt)
if err != nil { if err != nil {
utils.Fatalf("Upload failed: %s", err) utils.Fatalf("Upload failed: %s", err)
} }
@ -97,7 +98,7 @@ func upload(ctx *cli.Context) {
if !recursive { if !recursive {
return "", errors.New("Argument is a directory and recursive upload is disabled") return "", errors.New("Argument is a directory and recursive upload is disabled")
} }
return client.UploadDirectory(file, defaultPath, "") return client.UploadDirectory(file, defaultPath, "", toEncrypt)
} }
} else { } else {
doUpload = func() (string, error) { doUpload = func() (string, error) {
@ -110,7 +111,7 @@ func upload(ctx *cli.Context) {
mimeType = detectMimeType(file) mimeType = detectMimeType(file)
} }
f.ContentType = mimeType f.ContentType = mimeType
return client.Upload(f, "") return client.Upload(f, "", toEncrypt)
} }
} }
hash, err := doUpload() hash, err := doUpload()