Skip to content

Commit 76f5f66

Browse files
frncmxzelig
authored andcommitted
cmd/swarm: FUSE do not require --ipcpath (#18112)
- Have `${DataDir}/bzzd.ipc` as IPC path default. - Respect the `--datadir` flag. - Keep only the global `--ipcpath` flag and drop the local `--ipcpath` flag as flags might overwrite each other. (Note: before global `--ipcpath` was ignored even if it was set) fixes ethersphere#795
1 parent 6b2cc89 commit 76f5f66

File tree

4 files changed

+69
-45
lines changed

4 files changed

+69
-45
lines changed

cmd/swarm/config_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import (
2626
"testing"
2727
"time"
2828

29+
"github.com/docker/docker/pkg/reexec"
30+
"github.com/ethereum/go-ethereum/cmd/utils"
2931
"github.com/ethereum/go-ethereum/rpc"
3032
"github.com/ethereum/go-ethereum/swarm"
3133
"github.com/ethereum/go-ethereum/swarm/api"
32-
33-
"github.com/docker/docker/pkg/reexec"
3434
)
3535

36-
func TestDumpConfig(t *testing.T) {
36+
func TestConfigDump(t *testing.T) {
3737
swarm := runSwarm(t, "dumpconfig")
3838
defaultConf := api.NewConfig()
3939
out, err := tomlSettings.Marshal(&defaultConf)
@@ -91,8 +91,8 @@ func TestConfigCmdLineOverrides(t *testing.T) {
9191
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
9292
fmt.Sprintf("--%s", SwarmDeliverySkipCheckFlag.Name),
9393
fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
94-
"--datadir", dir,
95-
"--ipcpath", conf.IPCPath,
94+
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
95+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
9696
}
9797
node.Cmd = runSwarm(t, flags...)
9898
node.Cmd.InputLine(testPassphrase)
@@ -189,9 +189,9 @@ func TestConfigFileOverrides(t *testing.T) {
189189
flags := []string{
190190
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
191191
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
192-
"--ens-api", "",
193-
"--ipcpath", conf.IPCPath,
194-
"--datadir", dir,
192+
fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
193+
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
194+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
195195
}
196196
node.Cmd = runSwarm(t, flags...)
197197
node.Cmd.InputLine(testPassphrase)
@@ -407,9 +407,9 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
407407
fmt.Sprintf("--%s", SwarmSyncDisabledFlag.Name),
408408
fmt.Sprintf("--%s", SwarmTomlConfigPathFlag.Name), f.Name(),
409409
fmt.Sprintf("--%s", SwarmAccountFlag.Name), account.Address.String(),
410-
"--ens-api", "",
411-
"--datadir", dir,
412-
"--ipcpath", conf.IPCPath,
410+
fmt.Sprintf("--%s", EnsAPIFlag.Name), "",
411+
fmt.Sprintf("--%s", utils.DataDirFlag.Name), dir,
412+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), conf.IPCPath,
413413
}
414414
node.Cmd = runSwarm(t, flags...)
415415
node.Cmd.InputLine(testPassphrase)
@@ -466,7 +466,7 @@ func TestConfigCmdLineOverridesFile(t *testing.T) {
466466
node.Shutdown()
467467
}
468468

469-
func TestValidateConfig(t *testing.T) {
469+
func TestConfigValidate(t *testing.T) {
470470
for _, c := range []struct {
471471
cfg *api.Config
472472
err string

cmd/swarm/fs.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/ethereum/go-ethereum/cmd/utils"
27-
"github.com/ethereum/go-ethereum/node"
27+
"github.com/ethereum/go-ethereum/log"
2828
"github.com/ethereum/go-ethereum/rpc"
2929
"github.com/ethereum/go-ethereum/swarm/fuse"
3030
"gopkg.in/urfave/cli.v1"
@@ -41,27 +41,24 @@ var fsCommand = cli.Command{
4141
Action: mount,
4242
CustomHelpTemplate: helpTemplate,
4343
Name: "mount",
44-
Flags: []cli.Flag{utils.IPCPathFlag},
4544
Usage: "mount a swarm hash to a mount point",
46-
ArgsUsage: "swarm fs mount --ipcpath <path to bzzd.ipc> <manifest hash> <mount point>",
45+
ArgsUsage: "swarm fs mount <manifest hash> <mount point>",
4746
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",
4847
},
4948
{
5049
Action: unmount,
5150
CustomHelpTemplate: helpTemplate,
5251
Name: "unmount",
53-
Flags: []cli.Flag{utils.IPCPathFlag},
5452
Usage: "unmount a swarmfs mount",
55-
ArgsUsage: "swarm fs unmount --ipcpath <path to bzzd.ipc> <mount point>",
53+
ArgsUsage: "swarm fs unmount <mount point>",
5654
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",
5755
},
5856
{
5957
Action: listMounts,
6058
CustomHelpTemplate: helpTemplate,
6159
Name: "list",
62-
Flags: []cli.Flag{utils.IPCPathFlag},
6360
Usage: "list swarmfs mounts",
64-
ArgsUsage: "swarm fs list --ipcpath <path to bzzd.ipc>",
61+
ArgsUsage: "swarm fs list",
6562
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",
6663
},
6764
},
@@ -70,7 +67,7 @@ var fsCommand = cli.Command{
7067
func mount(cliContext *cli.Context) {
7168
args := cliContext.Args()
7269
if len(args) < 2 {
73-
utils.Fatalf("Usage: swarm fs mount --ipcpath <path to bzzd.ipc> <manifestHash> <file name>")
70+
utils.Fatalf("Usage: swarm fs mount <manifestHash> <file name>")
7471
}
7572

7673
client, err := dialRPC(cliContext)
@@ -97,7 +94,7 @@ func unmount(cliContext *cli.Context) {
9794
args := cliContext.Args()
9895

9996
if len(args) < 1 {
100-
utils.Fatalf("Usage: swarm fs unmount --ipcpath <path to bzzd.ipc> <mount path>")
97+
utils.Fatalf("Usage: swarm fs unmount <mount path>")
10198
}
10299
client, err := dialRPC(cliContext)
103100
if err != nil {
@@ -145,20 +142,21 @@ func listMounts(cliContext *cli.Context) {
145142
}
146143

147144
func dialRPC(ctx *cli.Context) (*rpc.Client, error) {
148-
var endpoint string
145+
endpoint := getIPCEndpoint(ctx)
146+
log.Info("IPC endpoint", "path", endpoint)
147+
return rpc.Dial(endpoint)
148+
}
149149

150-
if ctx.IsSet(utils.IPCPathFlag.Name) {
151-
endpoint = ctx.String(utils.IPCPathFlag.Name)
152-
} else {
153-
utils.Fatalf("swarm ipc endpoint not specified")
154-
}
150+
func getIPCEndpoint(ctx *cli.Context) string {
151+
cfg := defaultNodeConfig
152+
utils.SetNodeConfig(ctx, &cfg)
153+
154+
endpoint := cfg.IPCEndpoint()
155155

156-
if endpoint == "" {
157-
endpoint = node.DefaultIPCEndpoint(clientIdentifier)
158-
} else if strings.HasPrefix(endpoint, "rpc:") || strings.HasPrefix(endpoint, "ipc:") {
156+
if strings.HasPrefix(endpoint, "rpc:") || strings.HasPrefix(endpoint, "ipc:") {
159157
// Backwards compatibility with geth < 1.5 which required
160158
// these prefixes.
161159
endpoint = endpoint[4:]
162160
}
163-
return rpc.Dial(endpoint)
161+
return endpoint
164162
}

cmd/swarm/fs_test.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package main
2020

2121
import (
2222
"bytes"
23+
"fmt"
2324
"io"
2425
"io/ioutil"
2526
"os"
@@ -28,6 +29,7 @@ import (
2829
"testing"
2930
"time"
3031

32+
"github.com/ethereum/go-ethereum/cmd/utils"
3133
"github.com/ethereum/go-ethereum/log"
3234
)
3335

@@ -36,6 +38,26 @@ type testFile struct {
3638
content string
3739
}
3840

41+
// TestCLISwarmFsDefaultIPCPath tests if the most basic fs command, i.e., list
42+
// can find and correctly connect to a running Swarm node on the default
43+
// IPCPath.
44+
func TestCLISwarmFsDefaultIPCPath(t *testing.T) {
45+
cluster := newTestCluster(t, 1)
46+
defer cluster.Shutdown()
47+
48+
handlingNode := cluster.Nodes[0]
49+
list := runSwarm(t, []string{
50+
"--datadir", handlingNode.Dir,
51+
"fs",
52+
"list",
53+
}...)
54+
55+
list.WaitExit()
56+
if list.Err != nil {
57+
t.Fatal(list.Err)
58+
}
59+
}
60+
3961
// TestCLISwarmFs is a high-level test of swarmfs
4062
//
4163
// This test fails on travis for macOS as this executable exits with code 1
@@ -59,9 +81,9 @@ func TestCLISwarmFs(t *testing.T) {
5981
log.Debug("swarmfs cli test: mounting first run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
6082

6183
mount := runSwarm(t, []string{
84+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
6285
"fs",
6386
"mount",
64-
"--ipcpath", filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
6587
mhash,
6688
mountPoint,
6789
}...)
@@ -101,9 +123,9 @@ func TestCLISwarmFs(t *testing.T) {
101123
log.Debug("swarmfs cli test: unmounting first run...", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
102124

103125
unmount := runSwarm(t, []string{
126+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
104127
"fs",
105128
"unmount",
106-
"--ipcpath", filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
107129
mountPoint,
108130
}...)
109131
_, matches := unmount.ExpectRegexp(hashRegexp)
@@ -136,9 +158,9 @@ func TestCLISwarmFs(t *testing.T) {
136158

137159
//remount, check files
138160
newMount := runSwarm(t, []string{
161+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
139162
"fs",
140163
"mount",
141-
"--ipcpath", filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
142164
hash, // the latest hash
143165
secondMountPoint,
144166
}...)
@@ -172,9 +194,9 @@ func TestCLISwarmFs(t *testing.T) {
172194
log.Debug("swarmfs cli test: unmounting second run", "ipc path", filepath.Join(handlingNode.Dir, handlingNode.IpcPath))
173195

174196
unmountSec := runSwarm(t, []string{
197+
fmt.Sprintf("--%s", utils.IPCPathFlag.Name), filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
175198
"fs",
176199
"unmount",
177-
"--ipcpath", filepath.Join(handlingNode.Dir, handlingNode.IpcPath),
178200
secondMountPoint,
179201
}...)
180202

cmd/utils/flags.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -978,16 +978,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
978978
setWS(ctx, cfg)
979979
setNodeUserIdent(ctx, cfg)
980980

981-
switch {
982-
case ctx.GlobalIsSet(DataDirFlag.Name):
983-
cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
984-
case ctx.GlobalBool(DeveloperFlag.Name):
985-
cfg.DataDir = "" // unless explicitly requested, use memory databases
986-
case ctx.GlobalBool(TestnetFlag.Name):
987-
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "testnet")
988-
case ctx.GlobalBool(RinkebyFlag.Name):
989-
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
990-
}
981+
setDataDir(ctx, cfg)
991982

992983
if ctx.GlobalIsSet(KeyStoreDirFlag.Name) {
993984
cfg.KeyStoreDir = ctx.GlobalString(KeyStoreDirFlag.Name)
@@ -1000,6 +991,19 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
1000991
}
1001992
}
1002993

994+
func setDataDir(ctx *cli.Context, cfg *node.Config) {
995+
switch {
996+
case ctx.GlobalIsSet(DataDirFlag.Name):
997+
cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
998+
case ctx.GlobalBool(DeveloperFlag.Name):
999+
cfg.DataDir = "" // unless explicitly requested, use memory databases
1000+
case ctx.GlobalBool(TestnetFlag.Name):
1001+
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "testnet")
1002+
case ctx.GlobalBool(RinkebyFlag.Name):
1003+
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "rinkeby")
1004+
}
1005+
}
1006+
10031007
func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
10041008
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
10051009
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)

0 commit comments

Comments
 (0)