| 1 | package libp2p |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | config "github.com/ipfs/kubo/config" |
| 7 | "github.com/libp2p/go-libp2p" |
| 8 | ) |
| 9 | |
| 10 | var NatPortMap = simpleOpt(libp2p.NATPortMap()) |
| 11 | |
| 12 | func AutoNATService(throttle *config.AutoNATThrottleConfig, v1only bool) func() Libp2pOpts { |
| 13 | return func() (opts Libp2pOpts) { |
| 14 | opts.Opts = append(opts.Opts, libp2p.EnableNATService()) |
| 15 | if throttle != nil { |
| 16 | opts.Opts = append(opts.Opts, |
| 17 | libp2p.AutoNATServiceRateLimit( |
| 18 | throttle.GlobalLimit, |
| 19 | throttle.PeerLimit, |
| 20 | throttle.Interval.WithDefault(time.Minute), |
| 21 | ), |
| 22 | ) |
| 23 | } |
| 24 | |
| 25 | // While V1 still exists and V2 rollout is in progress |
| 26 | // (https://github.com/ipfs/kubo/issues/10091) we check a flag that |
| 27 | // allows users to disable V2 and run V1-only mode |
| 28 | if !v1only { |
| 29 | opts.Opts = append(opts.Opts, libp2p.EnableAutoNATv2()) |
| 30 | } |
| 31 | return opts |
| 32 | } |
| 33 | } |