diff --git a/client/rpc/api_test.go b/client/rpc/api_test.go index 3b8179c4bf4d..c0da3d7b04e1 100644 --- a/client/rpc/api_test.go +++ b/client/rpc/api_test.go @@ -46,8 +46,6 @@ func (np NodeProvider) MakeAPISwarm(t *testing.T, ctx context.Context, fullIdent c := n.ReadConfig() c.Experimental.FilestoreEnabled = true n.WriteConfig(c) - - n.Runner.Env["LAN_DHT_INCLUDE_LOOPBACK"] = "true" n.StartDaemon("--enable-pubsub-experiment", "--offline="+strconv.FormatBool(!online)) if online { diff --git a/config/profile.go b/config/profile.go index 83d53359dae8..4bd58ef0006d 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 60faa605cceb..1bbcafa9080f 100644 --- a/config/routing.go +++ b/config/routing.go @@ -17,6 +17,9 @@ type Routing struct { AcceleratedDHTClient bool + LoopbackAddressesOnLanDHT bool + PrivateAddressesOnWanDHT bool + Routers Routers Methods Methods diff --git a/core/node/libp2p/host.go b/core/node/libp2p/host.go index afbd2080c073..4086fe4e62dc 100644 --- a/core/node/libp2p/host.go +++ b/core/node/libp2p/host.go @@ -60,6 +60,8 @@ 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, + PrivateAddressesOnWanDHT: cfg.Routing.PrivateAddressesOnWanDHT, } 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 2bd701835d02..d81c267cfbd5 100644 --- a/core/node/libp2p/routingopt.go +++ b/core/node/libp2p/routingopt.go @@ -26,6 +26,8 @@ type RoutingOptionArgs struct { BootstrapPeers []peer.AddrInfo OptimisticProvide bool OptimisticProvideJobsPoolSize int + LoopbackAddressesOnLanDHT bool + PrivateAddressesOnWanDHT bool } type RoutingOption func(args RoutingOptionArgs) (routing.Routing, error) @@ -116,16 +118,21 @@ func constructDHTRouting(mode dht.ModeOpt) RoutingOption { if args.OptimisticProvideJobsPoolSize != 0 { dhtOpts = append(dhtOpts, dht.OptimisticProvideJobsPoolSize(args.OptimisticProvideJobsPoolSize)) } - dualOptions := []dual.Option{ - dual.DHTOption(dhtOpts...), - dual.WanDHTOption(dht.BootstrapPeers(args.BootstrapPeers...)), + wanOptions := []dht.Option{ + dht.BootstrapPeers(args.BootstrapPeers...), + } + if args.PrivateAddressesOnWanDHT { + wanOptions = append(wanOptions, dht.AddressFilter(nil)) } - if os.Getenv("LAN_DHT_INCLUDE_LOOPBACK") == "true" { - dualOptions = append(dualOptions, dual.LanDHTOption(dht.AddressFilter(nil))) + lanOptions := []dht.Option{} + if args.LoopbackAddressesOnLanDHT { + lanOptions = append(lanOptions, dht.AddressFilter(nil)) } return dual.New( args.Ctx, args.Host, - dualOptions..., + dual.DHTOption(dhtOpts...), + dual.WanDHTOption(wanOptions...), + dual.LanDHTOption(lanOptions...), ) } } diff --git a/docs/changelogs/v0.28.md b/docs/changelogs/v0.28.md index 0d399c6ec132..78c2795e8988 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,11 @@ 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)). + +##### No longer publishes loopback and private addresses on DHT + +Kubo no longer publishes loopback and private addresses on the LAN and WAN DHTs, respectively. This means that other nodes will not try to dial undialable addresses. If, for some reason, you need this, we have added two new boolean options to the configuration: `Routing.LoopbackAddressesOnLanDHT` and `Routing.PrivateAddressesOnWanDHT`. + ### ๐Ÿ“ Changelog ### ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributors diff --git a/docs/config.md b/docs/config.md index 0fa5000ac45b..d0486a33542c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1612,6 +1612,23 @@ Default: `false` Type: `bool` (missing means `false`) +### `Routing.LoopbackAddressesOnLanDHT` + +Whether loopback addresses (e.g. 127.0.0.1) should be published on the local LAN DHT. +This can be useful if, for example, you run multiple Kubo nodes on the same machine. + +Default: `false` + +Type: `bool` (missing means `false`) + +### `Routing.PrivateAddressesOnWanDHT` + +Whether private addresses should be published on the WAN DHT. + +Default: `false` + +Type: `bool` (missing means `false`) + ### `Routing.Routers` **EXPERIMENTAL: `Routing.Routers` configuration may change in future release** diff --git a/test/cli/backup_bootstrap_test.go b/test/cli/backup_bootstrap_test.go index 464ebedab788..017499f3d631 100644 --- a/test/cli/backup_bootstrap_test.go +++ b/test/cli/backup_bootstrap_test.go @@ -13,8 +13,6 @@ import ( func TestBackupBootstrapPeers(t *testing.T) { nodes := harness.NewT(t).NewNodes(3).Init() nodes.ForEachPar(func(n *harness.Node) { - n.Runner.Env["LAN_DHT_INCLUDE_LOOPBACK"] = "true" - n.UpdateConfig(func(cfg *config.Config) { cfg.Bootstrap = []string{} cfg.Addresses.Swarm = []string{fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", harness.NewRandPort())} diff --git a/test/cli/harness/node.go b/test/cli/harness/node.go index d030c7c94048..18514c517e36 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 = true }) return n } diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index e9fae99d5a89..69fd2e66cf85 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -42,9 +42,6 @@ ln -sf lib/sharness/lib-sharness . exit 1 } -# Ensure that the local DHT in the tests contains loopback addresses. -export LAN_DHT_INCLUDE_LOOPBACK=true - # Please put go-ipfs specific shell functions below ###