fix: add configuration option

pull/3904/head
yahtoo 3 years ago
parent 1133948ea9
commit aae369babc
  1. 8
      cmd/harmony/config_migrations.go
  2. 1
      cmd/harmony/default.go
  3. 13
      cmd/harmony/flags.go
  4. 25
      cmd/harmony/flags_test.go
  5. 5
      cmd/harmony/main.go
  6. 1
      internal/configs/harmony/harmony.go
  7. 1
      internal/configs/node/network.go
  8. 1
      p2p/security/security.go
  9. 4
      test/deploy.sh

@ -4,11 +4,12 @@ import (
"errors"
"fmt"
goversion "github.com/hashicorp/go-version"
"github.com/pelletier/go-toml"
"github.com/harmony-one/harmony/api/service/legacysync"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
goversion "github.com/hashicorp/go-version"
"github.com/pelletier/go-toml"
)
const legacyConfigVersion = "1.0.4"
@ -188,6 +189,9 @@ func init() {
if confTree.Get("P2P.DiscConcurrency") == nil {
confTree.Set("P2P.DiscConcurrency", defaultConfig.P2P.DiscConcurrency)
}
if confTree.Get("P2P.MaxConnsPerIP") == nil {
confTree.Set("P2P.MaxConnsPerIP", defaultConfig.P2P.MaxConnsPerIP)
}
confTree.Set("Version", "2.2.0")
return confTree

@ -28,6 +28,7 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
},
HTTP: harmonyconfig.HttpConfig{
Enabled: true,

@ -7,10 +7,11 @@ import (
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/spf13/cobra"
"github.com/harmony-one/harmony/api/service/legacysync"
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/spf13/cobra"
)
var (
@ -57,6 +58,7 @@ var (
p2pDHTDataStoreFlag,
p2pDiscoveryConcurrencyFlag,
legacyKeyFileFlag,
maxConnPerIPFlag,
}
httpFlags = []cli.Flag{
@ -525,6 +527,11 @@ var (
Usage: "the pubsub's DHT discovery concurrency num (default with raw libp2p dht option)",
DefValue: defaultConfig.P2P.DiscConcurrency,
}
maxConnPerIPFlag = cli.IntFlag{
Name: "p2p.security.max-conn-per-ip",
Usage: "maximum number of connections allowed per node",
DefValue: defaultConfig.P2P.MaxConnsPerIP,
}
)
func applyP2PFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
@ -552,6 +559,10 @@ func applyP2PFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, p2pDiscoveryConcurrencyFlag) {
config.P2P.DiscConcurrency = cli.GetIntFlagValue(cmd, p2pDiscoveryConcurrencyFlag)
}
if cli.IsFlagChanged(cmd, maxConnPerIPFlag) {
config.P2P.MaxConnsPerIP = cli.GetIntFlagValue(cmd, maxConnPerIPFlag)
}
}
// http flags

@ -8,9 +8,10 @@ import (
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/spf13/cobra"
"github.com/harmony-one/harmony/internal/cli"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/spf13/cobra"
)
var (
@ -30,7 +31,7 @@ func TestHarmonyFlags(t *testing.T) {
"2p/QmRVbTpEYup8dSaURZfF6ByrMTSKa4UyUzJhSjahFzRqNj --ip 8.8.8.8 --port 9000 --network_type=mainn" +
"et --dns_zone=t.hmny.io --blacklist=./.hmy/blacklist.txt --min_peers=6 --max_bls_keys_per_node=" +
"10 --broadcast_invalid_tx=true --verbosity=3 --is_archival=false --shard_id=-1 --staking=true -" +
"-aws-config-source file:config.json --p2p.disc.concurrency 5",
"-aws-config-source file:config.json --p2p.disc.concurrency 5 --p2p.security.max-conn-per-ip 5",
expConfig: harmonyconfig.HarmonyConfig{
Version: tomlConfigVersion,
General: harmonyconfig.GeneralConfig{
@ -61,6 +62,7 @@ func TestHarmonyFlags(t *testing.T) {
IP: defaultConfig.P2P.IP,
KeyFile: defaultConfig.P2P.KeyFile,
DiscConcurrency: 5,
MaxConnsPerIP: 5,
},
HTTP: harmonyconfig.HttpConfig{
Enabled: true,
@ -363,27 +365,30 @@ func TestP2PFlags(t *testing.T) {
args: []string{"--p2p.port", "9001", "--p2p.keyfile", "./key.file", "--p2p.dht.datastore",
defDataStore},
expConfig: harmonyconfig.P2pConfig{
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
DHTDataStore: &defDataStore,
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
DHTDataStore: &defDataStore,
MaxConnsPerIP: 2,
},
},
{
args: []string{"--port", "9001", "--key", "./key.file"},
expConfig: harmonyconfig.P2pConfig{
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./key.file",
MaxConnsPerIP: 2,
},
},
{
args: []string{"--p2p.port", "9001", "--p2p.disc.concurrency", "5"},
args: []string{"--p2p.port", "9001", "--p2p.disc.concurrency", "5", "--p2p.security.max-conn-per-ip", "5"},
expConfig: harmonyconfig.P2pConfig{
Port: 9001,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: 5,
MaxConnsPerIP: 5,
},
},
}

@ -20,10 +20,11 @@ import (
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/service"
"github.com/harmony-one/harmony/api/service/pprof"
"github.com/harmony-one/harmony/api/service/prometheus"
@ -579,13 +580,13 @@ func createGlobalConfig(hc harmonyconfig.HarmonyConfig) (*nodeconfig.ConfigType,
Port: strconv.Itoa(hc.P2P.Port),
ConsensusPubKey: nodeConfig.ConsensusPriKey[0].Pub.Object,
}
myHost, err = p2p.NewHost(p2p.HostConfig{
Self: &selfPeer,
BLSKey: nodeConfig.P2PPriKey,
BootNodes: hc.Network.BootNodes,
DataStoreFile: hc.P2P.DHTDataStore,
DiscConcurrency: hc.P2P.DiscConcurrency,
MaxConnPerIP: hc.P2P.MaxConnsPerIP,
})
if err != nil {
return nil, errors.Wrap(err, "cannot create P2P network host")

@ -50,6 +50,7 @@ type P2pConfig struct {
KeyFile string
DHTDataStore *string `toml:",omitempty"`
DiscConcurrency int // Discovery Concurrency value
MaxConnsPerIP int
}
type GeneralConfig struct {

@ -58,6 +58,7 @@ const (
DefaultPrometheusPort = 9900
// DefaultP2PConcurrency is the default P2P concurrency, 0 means is set the default value of P2P Discovery, the actual value is 10
DefaultP2PConcurrency = 0
DefaultMaxConnPerIP = 2
)
const (

@ -53,7 +53,6 @@ func (m *Manager) OnConnectCheck(net libp2p_network.Network, conn libp2p_network
peers = append(peers, peerID)
m.peers.Store(ip, peers)
}
if len(peers) > m.maxConnPerIP {
if err := net.ClosePeer(conn.RemotePeer()); err != nil {
return err

@ -54,7 +54,7 @@ function setup() {
function launch_bootnode() {
echo "launching boot node ..."
${DRYRUN} ${ROOT}/bin/bootnode -port 19876 >"${log_folder}"/bootnode.log 2>&1 | tee -a "${LOG_FILE}" &
${DRYRUN} ${ROOT}/bin/bootnode -port 19876 -max_conn_per_ip 100 >"${log_folder}"/bootnode.log 2>&1 | tee -a "${LOG_FILE}" &
sleep 1
BN_MA=$(grep "BN_MA" "${log_folder}"/bootnode.log | awk -F\= ' { print $2 } ')
echo "bootnode launched." + " $BN_MA"
@ -72,7 +72,7 @@ function launch_localnet() {
verbosity=3
fi
base_args=(--log_folder "${log_folder}" --min_peers "${MIN}" --bootnodes "${BN_MA}" "--network_type=$NETWORK" --blspass file:"${ROOT}/.hmy/blspass.txt" "--dns=false" "--verbosity=${verbosity}")
base_args=(--log_folder "${log_folder}" --min_peers "${MIN}" --bootnodes "${BN_MA}" "--network_type=$NETWORK" --blspass file:"${ROOT}/.hmy/blspass.txt" "--dns=false" "--verbosity=${verbosity}" "--p2p.security.max-conn-per-ip=100")
sleep 2
# Start nodes

Loading…
Cancel
Save