Skip to content

Commit

Permalink
feat(dot/network): introduce libp2p resource manager + prometheus met…
Browse files Browse the repository at this point in the history
…rics (#3333)
  • Loading branch information
EclesioMeloJunior authored Jun 20, 2023
1 parent 246900d commit f166746
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit f166746

Please sign in to comment.