From fa3c7d4bc372a44141457e515cf8b04e36c683a9 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 6 Aug 2024 00:29:59 +0200 Subject: [PATCH] feat: libp2p.EnableAutoNATv2 Part of https://github.com/ipfs/kubo/issues/10091 We include a flag that allows shutting down V2 in case there are issues with it. --- config/autonat.go | 7 +++++++ core/node/groups.go | 4 +++- core/node/libp2p/nat.go | 9 ++++++++- docs/config.md | 19 ++++++++++++++----- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/config/autonat.go b/config/autonat.go index eb87b48e6f4..e8940d14eeb 100644 --- a/config/autonat.go +++ b/config/autonat.go @@ -20,6 +20,9 @@ const ( // AutoNATServiceDisabled indicates that the user has disabled the // AutoNATService. AutoNATServiceDisabled + // AutoNATServiceEnabledV1Only forces use of V1 and disables V2 + // (used for testing) + AutoNATServiceEnabledV1Only ) func (m *AutoNATServiceMode) UnmarshalText(text []byte) error { @@ -30,6 +33,8 @@ func (m *AutoNATServiceMode) UnmarshalText(text []byte) error { *m = AutoNATServiceEnabled case "disabled": *m = AutoNATServiceDisabled + case "legacy-v1": + *m = AutoNATServiceEnabledV1Only default: return fmt.Errorf("unknown autonat mode: %s", string(text)) } @@ -44,6 +49,8 @@ func (m AutoNATServiceMode) MarshalText() ([]byte, error) { return []byte("enabled"), nil case AutoNATServiceDisabled: return []byte("disabled"), nil + case AutoNATServiceEnabledV1Only: + return []byte("legacy-v1"), nil default: return nil, fmt.Errorf("unknown autonat mode: %d", m) } diff --git a/core/node/groups.go b/core/node/groups.go index 3df945fd2cc..a12cc7b7f1d 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -105,7 +105,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part // to dhtclient. fallthrough case config.AutoNATServiceEnabled: - autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle)) + autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, false)) + case config.AutoNATServiceEnabledV1Only: + autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, true)) } enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint diff --git a/core/node/libp2p/nat.go b/core/node/libp2p/nat.go index fc72d7fb3c0..6d3cd09c38e 100644 --- a/core/node/libp2p/nat.go +++ b/core/node/libp2p/nat.go @@ -9,7 +9,7 @@ import ( var NatPortMap = simpleOpt(libp2p.NATPortMap()) -func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts { +func AutoNATService(throttle *config.AutoNATThrottleConfig, v1only bool) func() Libp2pOpts { return func() (opts Libp2pOpts) { opts.Opts = append(opts.Opts, libp2p.EnableNATService()) if throttle != nil { @@ -21,6 +21,13 @@ func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts { ), ) } + + // While V1 still exists and V2 rollout is in progress + // (https://github.com/ipfs/kubo/issues/10091) we check a flag that + // allows users to disable V2 and run V1-only mode + if !v1only { + opts.Opts = append(opts.Opts, libp2p.EnableAutoNATv2()) + } return opts } } diff --git a/docs/config.md b/docs/config.md index 8a09b7fe066..b37543e9cc8 100644 --- a/docs/config.md +++ b/docs/config.md @@ -552,7 +552,7 @@ Type: `array[string]` ## `AutoNAT` -Contains the configuration options for the AutoNAT service. The AutoNAT service +Contains the configuration options for the [AutoNAT]() service. The AutoNAT service helps other nodes on the network determine if they're publicly reachable from the rest of the internet. @@ -561,13 +561,22 @@ the rest of the internet. When unset (default), the AutoNAT service defaults to _enabled_. Otherwise, this field can take one of two values: -* "enabled" - Enable the service (unless the node determines that it, itself, - isn't reachable by the public internet). -* "disabled" - Disable the service. +* `enabled` - Enable the V1+V2 service (unless the node determines that it, + itself, isn't reachable by the public internet). +* `legacy-v1` - Same as `enabled` but only V1 service is enabled. Used for testing + during as few releases as we [transition to V2](https://github.com/ipfs/kubo/issues/10091), will be removed in the future. +* `disabled` - Disable the service. Additional modes may be added in the future. -Type: `string` (one of `"enabled"` or `"disabled"`) +> [!IMPORTANT] +> We are in the progress of [rolling out AutoNAT V2](https://github.com/ipfs/kubo/issues/10091). +> Right now, by default, a publicly diallable Kubo provides both V1 and V2 service to other peers, +> but only V1 is used by Kubo as a client. In a future release we will remove V1 and switch client to use V2. + +Default: `enabled` + +Type: `optionalString` ### `AutoNAT.Throttle`