2017-03-15 21:03:01 +00:00
|
|
|
package params
|
|
|
|
|
|
|
|
import (
|
2017-04-12 18:26:54 +00:00
|
|
|
"bytes"
|
2018-07-04 09:30:57 +00:00
|
|
|
"crypto/ecdsa"
|
2017-03-15 21:03:01 +00:00
|
|
|
"encoding/json"
|
2017-03-18 18:23:58 +00:00
|
|
|
"errors"
|
2017-05-02 14:30:11 +00:00
|
|
|
"fmt"
|
2018-08-21 12:46:10 +00:00
|
|
|
"go/build"
|
2017-03-15 21:03:01 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2018-08-21 12:46:10 +00:00
|
|
|
"path"
|
2017-03-15 21:03:01 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2018-08-24 03:17:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-03-15 21:03:01 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2018-07-04 09:30:57 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-03-20 18:35:28 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2018-04-10 06:44:09 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/discv5"
|
2018-08-24 03:17:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2017-03-15 21:03:01 +00:00
|
|
|
)
|
|
|
|
|
2017-05-03 14:24:48 +00:00
|
|
|
// errors
|
2017-03-15 21:03:01 +00:00
|
|
|
var (
|
2017-07-13 06:54:10 +00:00
|
|
|
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")
|
|
|
|
ErrEmptyAuthorizationKeyFile = errors.New("authorization key file cannot be empty")
|
|
|
|
ErrAuthorizationKeyFileNotSet = errors.New("authorization key file is not set")
|
2017-03-15 21:03:01 +00:00
|
|
|
)
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// LightEthConfig
|
|
|
|
// ----------
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// LightEthConfig holds LES-related configuration
|
|
|
|
// Status nodes are always lightweight clients (due to mobile platform constraints)
|
|
|
|
type LightEthConfig struct {
|
2017-05-11 13:20:27 +00:00
|
|
|
// Enabled flag specifies whether protocol is enabled
|
2017-03-28 09:04:52 +00:00
|
|
|
Enabled bool
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// Genesis is JSON to seed the chain database with
|
|
|
|
Genesis string
|
|
|
|
|
|
|
|
// DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced)
|
|
|
|
DatabaseCache int
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// FirebaseConfig
|
|
|
|
// ----------
|
|
|
|
|
2017-05-03 14:24:48 +00:00
|
|
|
// FirebaseConfig holds FCM-related configuration
|
2017-04-12 18:26:54 +00:00
|
|
|
type FirebaseConfig struct {
|
|
|
|
// AuthorizationKeyFile file path that contains FCM authorization key
|
|
|
|
AuthorizationKeyFile string
|
|
|
|
|
|
|
|
// NotificationTriggerURL URL used to send push notification requests to
|
|
|
|
NotificationTriggerURL string
|
|
|
|
}
|
|
|
|
|
2017-07-13 06:54:10 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// WhisperConfig
|
|
|
|
// ----------
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// WhisperConfig holds SHH-related configuration
|
2017-03-28 09:04:52 +00:00
|
|
|
type WhisperConfig struct {
|
2017-05-11 13:20:27 +00:00
|
|
|
// Enabled flag specifies whether protocol is enabled
|
2017-03-28 09:04:52 +00:00
|
|
|
Enabled bool
|
2017-04-09 22:16:05 +00:00
|
|
|
|
2018-03-02 09:25:30 +00:00
|
|
|
// LightClient should be true if the node should start with an empty bloom filter and not forward messages from other nodes
|
|
|
|
LightClient bool
|
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
// EnableMailServer is mode when node is capable of delivering expired messages on demand
|
|
|
|
EnableMailServer bool
|
2017-04-09 22:16:05 +00:00
|
|
|
|
|
|
|
// DataDir is the file system folder Whisper should use for any data storage needs.
|
2017-12-04 16:11:14 +00:00
|
|
|
// For instance, MailServer will use this directory to store its data.
|
2017-04-09 22:16:05 +00:00
|
|
|
DataDir string
|
|
|
|
|
|
|
|
// MinimumPoW minimum PoW for Whisper messages
|
|
|
|
MinimumPoW float64
|
|
|
|
|
2018-07-04 09:30:57 +00:00
|
|
|
// MailServerPasswordFile contains a password for symmetric encryption with MailServer.
|
|
|
|
MailServerPasswordFile string
|
|
|
|
|
|
|
|
// MailServerPassword for symmetric encryption with MailServer.
|
|
|
|
// (if no account file selected, then this password is used for symmetric encryption).
|
|
|
|
MailServerPassword string
|
|
|
|
|
|
|
|
// MailServerAsymKeyFile is a file with an asymmetric key to decrypt messages sent to MailServer.
|
|
|
|
MailServerAsymKeyFile string
|
|
|
|
|
|
|
|
// MailServerAsymKey is an asymmetric key to decrypt messages sent to MailServer.
|
|
|
|
MailServerAsymKey *ecdsa.PrivateKey
|
|
|
|
|
2018-05-17 11:21:04 +00:00
|
|
|
// RateLimit minimum time between queries to mail server per peer
|
|
|
|
MailServerRateLimit int
|
|
|
|
|
|
|
|
// MailServerCleanupPeriod time in seconds to wait to run mail server cleanup
|
|
|
|
MailServerCleanupPeriod int
|
|
|
|
|
2017-04-09 22:16:05 +00:00
|
|
|
// TTL time to live for messages, in seconds
|
|
|
|
TTL int
|
2017-04-12 18:26:54 +00:00
|
|
|
|
|
|
|
// FirebaseConfig extra configuration for Firebase Cloud Messaging
|
|
|
|
FirebaseConfig *FirebaseConfig `json:"FirebaseConfig,"`
|
2018-06-13 11:24:04 +00:00
|
|
|
|
|
|
|
// EnableNTPSync enables NTP synchronizations
|
|
|
|
EnableNTPSync bool
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2018-07-04 09:30:57 +00:00
|
|
|
// ReadMailServerPasswordFile reads and returns content of the password file
|
|
|
|
func (c *WhisperConfig) ReadMailServerPasswordFile() error {
|
|
|
|
if len(c.MailServerPasswordFile) == 0 {
|
2017-12-07 16:58:11 +00:00
|
|
|
return ErrNoPasswordFileValueSet
|
2017-07-13 06:54:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 09:30:57 +00:00
|
|
|
password, err := ioutil.ReadFile(c.MailServerPasswordFile)
|
2017-07-13 06:54:10 +00:00
|
|
|
if err != nil {
|
2017-12-07 16:58:11 +00:00
|
|
|
return err
|
2017-07-13 06:54:10 +00:00
|
|
|
}
|
|
|
|
password = bytes.TrimRight(password, "\n")
|
|
|
|
|
|
|
|
if len(password) == 0 {
|
2017-12-07 16:58:11 +00:00
|
|
|
return ErrEmptyPasswordFile
|
2017-07-13 06:54:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 09:30:57 +00:00
|
|
|
c.MailServerPassword = string(password)
|
2017-12-07 16:58:11 +00:00
|
|
|
|
|
|
|
return nil
|
2017-07-13 06:54:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 09:30:57 +00:00
|
|
|
// ReadMailServerAsymKeyFile reads and returns a private key from a given file.
|
|
|
|
func (c *WhisperConfig) ReadMailServerAsymKeyFile() (err error) {
|
|
|
|
c.MailServerAsymKey, err = crypto.LoadECDSA(c.MailServerAsymKeyFile)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-13 06:54:10 +00:00
|
|
|
// String dumps config object as nicely indented JSON
|
|
|
|
func (c *WhisperConfig) String() string {
|
2018-01-17 16:46:21 +00:00
|
|
|
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
|
2017-07-13 06:54:10 +00:00
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// SwarmConfig
|
|
|
|
// ----------
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// SwarmConfig holds Swarm-related configuration
|
2017-03-28 09:04:52 +00:00
|
|
|
type SwarmConfig struct {
|
2017-05-11 13:20:27 +00:00
|
|
|
// Enabled flag specifies whether protocol is enabled
|
2017-03-28 09:04:52 +00:00
|
|
|
Enabled bool
|
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2017-07-13 06:54:10 +00:00
|
|
|
// String dumps config object as nicely indented JSON
|
|
|
|
func (c *SwarmConfig) String() string {
|
2018-01-17 16:46:21 +00:00
|
|
|
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
|
2017-07-13 06:54:10 +00:00
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
2018-03-20 14:05:21 +00:00
|
|
|
// ClusterConfig
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
|
2018-03-20 14:05:21 +00:00
|
|
|
// ClusterConfig holds configuration for supporting cluster peers, which is a temporary
|
2017-05-11 13:20:27 +00:00
|
|
|
// 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).
|
2018-03-20 14:05:21 +00:00
|
|
|
type ClusterConfig struct {
|
2017-05-11 13:20:27 +00:00
|
|
|
// Enabled flag specifies whether feature is enabled
|
|
|
|
Enabled bool
|
|
|
|
|
2018-07-25 14:03:35 +00:00
|
|
|
// Fleet is a type of selected fleet.
|
|
|
|
Fleet string
|
|
|
|
|
2018-03-20 14:05:21 +00:00
|
|
|
// StaticNodes lists the static nodes taken from compiled or passed cluster.json
|
|
|
|
StaticNodes []string
|
|
|
|
|
2018-04-18 15:13:27 +00:00
|
|
|
// BootNodes list of cluster peer nodes for a given network (Mainnet, Ropsten, Rinkeby, Homestead),
|
2017-08-04 16:14:17 +00:00
|
|
|
// for a given mode (production vs development)
|
|
|
|
BootNodes []string
|
2018-07-04 10:51:47 +00:00
|
|
|
|
2018-07-25 14:48:02 +00:00
|
|
|
// TrustedMailServers is a list of verified Mail Servers.
|
|
|
|
TrustedMailServers []string
|
|
|
|
|
2018-07-04 10:51:47 +00:00
|
|
|
// RendezvousNodes is a rendezvous discovery server.
|
|
|
|
RendezvousNodes []string
|
2017-05-11 13:20:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 06:54:10 +00:00
|
|
|
// String dumps config object as nicely indented JSON
|
2018-03-20 14:05:21 +00:00
|
|
|
func (c *ClusterConfig) String() string {
|
2018-01-17 16:46:21 +00:00
|
|
|
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
|
2017-07-13 06:54:10 +00:00
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:44:09 +00:00
|
|
|
// Limits represent min and max amount of peers
|
2018-04-20 07:39:31 +00:00
|
|
|
type Limits struct {
|
|
|
|
Min, Max int
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewLimits creates new Limits config with given min and max values.
|
|
|
|
func NewLimits(min, max int) Limits {
|
|
|
|
return Limits{
|
|
|
|
Min: min,
|
|
|
|
Max: max,
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:44:09 +00:00
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// UpstreamRPCConfig
|
|
|
|
// ----------
|
2017-08-15 10:27:12 +00:00
|
|
|
|
|
|
|
// UpstreamRPCConfig stores configuration for upstream rpc connection.
|
|
|
|
type UpstreamRPCConfig struct {
|
|
|
|
// Enabled flag specifies whether feature is enabled
|
|
|
|
Enabled bool
|
|
|
|
|
|
|
|
// URL sets the rpc upstream host address for communication with
|
|
|
|
// a non-local infura endpoint.
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ----------
|
|
|
|
// NodeConfig
|
|
|
|
// ----------
|
2017-08-15 10:27:12 +00:00
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// NodeConfig stores configuration options for a node
|
|
|
|
type NodeConfig struct {
|
2017-05-03 14:24:48 +00:00
|
|
|
// NetworkID sets network to use for selecting peers to connect to
|
2017-08-10 15:31:29 +00:00
|
|
|
NetworkID uint64 `json:"NetworkId" validate:"required"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
// DataDir is the file system folder the node should use for any data storage needs.
|
2017-08-10 15:31:29 +00:00
|
|
|
DataDir string `validate:"required"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2017-04-28 08:49:15 +00:00
|
|
|
// KeyStoreDir is the file system folder that contains private keys.
|
|
|
|
// If KeyStoreDir is empty, the default location is the "keystore" subdirectory of DataDir.
|
|
|
|
KeyStoreDir string
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// NodeKeyFile is a filename with node ID (private key)
|
2017-04-09 22:16:05 +00:00
|
|
|
// This file should contain a valid secp256k1 private key that will be used for both
|
|
|
|
// remote peer identification as well as network traffic encryption.
|
|
|
|
NodeKeyFile string
|
|
|
|
|
2018-05-10 11:45:51 +00:00
|
|
|
// NoDiscovery set to true will disable discovery protocol.
|
|
|
|
NoDiscovery bool
|
2018-01-23 05:16:13 +00:00
|
|
|
|
2018-07-04 10:51:47 +00:00
|
|
|
// Rendezvous enables discovery protocol.
|
|
|
|
Rendezvous bool
|
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
// ListenAddr is an IP address and port of this node (e.g. 127.0.0.1:30303).
|
|
|
|
ListenAddr string
|
|
|
|
|
2018-08-17 06:25:55 +00:00
|
|
|
// AdvertiseAddr is a public IP address the node wants to be found with.
|
|
|
|
// It is especially useful when using floating IPs attached to a server.
|
|
|
|
AdvertiseAddr string
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// Name sets the instance name of the node. It must not contain the / character.
|
2017-08-10 15:31:29 +00:00
|
|
|
Name string `validate:"excludes=/"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
// Version exposes program's version. It is used in the devp2p node identifier.
|
|
|
|
Version string
|
|
|
|
|
|
|
|
// APIModules is a comma-separated list of API modules exposed via *any* (HTTP/WS/IPC) RPC interface.
|
|
|
|
APIModules string
|
|
|
|
|
|
|
|
// HTTPHost is the host interface on which to start the HTTP RPC server.
|
|
|
|
// Pass empty string if no HTTP RPC interface needs to be started.
|
|
|
|
HTTPHost string
|
|
|
|
|
2017-07-13 06:54:10 +00:00
|
|
|
// RPCEnabled specifies whether the http RPC server is to be enabled by default.
|
|
|
|
RPCEnabled bool
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
|
|
|
|
HTTPPort int
|
|
|
|
|
|
|
|
// IPCFile is filename of exposed IPC RPC Server
|
|
|
|
IPCFile string
|
|
|
|
|
|
|
|
// IPCEnabled specifies whether IPC-RPC Server is enabled or not
|
|
|
|
IPCEnabled bool
|
|
|
|
|
|
|
|
// TLSEnabled specifies whether TLS support should be enabled on node or not
|
|
|
|
// TLS support is only planned in go-ethereum, so we are using our own patch.
|
|
|
|
TLSEnabled bool
|
|
|
|
|
|
|
|
// MaxPeers is the maximum number of (global) peers that can be connected.
|
|
|
|
// Set to zero, if only static or trusted peers are allowed to connect.
|
|
|
|
MaxPeers int
|
|
|
|
|
|
|
|
// MaxPendingPeers is the maximum number of peers that can be pending in the
|
|
|
|
// handshake phase, counted separately for inbound and outbound connections.
|
|
|
|
MaxPendingPeers int
|
|
|
|
|
2018-03-20 18:35:28 +00:00
|
|
|
log log.Logger
|
|
|
|
|
2018-04-26 16:28:42 +00:00
|
|
|
// LogEnabled enables the logger
|
|
|
|
LogEnabled bool `json:"LogEnabled"`
|
|
|
|
|
2017-03-18 19:00:40 +00:00
|
|
|
// LogFile is filename where exposed logs get written to
|
|
|
|
LogFile string
|
|
|
|
|
2018-01-03 14:11:21 +00:00
|
|
|
// LogLevel defines minimum log level. Valid names are "ERROR", "WARN", "INFO", "DEBUG", and "TRACE".
|
|
|
|
LogLevel string `validate:"eq=ERROR|eq=WARN|eq=INFO|eq=DEBUG|eq=TRACE"`
|
2017-03-18 19:00:40 +00:00
|
|
|
|
2017-05-02 14:30:11 +00:00
|
|
|
// LogToStderr defines whether logged info should also be output to os.Stderr
|
|
|
|
LogToStderr bool
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2017-08-15 10:27:12 +00:00
|
|
|
// UpstreamConfig extra config for providing upstream infura server.
|
|
|
|
UpstreamConfig UpstreamRPCConfig `json:"UpstreamConfig"`
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// ClusterConfigFile contains the file name of the cluster configuration. If
|
|
|
|
// empty the statical configuration data will be taken.
|
|
|
|
ClusterConfigFile string `json:"ClusterConfigFile"`
|
|
|
|
|
2018-03-20 14:05:21 +00:00
|
|
|
// ClusterConfig extra configuration for supporting cluster peers.
|
|
|
|
ClusterConfig *ClusterConfig `json:"ClusterConfig," validate:"structonly"`
|
2017-05-11 13:20:27 +00:00
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// LightEthConfig extra configuration for LES
|
2017-08-10 15:31:29 +00:00
|
|
|
LightEthConfig *LightEthConfig `json:"LightEthConfig," validate:"structonly"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
// WhisperConfig extra configuration for SHH
|
2017-08-10 15:31:29 +00:00
|
|
|
WhisperConfig *WhisperConfig `json:"WhisperConfig," validate:"structonly"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
// SwarmConfig extra configuration for Swarm and ENS
|
2017-08-10 15:31:29 +00:00
|
|
|
SwarmConfig *SwarmConfig `json:"SwarmConfig," validate:"structonly"`
|
2018-04-10 06:44:09 +00:00
|
|
|
|
2018-07-16 07:40:40 +00:00
|
|
|
// RegisterTopics a list of specific topics where the peer wants to be
|
|
|
|
// discoverable.
|
|
|
|
RegisterTopics []discv5.Topic `json:"RegisterTopics"`
|
|
|
|
|
|
|
|
// RequiredTopics list of topics where a client wants to search for
|
|
|
|
// discoverable peers with the discovery limits.
|
|
|
|
RequireTopics map[discv5.Topic]Limits `json:"RequireTopics"`
|
2018-05-03 10:36:56 +00:00
|
|
|
|
|
|
|
// StatusServiceEnabled enables status service api
|
|
|
|
StatusServiceEnabled bool
|
2018-06-25 13:27:17 +00:00
|
|
|
|
|
|
|
// DebugAPIEnabled enables debug api
|
|
|
|
DebugAPIEnabled bool
|
2018-08-20 13:55:43 +00:00
|
|
|
|
|
|
|
// MailServerRegistryAddress is the MailServerRegistry contract address
|
|
|
|
MailServerRegistryAddress string
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewNodeConfig creates new node configuration object
|
2018-07-25 14:03:35 +00:00
|
|
|
func NewNodeConfig(dataDir, clstrCfgFile, fleet string, networkID uint64) (*NodeConfig, error) {
|
2017-03-15 21:03:01 +00:00
|
|
|
nodeConfig := &NodeConfig{
|
2018-03-19 16:22:09 +00:00
|
|
|
NetworkID: networkID,
|
|
|
|
DataDir: dataDir,
|
|
|
|
Name: ClientIdentifier,
|
|
|
|
Version: Version,
|
|
|
|
RPCEnabled: RPCEnabledDefault,
|
|
|
|
HTTPHost: HTTPHost,
|
|
|
|
HTTPPort: HTTPPort,
|
|
|
|
ListenAddr: ListenAddr,
|
|
|
|
APIModules: APIModules,
|
|
|
|
MaxPeers: MaxPeers,
|
|
|
|
MaxPendingPeers: MaxPendingPeers,
|
|
|
|
IPCFile: IPCFile,
|
2018-06-08 11:29:50 +00:00
|
|
|
log: log.New("package", "status-go/params.NodeConfig"),
|
2018-03-19 16:22:09 +00:00
|
|
|
LogFile: LogFile,
|
|
|
|
LogLevel: LogLevel,
|
|
|
|
LogToStderr: LogToStderr,
|
|
|
|
ClusterConfigFile: clstrCfgFile,
|
2018-03-20 14:05:21 +00:00
|
|
|
ClusterConfig: &ClusterConfig{
|
2018-08-26 10:54:58 +00:00
|
|
|
Enabled: true, // cluster must be enabled by default
|
2018-07-25 14:03:35 +00:00
|
|
|
Fleet: fleet,
|
2018-03-20 14:05:21 +00:00
|
|
|
StaticNodes: []string{},
|
|
|
|
BootNodes: []string{},
|
2017-08-04 16:14:17 +00:00
|
|
|
},
|
|
|
|
LightEthConfig: &LightEthConfig{
|
|
|
|
Enabled: true,
|
|
|
|
DatabaseCache: DatabaseCache,
|
2017-05-11 13:20:27 +00:00
|
|
|
},
|
2017-03-28 09:04:52 +00:00
|
|
|
WhisperConfig: &WhisperConfig{
|
2017-04-09 22:16:05 +00:00
|
|
|
Enabled: true,
|
|
|
|
MinimumPoW: WhisperMinimumPoW,
|
|
|
|
TTL: WhisperTTL,
|
2017-04-12 18:26:54 +00:00
|
|
|
FirebaseConfig: &FirebaseConfig{
|
|
|
|
NotificationTriggerURL: FirebaseNotificationTriggerURL,
|
|
|
|
},
|
2018-06-13 11:24:04 +00:00
|
|
|
EnableNTPSync: true,
|
2017-03-28 09:04:52 +00:00
|
|
|
},
|
2018-04-20 12:23:18 +00:00
|
|
|
SwarmConfig: &SwarmConfig{},
|
|
|
|
RegisterTopics: []discv5.Topic{},
|
|
|
|
RequireTopics: map[discv5.Topic]Limits{},
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 03:24:56 +00:00
|
|
|
// adjust dependent values
|
|
|
|
if err := nodeConfig.updateConfig(); err != nil {
|
2017-05-02 14:30:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadNodeConfig parses incoming JSON and returned it as Config
|
|
|
|
func LoadNodeConfig(configJSON string) (*NodeConfig, error) {
|
2017-08-10 15:31:29 +00:00
|
|
|
nodeConfig, err := loadNodeConfig(configJSON)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := nodeConfig.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadNodeConfig(configJSON string) (*NodeConfig, error) {
|
2018-08-26 10:54:58 +00:00
|
|
|
nodeConfig, err := NewNodeConfig("", "", FleetUndefined, 0)
|
2017-03-15 21:03:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(strings.NewReader(configJSON))
|
|
|
|
|
|
|
|
// override default configuration with values by JSON input
|
|
|
|
if err := decoder.Decode(&nodeConfig); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// repopulate
|
2017-05-16 03:24:56 +00:00
|
|
|
if err := nodeConfig.updateConfig(); err != nil {
|
2017-05-02 14:30:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2017-08-10 15:31:29 +00:00
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate checks if NodeConfig fields have valid values.
|
|
|
|
//
|
|
|
|
// It returns nil if there are no errors, otherwise one or more errors
|
|
|
|
// can be returned. Multiple errors are joined with a new line.
|
|
|
|
//
|
|
|
|
// A single error for a struct:
|
|
|
|
//
|
|
|
|
// type TestStruct struct {
|
|
|
|
// TestField string `validate:"required"`
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// has the following format:
|
|
|
|
//
|
|
|
|
// Key: 'TestStruct.TestField' Error:Field validation for 'TestField' failed on the 'required' tag
|
|
|
|
//
|
|
|
|
func (c *NodeConfig) Validate() error {
|
|
|
|
validate := NewValidator()
|
|
|
|
|
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:05:21 +00:00
|
|
|
if c.ClusterConfig.Enabled {
|
|
|
|
if err := validate.Struct(c.ClusterConfig); err != nil {
|
2017-08-10 15:31:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 15:31:29 +00:00
|
|
|
if c.LightEthConfig.Enabled {
|
|
|
|
if err := validate.Struct(c.LightEthConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.WhisperConfig.Enabled {
|
|
|
|
if err := validate.Struct(c.WhisperConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SwarmConfig.Enabled {
|
|
|
|
if err := validate.Struct(c.SwarmConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save dumps configuration to the disk
|
|
|
|
func (c *NodeConfig) Save() error {
|
|
|
|
data, err := json.MarshalIndent(c, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.DataDir, os.ModePerm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
configFilePath := filepath.Join(c.DataDir, "config.json")
|
|
|
|
if err := ioutil.WriteFile(configFilePath, data, os.ModePerm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:35:28 +00:00
|
|
|
c.log.Info("config file saved", "path", configFilePath)
|
2017-03-15 21:03:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-16 03:24:56 +00:00
|
|
|
// updateConfig traverses configuration and adjusts dependent fields
|
|
|
|
// (we have a development/production and mobile/full node dependent configurations)
|
|
|
|
func (c *NodeConfig) updateConfig() error {
|
2018-03-15 11:36:28 +00:00
|
|
|
// Update separate configurations.
|
2017-05-16 03:24:56 +00:00
|
|
|
if err := c.updateGenesisConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-08-15 10:27:12 +00:00
|
|
|
|
|
|
|
if err := c.updateUpstreamConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
if err := c.updateClusterConfig(); err != nil {
|
2017-05-16 03:24:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-04-20 12:23:18 +00:00
|
|
|
c.updatePeerLimits()
|
2018-04-12 10:26:25 +00:00
|
|
|
return c.updateRelativeDirsConfig()
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// updateGenesisConfig does necessary adjustments to config object (depending on network node will be running on)
|
|
|
|
func (c *NodeConfig) updateGenesisConfig() error {
|
|
|
|
var genesis *core.Genesis
|
|
|
|
|
|
|
|
switch c.NetworkID {
|
|
|
|
case MainNetworkID:
|
|
|
|
genesis = core.DefaultGenesisBlock()
|
|
|
|
case RopstenNetworkID:
|
|
|
|
genesis = core.DefaultTestnetGenesisBlock()
|
|
|
|
case RinkebyNetworkID:
|
|
|
|
genesis = core.DefaultRinkebyGenesisBlock()
|
2017-10-16 21:54:56 +00:00
|
|
|
case StatusChainNetworkID:
|
|
|
|
var err error
|
|
|
|
genesis, err = c.DefaultStatusChainGenesisBlock()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-05-16 03:24:56 +00:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// encode the genesis into JSON
|
|
|
|
enc, err := json.Marshal(genesis)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.LightEthConfig.Genesis = string(enc)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-10-16 21:54:56 +00:00
|
|
|
// DefaultStatusChainGenesisBlock returns the StatusChain network genesis block.
|
|
|
|
func (c *NodeConfig) DefaultStatusChainGenesisBlock() (*core.Genesis, error) {
|
2018-08-21 12:46:10 +00:00
|
|
|
genesisJSON, err := ioutil.ReadFile(path.Join(GetStatusHome(), "static/config/status-chain-genesis.json"))
|
2017-10-16 21:54:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("status-chain-genesis.json could not be loaded: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var genesis *core.Genesis
|
2017-10-20 09:06:22 +00:00
|
|
|
err = json.Unmarshal(genesisJSON, &genesis)
|
|
|
|
if err != nil {
|
2017-10-16 21:54:56 +00:00
|
|
|
return nil, fmt.Errorf("cannot unmarshal status-chain-genesis.json: %s", err)
|
|
|
|
}
|
|
|
|
return genesis, nil
|
|
|
|
}
|
|
|
|
|
2017-08-15 10:27:12 +00:00
|
|
|
// updateUpstreamConfig sets the proper UpstreamConfig.URL for the network id being used.
|
|
|
|
func (c *NodeConfig) updateUpstreamConfig() error {
|
|
|
|
|
|
|
|
// If we have a URL already set then keep URL incase
|
|
|
|
// of custom server.
|
|
|
|
if c.UpstreamConfig.URL != "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c.NetworkID {
|
|
|
|
case MainNetworkID:
|
2017-10-25 12:08:33 +00:00
|
|
|
c.UpstreamConfig.URL = MainnetEthereumNetworkURL
|
2017-08-15 10:27:12 +00:00
|
|
|
case RopstenNetworkID:
|
2017-10-25 12:08:33 +00:00
|
|
|
c.UpstreamConfig.URL = RopstenEthereumNetworkURL
|
2017-08-15 10:27:12 +00:00
|
|
|
case RinkebyNetworkID:
|
2017-10-25 12:08:33 +00:00
|
|
|
c.UpstreamConfig.URL = RinkebyEthereumNetworkURL
|
2017-08-15 10:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
// updateClusterConfig loads static peer nodes and CHT for a given network and mode.
|
2017-08-04 16:14:17 +00:00
|
|
|
// This is necessary until we have LES protocol support CHT sync, and better node
|
|
|
|
// discovery on mobile devices)
|
2018-03-19 16:22:09 +00:00
|
|
|
func (c *NodeConfig) updateClusterConfig() error {
|
2018-03-20 14:05:21 +00:00
|
|
|
if !c.ClusterConfig.Enabled {
|
2017-08-04 16:14:17 +00:00
|
|
|
return nil
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
2017-07-13 06:54:10 +00:00
|
|
|
|
2018-08-21 13:48:58 +00:00
|
|
|
c.log.Info("update cluster config", "configFile", c.ClusterConfigFile, "fleet", c.ClusterConfig.Fleet)
|
2018-07-25 14:03:35 +00:00
|
|
|
|
2018-08-26 10:54:58 +00:00
|
|
|
var cluster Cluster
|
2018-07-25 14:03:35 +00:00
|
|
|
|
2018-03-19 16:22:09 +00:00
|
|
|
if c.ClusterConfigFile != "" {
|
|
|
|
// Load cluster configuration from external file.
|
2018-03-26 12:52:19 +00:00
|
|
|
configFile, err := ioutil.ReadFile(c.ClusterConfigFile)
|
2018-03-19 16:22:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cluster configuration file '%s' could not be loaded: %s", c.ClusterConfigFile, err)
|
|
|
|
}
|
2018-08-26 10:54:58 +00:00
|
|
|
err = json.Unmarshal(configFile, &cluster)
|
2018-03-19 16:22:09 +00:00
|
|
|
if err != nil {
|
2018-03-26 12:52:19 +00:00
|
|
|
return fmt.Errorf("failed to unmarshal cluster configuration file: %s", err)
|
2018-03-19 16:22:09 +00:00
|
|
|
}
|
2018-03-26 12:52:19 +00:00
|
|
|
} else {
|
2018-08-26 10:54:58 +00:00
|
|
|
cluster, _ = ClusterForFleet(c.ClusterConfig.Fleet)
|
2017-08-04 16:14:17 +00:00
|
|
|
}
|
2017-07-13 06:54:10 +00:00
|
|
|
|
2018-08-26 10:54:58 +00:00
|
|
|
// allow to override bootnodes only if they were not defined earlier
|
|
|
|
if len(c.ClusterConfig.BootNodes) == 0 {
|
|
|
|
c.ClusterConfig.BootNodes = cluster.BootNodes
|
|
|
|
}
|
|
|
|
// allow to override static nodes only if they were not defined earlier
|
|
|
|
if len(c.ClusterConfig.StaticNodes) == 0 {
|
|
|
|
c.ClusterConfig.StaticNodes = cluster.StaticNodes
|
|
|
|
}
|
|
|
|
// No point in running discovery if we don't have bootnodes.
|
|
|
|
// In a case when we do have bootnodes, NoDiscovery=true is preserved.
|
|
|
|
if len(cluster.BootNodes) == 0 {
|
|
|
|
c.NoDiscovery = true
|
|
|
|
}
|
|
|
|
if len(c.ClusterConfig.RendezvousNodes) == 0 {
|
|
|
|
c.ClusterConfig.RendezvousNodes = cluster.RendezvousNodes
|
|
|
|
}
|
|
|
|
if len(c.ClusterConfig.RendezvousNodes) != 0 {
|
|
|
|
c.Rendezvous = true
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
2018-08-26 10:54:58 +00:00
|
|
|
c.ClusterConfig.TrustedMailServers = cluster.MailServers
|
2017-05-16 03:24:56 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// updateRelativeDirsConfig updates directories that should be wrt to DataDir
|
|
|
|
func (c *NodeConfig) updateRelativeDirsConfig() error {
|
|
|
|
makeSubDirPath := func(baseDir, subDir string) string {
|
|
|
|
if len(baseDir) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(baseDir, subDir)
|
|
|
|
}
|
|
|
|
if len(c.KeyStoreDir) == 0 {
|
|
|
|
c.KeyStoreDir = makeSubDirPath(c.DataDir, KeyStoreDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(c.WhisperConfig.DataDir) == 0 {
|
|
|
|
c.WhisperConfig.DataDir = makeSubDirPath(c.DataDir, WhisperDataDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-04-20 12:23:18 +00:00
|
|
|
// updatePeerLimits will set default peer limits expectations based on enabled services.
|
|
|
|
func (c *NodeConfig) updatePeerLimits() {
|
2018-08-24 03:17:32 +00:00
|
|
|
if c.NoDiscovery && !c.Rendezvous {
|
2018-04-20 12:23:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if c.WhisperConfig.Enabled {
|
|
|
|
c.RequireTopics[WhisperDiscv5Topic] = WhisperDiscv5Limits
|
|
|
|
// TODO(dshulyak) register mailserver limits when we will change how they are handled.
|
|
|
|
}
|
2018-08-24 11:20:50 +00:00
|
|
|
if c.LightEthConfig.Enabled {
|
|
|
|
c.RequireTopics[discv5.Topic(LesTopic(int(c.NetworkID)))] = LesDiscoveryLimits
|
|
|
|
}
|
2018-04-20 12:23:18 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// String dumps config object as nicely indented JSON
|
|
|
|
func (c *NodeConfig) String() string {
|
|
|
|
data, _ := json.MarshalIndent(c, "", " ")
|
|
|
|
return string(data)
|
|
|
|
}
|
2018-04-12 16:17:10 +00:00
|
|
|
|
|
|
|
// FormatAPIModules returns a slice of APIModules.
|
|
|
|
func (c *NodeConfig) FormatAPIModules() []string {
|
|
|
|
if len(c.APIModules) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Split(c.APIModules, ",")
|
|
|
|
}
|
2018-05-08 21:57:29 +00:00
|
|
|
|
|
|
|
// AddAPIModule adds a mobule to APIModules
|
|
|
|
func (c *NodeConfig) AddAPIModule(m string) {
|
|
|
|
c.APIModules = fmt.Sprintf("%s,%s", c.APIModules, m)
|
|
|
|
}
|
2018-08-21 12:46:10 +00:00
|
|
|
|
|
|
|
// GetStatusHome gets home directory of status-go
|
|
|
|
func GetStatusHome() string {
|
|
|
|
gopath := os.Getenv("GOPATH")
|
|
|
|
if gopath == "" {
|
|
|
|
gopath = build.Default.GOPATH
|
|
|
|
}
|
|
|
|
return path.Join(gopath, "/src/github.com/status-im/status-go/")
|
|
|
|
}
|
2018-08-24 03:17:32 +00:00
|
|
|
|
|
|
|
// LesTopic returns discovery v5 topic derived from genesis of the provided network.
|
|
|
|
// 1 - mainnet, 4 - ropsten
|
|
|
|
func LesTopic(netid int) string {
|
|
|
|
switch netid {
|
|
|
|
case 1:
|
|
|
|
return "LES2@" + common.Bytes2Hex(params.MainnetGenesisHash.Bytes()[:8])
|
|
|
|
case 3:
|
|
|
|
return "LES2@" + common.Bytes2Hex(params.TestnetGenesisHash.Bytes()[:8])
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|