feat: Routing.Type=auto (DHT+IPNI) (#9475)
This changes the default routing to use both DHT and IPNI at the same time. Closes #9454 Closes #9422 Full context: https://github.com/ipfs/kubo/issues/9454 https://github.com/ipfs/kubo/issues/9422 Co-authored-by: Steve Loeppky <biglep@protocol.ai> Co-authored-by: Gus Eggert <gus@gus.dev> Co-authored-by: Steve Loeppky <biglep@protocol.ai>
Marcin Rataj committed
Dec 8, 2022 at 23:20 UTC
70e604ff9999752a2773772b6dd14db048d28759
19 files changed
+210
-90
cmd/ipfs/daemon.go
+27
-16
@@ -30,6 +30,7 @@ import (
30
fsrepo "github.com/ipfs/kubo/repo/fsrepo"
31
"github.com/ipfs/kubo/repo/fsrepo/migrations"
32
"github.com/ipfs/kubo/repo/fsrepo/migrations/ipfsfetcher"
33
+ pnet "github.com/libp2p/go-libp2p/core/pnet"
34
sockets "github.com/libp2p/go-socket-activation"
35
36
cmds "github.com/ipfs/go-ipfs-cmds"
@@ -61,6 +62,7 @@ const (
62
routingOptionNoneKwd = "none"
63
routingOptionCustomKwd = "custom"
64
routingOptionDefaultKwd = "default"
65
+ routingOptionAutoKwd = "auto"
66
unencryptTransportKwd = "disable-transport-encryption"
67
unrestrictedAPIAccessKwd = "unrestricted-api"
68
writableKwd = "writable"
@@ -89,7 +91,7 @@ For example, to change the 'Gateway' port:
91
92
ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/8082
93
92
-The API address can be changed the same way:
94
+The RPC API address can be changed the same way:
95
96
ipfs config Addresses.API /ip4/127.0.0.1/tcp/5002
97
@@ -100,14 +102,14 @@ other computers in the network, use 0.0.0.0 as the ip address:
102
103
ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
104
103
-Be careful if you expose the API. It is a security risk, as anyone could
105
+Be careful if you expose the RPC API. It is a security risk, as anyone could
106
control your node remotely. If you need to control the node remotely,
107
make sure to protect the port as you would other services or database
108
(firewall, authenticated proxy, etc).
109
110
HTTP Headers
111
110
-ipfs supports passing arbitrary headers to the API and Gateway. You can
112
+ipfs supports passing arbitrary headers to the RPC API and Gateway. You can
113
do this by setting headers on the API.HTTPHeaders and Gateway.HTTPHeaders
114
keys:
115
@@ -141,18 +143,6 @@ environment variable:
143
144
export IPFS_PATH=/path/to/ipfsrepo
145
144
-Routing
145
-
146
-IPFS by default will use a DHT for content routing. There is an alternative
147
-that operates the DHT in a 'client only' mode that can be enabled by
148
-running the daemon as:
149
-
150
- ipfs daemon --routing=dhtclient
151
-
152
-Or you can set routing to dhtclient in the config:
153
-
154
- ipfs config Routing.Type dhtclient
155
-
146
DEPRECATION NOTICE
147
148
Previously, ipfs used an environment variable as seen below:
@@ -402,14 +392,30 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
392
393
routingOption, _ := req.Options[routingOptionKwd].(string)
394
if routingOption == routingOptionDefaultKwd {
405
- routingOption = cfg.Routing.Type
395
+ routingOption = cfg.Routing.Type.WithDefault(routingOptionAutoKwd)
396
if routingOption == "" {
397
+ routingOption = routingOptionAutoKwd
398
+ }
399
+ }
400
+
401
+ // Private setups can't leverage peers returned by default IPNIs (Routing.Type=auto)
402
+ // To avoid breaking existing setups, switch them to DHT-only.
403
+ if routingOption == routingOptionAutoKwd {
404
+ if key, _ := repo.SwarmKey(); key != nil || pnet.ForcePrivateNetwork {
405
+ log.Error("Private networking (swarm.key / LIBP2P_FORCE_PNET) does not work with public HTTP IPNIs enabled by Routing.Type=auto. Kubo will use Routing.Type=dht instead. Update config to remove this message.")
406
routingOption = routingOptionDHTKwd
407
}
408
}
409
+
410
switch routingOption {
411
case routingOptionSupernodeKwd:
412
return errors.New("supernode routing was never fully implemented and has been removed")
413
+ case routingOptionDefaultKwd, routingOptionAutoKwd:
414
+ ncfg.Routing = libp2p.ConstructDefaultRouting(
415
+ cfg.Identity.PeerID,
416
+ cfg.Addresses.Swarm,
417
+ cfg.Identity.PrivKey,
418
+ )
419
case routingOptionDHTClientKwd:
420
ncfg.Routing = libp2p.DHTClientOption
421
case routingOptionDHTKwd:
@@ -446,6 +452,11 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
452
fmt.Printf("Swarm key fingerprint: %x\n", node.PNetFingerprint)
453
}
454
455
+ if (pnet.ForcePrivateNetwork || node.PNetFingerprint != nil) && routingOption == routingOptionAutoKwd {
456
+ // This should never happen, but better safe than sorry
457
+ log.Fatal("Private network does not work with Routing.Type=auto. Update your config to Routing.Type=dht (or none, and do manual peering)")
458
+ }
459
+
460
printSwarmAddrs(node)
461
462
defer func() {
config/init.go
+1
-1
@@ -48,7 +48,7 @@ func InitWithIdentity(identity Identity) (*Config, error) {
48
},
49
50
Routing: Routing{
51
- Type: "dht",
51
+ Type: nil,
52
Methods: nil,
53
Routers: nil,
54
},
config/profile.go
+1
-1
@@ -174,7 +174,7 @@ functionality - performance of content discovery and data
174
fetching may be degraded.
175
`,
176
Transform: func(c *Config) error {
177
- c.Routing.Type = "dhtclient"
177
+ c.Routing.Type = NewOptionalString("dhtclient") // TODO: https://github.com/ipfs/kubo/issues/9480
178
c.AutoNAT.ServiceMode = AutoNATServiceDisabled
179
c.Reprovider.Interval = NewOptionalDuration(0)
180
config/reprovider.go
+5
@@ -1,5 +1,10 @@
1
package config
2
3
+import "time"
4
+
5
+const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326
6
+const DefaultReproviderStrategy = "all"
7
+
8
type Reprovider struct {
9
Interval *OptionalDuration `json:",omitempty"` // Time period to reprovide locally stored objects to the network
10
Strategy *OptionalString `json:",omitempty"` // Which keys to announce
config/routing.go
+4
-3
@@ -10,9 +10,10 @@ import (
10
type Routing struct {
11
// Type sets default daemon routing mode.
12
//
13
- // Can be one of "dht", "dhtclient", "dhtserver", "none", or "custom".
14
- // When "custom" is set, you can specify a list of Routers.
15
- Type string
13
+ // Can be one of "auto", "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"`
17
18
Routers Routers
19
config/routing_test.go
+2
-2
@@ -13,7 +13,7 @@ func TestRouterParameters(t *testing.T) {
13
sec := time.Second
14
min := time.Minute
15
r := Routing{
16
- Type: "custom",
16
+ Type: NewOptionalString("custom"),
17
Routers: map[string]RouterParser{
18
"router-dht": {Router{
19
Type: RouterTypeDHT,
@@ -113,7 +113,7 @@ func TestRouterMissingParameters(t *testing.T) {
113
require := require.New(t)
114
115
r := Routing{
116
- Type: "custom",
116
+ Type: NewOptionalString("custom"),
117
Routers: map[string]RouterParser{
118
"router-wrong-reframe": {Router{
119
Type: RouterTypeReframe,
core/core_test.go
+1
-1
@@ -221,7 +221,7 @@ func GetNode(t *testing.T, reframeURLs ...string) *IpfsNode {
221
API: []string{"/ip4/127.0.0.1/tcp/0"},
222
},
223
Routing: config.Routing{
224
- Type: "custom",
224
+ Type: config.NewOptionalString("custom"),
225
Routers: routers,
226
Methods: config.Methods{
227
config.MethodNameFindPeers: config.Method{
core/node/groups.go
+4
-4
@@ -294,8 +294,8 @@ func Online(bcfg *BuildCfg, cfg *config.Config) fx.Option {
294
OnlineProviders(
295
cfg.Experimental.StrategicProviding,
296
cfg.Experimental.AcceleratedDHTClient,
297
- cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
298
- cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
297
+ cfg.Reprovider.Strategy.WithDefault(config.DefaultReproviderStrategy),
298
+ cfg.Reprovider.Interval.WithDefault(config.DefaultReproviderInterval),
299
),
300
)
301
}
@@ -312,8 +312,8 @@ func Offline(cfg *config.Config) fx.Option {
312
OfflineProviders(
313
cfg.Experimental.StrategicProviding,
314
cfg.Experimental.AcceleratedDHTClient,
315
- cfg.Reprovider.Strategy.WithDefault(DefaultReproviderStrategy),
316
- cfg.Reprovider.Interval.WithDefault(DefaultReproviderInterval),
315
+ cfg.Reprovider.Strategy.WithDefault(config.DefaultReproviderStrategy),
316
+ cfg.Reprovider.Interval.WithDefault(config.DefaultReproviderInterval),
317
),
318
)
319
}
core/node/libp2p/routingopt.go
+59
@@ -2,6 +2,7 @@ package libp2p
2
3
import (
4
"context"
5
+ "time"
6
7
"github.com/ipfs/go-datastore"
8
"github.com/ipfs/kubo/config"
@@ -23,6 +24,63 @@ type RoutingOption func(
24
...peer.AddrInfo,
25
) (routing.Routing, error)
26
27
+// Default HTTP routers used in parallel to DHT when Routing.Type = "auto"
28
+var defaultHTTPRouters = []string{
29
+ "https://cid.contact", // https://github.com/ipfs/kubo/issues/9422#issuecomment-1338142084
30
+ // TODO: add an independent router from Cloudflare
31
+}
32
+
33
+// ConstructDefaultRouting returns routers used when Routing.Type is unset or set to "auto"
34
+func ConstructDefaultRouting(peerID string, addrs []string, privKey string) func(
35
+ ctx context.Context,
36
+ host host.Host,
37
+ dstore datastore.Batching,
38
+ validator record.Validator,
39
+ bootstrapPeers ...peer.AddrInfo,
40
+) (routing.Routing, error) {
41
+ return func(
42
+ ctx context.Context,
43
+ host host.Host,
44
+ dstore datastore.Batching,
45
+ validator record.Validator,
46
+ bootstrapPeers ...peer.AddrInfo,
47
+ ) (routing.Routing, error) {
48
+ // Defined routers will be queried in parallel (optimizing for response speed)
49
+ // Different trade-offs can be made by setting Routing.Type = "custom" with own Routing.Routers
50
+ var routers []*routinghelpers.ParallelRouter
51
+
52
+ // Run the default DHT routing (same as Routing.Type = "dht")
53
+ dhtRouting, err := DHTOption(ctx, host, dstore, validator, bootstrapPeers...)
54
+ if err != nil {
55
+ return nil, err
56
+ }
57
+ routers = append(routers, &routinghelpers.ParallelRouter{
58
+ Router: dhtRouting,
59
+ IgnoreError: false,
60
+ Timeout: 5 * time.Minute, // https://github.com/ipfs/kubo/pull/9475#discussion_r1042501333
61
+ ExecuteAfter: 0,
62
+ })
63
+
64
+ // Append HTTP routers for additional speed
65
+ for _, endpoint := range defaultHTTPRouters {
66
+ httpRouter, err := irouting.ConstructHTTPRouter(endpoint, peerID, addrs, privKey)
67
+ if err != nil {
68
+ return nil, err
69
+ }
70
+ routers = append(routers, &routinghelpers.ParallelRouter{
71
+ Router: httpRouter,
72
+ IgnoreError: true, // https://github.com/ipfs/kubo/pull/9475#discussion_r1042507387
73
+ Timeout: 15 * time.Second, // 5x server value from https://github.com/ipfs/kubo/pull/9475#discussion_r1042428529
74
+ ExecuteAfter: 0,
75
+ })
76
+ }
77
+
78
+ routing := routinghelpers.NewComposableParallel(routers)
79
+ return routing, nil
80
+ }
81
+}
82
+
83
+// constructDHTRouting is used when Routing.Type = "dht"
84
func constructDHTRouting(mode dht.ModeOpt) func(
85
ctx context.Context,
86
host host.Host,
@@ -49,6 +107,7 @@ func constructDHTRouting(mode dht.ModeOpt) func(
107
}
108
}
109
110
+// ConstructDelegatedRouting is used when Routing.Type = "custom"
111
func ConstructDelegatedRouting(routers config.Routers, methods config.Methods, peerID string, addrs []string, privKey string) func(
112
ctx context.Context,
113
host host.Host,
core/node/provider.go
-3
@@ -18,9 +18,6 @@ import (
18
irouting "github.com/ipfs/kubo/routing"
19
)
20
21
-const DefaultReproviderInterval = time.Hour * 22 // https://github.com/ipfs/kubo/pull/9326
22
-const DefaultReproviderStrategy = "all"
23
-
21
// SIMPLE
22
23
// ProviderQueue creates new datastore backed provider queue
docs/changelogs/v0.18.md
+25
-1
@@ -11,6 +11,7 @@ Below is an outline of all that is in this release, so you get a sense of all th
11
- [Overview](#overview)
12
- [🔦 Highlights](#-highlights)
13
- [(DAG-)JSON and (DAG-)CBOR Response Formats on Gateways](#dag-json-and-dag-cbor-response-formats-on-gateways)
14
+ - [Content Routing](#content-routing)
15
- [Increased `Reprovider.Interval`](#increased-reproviderinterval)
16
- [Changelog](#changelog)
17
- [Contributors](#contributors)
@@ -22,7 +23,7 @@ Below is an outline of all that is in this release, so you get a sense of all th
23
Implemented [IPIP-328](https://github.com/ipfs/specs/pull/328) which adds support
24
to DAG-JSON and DAG-CBOR, as well as their non-DAG variants, to the gateway. Now,
25
CIDs that encode JSON, CBOR, DAG-JSON and DAG-CBOR objects can be retrieved, and
25
-traversed through IPLD Links.
26
+traversed thanks to the [special meaning of CBOR Tag 42](https://github.com/ipld/cid-cbor/).
27
28
HTTP clients can request JSON, CBOR, DAG-JSON, and DAG-CBOR responses by either
29
passing the query parameter `?format` or setting the `Accept` HTTP header to the
@@ -69,6 +70,24 @@ $ curl "http://127.0.0.1:8080/ipfs/$DIR_CID?format=dag-json" | jq
70
}
71
```
72
73
+
74
+#### Content Routing
75
+
76
+Content routing is the process of discovering which peers provide a piece of content. Kubo has traditionally only supported [libp2p's implementation of Kademlia DHT](https://github.com/libp2p/specs/tree/master/kad-dht) for content routing.
77
+
78
+Kubo can now bridge networks by including support for the [delegated routing HTTP API](https://github.com/ipfs/specs/pull/337). Users can compose content routers using the `Routing.Routers` config, to pick content routers with different tradeoffs than a Kademlia DHT (for example, high-performance and high-capacity centralized endpoints, dedicated Kademlia DHT nodes, routers with unique provider records, privacy-focused content routers, etc.).
79
+
80
+One example is [InterPlanetary Network Indexers](https://github.com/ipni/specs/blob/main/IPNI.md#readme), which are HTTP endpoints that cache records from both the IPFS network and other sources such as web3.storage and Filecoin. This improves not only content availability by enabling Kubo to transparently fetch content directly from Filecoin storage providers, but also improves IPFS content routing latency by an order of magnitude and decreases resource consumption.
81
+*Note:* it's possible to retrieve content stored by Filecoin Storage Providers (SPs) from Kubo if the SPs service Bitswap requests. As of this release, some SPs are advertising Bitswap. You can follow the roadmap progress for IPNIs and Bitswap in SPs [here](https://www.starmaps.app/roadmap/github.com/protocol/bedrock/issues/1).
82
+
83
+In this release, the default content router is changed from `dht` to `auto`. The `auto` router includes the IPFS DHT in addition to the [cid.contact](https://cid.contact) IPNI instance. In future releases, we plan to expand the functionality of `auto` to encompass automatic discovery of content routers, which will improve performance and content availability (for example, see [IPIP-342](https://github.com/ipfs/specs/pull/342)).
84
+
85
+Previous behavior can be restored by setting `Routing.Type` to `dht`.
86
+
87
+Alternative routing rules, including alternative IPNI endpoints, can be configured in `Routing.Routers` after setting `Routing.Type` to `custom`.
88
+
89
+Learn more in [`Routing` docs](https://github.com/ipfs/kubo/blob/master/docs/config.md#routing).
90
+
91
#### Increased `Reprovider.Interval`
92
93
Default changed from 12h to 22h.
@@ -79,6 +98,11 @@ and [kubo#9326](https://github.com/ipfs/kubo/pull/9326).
98
99
Learn more: [`Reprovider` config](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#reprovider)
100
101
+#### Lowered `ConnMgr`
102
+
103
+<!-- TODO: https://github.com/ipfs/kubo/pull/9483 -->
104
+
105
+
106
### Changelog
107
108
### Contributors
docs/config.md
+46
-47
@@ -105,11 +105,11 @@ config file at runtime.
105
- [`Reprovider.Interval`](#reproviderinterval)
106
- [`Reprovider.Strategy`](#reproviderstrategy)
107
- [`Routing`](#routing)
108
+ - [`Routing.Type`](#routingtype)
109
- [`Routing.Routers`](#routingrouters)
110
- [`Routing.Routers: Type`](#routingrouters-type)
111
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
112
- [`Routing: Methods`](#routing-methods)
112
- - [`Routing.Type`](#routingtype)
113
- [`Swarm`](#swarm)
114
- [`Swarm.AddrFilters`](#swarmaddrfilters)
115
- [`Swarm.DisableBandwidthMetrics`](#swarmdisablebandwidthmetrics)
@@ -1318,6 +1318,49 @@ Type: `string` (or unset for the default, which is "all")
1318
1319
Contains options for content, peer, and IPNS routing mechanisms.
1320
1321
+### `Routing.Type`
1322
+
1323
+There are multiple routing options: "auto", "none", "dht" and "custom".
1324
+
1325
+* **DEFAULT:** If unset, or set to "auto", your node will use the IPFS DHT
1326
+ and parallel HTTP routers listed below for additional speed.
1327
+
1328
+* If set to "none", your node will use _no_ routing system. You'll have to
1329
+ explicitly connect to peers that have the content you're looking for.
1330
+
1331
+* If set to "dht" (or "dhtclient"/"dhtserver"), your node will ONLY use the IPFS DHT (no HTTP routers).
1332
+
1333
+* If set to "custom", all default routers are disabled, and only ones defined in `Routing.Routers` will be used.
1334
+
1335
+When the DHT is enabled, it can operate in two modes: client and server.
1336
+
1337
+* In server mode, your node will query other peers for DHT records, and will
1338
+ respond to requests from other peers (both requests to store records and
1339
+ requests to retrieve records).
1340
+
1341
+* In client mode, your node will query the DHT as a client but will not respond
1342
+ to requests from other peers. This mode is less resource-intensive than server
1343
+ mode.
1344
+
1345
+When `Routing.Type` is set to `auto` or `dht`, your node will start as a DHT client, and
1346
+switch to a DHT server when and if it determines that it's reachable from the
1347
+public internet (e.g., it's not behind a firewall).
1348
+
1349
+To force a specific DHT-only mode, client or server, set `Routing.Type` to
1350
+`dhtclient` or `dhtserver` respectively. Please do not set this to `dhtserver`
1351
+unless you're sure your node is reachable from the public network.
1352
+
1353
+When `Routing.Type` is set to `auto` your node will accelerate some types of routing
1354
+by leveraging HTTP endpoints compatible with [IPIP-337](https://github.com/ipfs/specs/pull/337)
1355
+in addition to the IPFS DHT.
1356
+By default, an instance of [IPNI](https://github.com/ipni/specs/blob/main/IPNI.md#readme)
1357
+at https://cid.contact is used.
1358
+Alternative routing rules can be configured in `Routing.Routers` after setting `Routing.Type` to `custom`.
1359
+
1360
+Default: `auto` (DHT + IPNI)
1361
+
1362
+Type: `optionalString` (`null`/missing means the default)
1363
+
1364
### `Routing.Routers`
1365
1366
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**
@@ -1341,9 +1384,8 @@ It specifies the routing type that will be created.
1384
1385
Currently supported types:
1386
1344
-- `reframe` **(DEPRECATED)** (delegated routing based on the [reframe protocol](https://github.com/ipfs/specs/tree/main/reframe#readme))
1345
-- `http` simple delegated routing based on HTTP protocol. <!-- TODO add link to specs when we have them merged. -->
1346
-- `dht`
1387
+- `http` simple delegated routing based on HTTP protocol from [IPIP-337](https://github.com/ipfs/specs/pull/337)
1388
+- `dht` provides decentralized routing based on [libp2p's kad-dht](https://github.com/libp2p/specs/tree/master/kad-dht)
1389
- `parallel` and `sequential`: Helpers that can be used to run several routers sequentially or in parallel.
1390
1391
Type: `string`
@@ -1354,9 +1396,6 @@ Type: `string`
1396
1397
Parameters needed to create the specified router. Supported params per router type:
1398
1357
-Reframe **(DEPRECATED)**:
1358
- - `Endpoint` (mandatory): URL that will be used to connect to a specified router.
1359
-
1399
HTTP:
1400
- `Endpoint` (mandatory): URL that will be used to connect to a specified router.
1401
- `MaxProvideBatchSize`: This number determines the maximum amount of CIDs sent per batch. Servers might not accept more than 100 elements per batch. 100 elements by default.
@@ -1459,46 +1498,6 @@ ipfs config Routing.Methods --json '{
1498
1499
```
1500
1462
-### `Routing.Type`
1463
-
1464
-There are three core routing options: "none", "dht" (default) and "custom".
1465
-
1466
-* If set to "none", your node will use _no_ routing system. You'll have to
1467
- explicitly connect to peers that have the content you're looking for.
1468
-* If set to "dht" (or "dhtclient"/"dhtserver"), your node will use the IPFS DHT.
1469
-* If set to "custom", `Routing.Routers` will be used.
1470
-
1471
-When the DHT is enabled, it can operate in two modes: client and server.
1472
-
1473
-* In server mode, your node will query other peers for DHT records, and will
1474
- respond to requests from other peers (both requests to store records and
1475
- requests to retrieve records).
1476
-* In client mode, your node will query the DHT as a client but will not respond
1477
- to requests from other peers. This mode is less resource-intensive than server
1478
- mode.
1479
-
1480
-When `Routing.Type` is set to `dht`, your node will start as a DHT client, and
1481
-switch to a DHT server when and if it determines that it's reachable from the
1482
-public internet (e.g., it's not behind a firewall).
1483
-
1484
-To force a specific DHT mode, client or server, set `Routing.Type` to
1485
-`dhtclient` or `dhtserver` respectively. Please do not set this to `dhtserver`
1486
-unless you're sure your node is reachable from the public network.
1487
-
1488
-**Example:**
1489
-
1490
-```json
1491
-{
1492
- "Routing": {
1493
- "Type": "dhtclient"
1494
- }
1495
-}
1496
-```
1497
-
1498
-Default: `dht`
1499
-
1500
-Type: `optionalString` (`null`/missing means the default)
1501
-
1501
## `Swarm`
1502
1503
Options for configuring the swarm.
repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go
+1
-1
@@ -188,7 +188,7 @@ func initTempNode(ctx context.Context, bootstrap []string, peers []peer.AddrInfo
188
}
189
190
// configure the temporary node
191
- cfg.Routing.Type = "dhtclient"
191
+ cfg.Routing.Type = config.NewOptionalString("dhtclient")
192
193
// Disable listening for inbound connections
194
cfg.Addresses.Gateway = []string{}
routing/delegated.go
+16
@@ -157,6 +157,22 @@ type ExtraHTTPParams struct {
157
PrivKeyB64 string
158
}
159
160
+func ConstructHTTPRouter(endpoint string, peerID string, addrs []string, privKey string) (routing.Routing, error) {
161
+ return httpRoutingFromConfig(
162
+ config.Router{
163
+ Type: "http",
164
+ Parameters: &config.HTTPRouterParams{
165
+ Endpoint: endpoint,
166
+ },
167
+ },
168
+ &ExtraHTTPParams{
169
+ PeerID: peerID,
170
+ Addrs: addrs,
171
+ PrivKeyB64: privKey,
172
+ },
173
+ )
174
+}
175
+
176
func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (routing.Routing, error) {
177
params := conf.Parameters.(*config.HTTPRouterParams)
178
if params.Endpoint == "" {
test/sharness/t0041-ping.sh
+1
-1
@@ -27,7 +27,7 @@ test_expect_success "test ping other" '
27
28
test_expect_success "test ping unreachable peer" '
29
printf "Looking up peer %s\n" "$BAD_PEER" > bad_ping_exp &&
30
- printf "PING QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJx.\nPing error: routing: not found\nError: ping failed\n" >> bad_ping_exp &&
30
+ printf "PING QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJx.\nPing error: no addresses\nError: ping failed\n" >> bad_ping_exp &&
31
! ipfsi 0 ping -n2 -- "$BAD_PEER" > bad_ping_actual 2>&1 &&
32
test_cmp bad_ping_exp bad_ping_actual
33
'
test/sharness/t0170-legacy-dht.sh
+4
@@ -13,6 +13,10 @@ test_dht() {
13
iptb testbed create -type localipfs -count $NUM_NODES -init
14
'
15
16
+ test_expect_success 'DHT-only routing' '
17
+ iptb run -- ipfs config Routing.Type dht
18
+ '
19
+
20
startup_cluster $NUM_NODES $@
21
22
test_expect_success 'peer ids' '
test/sharness/t0170-routing-dht.sh
+5
-1
@@ -2,7 +2,7 @@
2
3
# This file does the same tests as t0170-dht.sh but uses 'routing' commands instead
4
# (only exception is query, which lives only under dht)
5
-test_description="Test routing command"
5
+test_description="Test routing command for DHT queries"
6
7
. lib/test-lib.sh
8
@@ -14,6 +14,10 @@ test_dht() {
14
iptb testbed create -type localipfs -count $NUM_NODES -init
15
'
16
17
+ test_expect_success 'DHT-only routing' '
18
+ iptb run -- ipfs config Routing.Type dht
19
+ '
20
+
21
startup_cluster $NUM_NODES $@
22
23
test_expect_success 'peer ids' '
test/sharness/t0175-reprovider.sh
+7
-7
@@ -34,7 +34,7 @@ reprovide() {
34
init_strategy 'all'
35
36
test_expect_success 'add test object' '
37
- HASH_0=$(echo "foo" | ipfsi 0 add -q --local)
37
+ HASH_0=$(date +"%FT%T.%N%z" | ipfsi 0 add -q --local)
38
'
39
40
findprovs_empty '$HASH_0'
@@ -49,8 +49,8 @@ test_expect_success 'Stop iptb' '
49
init_strategy 'pinned'
50
51
test_expect_success 'prepare test files' '
52
- echo foo > f1 &&
53
- echo bar > f2
52
+ date +"%FT%T.%N%z" > f1 &&
53
+ date +"%FT%T.%N%z" > f2
54
'
55
56
test_expect_success 'add test objects' '
@@ -77,9 +77,9 @@ test_expect_success 'Stop iptb' '
77
init_strategy 'roots'
78
79
test_expect_success 'prepare test files' '
80
- echo foo > f1 &&
81
- echo bar > f2 &&
82
- echo baz > f3
80
+ date +"%FT%T.%N%z" > f1 &&
81
+ date +"%FT%T.%N%z" > f2 &&
82
+ date +"%FT%T.%N%z" > f3
83
'
84
85
test_expect_success 'add test objects' '
@@ -121,7 +121,7 @@ test_expect_success 'Disable reprovider ticking' '
121
startup_cluster ${NUM_NODES}
122
123
test_expect_success 'add test object' '
124
- HASH_0=$(echo "foo" | ipfsi 0 add -q --offline)
124
+ HASH_0=$(date +"%FT%T.%N%z" | ipfsi 0 add -q --offline)
125
'
126
127
findprovs_empty '$HASH_0'
test/sharness/t0175-strategic-provider.sh
+1
-1
@@ -22,7 +22,7 @@ test_expect_success 'use strategic providing' '
22
startup_cluster ${NUM_NODES}
23
24
test_expect_success 'add test object' '
25
- HASH_0=$(echo "foo" | ipfsi 0 add -q)
25
+ HASH_0=$(date +"%FT%T.%N%z" | ipfsi 0 add -q)
26
'
27
28
findprovs_empty '$HASH_0'