feat: run AutoNAT V2 service in addition to V1 (#10468)
* 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. * docs: EnableAutoNATv2
Marcin Rataj committed
Aug 6, 2024 at 21:51 UTC
ffab7b271a9b7fcdc9d4b758d19aae5ecd412312
5 files changed
+39
-7
config/autonat.go
+7
@@ -20,6 +20,9 @@ const (
20
// AutoNATServiceDisabled indicates that the user has disabled the
21
// AutoNATService.
22
AutoNATServiceDisabled
23
+ // AutoNATServiceEnabledV1Only forces use of V1 and disables V2
24
+ // (used for testing)
25
+ AutoNATServiceEnabledV1Only
26
)
27
28
func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
@@ -30,6 +33,8 @@ func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
33
*m = AutoNATServiceEnabled
34
case "disabled":
35
*m = AutoNATServiceDisabled
36
+ case "legacy-v1":
37
+ *m = AutoNATServiceEnabledV1Only
38
default:
39
return fmt.Errorf("unknown autonat mode: %s", string(text))
40
}
@@ -44,6 +49,8 @@ func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
49
return []byte("enabled"), nil
50
case AutoNATServiceDisabled:
51
return []byte("disabled"), nil
52
+ case AutoNATServiceEnabledV1Only:
53
+ return []byte("legacy-v1"), nil
54
default:
55
return nil, fmt.Errorf("unknown autonat mode: %d", m)
56
}
core/node/groups.go
+3
-1
@@ -105,7 +105,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
105
// to dhtclient.
106
fallthrough
107
case config.AutoNATServiceEnabled:
108
- autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle))
108
+ autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, false))
109
+ case config.AutoNATServiceEnabledV1Only:
110
+ autonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, true))
111
}
112
113
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint
core/node/libp2p/nat.go
+8
-1
@@ -9,7 +9,7 @@ import (
9
10
var NatPortMap = simpleOpt(libp2p.NATPortMap())
11
12
-func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
12
+func AutoNATService(throttle *config.AutoNATThrottleConfig, v1only bool) func() Libp2pOpts {
13
return func() (opts Libp2pOpts) {
14
opts.Opts = append(opts.Opts, libp2p.EnableNATService())
15
if throttle != nil {
@@ -21,6 +21,13 @@ func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
21
),
22
)
23
}
24
+
25
+ // While V1 still exists and V2 rollout is in progress
26
+ // (https://github.com/ipfs/kubo/issues/10091) we check a flag that
27
+ // allows users to disable V2 and run V1-only mode
28
+ if !v1only {
29
+ opts.Opts = append(opts.Opts, libp2p.EnableAutoNATv2())
30
+ }
31
return opts
32
}
33
}
docs/changelogs/v0.30.md
+7
@@ -7,6 +7,7 @@
7
- [Overview](#overview)
8
- [🔦 Highlights](#-highlights)
9
- [WebRTC-Direct Transport enabled by default](#webrtc-direct-transport-enabled-by-default)
10
+ - [AutoNAT V2 Service Introduced Alongside V1](#autonat-v2-service-introduced-alongside-v1)
11
- [Automated `ipfs version check`](#automated-ipfs-version-check)
12
- [Version Suffix Configuration](#version-suffix-configuration)
13
- [📝 Changelog](#-changelog)
@@ -27,6 +28,12 @@ Learn more: [`Swarm.Transports.Network.WebRTCDirect`](https://github.com/ipfs/ku
28
> [!NOTE]
29
> Kubo 0.30 includes a migration for existing users that adds `/webrtc-direct` listener on the same UDP port as `/udp/{port}/quic-v1`. This supports the WebRTC-Direct rollout by reusing preexisting UDP firewall settings and port mappings created for QUIC.
30
31
+#### AutoNAT V2 Service Introduced Alongside V1
32
+
33
+The AutoNAT service enables nodes to determine their public reachability on the internet. AutoNAT V2 enhances this protocol with improved features. In this release, Kubo will offer both V1 and V2 services to other peers, although it will continue to use only V1 when acting as a client. Future releases will phase out V1, transitioning clients to utilize V2 exclusively.
34
+
35
+For more details, see the [Deployment Plan for AutoNAT V2](https://github.com/ipfs/kubo/issues/10091) and [`AutoNAT`](https://github.com/ipfs/kubo/blob/master/docs/config.md#autonat) configuration options.
36
+
37
#### Automated `ipfs version check`
38
39
Kubo now performs privacy-preserving version checks using the [libp2p identify protocol](https://github.com/libp2p/specs/blob/master/identify/README.md) on peers detected by the Amino DHT client.
docs/config.md
+14
-5
@@ -552,7 +552,7 @@ Type: `array[string]`
552
553
## `AutoNAT`
554
555
-Contains the configuration options for the AutoNAT service. The AutoNAT service
555
+Contains the configuration options for the libp2p's [AutoNAT](https://github.com/libp2p/specs/tree/master/autonat) service. The AutoNAT service
556
helps other nodes on the network determine if they're publicly reachable from
557
the rest of the internet.
558
@@ -561,13 +561,22 @@ the rest of the internet.
561
When unset (default), the AutoNAT service defaults to _enabled_. Otherwise, this
562
field can take one of two values:
563
564
-* "enabled" - Enable the service (unless the node determines that it, itself,
565
- isn't reachable by the public internet).
566
-* "disabled" - Disable the service.
564
+* `enabled` - Enable the V1+V2 service (unless the node determines that it,
565
+ itself, isn't reachable by the public internet).
566
+* `legacy-v1` - Same as `enabled` but only V1 service is enabled. Used for testing
567
+ during as few releases as we [transition to V2](https://github.com/ipfs/kubo/issues/10091), will be removed in the future.
568
+* `disabled` - Disable the service.
569
570
Additional modes may be added in the future.
571
570
-Type: `string` (one of `"enabled"` or `"disabled"`)
572
+> [!IMPORTANT]
573
+> We are in the progress of [rolling out AutoNAT V2](https://github.com/ipfs/kubo/issues/10091).
574
+> Right now, by default, a publicly diallable Kubo provides both V1 and V2 service to other peers,
575
+> but only V1 is used by Kubo as a client. In a future release we will remove V1 and switch client to use V2.
576
+
577
+Default: `enabled`
578
+
579
+Type: `optionalString`
580
581
### `AutoNAT.Throttle`
582