@cryptotaxi247 / kubo / commits / 35da08859

daemon: config option for routing

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Aug 20, 2017 at 16:24 UTC 35da08859a91d298355543e2f3b0d924fcbb390b
4 files changed +36 -5
cmd/ipfs/daemon.go
+18
@@ -45,6 +45,7 @@ const (
45 routingOptionDHTClientKwd = "dhtclient"
46 routingOptionDHTKwd = "dht"
47 routingOptionNoneKwd = "none"
48 + routingOptionDefaultKwd = "default"
49 unencryptTransportKwd = "disable-transport-encryption"
50 unrestrictedApiAccessKwd = "unrestricted-api"
51 writableKwd = "writable"
@@ -151,6 +152,7 @@ Headers.
152 cmdkit.BoolOption(initOptionKwd, "Initialize ipfs with default settings if not already initialized"),
153 cmdkit.StringOption(initProfileOptionKwd, "Configuration profiles to apply for --init. See ipfs init --help for more"),
154 cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault("dht"),
155 + cmdkit.StringOption(routingOptionKwd, "Overrides the routing option").WithDefault("default"),
156 cmdkit.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
157 cmdkit.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
158 cmdkit.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting."),
@@ -300,6 +302,22 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
302 }
303
304 routingOption, _ := req.Options[routingOptionKwd].(string)
305 + if err != nil {
306 + re.SetError(err, cmdkit.ErrNormal)
307 + return
308 + }
309 + if routingOption == routingOptionDefaultKwd {
310 + cfg, err := repo.Config()
311 + if err != nil {
312 + re.SetError(err, cmdkit.ErrNormal)
313 + return
314 + }
315 +
316 + routingOption = cfg.Discovery.Routing
317 + if routingOption == "" {
318 + routingOption = routingOptionDHTKwd
319 + }
320 + }
321 switch routingOption {
322 case routingOptionSupernodeKwd:
323 re.SetError(errors.New("supernode routing was never fully implemented and has been removed"), cmdkit.ErrNormal)
docs/config.md
+7
@@ -197,6 +197,13 @@ Default: `true`
197 - `Interval`
198 A number of seconds to wait between discovery checks.
199
200 +- `Routing`
201 +Content routing mode. Can be overridden with daemon `--routing` flag.
202 +Valid modes are:
203 + - `dht` (default)
204 + - `dhtclient`
205 + - `none`
206 + - `supernode` (deprecated)
207
208 ## `Gateway`
209 Options for the HTTP gateway.
repo/config/discovery.go
+4 -1
@@ -1,7 +1,10 @@
1 package config
2
3 type Discovery struct {
4 - MDNS MDNS
4 + MDNS MDNS
5 +
6 + //Routing sets default daemon routing mode.
7 + Routing string
8 }
9
10 type MDNS struct {
repo/config/init.go
+7 -4
@@ -38,10 +38,13 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
38 Datastore: datastore,
39 Bootstrap: BootstrapPeerStrings(bootstrapPeers),
40 Identity: identity,
41 - Discovery: Discovery{MDNS{
42 - Enabled: true,
43 - Interval: 10,
44 - }},
41 + Discovery: Discovery{
42 + MDNS: MDNS{
43 + Enabled: true,
44 + Interval: 10,
45 + },
46 + Routing: "dht",
47 + },
48
49 // setup the node mount points.
50 Mounts: Mounts{