Add DisableNatPortMap option.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Mar 18, 2017 at 18:50 UTC
da95e9f929d7678e198fc7fff0cd81afc6115b54
4 files changed
+19
-6
core/core.go
+13
-4
@@ -214,7 +214,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
214
}
215
216
peerhost, err := hostOption(ctx, n.Identity, n.Peerstore, n.Reporter,
217
- addrfilter, tpt, protec)
217
+ addrfilter, tpt, protec, &ConstructPeerHostOpts{DisableNatPortMap: cfg.Swarm.DisableNatPortMap})
218
if err != nil {
219
return err
220
}
@@ -709,12 +709,16 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
709
return listen, nil
710
}
711
712
-type HostOption func(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, tpt smux.Transport, protc ipnet.Protector) (p2phost.Host, error)
712
+type ConstructPeerHostOpts struct {
713
+ DisableNatPortMap bool
714
+}
715
+
716
+type HostOption func(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, tpt smux.Transport, protc ipnet.Protector, opts *ConstructPeerHostOpts) (p2phost.Host, error)
717
718
var DefaultHostOption HostOption = constructPeerHost
719
720
// isolates the complex initialization steps
717
-func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, tpt smux.Transport, protec ipnet.Protector) (p2phost.Host, error) {
721
+func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, tpt smux.Transport, protec ipnet.Protector, opts *ConstructPeerHostOpts) (p2phost.Host, error) {
722
723
// no addresses to begin with. we'll start later.
724
swrm, err := swarm.NewSwarmWithProtector(ctx, nil, id, ps, protec, tpt, bwr)
@@ -728,7 +732,12 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
732
network.Swarm().Filters.AddDialFilter(f)
733
}
734
731
- host := p2pbhost.New(network, p2pbhost.NATPortMap, bwr)
735
+ hostOpts := []interface{}{bwr}
736
+ if !opts.DisableNatPortMap {
737
+ hostOpts = append(hostOpts, p2pbhost.NATPortMap)
738
+ }
739
+
740
+ host := p2pbhost.New(network, hostOpts...)
741
742
return host, nil
743
}
core/mock/mock.go
+1
-1
@@ -34,7 +34,7 @@ func NewMockNode() (*core.IpfsNode, error) {
34
}
35
36
func MockHostOption(mn mocknet.Mocknet) core.HostOption {
37
- return func(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, _ smux.Transport, _ ipnet.Protector) (host.Host, error) {
37
+ return func(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr metrics.Reporter, fs []*net.IPNet, _ smux.Transport, _ ipnet.Protector, _ *core.ConstructPeerHostOpts) (host.Host, error) {
38
return mn.AddPeerWithPeerstore(id, ps)
39
}
40
}
docs/config.md
+4
-1
@@ -216,7 +216,10 @@ See https://github.com/ipfs/go-ipfs/issues/1226#issuecomment-120494604 for more
216
- `DisableBandwidthMetrics`
217
A boolean value that when set to true, will cause ipfs to not keep track of
218
bandwidth metrics. Disabling bandwidth metrics can lead to a slight performance
219
-improvement, as well as a reduction in memory usage.
219
+improvement, as well as a reduction in memory usage.
220
+
221
+- `DisableNatPortMap`
222
+Disable NAT discovery.
223
224
## `Tour`
225
Unused.
repo/config/swarm.go
+1
@@ -3,4 +3,5 @@ package config
3
type SwarmConfig struct {
4
AddrFilters []string
5
DisableBandwidthMetrics bool
6
+ DisableNatPortMap bool
7
}