From 2d54d32dabe4a75769794ac963a3b426fbedeb23 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 14 Nov 2021 11:35:10 +0400 Subject: [PATCH 1/5] enable hole punching --- core/node/groups.go | 1 + core/node/libp2p/relay.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/core/node/groups.go b/core/node/groups.go index 914e7c59b92..35a7c0db994 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -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)), diff --git a/core/node/libp2p/relay.go b/core/node/libp2p/relay.go index d456179294b..702ed1d2d14 100644 --- a/core/node/libp2p/relay.go +++ b/core/node/libp2p/relay.go @@ -70,3 +70,12 @@ 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) hasRelayClient { + opts.Opts = append(opts.Opts, libp2p.EnableHolePunching()) + } + return + } +} From 8f7ad38632494a0e0afe49d58ff010261d97368b Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 24 Nov 2021 17:42:11 +0100 Subject: [PATCH 2/5] docs: Swarm.EnableHolePunching --- docs/config.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/config.md b/docs/config.md index 3a9fb90127c..49b282c1b49 100644 --- a/docs/config.md +++ b/docs/config.md @@ -99,6 +99,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) @@ -1279,6 +1280,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. +For good results, use with `RelayClient.Enabled` set to `true`. + +Default: `false` + +Type: `flag` + ### `Swarm.EnableAutoRelay` Deprecated: Set `Swarm.RelayClient.Enabled` to `true`. From 96a3301d32c49979aaa4e26ddefdbc4bd3d390b5 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 30 Nov 2021 13:52:18 -0500 Subject: [PATCH 3/5] require relay client to be enabled to enable hole punching --- core/node/libp2p/relay.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/node/libp2p/relay.go b/core/node/libp2p/relay.go index 702ed1d2d14..33d958d5c9d 100644 --- a/core/node/libp2p/relay.go +++ b/core/node/libp2p/relay.go @@ -73,7 +73,10 @@ func AutoRelay(addDefaultRelays bool) func() (opts Libp2pOpts, err error) { func HolePunching(flag config.Flag, hasRelayClient bool) func() (opts Libp2pOpts, err error) { return func() (opts Libp2pOpts, err error) { - if flag.WithDefault(false) hasRelayClient { + 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 From aba3d4edd650faf59226e66fbb28d3744dfb1d73 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 30 Nov 2021 20:00:06 +0100 Subject: [PATCH 4/5] docs: EnableHolePunching requires RelayClient.Enabled --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index 49b282c1b49..fbe4d6b45a9 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1289,7 +1289,7 @@ 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. -For good results, use with `RelayClient.Enabled` set to `true`. +This feature requires `Swarm.RelayClient.Enabled` set to `true`. Default: `false` From 3e9c2bd31634aa430cc4adbdcc6f14aca9f509d6 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 30 Nov 2021 14:01:19 -0500 Subject: [PATCH 5/5] grammar --- docs/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index fbe4d6b45a9..69f7e523c79 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1289,7 +1289,7 @@ 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` set to `true`. +This feature requires `Swarm.RelayClient.Enabled` to be set to `true`. Default: `false`