From b1afa8744d7efba50e6dd3a8234283fa91cb7615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 31 Oct 2017 19:34:38 +0100 Subject: [PATCH] config: apply review to lowpower profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- cmd/ipfs/daemon.go | 4 ++-- docs/config.md | 1 - repo/config/config.go | 1 + repo/config/discovery.go | 3 --- repo/config/init.go | 5 ++++- repo/config/profile.go | 8 +++++++- repo/config/routing.go | 7 +++++++ test/sharness/t0020-init.sh | 10 +++++----- test/sharness/t0021-config.sh | 3 +-- 9 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 repo/config/routing.go diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 7c427fb6642a..7260c6c3930f 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -308,11 +308,11 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) { if routingOption == routingOptionDefaultKwd { cfg, err := repo.Config() if err != nil { - res.SetError(err, cmds.ErrNormal) + re.SetError(err, cmdkit.ErrNormal) return } - routingOption = cfg.Discovery.Routing + routingOption = cfg.Routing.Type if routingOption == "" { routingOption = routingOptionDHTKwd } diff --git a/docs/config.md b/docs/config.md index 1e21aaf771b6..e89a8fc9fd5f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -203,7 +203,6 @@ Valid modes are: - `dht` (default) - `dhtclient` - `none` - - `supernode` (deprecated) ## `Gateway` Options for the HTTP gateway. diff --git a/repo/config/config.go b/repo/config/config.go index ac7c1152b777..719170baad8f 100644 --- a/repo/config/config.go +++ b/repo/config/config.go @@ -19,6 +19,7 @@ type Config struct { Addresses Addresses // local node's addresses Mounts Mounts // local node's mount points Discovery Discovery // local node's discovery mechanisms + Routing Routing // local node's routing settings Ipns Ipns // Ipns settings Bootstrap []string // local nodes's bootstrap peer addresses Gateway Gateway // local node's gateway server options diff --git a/repo/config/discovery.go b/repo/config/discovery.go index 64f7af64a682..4fb8508f00a6 100644 --- a/repo/config/discovery.go +++ b/repo/config/discovery.go @@ -2,9 +2,6 @@ package config type Discovery struct { MDNS MDNS - - //Routing sets default daemon routing mode. - Routing string } type MDNS struct { diff --git a/repo/config/init.go b/repo/config/init.go index e34960c62e52..ae727981a322 100644 --- a/repo/config/init.go +++ b/repo/config/init.go @@ -38,7 +38,10 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) { Enabled: true, Interval: 10, }, - Routing: "dht", + }, + + Routing: Routing{ + Type: "dht", }, // setup the node mount points. diff --git a/repo/config/profile.go b/repo/config/profile.go index 6aa5f5053806..b20382ef4ed8 100644 --- a/repo/config/profile.go +++ b/repo/config/profile.go @@ -1,5 +1,7 @@ package config +import "time" + // Transformer is a function which takes configuration and applies some filter to it type Transformer func(c *Config) error @@ -74,8 +76,12 @@ var Profiles = map[string]Transformer{ return nil }, "lowpower": func(c *Config) error { - c.Discovery.Routing = "dhtclient" + c.Routing.Type = "dhtclient" c.Reprovider.Interval = "0" + + c.Swarm.ConnMgr.LowWater = 20 + c.Swarm.ConnMgr.HighWater = 40 + c.Swarm.ConnMgr.GracePeriod = time.Minute.String() return nil }, } diff --git a/repo/config/routing.go b/repo/config/routing.go new file mode 100644 index 000000000000..e601cd5e8d39 --- /dev/null +++ b/repo/config/routing.go @@ -0,0 +1,7 @@ +package config + +// Routing defines configuration options for libp2p routing +type Routing struct { + // Type sets default daemon routing mode. + Type string +} diff --git a/test/sharness/t0020-init.sh b/test/sharness/t0020-init.sh index a01c08763341..9a77dbc44222 100755 --- a/test/sharness/t0020-init.sh +++ b/test/sharness/t0020-init.sh @@ -168,17 +168,17 @@ test_expect_success "clean up ipfs dir" ' ' test_expect_success "'ipfs init --profile=lowpower' succeeds" ' - BITS="1024" && - ipfs init --bits="$BITS" --profile=lowpower + BITS="1024" && + ipfs init --bits="$BITS" --profile=lowpower ' test_expect_success "'ipfs config Discovery.Routing' looks good" ' - ipfs config Discovery.Routing > actual_config && - test $(cat actual_config) = "dhtclient" + ipfs config Routing.Type > actual_config && + test $(cat actual_config) = "dhtclient" ' test_expect_success "clean up ipfs dir" ' - rm -rf "$IPFS_PATH" + rm -rf "$IPFS_PATH" ' test_init_ipfs diff --git a/test/sharness/t0021-config.sh b/test/sharness/t0021-config.sh index 17bb0930c211..5ade07d0326a 100755 --- a/test/sharness/t0021-config.sh +++ b/test/sharness/t0021-config.sh @@ -45,8 +45,7 @@ CONFIG_SET_JSON_TEST='{ "MDNS": { "Enabled": true, "Interval": 10 - }, - "Routing": "dht" + } }' test_profile_apply_revert() {