mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
cmd, node: initialize ports with --instance
cmd/utils, node: const for listen and disc ports amend usage description
This commit is contained in:
parent
c611924727
commit
24c4018e53
4 changed files with 43 additions and 7 deletions
|
|
@ -127,6 +127,7 @@ var (
|
||||||
utils.NoDiscoverFlag,
|
utils.NoDiscoverFlag,
|
||||||
utils.DiscoveryV4Flag,
|
utils.DiscoveryV4Flag,
|
||||||
utils.DiscoveryV5Flag,
|
utils.DiscoveryV5Flag,
|
||||||
|
utils.InstanceFlag,
|
||||||
utils.LegacyDiscoveryV5Flag, // deprecated
|
utils.LegacyDiscoveryV5Flag, // deprecated
|
||||||
utils.NetrestrictFlag,
|
utils.NetrestrictFlag,
|
||||||
utils.NodeKeyFileFlag,
|
utils.NodeKeyFileFlag,
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,13 @@ var (
|
||||||
Usage: "Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled)",
|
Usage: "Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled)",
|
||||||
Category: flags.EthCategory,
|
Category: flags.EthCategory,
|
||||||
}
|
}
|
||||||
|
InstanceFlag = &cli.IntFlag{
|
||||||
|
Name: "instance",
|
||||||
|
Usage: "Configures the ports to avoid conflicts when running multiple nodes on the same machine. Maximum is 200. Changes to the following port numbers: - port = default + `instance` - 1 - discovery.port = default + `instance` - 1 - authrpc.port = default + `instance`*100 - 100 - http.port = default - `instance` + 1 - ws.port = default + `instance`*2 - 2",
|
||||||
|
Value: 1,
|
||||||
|
Category: flags.EthCategory,
|
||||||
|
}
|
||||||
|
|
||||||
KeyStoreDirFlag = &flags.DirectoryFlag{
|
KeyStoreDirFlag = &flags.DirectoryFlag{
|
||||||
Name: "keystore",
|
Name: "keystore",
|
||||||
Usage: "Directory for the keystore (default = inside the datadir)",
|
Usage: "Directory for the keystore (default = inside the datadir)",
|
||||||
|
|
@ -1386,6 +1393,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
|
|
||||||
// SetNodeConfig applies node-related command line flags to the config.
|
// SetNodeConfig applies node-related command line flags to the config.
|
||||||
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
||||||
|
setInstance(ctx, cfg)
|
||||||
SetP2PConfig(ctx, &cfg.P2P)
|
SetP2PConfig(ctx, &cfg.P2P)
|
||||||
setIPC(ctx, cfg)
|
setIPC(ctx, cfg)
|
||||||
setHTTP(ctx, cfg)
|
setHTTP(ctx, cfg)
|
||||||
|
|
@ -2216,3 +2224,24 @@ func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, read
|
||||||
}
|
}
|
||||||
return triedb.NewDatabase(disk, config)
|
return triedb.NewDatabase(disk, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setInstance configures the port numbers for the given instance.
|
||||||
|
func setInstance(ctx *cli.Context, cfg *node.Config) {
|
||||||
|
if ctx.IsSet(InstanceFlag.Name) {
|
||||||
|
cfg.Instance = ctx.Int(InstanceFlag.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Instance > 200 {
|
||||||
|
Fatalf("Instance number %d is too high, maximum is 200", cfg.Instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Instance == 1 { // using default ports
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.AuthPort = node.DefaultConfig.AuthPort + cfg.Instance*100 - 100
|
||||||
|
cfg.HTTPPort = node.DefaultHTTPPort - cfg.Instance + 1
|
||||||
|
cfg.WSPort = node.DefaultWSPort + cfg.Instance*2 - 2
|
||||||
|
cfg.P2P.ListenAddr = fmt.Sprintf(":%d", node.DefaultListenPort+cfg.Instance-1)
|
||||||
|
cfg.P2P.DiscAddr = fmt.Sprintf(":%d", node.DefaultDiscPort+cfg.Instance-1)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,8 @@ type Config struct {
|
||||||
EnablePersonal bool `toml:"-"`
|
EnablePersonal bool `toml:"-"`
|
||||||
|
|
||||||
DBEngine string `toml:",omitempty"`
|
DBEngine string `toml:",omitempty"`
|
||||||
|
|
||||||
|
Instance int `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -28,12 +29,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
|
DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
|
||||||
DefaultHTTPPort = 8545 // Default TCP port for the HTTP RPC server
|
DefaultHTTPPort = 8545 // Default TCP port for the HTTP RPC server
|
||||||
DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
|
DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
|
||||||
DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
|
DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
|
||||||
DefaultAuthHost = "localhost" // Default host interface for the authenticated apis
|
DefaultAuthHost = "localhost" // Default host interface for the authenticated apis
|
||||||
DefaultAuthPort = 8551 // Default port for the authenticated apis
|
DefaultAuthPort = 8551 // Default port for the authenticated apis
|
||||||
|
DefaultListenPort = 30303 // Default port for the TCP listening address
|
||||||
|
DefaultDiscPort = 30303 // Default port for the UDP discovery address
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -68,11 +71,12 @@ var DefaultConfig = Config{
|
||||||
BatchResponseMaxSize: 25 * 1000 * 1000,
|
BatchResponseMaxSize: 25 * 1000 * 1000,
|
||||||
GraphQLVirtualHosts: []string{"localhost"},
|
GraphQLVirtualHosts: []string{"localhost"},
|
||||||
P2P: p2p.Config{
|
P2P: p2p.Config{
|
||||||
ListenAddr: ":30303",
|
ListenAddr: fmt.Sprintf(":%d", DefaultListenPort),
|
||||||
MaxPeers: 50,
|
MaxPeers: 50,
|
||||||
NAT: nat.Any(),
|
NAT: nat.Any(),
|
||||||
},
|
},
|
||||||
DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported
|
DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported
|
||||||
|
Instance: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultDataDir is the default data directory to use for the databases and other
|
// DefaultDataDir is the default data directory to use for the databases and other
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue