mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
1. Enable AutoNATService on _all_ nodes by default. If it's an issue, we can disable it in RC3 but this will give us the best testing results. 2. Expose options to configure AutoNAT rate limiting.
29 lines
635 B
Go
29 lines
635 B
Go
package libp2p
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ipfs/go-ipfs-config"
|
|
"github.com/libp2p/go-libp2p"
|
|
)
|
|
|
|
var NatPortMap = simpleOpt(libp2p.NATPortMap())
|
|
|
|
func AutoNATService(throttle *config.AutoNATThrottleConfig) func() Libp2pOpts {
|
|
return func() (opts Libp2pOpts) {
|
|
opts.Opts = append(opts.Opts, libp2p.EnableNATService())
|
|
if throttle != nil {
|
|
global := throttle.GlobalLimit
|
|
peer := throttle.PeerLimit
|
|
interval := time.Duration(throttle.Interval)
|
|
if interval == 0 {
|
|
interval = time.Minute
|
|
}
|
|
opts.Opts = append(opts.Opts,
|
|
libp2p.AutoNATServiceRateLimit(global, peer, interval),
|
|
)
|
|
}
|
|
return opts
|
|
}
|
|
}
|