Skip to content

Commit e9d2817

Browse files
committed
daemon: config option for routing
License: MIT Signed-off-by: Łukasz Magiera <[email protected]>
1 parent b6eb085 commit e9d2817

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

cmd/ipfs/daemon.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
routingOptionDHTClientKwd = "dhtclient"
4444
routingOptionDHTKwd = "dht"
4545
routingOptionNoneKwd = "none"
46+
routingOptionDefaultKwd = "default"
4647
unencryptTransportKwd = "disable-transport-encryption"
4748
unrestrictedApiAccessKwd = "unrestricted-api"
4849
writableKwd = "writable"
@@ -146,7 +147,7 @@ Headers.
146147

147148
Options: []cmds.Option{
148149
cmds.BoolOption(initOptionKwd, "Initialize ipfs with default settings if not already initialized").Default(false),
149-
cmds.StringOption(routingOptionKwd, "Overrides the routing option").Default("dht"),
150+
cmds.StringOption(routingOptionKwd, "Overrides the routing option").Default("default"),
150151
cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem").Default(false),
151152
cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)").Default(false),
152153
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
@@ -302,6 +303,18 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
302303
res.SetError(err, cmds.ErrNormal)
303304
return
304305
}
306+
if routingOption == routingOptionDefaultKwd {
307+
cfg, err := repo.Config()
308+
if err != nil {
309+
res.SetError(err, cmds.ErrNormal)
310+
return
311+
}
312+
313+
routingOption = cfg.Discovery.Routing
314+
if routingOption == "" {
315+
routingOption = routingOptionDHTKwd
316+
}
317+
}
305318
switch routingOption {
306319
case routingOptionSupernodeKwd:
307320
servers, err := cfg.SupernodeRouting.ServerIPFSAddrs()

docs/config.md

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ Default: `true`
121121
- `Interval`
122122
A number of seconds to wait between discovery checks.
123123

124+
- `Routing`
125+
Content routing mode. Can be overridden with daemon `--routing` flag.
126+
Valid modes are:
127+
- `dht` (default)
128+
- `dhtclient`
129+
- `none`
130+
- `supernode` (deprecated)
124131

125132
## `Gateway`
126133
Options for the HTTP gateway.

repo/config/discovery.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package config
22

33
type Discovery struct {
4-
MDNS MDNS
4+
MDNS MDNS
5+
6+
//Routing sets default daemon routing mode.
7+
Routing string
58
}
69

710
type MDNS struct {

repo/config/init.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
4545
Datastore: datastore,
4646
Bootstrap: BootstrapPeerStrings(bootstrapPeers),
4747
Identity: identity,
48-
Discovery: Discovery{MDNS{
49-
Enabled: true,
50-
Interval: 10,
51-
}},
48+
Discovery: Discovery{
49+
MDNS: MDNS{
50+
Enabled: true,
51+
Interval: 10,
52+
},
53+
Routing: "dht",
54+
},
5255

5356
// setup the node mount points.
5457
Mounts: Mounts{

0 commit comments

Comments
 (0)