Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 79f0782

Browse files
committedAug 6, 2024
feat: libp2p.EnableAutoNATv2
Part of #10091 We include a flag that allows shutting down V2 in case there are issues with it.
1 parent feef085 commit 79f0782

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed
 

‎config/autonat.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
// AutoNATServiceDisabled indicates that the user has disabled the
2121
// AutoNATService.
2222
AutoNATServiceDisabled
23+
// AutoNATServiceEnabledV1Only forces use of V1 and disables V2
24+
// (used for testing)
25+
AutoNATServiceEnabledV1Only
2326
)
2427

2528
func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
@@ -30,6 +33,8 @@ func (m *AutoNATServiceMode) UnmarshalText(text []byte) error {
3033
*m = AutoNATServiceEnabled
3134
case "disabled":
3235
*m = AutoNATServiceDisabled
36+
case "legacy-v1":
37+
*m = AutoNATServiceEnabledV1Only
3338
default:
3439
return fmt.Errorf("unknown autonat mode: %s", string(text))
3540
}
@@ -44,6 +49,8 @@ func (m AutoNATServiceMode) MarshalText() ([]byte, error) {
4449
return []byte("enabled"), nil
4550
case AutoNATServiceDisabled:
4651
return []byte("disabled"), nil
52+
case AutoNATServiceEnabledV1Only:
53+
return []byte("legacy-v1"), nil
4754
default:
4855
return nil, fmt.Errorf("unknown autonat mode: %d", m)
4956
}

‎core/node/groups.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part
105105
// to dhtclient.
106106
fallthrough
107107
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))
109111
}
110112

111113
enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint

‎core/node/libp2p/nat.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
var NatPortMap = simpleOpt(libp2p.NATPortMap())
1111

12-
func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
12+
func AutoNATService(throttle *config.AutoNATThrottleConfig, v1only bool) func() Libp2pOpts {
1313
return func() (opts Libp2pOpts) {
1414
opts.Opts = append(opts.Opts, libp2p.EnableNATService())
1515
if throttle != nil {
@@ -21,6 +21,13 @@ func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
2121
),
2222
)
2323
}
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+
}
2431
return opts
2532
}
2633
}

‎docs/config.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ Type: `array[string]`
552552

553553
## `AutoNAT`
554554

555-
Contains the configuration options for the AutoNAT service. The AutoNAT service
555+
Contains the configuration options for the [AutoNAT]() service. The AutoNAT service
556556
helps other nodes on the network determine if they're publicly reachable from
557557
the rest of the internet.
558558

@@ -561,13 +561,22 @@ the rest of the internet.
561561
When unset (default), the AutoNAT service defaults to _enabled_. Otherwise, this
562562
field can take one of two values:
563563

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.
567569

568570
Additional modes may be added in the future.
569571

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`
571580

572581
### `AutoNAT.Throttle`
573582

0 commit comments

Comments
 (0)
Please sign in to comment.