diff --git a/client/rpc/api_test.go b/client/rpc/api_test.go index 25bd26ceea6..c0da3d7b04e 100644 --- a/client/rpc/api_test.go +++ b/client/rpc/api_test.go @@ -46,7 +46,6 @@ func (np NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdent c := n.ReadConfig() c.Experimental.FilestoreEnabled = true n.WriteConfig(c) - n.StartDaemon("--enable-pubsub-experiment", "--offline="+strconv.FormatBool(!online)) if online { diff --git a/config/profile.go b/config/profile.go index 24bbe1533fa..068498715c5 100644 --- a/config/profile.go +++ b/config/profile.go @@ -82,6 +82,7 @@ is useful when using the daemon in test environments.`, } c.Swarm.DisableNatPortMap = true + c.Routing.LoopbackAddressesOnLanDHT = True c.Bootstrap = []string{} c.Discovery.MDNS.Enabled = false diff --git a/config/routing.go b/config/routing.go index f8941f84877..231cbca732c 100644 --- a/config/routing.go +++ b/config/routing.go @@ -7,7 +7,8 @@ import ( ) var ( - DefaultAcceleratedDHTClient = false + DefaultAcceleratedDHTClient = false + DefaultLoopbackAddressesOnLanDHT = false ) // Routing defines configuration options for libp2p routing. @@ -21,6 +22,8 @@ type Routing struct { AcceleratedDHTClient Flag `json:",omitempty"` + LoopbackAddressesOnLanDHT Flag `json:",omitempty"` + Routers Routers Methods Methods diff --git a/core/node/libp2p/host.go b/core/node/libp2p/host.go index afbd2080c07..7950f3dc6bc 100644 --- a/core/node/libp2p/host.go +++ b/core/node/libp2p/host.go @@ -11,6 +11,7 @@ import ( "github.com/libp2p/go-libp2p/core/routing" routedhost "github.com/libp2p/go-libp2p/p2p/host/routed" + "github.com/ipfs/kubo/config" "github.com/ipfs/kubo/core/node/helpers" "github.com/ipfs/kubo/repo" @@ -60,6 +61,7 @@ func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHo BootstrapPeers: bootstrappers, OptimisticProvide: cfg.Experimental.OptimisticProvide, OptimisticProvideJobsPoolSize: cfg.Experimental.OptimisticProvideJobsPoolSize, + LoopbackAddressesOnLanDHT: cfg.Routing.LoopbackAddressesOnLanDHT.WithDefault(config.DefaultLoopbackAddressesOnLanDHT), } opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) { args := routingOptArgs diff --git a/core/node/libp2p/routingopt.go b/core/node/libp2p/routingopt.go index a58a8c49885..869b7ef0652 100644 --- a/core/node/libp2p/routingopt.go +++ b/core/node/libp2p/routingopt.go @@ -26,6 +26,7 @@ type RoutingOptionArgs struct { BootstrapPeers []peer.AddrInfo OptimisticProvide bool OptimisticProvideJobsPoolSize int + LoopbackAddressesOnLanDHT bool } type RoutingOption func(args RoutingOptionArgs) (routing.Routing, error) @@ -116,10 +117,18 @@ func constructDHTRouting(mode dht.ModeOpt) RoutingOption { if args.OptimisticProvideJobsPoolSize != 0 { dhtOpts = append(dhtOpts, dht.OptimisticProvideJobsPoolSize(args.OptimisticProvideJobsPoolSize)) } + wanOptions := []dht.Option{ + dht.BootstrapPeers(args.BootstrapPeers...), + } + lanOptions := []dht.Option{} + if args.LoopbackAddressesOnLanDHT { + lanOptions = append(lanOptions, dht.AddressFilter(nil)) + } return dual.New( args.Ctx, args.Host, dual.DHTOption(dhtOpts...), - dual.WanDHTOption(dht.BootstrapPeers(args.BootstrapPeers...)), + dual.WanDHTOption(wanOptions...), + dual.LanDHTOption(lanOptions...), ) } } diff --git a/docs/changelogs/v0.28.md b/docs/changelogs/v0.28.md index 0d399c6ec13..7e5361eb570 100644 --- a/docs/changelogs/v0.28.md +++ b/docs/changelogs/v0.28.md @@ -9,6 +9,7 @@ - [RPC client: removed deprecated DHT API](#rpc-client-removed-deprecated-dht-api) - [Gateway: `/api/v0` is removed](#gateway-apiv0-is-removed) - [Removed deprecated Object API commands](#removed-deprecated-object-api-commands) + - [No longer publishes loopback and private addresses on DHT](#no-longer-publishes-loopback-and-private-addresses-on-dht) - [๐Ÿ“ Changelog](#-changelog) - [๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors](#-contributors) @@ -28,6 +29,12 @@ If you have a legacy software that relies on this behavior, and want to expose p 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)). +##### Kubo ignores loopback addresses on LAN DHT and private addresses on WAN DHT + +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. + +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. + ### ๐Ÿ“ Changelog ### ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors diff --git a/docs/config.md b/docs/config.md index d9addc7134a..ad308b18c5b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -117,6 +117,7 @@ config file at runtime. - [`Routing`](#routing) - [`Routing.Type`](#routingtype) - [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient) + - [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht) - [`Routing.Routers`](#routingrouters) - [`Routing.Routers: Type`](#routingrouters-type) - [`Routing.Routers: Parameters`](#routingrouters-parameters) @@ -1612,6 +1613,18 @@ Default: `false` Type: `flag` +### `Routing.LoopbackAddressesOnLanDHT` + +**EXPERIMENTAL: `Routing.LoopbackAddressesOnLanDHT` configuration may change in future release** + +Whether loopback addresses (e.g. 127.0.0.1) should not be ignored on the local LAN DHT. + +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`. + +Default: `false` + +Type: `bool` (missing means `false`) + ### `Routing.Routers` **EXPERIMENTAL: `Routing.Routers` configuration may change in future release** diff --git a/go.mod b/go.mod index 736901ae5a0..d02a8d8bcce 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/libp2p/go-doh-resolver v0.4.0 github.com/libp2p/go-libp2p v0.33.2 github.com/libp2p/go-libp2p-http v0.5.0 - github.com/libp2p/go-libp2p-kad-dht v0.24.4 + github.com/libp2p/go-libp2p-kad-dht v0.25.2 github.com/libp2p/go-libp2p-kbucket v0.6.3 github.com/libp2p/go-libp2p-pubsub v0.10.0 github.com/libp2p/go-libp2p-pubsub-router v0.6.0 diff --git a/go.sum b/go.sum index 17e57d5618c..dc33871f7dc 100644 --- a/go.sum +++ b/go.sum @@ -518,8 +518,8 @@ github.com/libp2p/go-libp2p-gostream v0.6.0 h1:QfAiWeQRce6pqnYfmIVWJFXNdDyfiR/qk github.com/libp2p/go-libp2p-gostream v0.6.0/go.mod h1:Nywu0gYZwfj7Jc91PQvbGU8dIpqbQQkjWgDuOrFaRdA= github.com/libp2p/go-libp2p-http v0.5.0 h1:+x0AbLaUuLBArHubbbNRTsgWz0RjNTy6DJLOxQ3/QBc= github.com/libp2p/go-libp2p-http v0.5.0/go.mod h1:glh87nZ35XCQyFsdzZps6+F4HYI6DctVFY5u1fehwSg= -github.com/libp2p/go-libp2p-kad-dht v0.24.4 h1:ktNiJe7ffsJ1wX3ULpMCwXts99mPqGFSE/Qn1i8pErQ= -github.com/libp2p/go-libp2p-kad-dht v0.24.4/go.mod h1:ybWBJ5Fbvz9sSLkNtXt+2+bK0JB8+tRPvhBbRGHegRU= +github.com/libp2p/go-libp2p-kad-dht v0.25.2 h1:FOIk9gHoe4YRWXTu8SY9Z1d0RILol0TrtApsMDPjAVQ= +github.com/libp2p/go-libp2p-kad-dht v0.25.2/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= github.com/libp2p/go-libp2p-kbucket v0.3.1/go.mod h1:oyjT5O7tS9CQurok++ERgc46YLwEpuGoFq9ubvoUOio= github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0= diff --git a/test/cli/harness/node.go b/test/cli/harness/node.go index d030c7c9404..ad8ac263bad 100644 --- a/test/cli/harness/node.go +++ b/test/cli/harness/node.go @@ -208,6 +208,7 @@ func (n *Node) Init(ipfsArgs ...string) *Node { cfg.Addresses.Gateway = []string{n.GatewayListenAddr.String()} cfg.Swarm.DisableNatPortMap = true cfg.Discovery.MDNS.Enabled = n.EnableMDNS + cfg.Routing.LoopbackAddressesOnLanDHT = config.True }) return n } diff --git a/test/sharness/lib/iptb-lib.sh b/test/sharness/lib/iptb-lib.sh index 3d2e95a4916..8b2d956c2e9 100644 --- a/test/sharness/lib/iptb-lib.sh +++ b/test/sharness/lib/iptb-lib.sh @@ -34,6 +34,10 @@ startup_cluster() { other_args="$@" bound=$(expr "$num_nodes" - 1) + test_expect_success "set Routing.LoopbackAddressesOnLanDHT to true" ' + iptb run [0-$bound] -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true + ' + if test -n "$other_args"; then test_expect_success "start up nodes with additional args" " iptb start -wait [0-$bound] -- ${other_args[@]} diff --git a/test/sharness/t0131-multinode-client-routing.sh b/test/sharness/t0131-multinode-client-routing.sh index b62c9790b9c..8949a1bdfd8 100755 --- a/test/sharness/t0131-multinode-client-routing.sh +++ b/test/sharness/t0131-multinode-client-routing.sh @@ -43,7 +43,8 @@ run_single_file_test() { NNODES=10 test_expect_success "set up testbed" ' - iptb testbed create -type localipfs -count $NNODES -force -init + iptb testbed create -type localipfs -count $NNODES -force -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true ' test_expect_success "start up nodes" ' diff --git a/test/sharness/t0142-testfilter.sh b/test/sharness/t0142-testfilter.sh index 971aa68397a..bdd7e4f76b1 100755 --- a/test/sharness/t0142-testfilter.sh +++ b/test/sharness/t0142-testfilter.sh @@ -13,7 +13,8 @@ AF="/ip4/127.0.0.0/ipcidr/24" NUM_NODES=3 test_expect_success "set up testbed" ' - iptb testbed create -type localipfs -count $NUM_NODES -force -init + iptb testbed create -type localipfs -count $NUM_NODES -force -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true ' test_expect_success 'filter 127.0.0.0/24 on node 1' ' diff --git a/test/sharness/t0181-private-network.sh b/test/sharness/t0181-private-network.sh index 86c6151d3e4..46dc45cdf3c 100755 --- a/test/sharness/t0181-private-network.sh +++ b/test/sharness/t0181-private-network.sh @@ -35,6 +35,7 @@ LIBP2P_FORCE_PNET=1 test_launch_ipfs_daemon test_expect_success "set up iptb testbed" ' iptb testbed create -type localipfs -count 5 -force -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true && iptb run -- ipfs config --json Addresses.Swarm '"'"'["/ip4/127.0.0.1/tcp/0"]'"'"' ' diff --git a/test/sharness/t0182-circuit-relay.sh b/test/sharness/t0182-circuit-relay.sh index d6e439ae318..c79edfc8ea8 100755 --- a/test/sharness/t0182-circuit-relay.sh +++ b/test/sharness/t0182-circuit-relay.sh @@ -7,7 +7,8 @@ test_description="Test circuit relay" # start iptb + wait for peering NUM_NODES=3 test_expect_success 'init iptb' ' - iptb testbed create -type localipfs -count $NUM_NODES -init + iptb testbed create -type localipfs -count $NUM_NODES -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true ' # Network toplogy: A <-> Relay <-> B diff --git a/test/sharness/t0184-http-proxy-over-p2p.sh b/test/sharness/t0184-http-proxy-over-p2p.sh index 9c5308277c2..98e2f3ab20c 100755 --- a/test/sharness/t0184-http-proxy-over-p2p.sh +++ b/test/sharness/t0184-http-proxy-over-p2p.sh @@ -142,6 +142,7 @@ function curl_send_multipart_form_request() { test_expect_success 'configure nodes' ' iptb testbed create -type localipfs -count 2 -force -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true && ipfsi 0 config --json Experimental.Libp2pStreamMounting true && ipfsi 1 config --json Experimental.Libp2pStreamMounting true && ipfsi 0 config --json Experimental.P2pHttpProxy true && diff --git a/test/sharness/t0276-cidv0v1.sh b/test/sharness/t0276-cidv0v1.sh index 2058a9d5497..c810f45449d 100755 --- a/test/sharness/t0276-cidv0v1.sh +++ b/test/sharness/t0276-cidv0v1.sh @@ -95,7 +95,8 @@ test_expect_success "check that we can access the file when converted to CIDv1" # test_expect_success "set up iptb testbed" ' - iptb testbed create -type localipfs -count 2 -init + iptb testbed create -type localipfs -count 2 -init && + iptb run -- ipfs config --json "Routing.LoopbackAddressesOnLanDHT" true ' test_expect_success "start nodes" '