Add http enable flag for Node, closes #191

* Add http enable flag for Node

* Fix errors with json test data

* Refactor changes with regards to review comments

* Return appropriate errors for novalue set

* Update changes with regard to config

* Update tests timeout value for makefile ci

* Add RPCEnabled for json config in api test

* Resolve test with RPCEnabled changes

* Remove RPCEnabled flag from unconcerned tests
This commit is contained in:
Ewetumo Alexander 2017-07-13 07:54:10 +01:00 committed by Ivan Tomilov
parent b3a56eb00b
commit fb7738b1bb
11 changed files with 138 additions and 91 deletions

View File

@ -47,12 +47,12 @@ statusgo-ios-simulator-mainnet: xgo
@echo "iOS framework cross compilation done (mainnet)."
ci:
build/env.sh go test -v ./geth/api
build/env.sh go test -v ./geth/common
build/env.sh go test -v ./geth/jail
build/env.sh go test -v ./geth/node
build/env.sh go test -v ./geth/params
build/env.sh go test -v ./extkeys
build/env.sh go test -timeout 40m -v ./geth/api
build/env.sh go test -timeout 40m -v ./geth/common
build/env.sh go test -timeout 40m -v ./geth/jail
build/env.sh go test -timeout 40m -v ./geth/node
build/env.sh go test -timeout 40m -v ./geth/params
build/env.sh go test -timeout 40m -v ./extkeys
generate:
cp ./node_modules/web3/dist/web3.js ./static/scripts/web3.js

View File

@ -46,6 +46,7 @@ func (s *APITestSuite) TestCHTUpdate() {
"DataDir": "` + tmpDir + `",
"LogEnabled": true,
"LogLevel": "INFO",
"RPCEnabled": true,
"LightEthConfig": {
"CHTRootConfigURL": "` + url + `"
}

View File

@ -269,7 +269,7 @@ func (s *BackendTestSuite) TestDiscardQueuedTransaction() {
// make sure you panic if transaction complete doesn't return
completeQueuedTransaction := make(chan struct{}, 1)
common.PanicAfter(20*time.Second, completeQueuedTransaction, s.T().Name())
common.PanicAfter(30*time.Second, completeQueuedTransaction, s.T().Name())
// replace transaction notification handler
var txID string
@ -434,7 +434,7 @@ func (s *BackendTestSuite) TestCompleteMultipleQueuedTransactions() {
select {
case <-allTestTxCompleted:
// pass
case <-time.After(20 * time.Second):
case <-time.After(30 * time.Second):
s.Fail("test timed out")
return
}
@ -535,6 +535,7 @@ func (s *BackendTestSuite) TestDiscardMultipleQueuedTransactions() {
if len(completeResults) != (testTxCount + 1) {
s.Fail(fmt.Sprint("unexpected number of errors (call to CompleteTransaction should not succeed)"))
}
for _, txResult := range completeResults {
if txResult.Error.Error() != "transaction hash not found" {
s.Fail(fmt.Sprintf("invalid error for %s", txResult.Hash.Hex()))
@ -572,7 +573,7 @@ func (s *BackendTestSuite) TestDiscardMultipleQueuedTransactions() {
select {
case <-allTestTxDiscarded:
// pass
case <-time.After(20 * time.Second):
case <-time.After(30 * time.Second):
s.Fail("test timed out")
return
}

View File

@ -74,7 +74,9 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err
if err != nil {
return nil, err
}
m.nodeStarted = make(chan struct{}, 1)
go func() {
defer HaltOnPanic()

View File

@ -105,7 +105,7 @@ func MakeNode(config *params.NodeConfig) (*node.Node, error) {
// defaultEmbeddedNodeConfig returns default stack configuration for mobile client node
func defaultEmbeddedNodeConfig(config *params.NodeConfig) *node.Config {
return &node.Config{
nc := &node.Config{
DataDir: config.DataDir,
KeyStoreDir: config.KeyStoreDir,
UseLightweightKDF: true,
@ -124,8 +124,6 @@ func defaultEmbeddedNodeConfig(config *params.NodeConfig) *node.Config {
MaxPendingPeers: config.MaxPendingPeers,
},
IPCPath: makeIPCPath(config),
HTTPHost: config.HTTPHost,
HTTPPort: config.HTTPPort,
HTTPCors: []string{"*"},
HTTPModules: strings.Split(config.APIModules, ","),
WSHost: makeWSHost(config),
@ -133,6 +131,13 @@ func defaultEmbeddedNodeConfig(config *params.NodeConfig) *node.Config {
WSOrigins: []string{"*"},
WSModules: strings.Split(config.APIModules, ","),
}
if config.RPCEnabled {
nc.HTTPHost = config.HTTPHost
nc.HTTPPort = config.HTTPPort
}
return nc
}
// updateCHT changes trusted canonical hash trie root
@ -263,6 +268,7 @@ func activateShhService(stack *node.Node, config *params.NodeConfig) error {
log.Info("SHH protocol is disabled")
return nil
}
serviceConstructor := func(*node.ServiceContext) (node.Service, error) {
whisperConfig := config.WhisperConfig
whisperService := whisper.New()

View File

@ -31,11 +31,14 @@ func init() {
// errors
var (
ErrMissingDataDir = errors.New("missing required 'DataDir' parameter")
ErrMissingNetworkID = errors.New("missing required 'NetworkID' parameter")
ErrEmptyPasswordFile = errors.New("password file cannot be empty")
ErrEmptyIdentityFile = errors.New("identity file cannot be empty")
ErrEmptyAuthorizationKeyFile = errors.New("authorization key file cannot be empty")
ErrMissingDataDir = errors.New("missing required 'DataDir' parameter")
ErrMissingNetworkID = errors.New("missing required 'NetworkID' parameter")
ErrEmptyPasswordFile = errors.New("password file cannot be empty")
ErrNoPasswordFileValueSet = errors.New("password file path not set")
ErrNoIdentityFileValueSet = errors.New("identity file path not set")
ErrEmptyIdentityFile = errors.New("identity file cannot be empty")
ErrEmptyAuthorizationKeyFile = errors.New("authorization key file cannot be empty")
ErrAuthorizationKeyFileNotSet = errors.New("authorization key file is not set")
)
// LightEthConfig holds LES-related configuration
@ -55,6 +58,8 @@ type LightEthConfig struct {
CHTRootConfigURL string
}
//=====================================================================================
// FirebaseConfig holds FCM-related configuration
type FirebaseConfig struct {
// AuthorizationKeyFile file path that contains FCM authorization key
@ -64,6 +69,28 @@ type FirebaseConfig struct {
NotificationTriggerURL string
}
// ReadAuthorizationKeyFile reads and loads FCM authorization key
func (c *FirebaseConfig) ReadAuthorizationKeyFile() ([]byte, error) {
if len(c.AuthorizationKeyFile) == 0 {
return nil, ErrAuthorizationKeyFileNotSet
}
key, err := ioutil.ReadFile(c.AuthorizationKeyFile)
if err != nil {
return nil, err
}
key = bytes.TrimRight(key, "\n")
if len(key) == 0 {
return nil, ErrEmptyAuthorizationKeyFile
}
return key, nil
}
//=====================================================================================
// WhisperConfig holds SHH-related configuration
type WhisperConfig struct {
// Enabled flag specifies whether protocol is enabled
@ -107,12 +134,65 @@ type WhisperConfig struct {
FirebaseConfig *FirebaseConfig `json:"FirebaseConfig,"`
}
// ReadPasswordFile reads and returns content of the password file
func (c *WhisperConfig) ReadPasswordFile() ([]byte, error) {
if len(c.PasswordFile) == 0 {
return nil, ErrNoPasswordFileValueSet
}
password, err := ioutil.ReadFile(c.PasswordFile)
if err != nil {
return nil, err
}
password = bytes.TrimRight(password, "\n")
if len(password) == 0 {
return nil, ErrEmptyPasswordFile
}
return password, nil
}
// ReadIdentityFile reads and loads identity private key
func (c *WhisperConfig) ReadIdentityFile() (*ecdsa.PrivateKey, error) {
if len(c.IdentityFile) == 0 {
return nil, ErrNoIdentityFileValueSet
}
identity, err := crypto.LoadECDSA(c.IdentityFile)
if err != nil {
return nil, err
}
if identity == nil {
return nil, ErrEmptyIdentityFile
}
return identity, nil
}
// String dumps config object as nicely indented JSON
func (c *WhisperConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
//=====================================================================================
// SwarmConfig holds Swarm-related configuration
type SwarmConfig struct {
// Enabled flag specifies whether protocol is enabled
Enabled bool
}
// String dumps config object as nicely indented JSON
func (c *SwarmConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
//=====================================================================================
// BootClusterConfig holds configuration for supporting boot cluster, which is a temporary
// means for mobile devices to get connected to Ethereum network (UDP-based discovery
// may not be available, so we need means to discover the network manually).
@ -128,6 +208,14 @@ type BootClusterConfig struct {
ConfigFile string
}
// String dumps config object as nicely indented JSON
func (c *BootClusterConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
//=====================================================================================
// NodeConfig stores configuration options for a node
type NodeConfig struct {
// DevMode is true when given configuration is to be used during development.
@ -163,6 +251,9 @@ type NodeConfig struct {
// Pass empty string if no HTTP RPC interface needs to be started.
HTTPHost string
// RPCEnabled specifies whether the http RPC server is to be enabled by default.
RPCEnabled bool
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
HTTPPort int
@ -226,6 +317,7 @@ func NewNodeConfig(dataDir string, networkID uint64, devMode bool) (*NodeConfig,
DataDir: dataDir,
Name: ClientIdentifier,
Version: Version,
RPCEnabled: RPCEnabledDefault,
HTTPHost: HTTPHost,
HTTPPort: HTTPPort,
WSHost: WSHost,
@ -323,12 +415,14 @@ func (c *NodeConfig) LoadBootClusterNodes() ([]string, error) {
var err error
filename := c.BootClusterConfig.ConfigFile
log.Info("Loading boot nodes config file", "source", filename)
if _, err = os.Stat(filename); os.IsNotExist(err) { // load from static resources
configData, err = static.Asset("bootcluster/" + filename)
} else {
configData, err = ioutil.ReadFile(filename)
}
if err != nil {
return nil, err
}
@ -387,6 +481,7 @@ func (c *NodeConfig) updateGenesisConfig() error {
// updateBootClusterConfig populates cluster config file, depending on dev/prod and mobile/full settings
func (c *NodeConfig) updateBootClusterConfig() error {
var configFile string
switch c.NetworkID {
case MainNetworkID:
configFile = "homestead.prod.json"
@ -395,9 +490,11 @@ func (c *NodeConfig) updateBootClusterConfig() error {
case RinkebyNetworkID:
configFile = "rinkeby.prod.json"
}
if c.DevMode {
configFile = strings.Replace(configFile, "prod", "dev", 1)
}
if len(configFile) > 0 {
c.BootClusterConfig.ConfigFile = configFile
}
@ -408,6 +505,7 @@ func (c *NodeConfig) updateBootClusterConfig() error {
// updateRPCConfig transforms RPC settings to meet requirements of a given configuration
func (c *NodeConfig) updateRPCConfig() error {
c.APIModules = ProdAPIModules
if c.DevMode {
c.APIModules = DevAPIModules
}
@ -440,77 +538,3 @@ func (c *NodeConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
// String dumps config object as nicely indented JSON
func (c *WhisperConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
// String dumps config object as nicely indented JSON
func (c *SwarmConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
// String dumps config object as nicely indented JSON
func (c *BootClusterConfig) String() string {
data, _ := json.MarshalIndent(c, "", " ")
return string(data)
}
// ReadPasswordFile reads and returns content of the password file
func (c *WhisperConfig) ReadPasswordFile() ([]byte, error) {
if len(c.PasswordFile) <= 0 {
return nil, ErrEmptyPasswordFile
}
password, err := ioutil.ReadFile(c.PasswordFile)
if err != nil {
return nil, err
}
password = bytes.TrimRight(password, "\n")
if len(password) == 0 {
return nil, ErrEmptyPasswordFile
}
return password, nil
}
// ReadIdentityFile reads and loads identity private key
func (c *WhisperConfig) ReadIdentityFile() (*ecdsa.PrivateKey, error) {
if len(c.IdentityFile) <= 0 {
return nil, ErrEmptyIdentityFile
}
identity, err := crypto.LoadECDSA(c.IdentityFile)
if err != nil {
return nil, err
}
if identity == nil {
return nil, ErrEmptyIdentityFile
}
return identity, nil
}
// ReadAuthorizationKeyFile reads and loads FCM authorization key
func (c *FirebaseConfig) ReadAuthorizationKeyFile() ([]byte, error) {
if len(c.AuthorizationKeyFile) <= 0 {
return nil, ErrEmptyAuthorizationKeyFile
}
key, err := ioutil.ReadFile(c.AuthorizationKeyFile)
if err != nil {
return nil, err
}
key = bytes.TrimRight(key, "\n")
if key == nil {
return nil, ErrEmptyAuthorizationKeyFile
}
return key, nil
}

View File

@ -29,6 +29,7 @@ var loadConfigTestCases = []struct {
"WSPort": 8546,
"IPCEnabled": true,
"WSEnabled": false,
"RPCEnabled": false,
"LightEthConfig": {
"DatabaseCache": 64
}
@ -134,6 +135,7 @@ var loadConfigTestCases = []struct {
"WSPort": 4242,
"IPCEnabled": true,
"WSEnabled": false,
"RPCEnabled": true,
"LightEthConfig": {
"DatabaseCache": 64
}
@ -159,6 +161,10 @@ var loadConfigTestCases = []struct {
t.Fatal("wrong HTTPHost")
}
if !nodeConfig.RPCEnabled {
t.Fatal("Wrong RPCEnabled flag")
}
if nodeConfig.WSPort != 4242 {
t.Fatal("wrong WSPort")
}

View File

@ -17,6 +17,10 @@ const (
// IPCFile is filename of exposed IPC RPC Server
IPCFile = "geth.ipc"
// RPCEnabledDefault is the default state of whether the http rpc server is supposed
// to be started along with a node.
RPCEnabledDefault = false
// HTTPHost is host interface for the HTTP RPC server
HTTPHost = "localhost"

View File

@ -8,6 +8,7 @@
"Version": "$VERSION",
"APIModules": "db,eth,net,web3,shh,personal,admin",
"HTTPHost": "localhost",
"RPCEnabled": false,
"HTTPPort": 8545,
"WSHost": "localhost",
"WSPort": 8546,

View File

@ -8,6 +8,7 @@
"Version": "$VERSION",
"APIModules": "db,eth,net,web3,shh,personal,admin",
"HTTPHost": "localhost",
"RPCEnabled": false,
"HTTPPort": 8545,
"WSHost": "localhost",
"WSPort": 8546,

View File

@ -8,6 +8,7 @@
"Version": "$VERSION",
"APIModules": "db,eth,net,web3,shh,personal,admin",
"HTTPHost": "localhost",
"RPCEnabled": false,
"HTTPPort": 8545,
"WSHost": "localhost",
"WSPort": 8546,