@cryptotaxi247 / kubo / commits / 1ef8f83a4

core/commands: remove 'ipfs dht' commands, except 'query' (#10328)

Henrique Dias committed Feb 7, 2024 at 10:56 UTC 1ef8f83a410c78aa6b048999b35c3039212e9ec5
6 files changed +8 -202
core/commands/commands_test.go
-5
@@ -117,11 +117,6 @@ func TestCommands(t *testing.T) {
117 "/dag/resolve",
118 "/dag/stat",
119 "/dht",
120 - "/dht/findpeer",
121 - "/dht/findprovs",
122 - "/dht/get",
123 - "/dht/provide",
124 - "/dht/put",
120 "/dht/query",
121 "/routing",
122 "/routing/put",
core/commands/dht.go
+1 -56
@@ -21,65 +21,10 @@ var DhtCmd = &cmds.Command{
21 },
22
23 Subcommands: map[string]*cmds.Command{
24 - "query": queryDhtCmd,
25 - "findprovs": findProvidersDhtCmd,
26 - "findpeer": findPeerDhtCmd,
27 - "get": getValueDhtCmd,
28 - "put": putValueDhtCmd,
29 - "provide": provideRefDhtCmd,
24 + "query": queryDhtCmd,
25 },
26 }
27
33 -var findProvidersDhtCmd = &cmds.Command{
34 - Helptext: findProvidersRoutingCmd.Helptext,
35 - Arguments: findProvidersRoutingCmd.Arguments,
36 - Options: findProvidersRoutingCmd.Options,
37 - Run: findProvidersRoutingCmd.Run,
38 - Encoders: findProvidersRoutingCmd.Encoders,
39 - Type: findProvidersRoutingCmd.Type,
40 - Status: cmds.Deprecated,
41 -}
42 -
43 -var findPeerDhtCmd = &cmds.Command{
44 - Helptext: findPeerRoutingCmd.Helptext,
45 - Arguments: findPeerRoutingCmd.Arguments,
46 - Options: findPeerRoutingCmd.Options,
47 - Run: findPeerRoutingCmd.Run,
48 - Encoders: findPeerRoutingCmd.Encoders,
49 - Type: findPeerRoutingCmd.Type,
50 - Status: cmds.Deprecated,
51 -}
52 -
53 -var getValueDhtCmd = &cmds.Command{
54 - Helptext: getValueRoutingCmd.Helptext,
55 - Arguments: getValueRoutingCmd.Arguments,
56 - Options: getValueRoutingCmd.Options,
57 - Run: getValueRoutingCmd.Run,
58 - Encoders: getValueRoutingCmd.Encoders,
59 - Type: getValueRoutingCmd.Type,
60 - Status: cmds.Deprecated,
61 -}
62 -
63 -var putValueDhtCmd = &cmds.Command{
64 - Helptext: putValueRoutingCmd.Helptext,
65 - Arguments: putValueRoutingCmd.Arguments,
66 - Options: putValueRoutingCmd.Options,
67 - Run: putValueRoutingCmd.Run,
68 - Encoders: putValueRoutingCmd.Encoders,
69 - Type: putValueRoutingCmd.Type,
70 - Status: cmds.Deprecated,
71 -}
72 -
73 -var provideRefDhtCmd = &cmds.Command{
74 - Helptext: provideRefRoutingCmd.Helptext,
75 - Arguments: provideRefRoutingCmd.Arguments,
76 - Options: provideRefRoutingCmd.Options,
77 - Run: provideRefRoutingCmd.Run,
78 - Encoders: provideRefRoutingCmd.Encoders,
79 - Type: provideRefRoutingCmd.Type,
80 - Status: cmds.Deprecated,
81 -}
82 -
28 // kademlia extends the routing interface with a command to get the peers closest to the target
29 type kademlia interface {
30 routing.Routing
docs/changelogs/v0.27.md
+6 -1
@@ -9,6 +9,7 @@
9 - [Gateway: support for `/api/v0` is deprecated](#gateway-support-for-apiv0-is-deprecated)
10 - [IPNS resolver cache's TTL can now be configured](#ipns-resolver-caches-ttl-can-now-be-configured)
11 - [RPC client: deprecated DHT API, added Routing API](#rpc-client-deprecated-dht-api-added-routing-api)
12 + - [Deprecated DHT commands removed from `/api/v0/dht`](#deprecated-dht-commands-removed-from-apiv0dht)
13 - [📝 Changelog](#-changelog)
14 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
15
@@ -28,10 +29,14 @@ You can now configure the upper-bound of a cached IPNS entry's Time-To-Live via
29
30 #### RPC client: deprecated DHT API, added Routing API
31
31 -The RPC client now includes a Routing API to match the available commands in `/api/v0/routing`. In addition, the DHT API has been marked as deprecated.
32 +The RPC client for GO (`kubo/client/rpc`) now includes a Routing API to match the available commands in `/api/v0/routing`. In addition, the DHT API has been marked as deprecated.
33
34 In the next version, all DHT deprecated methods will be removed from the Go RPC client.
35
36 +#### Deprecated DHT commands removed from `/api/v0/dht`
37 +
38 +All the DHT commands that were deprecated for over a year were finally removed from `/api/v0/dht`. Users should switch to modern `/api/v0/routing` which works with [both Amino DHT and Delegated Routers](https://github.com/ipfs/kubo/blob/master/docs/config.md#routing).
39 +
40 ### 📝 Changelog
41
42 ### 👨‍👩‍👧‍👦 Contributors
docs/file-transfer.md
+1 -1
@@ -85,7 +85,7 @@ In the case where node B simply cannot form a connection to node A, despite
85 knowing that it needs to, the likely culprit is a bad NAT. When node B learns
86 that it needs to connect to node A, it checks the DHT for addresses for node A,
87 and then starts trying to connect to them. We can check those addresses by
88 -running `ipfs dht findpeer <node A peerID>` on node B. This command should
88 +running `ipfs routing findpeer <node A peerID>` on node B. This command should
89 return a list of addresses for node A. If it doesn't return any addresses, then
90 you should try running the manual providing command from the previous steps.
91 Example output of addresses might look something like this:
test/cli/basic_commands_test.go
-2
@@ -154,7 +154,6 @@ func TestCommandDocsWidth(t *testing.T) {
154 "ipfs pin remote rm": true,
155 "ipfs pin remote ls": true,
156 "ipfs pin verify": true,
157 - "ipfs dht get": true,
157 "ipfs pin remote service add": true,
158 "ipfs pin update": true,
159 "ipfs pin rm": true,
@@ -167,7 +166,6 @@ func TestCommandDocsWidth(t *testing.T) {
166 "ipfs name": true,
167 "ipfs object patch append-data": true,
168 "ipfs object patch set-data": true,
170 - "ipfs dht put": true,
169 "ipfs diag profile": true,
170 "ipfs diag cmds": true,
171 "ipfs swarm addrs local": true,
test/cli/dht_legacy_test.go deleted
-137
@@ -1,137 +0,0 @@
1 -package cli
2 -
3 -import (
4 - "sort"
5 - "sync"
6 - "testing"
7 -
8 - "github.com/ipfs/kubo/test/cli/harness"
9 - "github.com/ipfs/kubo/test/cli/testutils"
10 - "github.com/libp2p/go-libp2p/core/peer"
11 - "github.com/stretchr/testify/assert"
12 - "github.com/stretchr/testify/require"
13 -)
14 -
15 -func TestLegacyDHT(t *testing.T) {
16 - t.Parallel()
17 - nodes := harness.NewT(t).NewNodes(5).Init()
18 - nodes.ForEachPar(func(node *harness.Node) {
19 - node.IPFS("config", "Routing.Type", "dht")
20 - })
21 - nodes.StartDaemons().Connect()
22 -
23 - t.Run("ipfs dht findpeer", func(t *testing.T) {
24 - t.Parallel()
25 - res := nodes[1].RunIPFS("dht", "findpeer", nodes[0].PeerID().String())
26 - assert.Equal(t, 0, res.ExitCode())
27 -
28 - swarmAddr := nodes[0].SwarmAddrsWithoutPeerIDs()[0]
29 - require.Equal(t, swarmAddr.String(), res.Stdout.Trimmed())
30 - })
31 -
32 - t.Run("ipfs dht get <key>", func(t *testing.T) {
33 - t.Parallel()
34 - hash := nodes[2].IPFSAddStr("hello world")
35 - nodes[2].IPFS("name", "publish", "/ipfs/"+hash)
36 -
37 - res := nodes[1].IPFS("dht", "get", "/ipns/"+nodes[2].PeerID().String())
38 - assert.Contains(t, res.Stdout.String(), "/ipfs/"+hash)
39 -
40 - t.Run("put round trips (#3124)", func(t *testing.T) {
41 - t.Parallel()
42 - nodes[0].WriteBytes("get_result", res.Stdout.Bytes())
43 - res := nodes[0].IPFS("dht", "put", "/ipns/"+nodes[2].PeerID().String(), "get_result")
44 - assert.Greater(t, len(res.Stdout.Lines()), 0, "should put to at least one node")
45 - })
46 -
47 - t.Run("put with bad keys fails (issue #5113, #4611)", func(t *testing.T) {
48 - t.Parallel()
49 - keys := []string{"foo", "/pk/foo", "/ipns/foo"}
50 - for _, key := range keys {
51 - key := key
52 - t.Run(key, func(t *testing.T) {
53 - t.Parallel()
54 - res := nodes[0].RunIPFS("dht", "put", key)
55 - assert.Equal(t, 1, res.ExitCode())
56 - assert.Contains(t, res.Stderr.String(), "invalid")
57 - assert.Empty(t, res.Stdout.String())
58 - })
59 - }
60 - })
61 -
62 - t.Run("get with bad keys (issue #4611)", func(t *testing.T) {
63 - for _, key := range []string{"foo", "/pk/foo"} {
64 - key := key
65 - t.Run(key, func(t *testing.T) {
66 - t.Parallel()
67 - res := nodes[0].RunIPFS("dht", "get", key)
68 - assert.Equal(t, 1, res.ExitCode())
69 - assert.Contains(t, res.Stderr.String(), "invalid")
70 - assert.Empty(t, res.Stdout.String())
71 - })
72 - }
73 - })
74 - })
75 -
76 - t.Run("ipfs dht findprovs", func(t *testing.T) {
77 - t.Parallel()
78 - hash := nodes[3].IPFSAddStr("some stuff")
79 - res := nodes[4].IPFS("dht", "findprovs", hash)
80 - assert.Equal(t, nodes[3].PeerID().String(), res.Stdout.Trimmed())
81 - })
82 -
83 - t.Run("ipfs dht query <peerID>", func(t *testing.T) {
84 - t.Parallel()
85 - t.Run("normal DHT configuration", func(t *testing.T) {
86 - t.Parallel()
87 - hash := nodes[0].IPFSAddStr("some other stuff")
88 - peerCounts := map[string]int{}
89 - peerCountsMut := sync.Mutex{}
90 - harness.Nodes(nodes).ForEachPar(func(node *harness.Node) {
91 - res := node.IPFS("dht", "query", hash)
92 - closestPeer := res.Stdout.Lines()[0]
93 - // check that it's a valid peer ID
94 - _, err := peer.Decode(closestPeer)
95 - require.NoError(t, err)
96 -
97 - peerCountsMut.Lock()
98 - peerCounts[closestPeer]++
99 - peerCountsMut.Unlock()
100 - })
101 - // 4 nodes should see the same peer ID
102 - // 1 node (the closest) should see a different one
103 - var counts []int
104 - for _, count := range peerCounts {
105 - counts = append(counts, count)
106 - }
107 - sort.IntSlice(counts).Sort()
108 - assert.Equal(t, []int{1, 4}, counts)
109 - })
110 - })
111 -
112 - t.Run("dht commands fail when offline", func(t *testing.T) {
113 - t.Parallel()
114 - node := harness.NewT(t).NewNode().Init()
115 -
116 - // these cannot be run in parallel due to repo locking (seems like a bug)
117 -
118 - t.Run("dht findprovs", func(t *testing.T) {
119 - res := node.RunIPFS("dht", "findprovs", testutils.CIDEmptyDir)
120 - assert.Equal(t, 1, res.ExitCode())
121 - assert.Contains(t, res.Stderr.String(), "this command must be run in online mode")
122 - })
123 -
124 - t.Run("dht findpeer", func(t *testing.T) {
125 - res := node.RunIPFS("dht", "findpeer", testutils.CIDEmptyDir)
126 - assert.Equal(t, 1, res.ExitCode())
127 - assert.Contains(t, res.Stderr.String(), "this command must be run in online mode")
128 - })
129 -
130 - t.Run("dht put", func(t *testing.T) {
131 - node.WriteBytes("foo", []byte("foo"))
132 - res := node.RunIPFS("dht", "put", "/ipns/"+node.PeerID().String(), "foo")
133 - assert.Equal(t, 1, res.ExitCode())
134 - assert.Contains(t, res.Stderr.String(), "can't put while offline: pass `--allow-offline` to override")
135 - })
136 - })
137 -}