Skip to content

Commit

Permalink
refactor to use config options
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Mar 28, 2024
1 parent fe340cb commit 48c603b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 13 deletions.
2 changes: 0 additions & 2 deletions client/rpc/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Routing struct {

AcceleratedDHTClient bool

LoopbackAddressesOnLanDHT bool
PrivateAddressesOnWanDHT bool

Routers Routers

Methods Methods
Expand Down
2 changes: 2 additions & 0 deletions core/node/libp2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions core/node/libp2p/routingopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...),
)
}
}
Expand Down
6 changes: 6 additions & 0 deletions docs/changelogs/v0.28.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
19 changes: 19 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ config file at runtime.
- [`Routing`](#routing)
- [`Routing.Type`](#routingtype)
- [`Routing.AcceleratedDHTClient`](#routingaccelerateddhtclient)
- [`Routing.LoopbackAddressesOnLanDHT`](#routingloopbackaddressesonlandht)
- [`Routing.PrivateAddressesOnWanDHT`](#routingprivateaddressesonwandht)
- [`Routing.Routers`](#routingrouters)
- [`Routing.Routers: Type`](#routingrouters-type)
- [`Routing.Routers: Parameters`](#routingrouters-parameters)
Expand Down Expand Up @@ -1612,6 +1614,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**
Expand Down
2 changes: 0 additions & 2 deletions test/cli/backup_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())}
Expand Down
1 change: 1 addition & 0 deletions test/cli/harness/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 0 additions & 3 deletions test/sharness/lib/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

###
Expand Down

0 comments on commit 48c603b

Please sign in to comment.