From acfda324c847166057ce57d25b14c835c468f41a Mon Sep 17 00:00:00 2001 From: GheisMohammadi Date: Fri, 10 Jan 2025 15:37:08 +0800 Subject: [PATCH] add resource manager to p2p configs only if it is enabled --- p2p/host.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/p2p/host.go b/p2p/host.go index b41656c98d..dbef233f63 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -165,12 +165,6 @@ func NewHost(cfg HostConfig) (Host, error) { return nil, fmt.Errorf("failed to open connection manager: %w", err) } - rmgr, err := makeResourceMgr(cfg.ResourceMgrEnabled, cfg.ResourceMgrMemoryLimitBytes, cfg.ResourceMgrFileDescriptorsLimit, cfg.ConnManagerHighWatermark) - if err != nil { - cancel() - return nil, fmt.Errorf("failed to open resource manager: %w", err) - } - // relay var relay libp2p_config.Option if cfg.NoRelay { @@ -205,8 +199,6 @@ func NewHost(cfg HostConfig) (Host, error) { */ // Connection manager connMngr, - // resource manager - libp2p.ResourceManager(rmgr), // NAT manager libp2p.NATManager(nat), // Band width Reporter @@ -221,6 +213,15 @@ func NewHost(cfg HostConfig) (Host, error) { libp2p.AutoNATServiceRateLimit(10, 5, time.Second*60), } + if cfg.ResourceMgrEnabled { + rmgr, err := makeResourceMgr(cfg.ResourceMgrEnabled, cfg.ResourceMgrMemoryLimitBytes, cfg.ResourceMgrFileDescriptorsLimit, cfg.ConnManagerHighWatermark) + if err != nil { + cancel() + return nil, fmt.Errorf("failed to open resource manager: %w", err) + } + p2pHostConfig = append(p2pHostConfig, libp2p.ResourceManager(rmgr)) + } + // Set host security if cfg.NoTransportSecurity { p2pHostConfig = append(p2pHostConfig, libp2p.Security(insecure.ID, insecure.NewWithIdentity))