Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable resource manager #19

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/caskadht/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -29,13 +30,15 @@ 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.")
flag.Parse()

if _, set := os.LookupEnv("GOLOG_LOG_LEVEL"); !set {
_ = log.SetLogLevel("*", *logLevel)
_ = log.SetLogLevel("net/identify", "error")
}

hOpts := []libp2p.Option{
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down