mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-22 16:17:19 +08:00
switch bool to enum
This commit is contained in:
+7
-10
@@ -48,12 +48,11 @@ type RoutingC func(host.Host) (routing.PeerRouting, error)
|
||||
|
||||
// autoNATConfig defines the AutoNAT behavior for the libp2p host.
|
||||
type AutoNATConfig struct {
|
||||
ForceReachabilityPublic bool
|
||||
ForceReachabilityPrivate bool
|
||||
EnableService bool
|
||||
ThrottleGlobalLimit int
|
||||
ThrottlePeerLimit int
|
||||
ThrottleInterval time.Duration
|
||||
ForceReachability *network.Reachability
|
||||
EnableService bool
|
||||
ThrottleGlobalLimit int
|
||||
ThrottlePeerLimit int
|
||||
ThrottleInterval time.Duration
|
||||
}
|
||||
|
||||
// Config describes a set of settings for a libp2p node
|
||||
@@ -337,10 +336,8 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
|
||||
// closed (as long as we close the underlying network).
|
||||
autonatOpts = append(autonatOpts, autonat.EnableService(dialerHost.Network()))
|
||||
}
|
||||
if cfg.AutoNATConfig.ForceReachabilityPublic {
|
||||
autonatOpts = append(autonatOpts, autonat.WithReachability(network.ReachabilityPublic))
|
||||
} else if cfg.AutoNATConfig.ForceReachabilityPrivate {
|
||||
autonatOpts = append(autonatOpts, autonat.WithReachability(network.ReachabilityPrivate))
|
||||
if cfg.AutoNATConfig.ForceReachability != nil {
|
||||
autonatOpts = append(autonatOpts, autonat.WithReachability(*cfg.AutoNATConfig.ForceReachability))
|
||||
}
|
||||
|
||||
if _, err = autonat.New(ctx, h, autonatOpts...); err != nil {
|
||||
|
||||
+5
-4
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/connmgr"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/libp2p/go-libp2p-core/metrics"
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/peerstore"
|
||||
"github.com/libp2p/go-libp2p-core/pnet"
|
||||
@@ -283,8 +284,8 @@ func DefaultStaticRelays() Option {
|
||||
// forcing the local node to believe it is reachable externally.
|
||||
func ForceReachabilityPublic() Option {
|
||||
return func(cfg *Config) error {
|
||||
cfg.AutoNATConfig.ForceReachabilityPublic = true
|
||||
cfg.AutoNATConfig.ForceReachabilityPrivate = false
|
||||
public := network.Reachability(network.ReachabilityPublic)
|
||||
cfg.AutoNATConfig.ForceReachability = &public
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -293,8 +294,8 @@ func ForceReachabilityPublic() Option {
|
||||
// forceing the local node to believe it is behind a NAT and not reachable externally.
|
||||
func ForceReachabilityPrivate() Option {
|
||||
return func(cfg *Config) error {
|
||||
cfg.AutoNATConfig.ForceReachabilityPrivate = true
|
||||
cfg.AutoNATConfig.ForceReachabilityPublic = false
|
||||
private := network.Reachability(network.ReachabilityPrivate)
|
||||
cfg.AutoNATConfig.ForceReachability = &private
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user