Skip to content

Commit

Permalink
feat: libp2p.EnableAutoNATv2
Browse files Browse the repository at this point in the history
Part of #10091
We include a flag that allows shutting down V2 in case there are issues
with it.
  • Loading branch information
lidel committed Aug 6, 2024
1 parent 4b117fc commit fa3c7d4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions config/autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion core/node/libp2p/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
19 changes: 14 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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`

Expand Down

0 comments on commit fa3c7d4

Please sign in to comment.