From dc326f6fb249379ae3eda97ed1806d109802fb0e Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:58:16 -0400 Subject: [PATCH] Rebased. --- p2p/host.go | 9 ++++++++- p2p/security/security.go | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/p2p/host.go b/p2p/host.go index 18dce6a46..4a4240c56 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -11,6 +11,13 @@ import ( "sync" "time" + "github.com/harmony-one/bls/ffi/go/bls" + nodeconfig "github.com/harmony-one/harmony/internal/configs/node" + "github.com/harmony-one/harmony/internal/utils" + "github.com/harmony-one/harmony/internal/utils/blockedpeers" + "github.com/harmony-one/harmony/p2p/discovery" + "github.com/harmony-one/harmony/p2p/security" + sttypes "github.com/harmony-one/harmony/p2p/stream/types" "github.com/libp2p/go-libp2p" dht "github.com/libp2p/go-libp2p-kad-dht" libp2p_pubsub "github.com/libp2p/go-libp2p-pubsub" @@ -247,7 +254,7 @@ func NewHost(cfg HostConfig) (Host, error) { subLogger := utils.Logger().With().Str("hostID", p2pHost.ID().Pretty()).Logger() banned := blockedpeers.NewManager(1024) - security := security.NewManager(cfg.MaxConnPerIP, int(cfg.MaxPeers, banned)) + security := security.NewManager(cfg.MaxConnPerIP, int(cfg.MaxPeers), banned) // has to save the private key for host h := &HostV2{ h: p2pHost, diff --git a/p2p/security/security.go b/p2p/security/security.go index db70c76d4..d363a9647 100644 --- a/p2p/security/security.go +++ b/p2p/security/security.go @@ -59,14 +59,14 @@ func (peerMap *peerMap) Range(f func(key string, value []string) bool) { type Manager struct { maxConnPerIP int - maxPeers int64 + maxPeers int mutex sync.Mutex - peers peerMap // All the connected nodes, key is the Peer's IP, value is the peer's ID array + peers *peerMap // All the connected nodes, key is the Peer's IP, value is the peer's ID array banned *blockedpeers.Manager } -func NewManager(maxConnPerIP int, maxPeers int64, banned *blockedpeers.Manager) *Manager { +func NewManager(maxConnPerIP int, maxPeers int, banned *blockedpeers.Manager) *Manager { if maxConnPerIP < 0 { panic("maximum connections per IP must not be negative") }