mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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.
This commit is contained in:
parent
840eaa7599
commit
2510f06364
@ -45,32 +45,33 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
adjustFDLimitKwd = "manage-fdlimit"
|
||||
enableGCKwd = "enable-gc"
|
||||
initOptionKwd = "init"
|
||||
initConfigOptionKwd = "init-config"
|
||||
initProfileOptionKwd = "init-profile"
|
||||
ipfsMountKwd = "mount-ipfs"
|
||||
ipnsMountKwd = "mount-ipns"
|
||||
migrateKwd = "migrate"
|
||||
mountKwd = "mount"
|
||||
offlineKwd = "offline" // global option
|
||||
routingOptionKwd = "routing"
|
||||
routingOptionSupernodeKwd = "supernode"
|
||||
routingOptionDHTClientKwd = "dhtclient"
|
||||
routingOptionDHTKwd = "dht"
|
||||
routingOptionDHTServerKwd = "dhtserver"
|
||||
routingOptionNoneKwd = "none"
|
||||
routingOptionCustomKwd = "custom"
|
||||
routingOptionDefaultKwd = "default"
|
||||
routingOptionAutoKwd = "auto"
|
||||
unencryptTransportKwd = "disable-transport-encryption"
|
||||
unrestrictedAPIAccessKwd = "unrestricted-api"
|
||||
writableKwd = "writable"
|
||||
enablePubSubKwd = "enable-pubsub-experiment"
|
||||
enableIPNSPubSubKwd = "enable-namesys-pubsub"
|
||||
enableMultiplexKwd = "enable-mplex-experiment"
|
||||
agentVersionSuffix = "agent-version-suffix"
|
||||
adjustFDLimitKwd = "manage-fdlimit"
|
||||
enableGCKwd = "enable-gc"
|
||||
initOptionKwd = "init"
|
||||
initConfigOptionKwd = "init-config"
|
||||
initProfileOptionKwd = "init-profile"
|
||||
ipfsMountKwd = "mount-ipfs"
|
||||
ipnsMountKwd = "mount-ipns"
|
||||
migrateKwd = "migrate"
|
||||
mountKwd = "mount"
|
||||
offlineKwd = "offline" // global option
|
||||
routingOptionKwd = "routing"
|
||||
routingOptionSupernodeKwd = "supernode"
|
||||
routingOptionDHTClientKwd = "dhtclient"
|
||||
routingOptionDHTKwd = "dht"
|
||||
routingOptionDHTServerKwd = "dhtserver"
|
||||
routingOptionNoneKwd = "none"
|
||||
routingOptionCustomKwd = "custom"
|
||||
routingOptionDefaultKwd = "default"
|
||||
routingOptionAutoKwd = "auto"
|
||||
routingOptionAutoClientKwd = "autoclient"
|
||||
unencryptTransportKwd = "disable-transport-encryption"
|
||||
unrestrictedAPIAccessKwd = "unrestricted-api"
|
||||
writableKwd = "writable"
|
||||
enablePubSubKwd = "enable-pubsub-experiment"
|
||||
enableIPNSPubSubKwd = "enable-namesys-pubsub"
|
||||
enableMultiplexKwd = "enable-mplex-experiment"
|
||||
agentVersionSuffix = "agent-version-suffix"
|
||||
// apiAddrKwd = "address-api"
|
||||
// swarmAddrKwd = "address-swarm"
|
||||
)
|
||||
@ -416,6 +417,14 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
|
||||
cfg.Identity.PeerID,
|
||||
cfg.Addresses.Swarm,
|
||||
cfg.Identity.PrivKey,
|
||||
libp2p.DHTOption,
|
||||
)
|
||||
case routingOptionAutoClientKwd:
|
||||
ncfg.Routing = libp2p.ConstructDefaultRouting(
|
||||
cfg.Identity.PeerID,
|
||||
cfg.Addresses.Swarm,
|
||||
cfg.Identity.PrivKey,
|
||||
libp2p.DHTClientOption,
|
||||
)
|
||||
case routingOptionDHTClientKwd:
|
||||
ncfg.Routing = libp2p.DHTClientOption
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
type Routing struct {
|
||||
// Type sets default daemon routing mode.
|
||||
//
|
||||
// Can be one of "auto", "dht", "dhtclient", "dhtserver", "none", or "custom".
|
||||
// Can be one of "auto", "autoclient", "dht", "dhtclient", "dhtserver", "none", or "custom".
|
||||
// When unset or set to "auto", DHT and implicit routers are used.
|
||||
// When "custom" is set, user-provided Routing.Routers is used.
|
||||
Type *OptionalString `json:",omitempty"`
|
||||
|
||||
@ -40,7 +40,7 @@ func init() {
|
||||
}
|
||||
|
||||
// ConstructDefaultRouting returns routers used when Routing.Type is unset or set to "auto"
|
||||
func ConstructDefaultRouting(peerID string, addrs []string, privKey string) func(
|
||||
func ConstructDefaultRouting(peerID string, addrs []string, privKey string, routingOpt RoutingOption) func(
|
||||
ctx context.Context,
|
||||
host host.Host,
|
||||
dstore datastore.Batching,
|
||||
@ -58,8 +58,7 @@ func ConstructDefaultRouting(peerID string, addrs []string, privKey string) func
|
||||
// Different trade-offs can be made by setting Routing.Type = "custom" with own Routing.Routers
|
||||
var routers []*routinghelpers.ParallelRouter
|
||||
|
||||
// Run the default DHT routing (same as Routing.Type = "dht")
|
||||
dhtRouting, err := DHTOption(ctx, host, dstore, validator, bootstrapPeers...)
|
||||
dhtRouting, err := routingOpt(ctx, host, dstore, validator, bootstrapPeers...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
- [Overview](#overview)
|
||||
- [🔦 Highlights](#-highlights)
|
||||
- [Improving the libp2p resource management integration](#improving-the-libp2p-resource-management-integration)
|
||||
- [Addition of "autoclient" router type](#addition-of-autoclient-router-type)
|
||||
- [📝 Changelog](#-changelog)
|
||||
- [👨👩👧👦 Contributors](#-contributors)
|
||||
|
||||
@ -22,6 +23,11 @@ and [0.18.1](https://github.com/ipfs/kubo/blob/master/docs/changelogs/v0.18.md#i
|
||||
- Note: we don't expect most users to need these capablities, but they are there if so.
|
||||
1. [Doc updates](https://github.com/ipfs/kubo/blob/master/docs/libp2p-resource-management.md).
|
||||
|
||||
#### Addition of "autoclient" router type
|
||||
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.
|
||||
|
||||
See the [Routing.Type documentation](https://github.com/ipfs/kubo/blob/master/docs/config.md#routingtype) for more information.
|
||||
|
||||
### 📝 Changelog
|
||||
|
||||
### 👨👩👧👦 Contributors
|
||||
|
||||
@ -1349,11 +1349,13 @@ Contains options for content, peer, and IPNS routing mechanisms.
|
||||
|
||||
### `Routing.Type`
|
||||
|
||||
There are multiple routing options: "auto", "none", "dht" and "custom".
|
||||
There are multiple routing options: "auto", "autoclient", "none", "dht", "dhtclient", and "custom".
|
||||
|
||||
* **DEFAULT:** If unset, or set to "auto", your node will use the IPFS DHT
|
||||
and parallel HTTP routers listed below for additional speed.
|
||||
|
||||
* If set to "autoclient", your node will behave as in "auto" but without running a DHT server.
|
||||
|
||||
* If set to "none", your node will use _no_ routing system. You'll have to
|
||||
explicitly connect to peers that have the content you're looking for.
|
||||
|
||||
@ -1379,7 +1381,7 @@ To force a specific DHT-only mode, client or server, set `Routing.Type` to
|
||||
`dhtclient` or `dhtserver` respectively. Please do not set this to `dhtserver`
|
||||
unless you're sure your node is reachable from the public network.
|
||||
|
||||
When `Routing.Type` is set to `auto` your node will accelerate some types of routing
|
||||
When `Routing.Type` is set to `auto` or `autoclient` your node will accelerate some types of routing
|
||||
by leveraging HTTP endpoints compatible with [IPIP-337](https://github.com/ipfs/specs/pull/337)
|
||||
in addition to the IPFS DHT.
|
||||
By default, an instance of [IPNI](https://github.com/ipni/specs/blob/main/IPNI.md#readme)
|
||||
|
||||
@ -94,7 +94,7 @@ func TestHTTPDelegatedRouting(t *testing.T) {
|
||||
}))
|
||||
t.Cleanup(server.Close)
|
||||
|
||||
node.IPFS("config", "Routing.Type", "--json", `"custom"`)
|
||||
node.IPFS("config", "Routing.Type", "custom")
|
||||
node.IPFS("config", "Routing.Routers.TestDelegatedRouter", "--json", ToJSONStr(JSONObj{
|
||||
"Type": "http",
|
||||
"Parameters": JSONObj{
|
||||
|
||||
39
test/cli/dht_autoclient_test.go
Normal file
39
test/cli/dht_autoclient_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/kubo/test/cli/harness"
|
||||
"github.com/ipfs/kubo/test/cli/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDHTAutoclient(t *testing.T) {
|
||||
t.Parallel()
|
||||
nodes := harness.NewT(t).NewNodes(10).Init()
|
||||
harness.Nodes(nodes[8:]).ForEachPar(func(node *harness.Node) {
|
||||
node.IPFS("config", "Routing.Type", "autoclient")
|
||||
})
|
||||
nodes.StartDaemons().Connect()
|
||||
|
||||
t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
randomBytes := testutils.RandomBytes(1000)
|
||||
hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes))
|
||||
|
||||
res := nodes[9].IPFS("cat", hash)
|
||||
assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
|
||||
})
|
||||
|
||||
t.Run("file added on node in server mode is retrievable from all nodes", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
randomBytes := testutils.RandomBytes(1000)
|
||||
hash := nodes[0].IPFSAdd(bytes.NewReader(randomBytes))
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
res := nodes[i].IPFS("cat", hash)
|
||||
assert.Equal(t, randomBytes, []byte(res.Stdout.Trimmed()))
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user