From ac405c714f7e9a5c1ae6350e40ae0361b1d1f740 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Mon, 25 Nov 2019 10:55:20 -0800 Subject: [PATCH] Enforce --p2p-max-peers (#4106) * Enforce p2p-max-peers * high == low --- beacon-chain/p2p/BUILD.bazel | 1 + beacon-chain/p2p/options.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 33f3d004f..35ccd8be4 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -48,6 +48,7 @@ go_library( "@com_github_libp2p_go_libp2p//:go_default_library", "@com_github_libp2p_go_libp2p//config:go_default_library", "@com_github_libp2p_go_libp2p//p2p/host/routed:go_default_library", + "@com_github_libp2p_go_libp2p_connmgr//:go_default_library", "@com_github_libp2p_go_libp2p_core//:go_default_library", "@com_github_libp2p_go_libp2p_core//crypto:go_default_library", "@com_github_libp2p_go_libp2p_core//host:go_default_library", diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index 01973db42..fa3ffe13a 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -4,8 +4,10 @@ import ( "crypto/ecdsa" "fmt" "net" + "time" "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p-connmgr" filter "github.com/libp2p/go-maddr-filter" "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr" @@ -22,6 +24,7 @@ func buildOptions(cfg *Config, ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt libp2p.EnableRelay(), libp2p.ListenAddrs(listen), whitelistSubnet(cfg.WhitelistCIDR), + libp2p.ConnectionManager(connmgr.NewConnManager(int(cfg.MaxPeers), int(cfg.MaxPeers), 1 * time.Minute)), } if cfg.EnableUPnP { options = append(options, libp2p.NATPortMap()) //Allow to use UPnP