Wire up ConnMgr config

This commit is contained in:
Łukasz Magiera 2019-12-17 17:09:43 +01:00
parent 535916e54b
commit 241c7c7ecc
3 changed files with 15 additions and 3 deletions

View File

@ -157,7 +157,6 @@ func libp2p() Option {
Override(NatPortMapKey, lp2p.NatPortMap),
// TODO: how do i pass config.Libp2p.ProtectedPeers here?
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
Override(new(*pubsub.PubSub), lp2p.GossipSub()),
@ -300,6 +299,11 @@ func ConfigCommon(cfg *config.Common) Option {
ApplyIf(func(s *Settings) bool { return s.Online },
Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)),
Override(ConnectionManagerKey, lp2p.ConnectionManager(
cfg.Libp2p.ConnMgrLow,
cfg.Libp2p.ConnMgrHigh,
time.Duration(cfg.Libp2p.ConnMgrGrace),
cfg.Libp2p.ProtectedPeers)),
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),

View File

@ -37,6 +37,10 @@ type Libp2p struct {
ListenAddresses []string
BootstrapPeers []string
ProtectedPeers []string
ConnMgrLow uint
ConnMgrHigh uint
ConnMgrGrace Duration
}
// // Full Node
@ -68,6 +72,10 @@ func defCommon() Common {
"/ip4/0.0.0.0/tcp/0",
"/ip6/::/tcp/0",
},
ConnMgrLow: 50,
ConnMgrHigh: 200,
ConnMgrGrace: Duration(20 * time.Second),
},
}

View File

@ -67,9 +67,9 @@ func genLibp2pKey() (crypto.PrivKey, error) {
// Misc options
func ConnectionManager(low, high int, grace time.Duration, protected []string) func() (opts Libp2pOpts, err error) {
func ConnectionManager(low, high uint, grace time.Duration, protected []string) func() (opts Libp2pOpts, err error) {
return func() (Libp2pOpts, error) {
cm := connmgr.NewConnManager(low, high, grace)
cm := connmgr.NewConnManager(int(low), int(high), grace)
for _, p := range protected {
pid, err := peer.IDFromString(p)
if err != nil {