From f758e074cbaff6a2689b50bb96805372d5b07bb1 Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Thu, 16 Feb 2023 14:42:48 +0000 Subject: [PATCH] Add option to disable resource manager Add the flag to completely disable resource manager. --- cmd/caskadht/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/caskadht/main.go b/cmd/caskadht/main.go index e740153..cbc6d86 100644 --- a/cmd/caskadht/main.go +++ b/cmd/caskadht/main.go @@ -12,6 +12,7 @@ import ( caskadht "github.com/ipni/caskadht" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/network" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" ) @@ -29,6 +30,7 @@ func main() { httpListenAddr := flag.String("httpListenAddr", "0.0.0.0:40080", "The caskadht HTTP server listen address in address:port format.") httpResponsePreferJson := flag.Bool("httpResponsePreferJson", false, `Whether to prefer responding with JSON instead of NDJSON when Accept header is set to "*/*".`) useAcceleratedDHT := flag.Bool("useAcceleratedDHT", true, "Weather to use accelerated DHT client when possible.") + useResourceManager := flag.Bool("useResourceManager", true, "Weather to use resource manager with built-in increased limits. When disabled Resource Manager is completely disabled.") ipniRequireQueryParam := flag.Bool("ipniRequireQueryParam", false, `Weather to require IPNI "cascade" query parameter with matching label in order to respond to HTTP lookup requests. Not required by default.`) ipniCascadeLabel := flag.String("ipniCascadeLabel", "ipfs-dht", "The IPNI cascade label associated to this instance.") logLevel := flag.String("logLevel", "info", "The logging level. Only applied if GOLOG_LOG_LEVEL environment variable is unset.") @@ -36,6 +38,7 @@ func main() { if _, set := os.LookupEnv("GOLOG_LOG_LEVEL"); !set { _ = log.SetLogLevel("*", *logLevel) + _ = log.SetLogLevel("net/identify", "error") } hOpts := []libp2p.Option{ @@ -58,7 +61,7 @@ func main() { if *libp2pListenAddrs != "" { hOpts = append(hOpts, libp2p.ListenAddrStrings(strings.Split(*libp2pListenAddrs, ",")...)) } - if *useAcceleratedDHT { + if *useAcceleratedDHT && *useResourceManager { // Adjust outbound connections and base limit FD to allow the accelerated DHT client to // (re)load its routing table. Because, currently the client does not gracefully handle // Resource Manager throttling. @@ -88,6 +91,9 @@ func main() { } hOpts = append(hOpts, libp2p.ResourceManager(rm)) } + if !*useResourceManager { + hOpts = append(hOpts, libp2p.ResourceManager(&network.NullResourceManager{})) + } h, err := libp2p.New(hOpts...) if err != nil { logger.Fatalw("Failed to instantiate libp2p host", "err", err)