add a ResourceManager option

This commit is contained in:
Marten Seemann
2022-01-06 10:39:16 +04:00
parent 4268804809
commit 5f9c4075aa
2 changed files with 14 additions and 0 deletions
+3
View File
@@ -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
View File
@@ -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 {