From 3ed8f14bf973bb8cc3c262240a291f07d45b3f3f Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Tue, 30 Mar 2021 10:04:14 -0400 Subject: [PATCH] p2p: connect max inbound peers configuration to new router (#6296) --- node/node.go | 21 ++++++++++++++++++--- p2p/router.go | 5 ----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/node/node.go b/node/node.go index 2c3a713f0..9304bf41c 100644 --- a/node/node.go +++ b/node/node.go @@ -640,6 +640,7 @@ func createRouter( privKey crypto.PrivKey, peerManager *p2p.PeerManager, transport p2p.Transport, + options p2p.RouterOptions, ) (*p2p.Router, error) { return p2p.NewRouter( @@ -649,7 +650,7 @@ func createRouter( privKey, peerManager, []p2p.Transport{transport}, - p2p.RouterOptions{QueueType: p2pRouterQueueType}, + options, ) } @@ -915,7 +916,8 @@ func NewSeedNode(config *cfg.Config, return nil, fmt.Errorf("failed to create peer manager: %w", err) } - router, err := createRouter(p2pLogger, p2pMetrics, nodeInfo, nodeKey.PrivKey, peerManager, transport) + router, err := createRouter(p2pLogger, p2pMetrics, nodeInfo, nodeKey.PrivKey, + peerManager, transport, getRouterConfig(config)) if err != nil { return nil, fmt.Errorf("failed to create router: %w", err) } @@ -1077,7 +1079,8 @@ func NewNode(config *cfg.Config, csMetrics, p2pMetrics, memplMetrics, smMetrics := metricsProvider(genDoc.ChainID) - router, err := createRouter(p2pLogger, p2pMetrics, nodeInfo, nodeKey.PrivKey, peerManager, transport) + router, err := createRouter(p2pLogger, p2pMetrics, nodeInfo, nodeKey.PrivKey, + peerManager, transport, getRouterConfig(config)) if err != nil { return nil, fmt.Errorf("failed to create router: %w", err) } @@ -1960,6 +1963,18 @@ func createAndStartPrivValidatorGRPCClient( return pvsc, nil } +func getRouterConfig(conf *cfg.Config) p2p.RouterOptions { + opts := p2p.RouterOptions{ + QueueType: p2pRouterQueueType, + } + + if conf.P2P.MaxNumInboundPeers > 0 { + opts.MaxIncommingConnectionsPerIP = uint(conf.P2P.MaxNumInboundPeers) + } + + return opts +} + // FIXME: Temporary helper function, shims should be removed. func makeChannelsFromShims( router *p2p.Router, diff --git a/p2p/router.go b/p2p/router.go index 2a3235ed6..8fbeccc8b 100644 --- a/p2p/router.go +++ b/p2p/router.go @@ -477,11 +477,6 @@ func (r *Router) acceptPeers(transport Transport) { r.logger.Debug("starting accept routine", "transport", transport) ctx := r.stopCtx() for { - // FIXME: The old P2P stack rejected multiple connections for the same IP - // unless P2PConfig.AllowDuplicateIP is true -- it's better to limit this - // by peer ID rather than IP address, so this hasn't been implemented and - // probably shouldn't (?). - // // FIXME: The old P2P stack supported ABCI-based IP address filtering via // /p2p/filter/addr/ queries, do we want to implement this here as well? // Filtering by node ID is probably better.