feat: add "autoclient" routing type
This routing type is the same as "auto" but it creates the DHT in "client" mode and hence does not start a DHT server.
Gus Eggert committed
Mar 8, 2023 at 16:26 UTC
0d94bac30c2060de3ffaab00954df20be3723e4b
7 files changed
+88
-33
cmd/ipfs/daemon.go
+35
-26
@@ -45,32 +45,33 @@ import (
45
)
46
47
const (
48
- adjustFDLimitKwd = "manage-fdlimit"
49
- enableGCKwd = "enable-gc"
50
- initOptionKwd = "init"
51
- initConfigOptionKwd = "init-config"
52
- initProfileOptionKwd = "init-profile"
53
- ipfsMountKwd = "mount-ipfs"
54
- ipnsMountKwd = "mount-ipns"
55
- migrateKwd = "migrate"
56
- mountKwd = "mount"
57
- offlineKwd = "offline" // global option
58
- routingOptionKwd = "routing"
59
- routingOptionSupernodeKwd = "supernode"
60
- routingOptionDHTClientKwd = "dhtclient"
61
- routingOptionDHTKwd = "dht"
62
- routingOptionDHTServerKwd = "dhtserver"
63
- routingOptionNoneKwd = "none"
64
- routingOptionCustomKwd = "custom"
65
- routingOptionDefaultKwd = "default"
66
- routingOptionAutoKwd = "auto"
67
- unencryptTransportKwd = "disable-transport-encryption"
68
- unrestrictedAPIAccessKwd = "unrestricted-api"
69
- writableKwd = "writable"
70
- enablePubSubKwd = "enable-pubsub-experiment"
71
- enableIPNSPubSubKwd = "enable-namesys-pubsub"
72
- enableMultiplexKwd = "enable-mplex-experiment"
73
- agentVersionSuffix = "agent-version-suffix"
48
+ adjustFDLimitKwd = "manage-fdlimit"
49
+ enableGCKwd = "enable-gc"
50
+ initOptionKwd = "init"
51
+ initConfigOptionKwd = "init-config"
52
+ initProfileOptionKwd = "init-profile"
53
+ ipfsMountKwd = "mount-ipfs"
54
+ ipnsMountKwd = "mount-ipns"
55
+ migrateKwd = "migrate"
56
+ mountKwd = "mount"
57
+ offlineKwd = "offline" // global option
58
+ routingOptionKwd = "routing"
59
+ routingOptionSupernodeKwd = "supernode"
60
+ routingOptionDHTClientKwd = "dhtclient"
61
+ routingOptionDHTKwd = "dht"
62
+ routingOptionDHTServerKwd = "dhtserver"
63
+ routingOptionNoneKwd = "none"
64
+ routingOptionCustomKwd = "custom"
65
+ routingOptionDefaultKwd = "default"
66
+ routingOptionAutoKwd = "auto"
67
+ routingOptionAutoClientKwd = "autoclient"
68
+ unencryptTransportKwd = "disable-transport-encryption"
69
+ unrestrictedAPIAccessKwd = "unrestricted-api"
70
+ writableKwd = "writable"
71
+ enablePubSubKwd = "enable-pubsub-experiment"
72
+ enableIPNSPubSubKwd = "enable-namesys-pubsub"
73
+ enableMultiplexKwd = "enable-mplex-experiment"
74
+ agentVersionSuffix = "agent-version-suffix"
75
// apiAddrKwd = "address-api"
76
// swarmAddrKwd = "address-swarm"
77
)
@@ -416,6 +417,14 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
417
cfg.Identity.PeerID,
418
cfg.Addresses.Swarm,
419
cfg.Identity.PrivKey,
420
+ libp2p.DHTOption,
421
+ )
422
+ case routingOptionAutoClientKwd:
423
+ ncfg.Routing = libp2p.ConstructDefaultRouting(
424
+ cfg.Identity.PeerID,
425
+ cfg.Addresses.Swarm,
426
+ cfg.Identity.PrivKey,
427
+ libp2p.DHTClientOption,
428
)
429
case routingOptionDHTClientKwd:
430
ncfg.Routing = libp2p.DHTClientOption
config/routing.go
+1
-1
@@ -10,7 +10,7 @@ import (
10
type Routing struct {
11
// Type sets default daemon routing mode.
12
//
13
- // Can be one of "auto", "dht", "dhtclient", "dhtserver", "none", or "custom".
13
+ // Can be one of "auto", "autoclient", "dht", "dhtclient", "dhtserver", "none", or "custom".
14
// When unset or set to "auto", DHT and implicit routers are used.
15
// When "custom" is set, user-provided Routing.Routers is used.
16
Type *OptionalString `json:",omitempty"`
core/node/libp2p/routingopt.go
+2
-3
@@ -40,7 +40,7 @@ func init() {
40
}
41
42
// ConstructDefaultRouting returns routers used when Routing.Type is unset or set to "auto"
43
-func ConstructDefaultRouting(peerID string, addrs []string, privKey string) func(
43
+func ConstructDefaultRouting(peerID string, addrs []string, privKey string, routingOpt RoutingOption) func(
44
ctx context.Context,
45
host host.Host,
46
dstore datastore.Batching,
@@ -58,8 +58,7 @@ func ConstructDefaultRouting(peerID string, addrs []string, privKey string) func
58
// Different trade-offs can be made by setting Routing.Type = "custom" with own Routing.Routers
59
var routers []*routinghelpers.ParallelRouter
60
61
- // Run the default DHT routing (same as Routing.Type = "dht")
62
- dhtRouting, err := DHTOption(ctx, host, dstore, validator, bootstrapPeers...)
61
+ dhtRouting, err := routingOpt(ctx, host, dstore, validator, bootstrapPeers...)
62
if err != nil {
63
return nil, err
64
}
docs/changelogs/v0.19.md
+6
@@ -7,6 +7,7 @@
7
- [Overview](#overview)
8
- [🔦 Highlights](#-highlights)
9
- [Improving the libp2p resource management integration](#improving-the-libp2p-resource-management-integration)
10
+ - [Addition of "autoclient" router type](#addition-of-autoclient-router-type)
11
- [📝 Changelog](#-changelog)
12
- [👨👩👧👦 Contributors](#-contributors)
13
@@ -22,6 +23,11 @@ and [0.18.1](https://github.com/ipfs/kubo/blob/master/docs/changelogs/v0.18.md#i
23
- Note: we don't expect most users to need these capablities, but they are there if so.
24
1. [Doc updates](https://github.com/ipfs/kubo/blob/master/docs/libp2p-resource-management.md).
25
26
+#### Addition of "autoclient" router type
27
+A new routing type "autoclient" has been added. This mode is similar to "auto", in that it is a hybrid of content routers (including Kademlia and HTTP routers), but it does not run a DHT server. This is similar to the difference between "dhtclient" and "dht" router types.
28
+
29
+See the [Routing.Type documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#routingtype) for more information.
30
+
31
### 📝 Changelog
32
33
### 👨👩👧👦 Contributors
docs/config.md
+4
-2
@@ -1349,11 +1349,13 @@ Contains options for content, peer, and IPNS routing mechanisms.
1349
1350
### `Routing.Type`
1351
1352
-There are multiple routing options: "auto", "none", "dht" and "custom".
1352
+There are multiple routing options: "auto", "autoclient", "none", "dht", "dhtclient", and "custom".
1353
1354
* **DEFAULT:** If unset, or set to "auto", your node will use the IPFS DHT
1355
and parallel HTTP routers listed below for additional speed.
1356
1357
+* If set to "autoclient", your node will behave as in "auto" but without running a DHT server.
1358
+
1359
* If set to "none", your node will use _no_ routing system. You'll have to
1360
explicitly connect to peers that have the content you're looking for.
1361
@@ -1379,7 +1381,7 @@ To force a specific DHT-only mode, client or server, set `Routing.Type` to
1381
`dhtclient` or `dhtserver` respectively. Please do not set this to `dhtserver`
1382
unless you're sure your node is reachable from the public network.
1383
1382
-When `Routing.Type` is set to `auto` your node will accelerate some types of routing
1384
+When `Routing.Type` is set to `auto` or `autoclient` your node will accelerate some types of routing
1385
by leveraging HTTP endpoints compatible with [IPIP-337](https://github.com/ipfs/specs/pull/337)
1386
in addition to the IPFS DHT.
1387
By default, an instance of [IPNI](https://github.com/ipni/specs/blob/main/IPNI.md#readme)
test/cli/delegated_routing_http_test.go
+1
-1
@@ -94,7 +94,7 @@ func TestHTTPDelegatedRouting(t *testing.T) {
94
}))
95
t.Cleanup(server.Close)
96
97
- node.IPFS("config", "Routing.Type", "--json", `"custom"`)
97
+ node.IPFS("config", "Routing.Type", "custom")
98
node.IPFS("config", "Routing.Routers.TestDelegatedRouter", "--json", ToJSONStr(JSONObj{
99
"Type": "http",
100
"Parameters": JSONObj{
test/cli/dht_autoclient_test.go
new
+39
@@ -0,0 +1,39 @@
1
+package cli
2
+
3
+import (
4
+ "bytes"
5
+ "testing"
6
+
7
+ "github.com/ipfs/kubo/test/cli/harness"
8
+ "github.com/ipfs/kubo/test/cli/testutils"
9
+ "github.com/stretchr/testify/assert"
10
+)
11
+
12
+func TestDHTAutoclient(t *testing.T) {
13
+ t.Parallel()
14
+ nodes := harness.NewT(t).NewNodes(10).Init()
15
+ harness.Nodes(nodes[8:]).ForEachPar(func(node *harness.Node) {
16
+ node.IPFS("config", "Routing.Type", "autoclient")
17
+ })
18
+ nodes.StartDaemons().Connect()
19
+
20
+ t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) {
21
+ t.Parallel()
22
+ randomBytes := testutils.RandomBytes(1000)
23
+ hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes))
24
+
25
+ res := nodes[9].IPFS("cat", hash)
26
+ assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
27
+ })
28
+
29
+ t.Run("file added on node in server mode is retrievable from all nodes", func(t *testing.T) {
30
+ t.Parallel()
31
+ randomBytes := testutils.RandomBytes(1000)
32
+ hash := nodes[0].IPFSAdd(bytes.NewReader(randomBytes))
33
+
34
+ for i := 0; i < 10; i++ {
35
+ res := nodes[i].IPFS("cat", hash)
36
+ assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
37
+ }
38
+ })
39
+}