Skip to content

Commit

Permalink
daemon: config option for routing
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Jan 22, 2018
1 parent 2140aa9 commit c66be07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
15 changes: 14 additions & 1 deletion cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
routingOptionDHTClientKwd = "dhtclient"
routingOptionDHTKwd = "dht"
routingOptionNoneKwd = "none"
routingOptionDefaultKwd = "default"
unencryptTransportKwd = "disable-transport-encryption"
unrestrictedApiAccessKwd = "unrestricted-api"
writableKwd = "writable"
Expand Down Expand Up @@ -147,7 +148,7 @@ Headers.

Options: []cmdkit.Option{
cmdkit.BoolOption(initOptionKwd, "Initialize ipfs with default settings if not already initialized"),
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 @@ -304,6 +305,18 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
re.SetError(err, cmdkit.ErrNormal)
return
}
if routingOption == routingOptionDefaultKwd {
cfg, err := repo.Config()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

routingOption = cfg.Discovery.Routing
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
7 changes: 7 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ 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`
- `supernode` (deprecated)

## `Gateway`
Options for the HTTP gateway.
Expand Down
5 changes: 4 additions & 1 deletion repo/config/discovery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package config

type Discovery struct {
MDNS MDNS
MDNS MDNS

//Routing sets default daemon routing mode.
Routing string
}

type MDNS struct {
Expand Down
11 changes: 7 additions & 4 deletions repo/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ 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: "dht",
},

// setup the node mount points.
Mounts: Mounts{
Expand Down

0 comments on commit c66be07

Please sign in to comment.