Skip to content

Commit

Permalink
default connection manager
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jan 18, 2022
1 parent 15d7dfb commit ad798e1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
tls "github.com/libp2p/go-libp2p-tls"
yamux "github.com/libp2p/go-libp2p-yamux"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-tcp-transport"
ws "github.com/libp2p/go-ws-transport"
"github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -92,11 +93,17 @@ var DefaultResourceManager = func(cfg *Config) error {
SetDefaultServiceLimits(limiter)

mgr, err := rcmgr.NewResourceManager(limiter)
return cfg.Apply(ResourceManager(mgr))
}

// DefaultConnManager creates a default connection manager
var DefaultConnectionManager = func(cfg *Config) error {
mgr, err := connmgr.NewConnManager(192, 256)
if err != nil {
return err
}

return cfg.Apply(ResourceManager(mgr))
return cfg.Apply(ConnectionManager(mgr))
}

// Complete list of default options and when to fallback on them.
Expand Down Expand Up @@ -139,6 +146,10 @@ var defaults = []struct {
fallback: func(cfg *Config) bool { return cfg.ResourceManager == nil },
opt: DefaultResourceManager,
},
{
fallback: func(cfg *Config) bool { return cfg.ConnManager == nil },
opt: DefaultConnectionManager,
},
}

// Defaults configures libp2p to use the default options. Can be combined with
Expand Down

0 comments on commit ad798e1

Please sign in to comment.