diff --git a/dot/network/host.go b/dot/network/host.go index 1374cb672f..3353799162 100644 --- a/dot/network/host.go +++ b/dot/network/host.go @@ -26,7 +26,10 @@ import ( "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds" + rm "github.com/libp2p/go-libp2p/p2p/host/resource-manager" + rmObs "github.com/libp2p/go-libp2p/p2p/host/resource-manager/obs" ma "github.com/multiformats/go-multiaddr" + "github.com/prometheus/client_golang/prometheus" ) func newPrivateIPFilters() (privateIPs *ma.Filters, err error) { @@ -178,8 +181,27 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) { return nil, fmt.Errorf("failed to create peerstore: %w", err) } + limiter := rm.NewFixedLimiter(rm.DefaultLimits.AutoScale()) + var managerOptions []rm.Option + + if cfg.Metrics.Publish { + rmObs.MustRegisterWith(prometheus.DefaultRegisterer) + reporter, err := rmObs.NewStatsTraceReporter() + if err != nil { + return nil, fmt.Errorf("while creating resource manager stats trace reporter: %w", err) + } + + managerOptions = append(managerOptions, rm.WithTraceReporter(reporter)) + } + + manager, err := rm.NewResourceManager(limiter, managerOptions...) + if err != nil { + return nil, fmt.Errorf("while creating the resource manager: %w", err) + } + // set libp2p host options opts := []libp2p.Option{ + libp2p.ResourceManager(manager), libp2p.ListenAddrs(addr), libp2p.DisableRelay(), libp2p.Identity(cfg.privateKey),