Skip to content

Commit

Permalink
Merge pull request #1299 from libp2p/feat/default-connmgr
Browse files Browse the repository at this point in the history
default connection manager
  • Loading branch information
vyzo committed Jan 18, 2022
2 parents 7e3f22f + f9e4c5c commit 228c629
Showing 1 changed file with 15 additions and 0 deletions.
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

0 comments on commit 228c629

Please sign in to comment.