Skip to content

Commit

Permalink
refactor: go-ipfs-config
Browse files Browse the repository at this point in the history
- nat.go needs to use OptionalDuration
- libp2p config no longer use relay v1 setting
  • Loading branch information
lidel committed Nov 15, 2021
1 parent 3aafda4 commit aec3c20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
fx.Provide(libp2p.Relay(enableRelay, cfg.Swarm.EnableRelayHop)),
fx.Provide(libp2p.Transports(cfg.Swarm.Transports)),
fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),
Expand Down
14 changes: 6 additions & 8 deletions core/node/libp2p/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package libp2p
import (
"time"

"github.com/ipfs/go-ipfs-config"
config "github.com/ipfs/go-ipfs-config"
"github.com/libp2p/go-libp2p"
)

Expand All @@ -13,14 +13,12 @@ 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),
libp2p.AutoNATServiceRateLimit(
throttle.GlobalLimit,
throttle.PeerLimit,
throttle.Interval.WithDefault(time.Minute),
),
)
}
return opts
Expand Down

0 comments on commit aec3c20

Please sign in to comment.