Skip to content

Commit

Permalink
Add Resource Manager to P2P Configs When Enabled (#4827)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophoah authored Jan 13, 2025
2 parents 5349795 + acfda32 commit 9dba11d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 9dba11d

Please sign in to comment.