Skip to content

Commit 11183bb

Browse files
hacdiaslidel
andauthored
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 <[email protected]>
1 parent cd78f2e commit 11183bb

17 files changed

+55
-10
lines changed

client/rpc/api_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (np NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdent
4646
c := n.ReadConfig()
4747
c.Experimental.FilestoreEnabled = true
4848
n.WriteConfig(c)
49-
5049
n.StartDaemon("--enable-pubsub-experiment", "--offline="+strconv.FormatBool(!online))
5150

5251
if online {

config/profile.go

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ is useful when using the daemon in test environments.`,
8282
}
8383

8484
c.Swarm.DisableNatPortMap = true
85+
c.Routing.LoopbackAddressesOnLanDHT = True
8586

8687
c.Bootstrap = []string{}
8788
c.Discovery.MDNS.Enabled = false

config/routing.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
)
88

99
var (
10-
DefaultAcceleratedDHTClient = false
10+
DefaultAcceleratedDHTClient = false
11+
DefaultLoopbackAddressesOnLanDHT = false
1112
)
1213

1314
// Routing defines configuration options for libp2p routing.
@@ -21,6 +22,8 @@ type Routing struct {
2122

2223
AcceleratedDHTClient Flag `json:",omitempty"`
2324

25+
LoopbackAddressesOnLanDHT Flag `json:",omitempty"`
26+
2427
Routers Routers
2528

2629
Methods Methods

core/node/libp2p/host.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/libp2p/go-libp2p/core/routing"
1212
routedhost "github.com/libp2p/go-libp2p/p2p/host/routed"
1313

14+
"github.com/ipfs/kubo/config"
1415
"github.com/ipfs/kubo/core/node/helpers"
1516
"github.com/ipfs/kubo/repo"
1617

@@ -60,6 +61,7 @@ func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHo
6061
BootstrapPeers: bootstrappers,
6162
OptimisticProvide: cfg.Experimental.OptimisticProvide,
6263
OptimisticProvideJobsPoolSize: cfg.Experimental.OptimisticProvideJobsPoolSize,
64+
LoopbackAddressesOnLanDHT: cfg.Routing.LoopbackAddressesOnLanDHT.WithDefault(config.DefaultLoopbackAddressesOnLanDHT),
6365
}
6466
opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
6567
args := routingOptArgs

core/node/libp2p/routingopt.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type RoutingOptionArgs struct {
2626
BootstrapPeers []peer.AddrInfo
2727
OptimisticProvide bool
2828
OptimisticProvideJobsPoolSize int
29+
LoopbackAddressesOnLanDHT bool
2930
}
3031

3132
type RoutingOption func(args RoutingOptionArgs) (routing.Routing, error)
@@ -116,10 +117,18 @@ func constructDHTRouting(mode dht.ModeOpt) RoutingOption {
116117
if args.OptimisticProvideJobsPoolSize != 0 {
117118
dhtOpts = append(dhtOpts, dht.OptimisticProvideJobsPoolSize(args.OptimisticProvideJobsPoolSize))
118119
}
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+
}
119127
return dual.New(
120128
args.Ctx, args.Host,
121129
dual.DHTOption(dhtOpts...),
122-
dual.WanDHTOption(dht.BootstrapPeers(args.BootstrapPeers...)),
130+
dual.WanDHTOption(wanOptions...),
131+
dual.LanDHTOption(lanOptions...),
123132
)
124133
}
125134
}

docs/changelogs/v0.28.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [RPC client: removed deprecated DHT API](#rpc-client-removed-deprecated-dht-api)
1010
- [Gateway: `/api/v0` is removed](#gateway-apiv0-is-removed)
1111
- [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)
1213
- [📝 Changelog](#-changelog)
1314
- [👨‍👩‍👧‍👦 Contributors](#-contributors)
1415

@@ -28,6 +29,12 @@ If you have a legacy software that relies on this behavior, and want to expose p
2829

2930
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)).
3031

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+
3138
### 📝 Changelog
3239

3340
### 👨‍👩‍👧‍👦 Contributors

docs/config.md

+13
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ config file at runtime.
117117
- [`Routing`](#routing)
118118
- [`Routing.Type`](#routingtype)
119119
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
120+
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
120121
- [`Routing.Routers`](#routingrouters)
121122
- [`Routing.Routers: Type`](#routingrouters-type)
122123
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
@@ -1612,6 +1613,18 @@ Default: `false`
16121613

16131614
Type: `flag`
16141615

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+
16151628
### `Routing.Routers`
16161629

16171630
**EXPERIMENTAL: `Routing.Routers` configuration may change in future release**

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ require (
4949
github.com/libp2p/go-doh-resolver v0.4.0
5050
github.com/libp2p/go-libp2p v0.33.2
5151
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
5353
github.com/libp2p/go-libp2p-kbucket v0.6.3
5454
github.com/libp2p/go-libp2p-pubsub v0.10.0
5555
github.com/libp2p/go-libp2p-pubsub-router v0.6.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ github.com/libp2p/go-libp2p-gostream v0.6.0 h1:QfAiWeQRce6pqnYfmIVWJFXNdDyfiR/qk
518518
github.com/libp2p/go-libp2p-gostream v0.6.0/go.mod h1:Nywu0gYZwfj7Jc91PQvbGU8dIpqbQQkjWgDuOrFaRdA=
519519
github.com/libp2p/go-libp2p-http v0.5.0 h1:+x0AbLaUuLBArHubbbNRTsgWz0RjNTy6DJLOxQ3/QBc=
520520
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=
523523
github.com/libp2p/go-libp2p-kbucket v0.3.1/go.mod h1:oyjT5O7tS9CQurok++ERgc46YLwEpuGoFq9ubvoUOio=
524524
github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0=
525525
github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0=

test/cli/harness/node.go

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (n *Node) Init(ipfsArgs ...string) *Node {
208208
cfg.Addresses.Gateway = []string{n.GatewayListenAddr.String()}
209209
cfg.Swarm.DisableNatPortMap = true
210210
cfg.Discovery.MDNS.Enabled = n.EnableMDNS
211+
cfg.Routing.LoopbackAddressesOnLanDHT = config.True
211212
})
212213
return n
213214
}

test/sharness/lib/iptb-lib.sh

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ startup_cluster() {
3434
other_args="$@"
3535
bound=$(expr "$num_nodes" - 1)
3636

37+
test_expect_success "set Routing.LoopbackAddressesOnLanDHT to true" '
38+
iptb run [0-$bound] -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true
39+
'
40+
3741
if test -n "$other_args"; then
3842
test_expect_success "start up nodes with additional args" "
3943
iptb start -wait [0-$bound] -- ${other_args[@]}

test/sharness/t0131-multinode-client-routing.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ run_single_file_test() {
4343
NNODES=10
4444

4545
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
4748
'
4849

4950
test_expect_success "start up nodes" '

test/sharness/t0142-testfilter.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ AF="/ip4/127.0.0.0/ipcidr/24"
1313
NUM_NODES=3
1414

1515
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
1718
'
1819

1920
test_expect_success 'filter 127.0.0.0/24 on node 1' '

test/sharness/t0181-private-network.sh

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ LIBP2P_FORCE_PNET=1 test_launch_ipfs_daemon
3535

3636
test_expect_success "set up iptb testbed" '
3737
iptb testbed create -type localipfs -count 5 -force -init &&
38+
iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true &&
3839
iptb run -- ipfs config --json Addresses.Swarm '"'"'["/ip4/127.0.0.1/tcp/0"]'"'"'
3940
'
4041

test/sharness/t0182-circuit-relay.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ test_description="Test circuit relay"
77
# start iptb + wait for peering
88
NUM_NODES=3
99
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
1112
'
1213

1314
# Network toplogy: A <-> Relay <-> B

test/sharness/t0184-http-proxy-over-p2p.sh

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function curl_send_multipart_form_request() {
142142

143143
test_expect_success 'configure nodes' '
144144
iptb testbed create -type localipfs -count 2 -force -init &&
145+
iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true &&
145146
ipfsi 0 config --json Experimental.Libp2pStreamMounting true &&
146147
ipfsi 1 config --json Experimental.Libp2pStreamMounting true &&
147148
ipfsi 0 config --json Experimental.P2pHttpProxy true &&

test/sharness/t0276-cidv0v1.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ test_expect_success "check that we can access the file when converted to CIDv1"
9595
#
9696

9797
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
99100
'
100101

101102
test_expect_success "start nodes" '

0 commit comments

Comments
 (0)