Browse Source

p2p: connect max inbound peers configuration to new router (#6296)

pull/6302/head
Sam Kleinman 4 years ago
committed by GitHub
parent
commit
3ed8f14bf9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions
  1. +18
    -3
      node/node.go
  2. +0
    -5
      p2p/router.go

+ 18
- 3
node/node.go View File

@ -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,


+ 0
- 5
p2p/router.go View File

@ -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/<ip> queries, do we want to implement this here as well?
// Filtering by node ID is probably better.


Loading…
Cancel
Save