From c6095290bad1901b71e9155fd86a160b26be3dd0 Mon Sep 17 00:00:00 2001 From: cody Date: Mon, 28 Oct 2024 18:28:02 +0800 Subject: [PATCH] feat: resource manage use json file --- core/node/libp2p/rcmgr.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/node/libp2p/rcmgr.go b/core/node/libp2p/rcmgr.go index fbcc01657..721d5ac46 100644 --- a/core/node/libp2p/rcmgr.go +++ b/core/node/libp2p/rcmgr.go @@ -2,12 +2,14 @@ package libp2p import ( "context" + "errors" "fmt" "os" "path/filepath" "strings" "github.com/benbjohnson/clock" + serialize "github.com/bittorrent/go-btfs-config/serialize" logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/network" @@ -56,6 +58,18 @@ func ResourceManager(cfg config.SwarmConfig) interface{} { return nil, opts, err } + partialLimitConfig := rcmgr.PartialLimitConfig{} + err = serialize.ReadConfigFile(filepath.Join(repoPath, "libp2p-resource-limit-overrides.json"), &partialLimitConfig) + if errors.Is(err, serialize.ErrNotInitialized) { + err = nil + } else { + if err != nil { + return nil, opts, err + } + } + + limitConfig = partialLimitConfig.Build(limitConfig) + // The logic for defaults and overriding with specified SwarmConfig.ResourceMgr.Limits // is documented in docs/config.md. // Any changes here should be reflected there.