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

default connection manager #1299

Merged
merged 2 commits into from
Jan 18, 2022
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
15 changes: 15 additions & 0 deletions 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 @@ -99,6 +100,16 @@ var DefaultResourceManager = func(cfg *Config) error {
return cfg.Apply(ResourceManager(mgr))
}

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

return cfg.Apply(ConnectionManager(mgr))
}

// Complete list of default options and when to fallback on them.
//
// Please *DON'T* specify default options any other way. Putting this all here
Expand Down Expand Up @@ -139,6 +150,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