Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add low power init profile #4154

Merged
merged 3 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
routingOptionDHTClientKwd = "dhtclient"
routingOptionDHTKwd = "dht"
routingOptionNoneKwd = "none"
routingOptionDefaultKwd = "default"
unencryptTransportKwd = "disable-transport-encryption"
unrestrictedApiAccessKwd = "unrestricted-api"
writableKwd = "writable"
Expand Down Expand Up @@ -150,7 +151,7 @@ Headers.
Options: []cmdkit.Option{
cmdkit.BoolOption(initOptionKwd, "Initialize ipfs with default settings if not already initialized"),
cmdkit.StringOption(initProfileOptionKwd, "Configuration profiles to apply for --init. See ipfs init --help for more"),
cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault("dht"),
cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault("default"),
cmdkit.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
cmdkit.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
cmdkit.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
Expand Down Expand Up @@ -300,6 +301,22 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}

routingOption, _ := req.Options[routingOptionKwd].(string)
if err != nil {
re.SetError(err, cmdkit.ErrNormal)
return
}
if routingOption == routingOptionDefaultKwd {
cfg, err := repo.Config()
if err != nil {
re.SetError(err, cmdkit.ErrNormal)
return
}

routingOption = cfg.Routing.Type
if routingOption == "" {
routingOption = routingOptionDHTKwd
}
}
switch routingOption {
case routingOptionSupernodeKwd:
re.SetError(errors.New("supernode routing was never fully implemented and has been removed"), cmdkit.ErrNormal)
Expand Down
3 changes: 3 additions & 0 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Available profiles:
running IPFS on machines with public IPv4 addresses.
'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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe 'laptop'? Honestly, laptop users should use this (less problems with random WiFis, fewer ephemeral DHT nodes, etc. Alternatively, we could have a separate laptop mode that occasionally reprovides pin roots.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the second option, I meant this setting for mobile devices (Android phones, etc.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"May affect node functionality" should be better described to tell what functionality it would affect. Seemingly, it seems to run the dht in client mode and also set really low ConnMgr values, meaning it would probably take longer to find and download content. Would be nice to add that to the description.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
Expand Down
6 changes: 6 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ Default: `true`
- `Interval`
A number of seconds to wait between discovery checks.

- `Routing`
Content routing mode. Can be overridden with daemon `--routing` flag.
Valid modes are:
- `dht` (default)
- `dhtclient`
- `none`

## `Gateway`
Options for the HTTP gateway.
Expand Down
1 change: 1 addition & 0 deletions repo/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions repo/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
Datastore: datastore,
Bootstrap: BootstrapPeerStrings(bootstrapPeers),
Identity: identity,
Discovery: Discovery{MDNS{
Enabled: true,
Interval: 10,
}},
Discovery: Discovery{
MDNS: MDNS{
Enabled: true,
Interval: 10,
},
},

Routing: Routing{
Type: "dht",
},

// setup the node mount points.
Mounts: Mounts{
Expand Down
11 changes: 11 additions & 0 deletions repo/config/profile.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -73,6 +75,15 @@ var Profiles = map[string]Transformer{
c.Datastore.Spec = DefaultDatastoreConfig().Spec
return nil
},
"lowpower": func(c *Config) error {
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
},
}

func appendSingle(a []string, b []string) []string {
Expand Down
7 changes: 7 additions & 0 deletions repo/config/routing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

// Routing defines configuration options for libp2p routing
type Routing struct {
// Type sets default daemon routing mode.
Type string
}
14 changes: 14 additions & 0 deletions test/sharness/t0020-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ test_expect_success "clean up ipfs dir" '
rm -rf "$IPFS_PATH"
'

test_expect_success "'ipfs init --profile=lowpower' succeeds" '
BITS="1024" &&
ipfs init --bits="$BITS" --profile=lowpower
'

test_expect_success "'ipfs config Discovery.Routing' looks good" '
ipfs config Routing.Type > actual_config &&
test $(cat actual_config) = "dhtclient"
'

test_expect_success "clean up ipfs dir" '
rm -rf "$IPFS_PATH"
'

test_init_ipfs

test_launch_ipfs_daemon
Expand Down