@cryptotaxi247 / kubo / commits / 11183bb2f

chore: upgrade go-libp2p-kad-dht (#10378)

* chore: upgrade go-libp2p-kad-dht * config: make LoopbackAddressesOnLanDHT a Flag * config: add DefaultLoopbackAddressesOnLanDHT * docs(config): Routing.LoopbackAddressesOnLanDHT --------- Co-authored-by: Marcin Rataj <lidel@lidel.org>

Henrique Dias committed Apr 4, 2024 at 14:56 UTC 11183bb2f530234007eed4a3ae3e924880b3df33
17 files changed +55 -10
client/rpc/api_test.go
-1
@@ -46,7 +46,6 @@ func (np NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdent
46 c := n.ReadConfig()
47 c.Experimental.FilestoreEnabled = true
48 n.WriteConfig(c)
49 -
49 n.StartDaemon("--enable-pubsub-experiment", "--offline="+strconv.FormatBool(!online))
50
51 if online {
config/profile.go
+1
@@ -82,6 +82,7 @@ is useful when using the daemon in test environments.`,
82 }
83
84 c.Swarm.DisableNatPortMap = true
85 + c.Routing.LoopbackAddressesOnLanDHT = True
86
87 c.Bootstrap = []string{}
88 c.Discovery.MDNS.Enabled = false
config/routing.go
+4 -1
@@ -7,7 +7,8 @@ import (
7 )
8
9 var (
10 - DefaultAcceleratedDHTClient = false
10 + DefaultAcceleratedDHTClient = false
11 + DefaultLoopbackAddressesOnLanDHT = false
12 )
13
14 // Routing defines configuration options for libp2p routing.
@@ -21,6 +22,8 @@ type Routing struct {
22
23 AcceleratedDHTClient Flag `json:",omitempty"`
24
25 + LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
26 +
27 Routers Routers
28
29 Methods Methods
core/node/libp2p/host.go
+2
@@ -11,6 +11,7 @@ import (
11 "github.com/libp2p/go-libp2p/core/routing"
12 routedhost "github.com/libp2p/go-libp2p/p2p/host/routed"
13
14 + "github.com/ipfs/kubo/config"
15 "github.com/ipfs/kubo/core/node/helpers"
16 "github.com/ipfs/kubo/repo"
17
@@ -60,6 +61,7 @@ func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHo
61 BootstrapPeers: bootstrappers,
62 OptimisticProvide: cfg.Experimental.OptimisticProvide,
63 OptimisticProvideJobsPoolSize: cfg.Experimental.OptimisticProvideJobsPoolSize,
64 + LoopbackAddressesOnLanDHT: cfg.Routing.LoopbackAddressesOnLanDHT.WithDefault(config.DefaultLoopbackAddressesOnLanDHT),
65 }
66 opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
67 args := routingOptArgs
core/node/libp2p/routingopt.go
+10 -1
@@ -26,6 +26,7 @@ type RoutingOptionArgs struct {
26 BootstrapPeers []peer.AddrInfo
27 OptimisticProvide bool
28 OptimisticProvideJobsPoolSize int
29 + LoopbackAddressesOnLanDHT bool
30 }
31
32 type RoutingOption func(args RoutingOptionArgs) (routing.Routing, error)
@@ -116,10 +117,18 @@ func constructDHTRouting(mode dht.ModeOpt) RoutingOption {
117 if args.OptimisticProvideJobsPoolSize != 0 {
118 dhtOpts = append(dhtOpts, dht.OptimisticProvideJobsPoolSize(args.OptimisticProvideJobsPoolSize))
119 }
120 + wanOptions := []dht.Option{
121 + dht.BootstrapPeers(args.BootstrapPeers...),
122 + }
123 + lanOptions := []dht.Option{}
124 + if args.LoopbackAddressesOnLanDHT {
125 + lanOptions = append(lanOptions, dht.AddressFilter(nil))
126 + }
127 return dual.New(
128 args.Ctx, args.Host,
129 dual.DHTOption(dhtOpts...),
122 - dual.WanDHTOption(dht.BootstrapPeers(args.BootstrapPeers...)),
130 + dual.WanDHTOption(wanOptions...),
131 + dual.LanDHTOption(lanOptions...),
132 )
133 }
134 }
docs/changelogs/v0.28.md
+7
@@ -9,6 +9,7 @@
9 - [RPC client: removed deprecated DHT API](#rpc-client-removed-deprecated-dht-api)
10 - [Gateway: `/api/v0` is removed](#gateway-apiv0-is-removed)
11 - [Removed deprecated Object API commands](#removed-deprecated-object-api-commands)
12 + - [No longer publishes loopback and private addresses on DHT](#no-longer-publishes-loopback-and-private-addresses-on-dht)
13 - [📝 Changelog](#-changelog)
14 - [👨‍👩‍👧‍👦 Contributors](#-contributors)
15
@@ -28,6 +29,12 @@ If you have a legacy software that relies on this behavior, and want to expose p
29
30 The Object API commands deprecated back in [2021](https://github.com/ipfs/kubo/issues/7936) have been removed, except for `object diff`, `object patch add-link` and `object patch rm-link`, whose alternatives have not yet been built (see issues [4801](https://github.com/ipfs/kubo/issues/4801) and [4782](https://github.com/ipfs/kubo/issues/4782)).
31
32 +##### Kubo ignores loopback addresses on LAN DHT and private addresses on WAN DHT
33 +
34 +Kubo no longer keeps track of loopback and private addresses on the LAN and WAN DHTs, respectively. This means that other nodes will not try to dial likely undialable addresses.
35 +
36 +To support testing scenarios where multiple Kubo instances run on the same machine, [`Routing.LoopbackAddressesOnLanDHT`](https://github.com/ipfs/kubo/blob/master/docs/config.md#routingloopbackaddressesonlandht) is set to `true` when the `test` profile is applied.
37 +
38 ### 📝 Changelog
39
40 ### 👨‍👩‍👧‍👦 Contributors
docs/config.md
+13
@@ -117,6 +117,7 @@ config file at runtime.
117 - [`Routing`](#routing)
118 - [`Routing.Type`](#routingtype)
119 - [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
120 + - [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
121 - [`Routing.Routers`](#routingrouters)
122 - [`Routing.Routers: Type`](#routingrouters-type)
123 - [`Routing.Routers: Parameters`](#routingrouters-parameters)
@@ -1612,6 +1613,18 @@ Default: `false`
1613
1614 Type: `flag`
1615
1616 +### `Routing.LoopbackAddressesOnLanDHT`
1617 +
1618 +**EXPERIMENTAL: `Routing.LoopbackAddressesOnLanDHT` configuration may change in future release**
1619 +
1620 +Whether loopback addresses (e.g. 127.0.0.1) should not be ignored on the local LAN DHT.
1621 +
1622 +Most users do not need this setting. It can be useful during testing, when multiple Kubo nodes run on the same machine but some of them do not have `Discovery.MDNS.Enabled`.
1623 +
1624 +Default: `false`
1625 +
1626 +Type: `bool` (missing means `false`)
1627 +
1628 ### `Routing.Routers`
1629
1630 **EXPERIMENTAL: `Routing.Routers` configuration may change in future release**
go.mod
+1 -1
@@ -49,7 +49,7 @@ require (
49 github.com/libp2p/go-doh-resolver v0.4.0
50 github.com/libp2p/go-libp2p v0.33.2
51 github.com/libp2p/go-libp2p-http v0.5.0
52 - github.com/libp2p/go-libp2p-kad-dht v0.24.4
52 + github.com/libp2p/go-libp2p-kad-dht v0.25.2
53 github.com/libp2p/go-libp2p-kbucket v0.6.3
54 github.com/libp2p/go-libp2p-pubsub v0.10.0
55 github.com/libp2p/go-libp2p-pubsub-router v0.6.0
go.sum
+2 -2
@@ -518,8 +518,8 @@ github.com/libp2p/go-libp2p-gostream v0.6.0 h1:QfAiWeQRce6pqnYfmIVWJFXNdDyfiR/qk
518 github.com/libp2p/go-libp2p-gostream v0.6.0/go.mod h1:Nywu0gYZwfj7Jc91PQvbGU8dIpqbQQkjWgDuOrFaRdA=
519 github.com/libp2p/go-libp2p-http v0.5.0 h1:+x0AbLaUuLBArHubbbNRTsgWz0RjNTy6DJLOxQ3/QBc=
520 github.com/libp2p/go-libp2p-http v0.5.0/go.mod h1:glh87nZ35XCQyFsdzZps6+F4HYI6DctVFY5u1fehwSg=
521 -github.com/libp2p/go-libp2p-kad-dht v0.24.4 h1:ktNiJe7ffsJ1wX3ULpMCwXts99mPqGFSE/Qn1i8pErQ=
522 -github.com/libp2p/go-libp2p-kad-dht v0.24.4/go.mod h1:ybWBJ5Fbvz9sSLkNtXt+2+bK0JB8+tRPvhBbRGHegRU=
521 +github.com/libp2p/go-libp2p-kad-dht v0.25.2 h1:FOIk9gHoe4YRWXTu8SY9Z1d0RILol0TrtApsMDPjAVQ=
522 +github.com/libp2p/go-libp2p-kad-dht v0.25.2/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo=
523 github.com/libp2p/go-libp2p-kbucket v0.3.1/go.mod h1:oyjT5O7tS9CQurok++ERgc46YLwEpuGoFq9ubvoUOio=
524 github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0=
525 github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0=
test/cli/harness/node.go
+1
@@ -208,6 +208,7 @@ func (n *Node) Init(ipfsArgs ...string) *Node {
208 cfg.Addresses.Gateway = []string{n.GatewayListenAddr.String()}
209 cfg.Swarm.DisableNatPortMap = true
210 cfg.Discovery.MDNS.Enabled = n.EnableMDNS
211 + cfg.Routing.LoopbackAddressesOnLanDHT = config.True
212 })
213 return n
214 }
test/sharness/lib/iptb-lib.sh
+4
@@ -34,6 +34,10 @@ startup_cluster() {
34 other_args="$@"
35 bound=$(expr "$num_nodes" - 1)
36
37 + test_expect_success "set Routing.LoopbackAddressesOnLanDHT to true" '
38 + iptb run [0-$bound] -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
39 + '
40 +
41 if test -n "$other_args"; then
42 test_expect_success "start up nodes with additional args" "
43 iptb start -wait [0-$bound] -- ${other_args[@]}
test/sharness/t0131-multinode-client-routing.sh
+2 -1
@@ -43,7 +43,8 @@ run_single_file_test() {
43 NNODES=10
44
45 test_expect_success "set up testbed" '
46 - iptb testbed create -type localipfs -count $NNODES -force -init
46 + iptb testbed create -type localipfs -count $NNODES -force -init &&
47 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
48 '
49
50 test_expect_success "start up nodes" '
test/sharness/t0142-testfilter.sh
+2 -1
@@ -13,7 +13,8 @@ AF="/ip4/127.0.0.0/ipcidr/24"
13 NUM_NODES=3
14
15 test_expect_success "set up testbed" '
16 - iptb testbed create -type localipfs -count $NUM_NODES -force -init
16 + iptb testbed create -type localipfs -count $NUM_NODES -force -init &&
17 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
18 '
19
20 test_expect_success 'filter 127.0.0.0/24 on node 1' '
test/sharness/t0181-private-network.sh
+1
@@ -35,6 +35,7 @@ LIBP2P_FORCE_PNET=1 test_launch_ipfs_daemon
35
36 test_expect_success "set up iptb testbed" '
37 iptb testbed create -type localipfs -count 5 -force -init &&
38 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true &&
39 iptb run -- ipfs config --json Addresses.Swarm '"'"'["/ip4/127.0.0.1/tcp/0"]'"'"'
40 '
41
test/sharness/t0182-circuit-relay.sh
+2 -1
@@ -7,7 +7,8 @@ test_description="Test circuit relay"
7 # start iptb + wait for peering
8 NUM_NODES=3
9 test_expect_success 'init iptb' '
10 - iptb testbed create -type localipfs -count $NUM_NODES -init
10 + iptb testbed create -type localipfs -count $NUM_NODES -init &&
11 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
12 '
13
14 # Network toplogy: A <-> Relay <-> B
test/sharness/t0184-http-proxy-over-p2p.sh
+1
@@ -142,6 +142,7 @@ function curl_send_multipart_form_request() {
142
143 test_expect_success 'configure nodes' '
144 iptb testbed create -type localipfs -count 2 -force -init &&
145 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true &&
146 ipfsi 0 config --json Experimental.Libp2pStreamMounting true &&
147 ipfsi 1 config --json Experimental.Libp2pStreamMounting true &&
148 ipfsi 0 config --json Experimental.P2pHttpProxy true &&
test/sharness/t0276-cidv0v1.sh
+2 -1
@@ -95,7 +95,8 @@ test_expect_success "check that we can access the file when converted to CIDv1"
95 #
96
97 test_expect_success "set up iptb testbed" '
98 - iptb testbed create -type localipfs -count 2 -init
98 + iptb testbed create -type localipfs -count 2 -init &&
99 + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
100 '
101
102 test_expect_success "start nodes" '