From 1c090bb7f88a64e355780805227af3481ab6e255 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 ++-- cmd/ipfs/init.go | 3 ++- 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 +-- 10 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 repo/config/routing.go diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 7c427fb6642..7260c6c3930 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/cmd/ipfs/init.go b/cmd/ipfs/init.go index 8cc2df80c4a..f9578719a94 100644 --- a/cmd/ipfs/init.go +++ b/cmd/ipfs/init.go @@ -39,7 +39,8 @@ Available profiles: 'test' - Reduces external interference of IPFS daemon, this is useful when using the daemon in test environments. 'lowpower' - Reduces daemon overhead on the system. May affect node - functionality. + functionality - performance of content discovery and data fetching + may be degraded. ipfs uses a repository in the local file system. By default, the repo is located at ~/.ipfs. To change the repo location, set the $IPFS_PATH diff --git a/docs/config.md b/docs/config.md index 1e21aaf771b..e89a8fc9fd5 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 ac7c1152b77..719170baad8 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 64f7af64a68..4fb8508f00a 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 e34960c62e5..ae727981a32 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 6aa5f505380..b20382ef4ed 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 00000000000..e601cd5e8d3 --- /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 a01c0876334..9a77dbc4422 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 17bb0930c21..5ade07d0326 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() {