@@ -214,7 +214,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
214
214
}
215
215
216
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
218
if err != nil {
219
219
return err
220
220
}
@@ -709,12 +709,16 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
709
709
return listen , nil
710
710
}
711
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 )
713
717
714
718
var DefaultHostOption HostOption = constructPeerHost
715
719
716
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 ) {
718
722
719
723
// no addresses to begin with. we'll start later.
720
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
728
732
network .Swarm ().Filters .AddDialFilter (f )
729
733
}
730
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 ... )
732
741
733
742
return host , nil
734
743
}
0 commit comments