mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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:
parent
029d82c4ea
commit
48a6cac00b
@ -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)),
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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`.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user