feat: Swarm.EnableHolePunching flag (#8562)

* feat: use Swarm.EnableHolePunching flag within libp2p
* docs: Swarm.EnableHolePunching

Co-authored-by: Marcin Rataj <lidel@lidel.org>
Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
This commit is contained in:
Marten Seemann 2021-11-30 23:18:51 +04:00 committed by GitHub
parent 029d82c4ea
commit 48a6cac00b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -154,6 +154,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),
fx.Provide(libp2p.ForceReachability(cfg.Internal.Libp2pForceReachability)),
fx.Provide(libp2p.StaticRelays(cfg.Swarm.RelayClient.StaticRelays)),
fx.Provide(libp2p.HolePunching(cfg.Swarm.EnableHolePunching, cfg.Swarm.RelayClient.Enabled.WithDefault(false))),
fx.Provide(libp2p.Security(!bcfg.DisableEncryptedConnections, cfg.Swarm.Transports)),

View File

@ -70,3 +70,15 @@ func AutoRelay(addDefaultRelays bool) func() (opts Libp2pOpts, err error) {
return
}
}
func HolePunching(flag config.Flag, hasRelayClient bool) func() (opts Libp2pOpts, err error) {
return func() (opts Libp2pOpts, err error) {
if flag.WithDefault(false) {
if !hasRelayClient {
log.Fatal("To enable `Swarm.EnableHolePunching` requires `Swarm.RelayClient.Enabled` to be enabled.")
}
opts.Opts = append(opts.Opts, libp2p.EnableHolePunching())
}
return
}
}

View File

@ -102,6 +102,7 @@ config file at runtime.
- [`Swarm.AddrFilters`](#swarmaddrfilters)
- [`Swarm.DisableBandwidthMetrics`](#swarmdisablebandwidthmetrics)
- [`Swarm.DisableNatPortMap`](#swarmdisablenatportmap)
- [`Swarm.EnableHolePunching`](#swarmenableholepunching)
- [`Swarm.EnableAutoRelay`](#swarmenableautorelay)
- [`Swarm.RelayClient`](#swarmrelayclient)
- [`Swarm.RelayClient.Enabled`](#swarmrelayclientenabled)
@ -1314,6 +1315,21 @@ Default: `false`
Type: `bool`
### `Swarm.EnableHolePunching`
Enable hole punching for NAT traversal
when port forwarding is not possible.
When enabled, go-ipfs will coordinate with the counterparty using
a [relayed connection](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md),
to [upgrade to a direct connection](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md)
through a NAT/firewall whenever possible.
This feature requires `Swarm.RelayClient.Enabled` to be set to `true`.
Default: `false`
Type: `flag`
### `Swarm.EnableAutoRelay`
Deprecated: Set `Swarm.RelayClient.Enabled` to `true`.