mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-23 00:27:05 +08:00
add a ResourceManager option
This commit is contained in:
@@ -181,6 +181,9 @@ func (cfg *Config) addTransports(h host.Host) error {
|
||||
if cfg.ConnectionGater != nil {
|
||||
opts = append(opts, tptu.WithConnectionGater(cfg.ConnectionGater))
|
||||
}
|
||||
if cfg.ResourceManager != nil {
|
||||
opts = append(opts, tptu.WithResourceManager(cfg.ResourceManager))
|
||||
}
|
||||
upgrader, err := tptu.New(secure, muxer, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+11
@@ -346,6 +346,17 @@ func ConnectionGater(cg connmgr.ConnectionGater) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceManager configures libp2p to use the given ResourceManager.
|
||||
func ResourceManager(rcmgr network.ResourceManager) Option {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.ResourceManager != nil {
|
||||
return errors.New("cannot configure multiple resource managers")
|
||||
}
|
||||
cfg.ResourceManager = rcmgr
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// NATPortMap configures libp2p to use the default NATManager. The default
|
||||
// NATManager will attempt to open a port in your network's firewall using UPnP.
|
||||
func NATPortMap() Option {
|
||||
|
||||
Reference in New Issue
Block a user