2017-03-15 21:03:01 +00:00
|
|
|
package params
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2019-01-22 07:08:29 +00:00
|
|
|
"errors"
|
2017-05-02 14:30:11 +00:00
|
|
|
"fmt"
|
2017-03-15 21:03:01 +00:00
|
|
|
"io/ioutil"
|
2018-09-13 16:31:29 +00:00
|
|
|
"net/url"
|
2017-03-15 21:03:01 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2019-01-15 09:21:33 +00:00
|
|
|
"time"
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2018-08-24 03:17:32 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
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"
|
2018-09-13 16:31:29 +00:00
|
|
|
"github.com/status-im/status-go/static"
|
2019-12-09 10:36:14 +00:00
|
|
|
"github.com/status-im/status-go/whisper/v6"
|
2018-09-13 16:31:29 +00:00
|
|
|
validator "gopkg.in/go-playground/validator.v9"
|
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
|
|
|
// DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced)
|
|
|
|
DatabaseCache int
|
2018-10-24 16:31:41 +00:00
|
|
|
|
|
|
|
// TrustedNodes is a list of trusted servers
|
|
|
|
TrustedNodes []string
|
|
|
|
|
|
|
|
//MinTrustedFraction is minimum percentage of connected trusted servers to validate header(1-100)
|
|
|
|
MinTrustedFraction int
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2019-04-24 10:24:21 +00:00
|
|
|
// MailServerPassword for symmetric encryption of whisper message history requests.
|
2018-07-04 09:30:57 +00:00
|
|
|
// (if no account file selected, then this password is used for symmetric encryption).
|
|
|
|
MailServerPassword string
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// MailServerAsymKey is an hex-encoded asymmetric key to decrypt messages sent to MailServer.
|
|
|
|
MailServerAsymKey string
|
2018-07-04 09:30:57 +00:00
|
|
|
|
2019-01-23 13:32:45 +00:00
|
|
|
// MailServerRateLimit minimum time between queries to mail server per peer.
|
2018-05-17 11:21:04 +00:00
|
|
|
MailServerRateLimit int
|
|
|
|
|
2019-01-23 13:32:45 +00:00
|
|
|
// MailServerDataRetention is a number of days data should be stored by MailServer.
|
|
|
|
MailServerDataRetention int
|
2018-05-17 11:21:04 +00:00
|
|
|
|
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
|
|
|
|
2018-06-13 11:24:04 +00:00
|
|
|
// EnableNTPSync enables NTP synchronizations
|
|
|
|
EnableNTPSync bool
|
2018-10-19 09:09:13 +00:00
|
|
|
|
|
|
|
// MaxMessageSize is a maximum size of a devp2p packet handled by the Whisper protocol,
|
|
|
|
// not only the size of envelopes sent in that packet.
|
|
|
|
MaxMessageSize uint32
|
2019-05-13 09:25:46 +00:00
|
|
|
|
|
|
|
// DatabaseConfig is configuration for which datastore we use
|
|
|
|
DatabaseConfig DatabaseConfig
|
2019-11-18 10:22:23 +00:00
|
|
|
|
|
|
|
// EnableRateLimiter set to true enables IP and peer ID rate limiting.
|
|
|
|
EnableRateLimiter bool
|
|
|
|
|
|
|
|
// RateLimitIP sets the limit on the number of messages per second
|
|
|
|
// from a given IP.
|
|
|
|
RateLimitIP int64
|
|
|
|
|
|
|
|
// RateLimitPeerID sets the limit on the number of messages per second
|
|
|
|
// from a given peer ID.
|
|
|
|
RateLimitPeerID int64
|
2019-05-13 09:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DatabaseConfig struct {
|
|
|
|
PGConfig PGConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type PGConfig struct {
|
2019-11-18 10:22:23 +00:00
|
|
|
// Enabled whether we should use a Postgres instance
|
2019-05-13 09:25:46 +00:00
|
|
|
Enabled bool
|
|
|
|
// The URI of the server
|
|
|
|
URI string
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
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 *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)
|
|
|
|
}
|
|
|
|
|
2019-04-29 12:05:49 +00:00
|
|
|
// IncentivisationConfig holds incentivisation-related configuration
|
|
|
|
type IncentivisationConfig struct {
|
|
|
|
// Enabled flag specifies whether protocol is enabled
|
|
|
|
Enabled bool `validate:"required"`
|
|
|
|
// Endpoint for the RPC calls
|
|
|
|
RPCEndpoint string `validate:"required"`
|
|
|
|
// Contract address
|
|
|
|
ContractAddress string `validate:"required"`
|
|
|
|
// IP address that is used
|
|
|
|
IP string `validate:"required"`
|
|
|
|
// Port
|
|
|
|
Port uint16 `validate:"required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// String dumps config object as nicely indented JSON
|
|
|
|
func (c *IncentivisationConfig) String() string {
|
|
|
|
data, _ := json.MarshalIndent(c, "", " ") // nolint: gas
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the IncentivisationConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *IncentivisationConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-10-04 10:40:26 +00:00
|
|
|
// Enabled flag specifies that nodes in this configuration are taken into account.
|
2017-05-11 13:20:27 +00:00
|
|
|
Enabled bool
|
|
|
|
|
2018-10-04 10:40:26 +00:00
|
|
|
// Fleet is a name of a selected fleet. If it has a value, nodes are loaded
|
|
|
|
// from a file, namely `fleet-*.{{ .Fleet }}.json`. Nodes can be added to any list
|
|
|
|
// in `ClusterConfig`.
|
2018-07-25 14:03:35 +00:00
|
|
|
Fleet string
|
|
|
|
|
2018-10-04 10:40:26 +00:00
|
|
|
// StaticNodes is a list of static nodes.
|
2018-03-20 14:05:21 +00:00
|
|
|
StaticNodes []string
|
|
|
|
|
2018-10-04 10:40:26 +00:00
|
|
|
// BootNodes is a list of bootnodes.
|
2017-08-04 16:14:17 +00:00
|
|
|
BootNodes []string
|
2018-07-04 10:51:47 +00:00
|
|
|
|
2018-10-04 10:40:26 +00:00
|
|
|
// TrustedMailServers is a list of verified and trusted Mail Server nodes.
|
2018-07-25 14:48:02 +00:00
|
|
|
TrustedMailServers []string
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// RendezvousNodes is a list rendezvous discovery nodes.
|
2018-07-04 10:51:47 +00:00
|
|
|
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.
|
2018-09-13 16:31:29 +00:00
|
|
|
KeyStoreDir string `validate:"required"`
|
2017-04-28 08:49:15 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// NodeKey is the hex-encoded node ID (private key). Should be a valid secp256k1 private key that will be used for both
|
2017-04-09 22:16:05 +00:00
|
|
|
// remote peer identification as well as network traffic encryption.
|
2018-09-13 16:31:29 +00:00
|
|
|
NodeKey string
|
2017-04-09 22:16:05 +00:00
|
|
|
|
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
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
// HTTPEnabled specifies whether the http RPC server is to be enabled by default.
|
|
|
|
HTTPEnabled bool
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
|
|
|
|
HTTPPort int
|
|
|
|
|
2018-10-12 12:58:32 +00:00
|
|
|
// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
|
|
|
|
// This is by default {'localhost'}. Using this prevents attacks like
|
|
|
|
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same
|
|
|
|
// origin. These attacks do not utilize CORS, since they are not cross-domain.
|
|
|
|
// By explicitly checking the Host-header, the server will not allow requests
|
|
|
|
// made against the server with a malicious host domain.
|
|
|
|
// Requests using an IP address directly are not affected.
|
|
|
|
HTTPVirtualHosts []string
|
|
|
|
|
|
|
|
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
|
|
|
|
// clients. Please be aware that CORS is a browser enforced security, it's fully
|
|
|
|
// useless for custom HTTP clients.
|
|
|
|
HTTPCors []string
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// IPCEnabled specifies whether IPC-RPC Server is enabled or not
|
|
|
|
IPCEnabled bool
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
// IPCFile is filename of exposed IPC RPC Server
|
|
|
|
IPCFile string
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// 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"`
|
|
|
|
|
2019-03-05 09:03:06 +00:00
|
|
|
// LogMobileSystem enables log redirection to android/ios system logger.
|
|
|
|
LogMobileSystem bool
|
|
|
|
|
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
|
|
|
|
2019-03-01 13:37:13 +00:00
|
|
|
// LogMaxBackups defines number of rotated log files that will be stored.
|
|
|
|
LogMaxBackups int
|
|
|
|
|
2019-04-24 10:24:21 +00:00
|
|
|
// LogMaxSize in megabytes after current size is reached log file will be rotated.
|
2019-03-01 13:37:13 +00:00
|
|
|
LogMaxSize int
|
|
|
|
|
|
|
|
// LogCompressRotated if true all rotated files will be gzipped.
|
|
|
|
LogCompressRotated bool
|
|
|
|
|
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
|
|
|
|
2019-01-17 12:56:22 +00:00
|
|
|
// EnableStatusService should be true to enable methods under status namespace.
|
|
|
|
EnableStatusService bool
|
|
|
|
|
2017-08-15 10:27:12 +00:00
|
|
|
// UpstreamConfig extra config for providing upstream infura server.
|
|
|
|
UpstreamConfig UpstreamRPCConfig `json:"UpstreamConfig"`
|
|
|
|
|
2018-03-20 14:05:21 +00:00
|
|
|
// ClusterConfig extra configuration for supporting cluster peers.
|
2018-09-13 16:31:29 +00:00
|
|
|
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
|
2018-09-13 16:31:29 +00:00
|
|
|
LightEthConfig LightEthConfig `json:"LightEthConfig," validate:"structonly"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
|
|
|
// WhisperConfig extra configuration for SHH
|
2018-09-13 16:31:29 +00:00
|
|
|
WhisperConfig WhisperConfig `json:"WhisperConfig," validate:"structonly"`
|
2017-03-15 21:03:01 +00:00
|
|
|
|
2019-04-29 12:05:49 +00:00
|
|
|
// IncentivisationConfig extra configuration for incentivisation service
|
|
|
|
IncentivisationConfig IncentivisationConfig `json:"IncentivisationConfig," validate:"structonly"`
|
|
|
|
|
2019-06-14 10:16:30 +00:00
|
|
|
// ShhextConfig extra configuration for service running under shhext namespace.
|
2019-01-22 07:08:29 +00:00
|
|
|
ShhextConfig ShhextConfig `json:"ShhextConfig," validate:"structonly"`
|
2019-01-17 12:56:22 +00:00
|
|
|
|
2019-06-14 10:16:30 +00:00
|
|
|
// WalletConfig extra configuration for wallet.Service.
|
|
|
|
WalletConfig WalletConfig
|
|
|
|
|
2019-07-17 05:28:37 +00:00
|
|
|
// BrowsersConfig extra configuration for browsers.Service.
|
|
|
|
BrowsersConfig BrowsersConfig
|
|
|
|
|
2019-07-21 05:41:30 +00:00
|
|
|
// PermissionsConfig extra configuration for permissions.Service.
|
|
|
|
PermissionsConfig PermissionsConfig
|
|
|
|
|
2019-09-04 06:25:33 +00:00
|
|
|
// MailserversConfig extra configuration for mailservers.Service
|
|
|
|
// (persistent storage of user's mailserver records).
|
|
|
|
MailserversConfig MailserversConfig
|
|
|
|
|
2017-03-15 21:03:01 +00:00
|
|
|
// SwarmConfig extra configuration for Swarm and ENS
|
2018-09-13 16: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
|
|
|
|
2018-08-20 13:55:43 +00:00
|
|
|
// MailServerRegistryAddress is the MailServerRegistry contract address
|
|
|
|
MailServerRegistryAddress string
|
2019-01-17 12:56:22 +00:00
|
|
|
}
|
2018-12-06 09:30:57 +00:00
|
|
|
|
2019-06-14 10:16:30 +00:00
|
|
|
// WalletConfig extra configuration for wallet.Service.
|
|
|
|
type WalletConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
}
|
|
|
|
|
2019-07-17 05:28:37 +00:00
|
|
|
// BrowsersConfig extra configuration for browsers.Service.
|
|
|
|
type BrowsersConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
}
|
|
|
|
|
2019-07-21 05:41:30 +00:00
|
|
|
// PermissionsConfig extra configuration for permissions.Service.
|
|
|
|
type PermissionsConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
}
|
|
|
|
|
2019-09-04 06:25:33 +00:00
|
|
|
// MailserversConfig extra configuration for mailservers.Service.
|
|
|
|
type MailserversConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:56:22 +00:00
|
|
|
// ShhextConfig defines options used by shhext service.
|
|
|
|
type ShhextConfig struct {
|
2019-01-22 07:08:29 +00:00
|
|
|
PFSEnabled bool
|
2019-01-17 12:56:22 +00:00
|
|
|
// BackupDisabledDataDir is the file system folder the node should use for any data storage needs that it doesn't want backed up.
|
2019-01-22 07:08:29 +00:00
|
|
|
BackupDisabledDataDir string
|
2019-01-17 12:56:22 +00:00
|
|
|
// InstallationId id of the current installation
|
2019-03-01 13:36:21 +00:00
|
|
|
InstallationID string
|
2018-12-06 09:30:57 +00:00
|
|
|
// MailServerConfirmations should be true if client wants to receive confirmatons only from a selected mail servers.
|
|
|
|
MailServerConfirmations bool
|
2019-01-17 12:56:22 +00:00
|
|
|
// EnableConnectionManager turns on management of the mail server connections if true.
|
|
|
|
EnableConnectionManager bool
|
|
|
|
// EnableLastUsedMonitor guarantees that last used mail server will be tracked and persisted into the storage.
|
|
|
|
EnableLastUsedMonitor bool
|
|
|
|
// ConnectionTarget will be used by connection manager. It will ensure that we connected with configured number of servers.
|
|
|
|
ConnectionTarget int
|
2019-01-15 09:21:33 +00:00
|
|
|
// RequestsDelay used to ensure that no similar requests are sent within short periods of time.
|
|
|
|
RequestsDelay time.Duration
|
2019-01-21 14:00:10 +00:00
|
|
|
|
|
|
|
// MaxServerFailures defines maximum allowed expired requests before server will be swapped to another one.
|
|
|
|
MaxServerFailures int
|
2019-03-01 13:36:21 +00:00
|
|
|
|
|
|
|
// MaxMessageDeliveryAttempts defines how many times we will try to deliver not-acknowledged envelopes.
|
|
|
|
MaxMessageDeliveryAttempts int
|
2019-04-30 06:46:12 +00:00
|
|
|
|
|
|
|
// WhisperCacheDir is a folder where whisper filters may persist messages before delivering them
|
|
|
|
// to a client.
|
|
|
|
WhisperCacheDir string
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// DisableGenericDiscoveryTopic indicates whether we should be listening on the old discovery
|
|
|
|
DisableGenericDiscoveryTopic bool
|
|
|
|
|
|
|
|
// SendV1Messages indicates whether we should be sending v1-compatible only messages
|
|
|
|
SendV1Messages bool
|
|
|
|
|
|
|
|
// DatasyncEnabled indicates whether we should enable dataasync
|
|
|
|
DataSyncEnabled bool
|
2019-01-17 12:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the ShhextConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *ShhextConfig) Validate(validate *validator.Validate) error {
|
2019-01-22 07:08:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.PFSEnabled && len(c.BackupDisabledDataDir) == 0 {
|
|
|
|
return errors.New("field BackupDisabledDataDir is required if PFSEnabled is true")
|
|
|
|
}
|
|
|
|
return nil
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
// Option is an additional setting when creating a NodeConfig
|
|
|
|
// using NewNodeConfigWithDefaults.
|
|
|
|
type Option func(*NodeConfig) error
|
|
|
|
|
|
|
|
// WithFleet loads one of the preconfigured Status fleets.
|
|
|
|
func WithFleet(fleet string) Option {
|
|
|
|
return func(c *NodeConfig) error {
|
|
|
|
if fleet == FleetUndefined {
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-27 13:20:17 +00:00
|
|
|
c.NoDiscovery = false
|
2018-10-04 10:40:26 +00:00
|
|
|
c.ClusterConfig.Enabled = true
|
2018-09-21 14:09:31 +00:00
|
|
|
return loadConfigFromAsset(fmt.Sprintf("../config/cli/fleet-%s.json", fleet), c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLES enabled LES protocol.
|
|
|
|
func WithLES() Option {
|
|
|
|
return func(c *NodeConfig) error {
|
|
|
|
return loadConfigFromAsset("../config/cli/les-enabled.json", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithMailserver enables MailServer.
|
|
|
|
func WithMailserver() Option {
|
|
|
|
return func(c *NodeConfig) error {
|
|
|
|
return loadConfigFromAsset("../config/cli/mailserver-enabled.json", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 18:29:42 +00:00
|
|
|
// NewNodeConfigWithDefaults creates new node configuration object
|
|
|
|
// with some defaults suitable for adhoc use.
|
2018-09-21 14:09:31 +00:00
|
|
|
func NewNodeConfigWithDefaults(dataDir string, networkID uint64, opts ...Option) (*NodeConfig, error) {
|
|
|
|
c, err := NewNodeConfig(dataDir, networkID)
|
2018-09-13 16:31:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-10-27 13:20:17 +00:00
|
|
|
c.NoDiscovery = true
|
2018-09-21 14:09:31 +00:00
|
|
|
c.HTTPHost = ""
|
|
|
|
c.ListenAddr = ":30303"
|
|
|
|
c.LogEnabled = true
|
|
|
|
c.LogLevel = "INFO"
|
2019-03-01 13:37:13 +00:00
|
|
|
c.LogMaxSize = 100
|
|
|
|
c.LogCompressRotated = true
|
|
|
|
c.LogMaxBackups = 3
|
2018-09-21 14:09:31 +00:00
|
|
|
c.LogToStderr = true
|
|
|
|
c.WhisperConfig.Enabled = true
|
|
|
|
c.WhisperConfig.EnableNTPSync = true
|
2018-09-13 16:31:29 +00:00
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
if err := opt(c); err != nil {
|
|
|
|
return nil, err
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
c.updatePeerLimits()
|
2018-09-13 16:31:29 +00:00
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-14 10:25:52 +00:00
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
return c, nil
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 18:29:42 +00:00
|
|
|
// NewNodeConfigWithDefaultsAndFiles creates new node configuration object
|
|
|
|
// with some defaults suitable for adhoc use and applies config files on top.
|
|
|
|
func NewNodeConfigWithDefaultsAndFiles(
|
2018-09-21 14:09:31 +00:00
|
|
|
dataDir string, networkID uint64, opts []Option, files []string,
|
2018-09-19 18:29:42 +00:00
|
|
|
) (*NodeConfig, error) {
|
2018-09-21 14:09:31 +00:00
|
|
|
c, err := NewNodeConfigWithDefaults(dataDir, networkID, opts...)
|
2018-09-19 18:29:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, file := range files {
|
|
|
|
if err := loadConfigConfigFromFile(file, c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.updatePeerLimits()
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
if err := c.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-19 18:29:42 +00:00
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2018-09-14 10:25:52 +00:00
|
|
|
// updatePeerLimits will set default peer limits expectations based on enabled services.
|
|
|
|
func (c *NodeConfig) updatePeerLimits() {
|
|
|
|
if c.NoDiscovery && !c.Rendezvous {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if c.WhisperConfig.Enabled {
|
|
|
|
c.RequireTopics[WhisperDiscv5Topic] = WhisperDiscv5Limits
|
|
|
|
// TODO(dshulyak) register mailserver limits when we will change how they are handled.
|
|
|
|
}
|
|
|
|
if c.LightEthConfig.Enabled {
|
|
|
|
c.RequireTopics[discv5.Topic(LesTopic(int(c.NetworkID)))] = LesDiscoveryLimits
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-04 11:44:01 +00:00
|
|
|
// NewNodeConfig creates new node configuration object with bare-minimum defaults.
|
|
|
|
// Important: the returned config is not validated.
|
2018-09-21 14:09:31 +00:00
|
|
|
func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
|
|
|
|
var keyStoreDir, wnodeDir string
|
|
|
|
|
|
|
|
if dataDir != "" {
|
|
|
|
keyStoreDir = filepath.Join(dataDir, "keystore")
|
|
|
|
}
|
|
|
|
if dataDir != "" {
|
|
|
|
wnodeDir = filepath.Join(dataDir, "wnode")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := &NodeConfig{
|
2019-01-17 12:56:22 +00:00
|
|
|
NetworkID: networkID,
|
|
|
|
DataDir: dataDir,
|
|
|
|
KeyStoreDir: keyStoreDir,
|
|
|
|
Version: Version,
|
|
|
|
HTTPHost: "localhost",
|
|
|
|
HTTPPort: 8545,
|
|
|
|
HTTPVirtualHosts: []string{"localhost"},
|
|
|
|
ListenAddr: ":0",
|
2019-06-14 10:16:30 +00:00
|
|
|
APIModules: "eth,net,web3,peer,wallet",
|
2019-01-17 12:56:22 +00:00
|
|
|
MaxPeers: 25,
|
|
|
|
MaxPendingPeers: 0,
|
|
|
|
IPCFile: "geth.ipc",
|
|
|
|
log: log.New("package", "status-go/params.NodeConfig"),
|
|
|
|
LogFile: "",
|
|
|
|
LogLevel: "ERROR",
|
|
|
|
NoDiscovery: true,
|
2018-09-13 16:31:29 +00:00
|
|
|
UpstreamConfig: UpstreamRPCConfig{
|
|
|
|
URL: getUpstreamURL(networkID),
|
|
|
|
},
|
|
|
|
LightEthConfig: LightEthConfig{
|
|
|
|
DatabaseCache: 16,
|
2017-05-11 13:20:27 +00:00
|
|
|
},
|
2018-09-13 16:31:29 +00:00
|
|
|
WhisperConfig: WhisperConfig{
|
2018-10-19 09:09:13 +00:00
|
|
|
DataDir: wnodeDir,
|
|
|
|
MinimumPoW: WhisperMinimumPoW,
|
|
|
|
TTL: WhisperTTL,
|
|
|
|
MaxMessageSize: whisper.DefaultMaxMessageSize,
|
2017-03-28 09:04:52 +00:00
|
|
|
},
|
2019-01-17 12:56:22 +00:00
|
|
|
ShhextConfig: ShhextConfig{
|
|
|
|
BackupDisabledDataDir: dataDir,
|
|
|
|
},
|
2018-09-13 16:31:29 +00:00
|
|
|
SwarmConfig: SwarmConfig{},
|
2018-04-20 12:23:18 +00:00
|
|
|
RegisterTopics: []discv5.Topic{},
|
|
|
|
RequireTopics: map[discv5.Topic]Limits{},
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
return config, nil
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// NewConfigFromJSON parses incoming JSON and returned it as Config
|
|
|
|
func NewConfigFromJSON(configJSON string) (*NodeConfig, error) {
|
2018-09-21 14:09:31 +00:00
|
|
|
config, err := NewNodeConfig("", 0)
|
2017-08-10 15:31:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
if err := loadConfigFromJSON(configJSON, config); err != nil {
|
2017-08-10 15:31:29 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
if err := config.Validate(); err != nil {
|
|
|
|
return nil, err
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
return config, nil
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
func loadConfigFromJSON(configJSON string, nodeConfig *NodeConfig) error {
|
2017-03-15 21:03:01 +00:00
|
|
|
decoder := json.NewDecoder(strings.NewReader(configJSON))
|
|
|
|
// override default configuration with values by JSON input
|
2018-09-21 14:09:31 +00:00
|
|
|
return decoder.Decode(&nodeConfig)
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func loadConfigConfigFromFile(path string, config *NodeConfig) error {
|
|
|
|
jsonConfig, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-05-02 14:30:11 +00:00
|
|
|
}
|
2018-09-21 14:09:31 +00:00
|
|
|
return loadConfigFromJSON(string(jsonConfig), config)
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
func loadConfigFromAsset(name string, config *NodeConfig) error {
|
|
|
|
data, err := static.Asset(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
2018-09-21 14:09:31 +00:00
|
|
|
return loadConfigFromJSON(string(data), config)
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
//
|
2019-01-04 11:44:01 +00:00
|
|
|
// nolint: gocyclo
|
2017-08-10 15:31:29 +00:00
|
|
|
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-09-13 16:31:29 +00:00
|
|
|
if c.NodeKey != "" {
|
|
|
|
if _, err := crypto.HexToECDSA(c.NodeKey); err != nil {
|
|
|
|
return fmt.Errorf("NodeKey is invalid (%s): %v", c.NodeKey, err)
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if c.UpstreamConfig.Enabled && c.LightEthConfig.Enabled {
|
|
|
|
return fmt.Errorf("both UpstreamConfig and LightEthConfig are enabled, but they are mutually exclusive")
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := c.validateChildStructs(validate); err != nil {
|
|
|
|
return err
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 11:44:01 +00:00
|
|
|
// Whisper's data directory must be relative to the main data directory
|
|
|
|
// if EnableMailServer is true.
|
|
|
|
if c.WhisperConfig.Enabled && c.WhisperConfig.EnableMailServer {
|
|
|
|
if !strings.HasPrefix(c.WhisperConfig.DataDir, c.DataDir) {
|
|
|
|
return fmt.Errorf("WhisperConfig.DataDir must start with DataDir fragment")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if !c.NoDiscovery && len(c.ClusterConfig.BootNodes) == 0 {
|
|
|
|
// No point in running discovery if we don't have bootnodes.
|
|
|
|
// In case we do have bootnodes, NoDiscovery should be true.
|
|
|
|
return fmt.Errorf("NoDiscovery is false, but ClusterConfig.BootNodes is empty")
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:56:22 +00:00
|
|
|
if c.ShhextConfig.PFSEnabled && len(c.ShhextConfig.InstallationID) == 0 {
|
2018-09-24 18:07:34 +00:00
|
|
|
return fmt.Errorf("PFSEnabled is true, but InstallationID is empty")
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if len(c.ClusterConfig.RendezvousNodes) == 0 {
|
|
|
|
if c.Rendezvous {
|
|
|
|
return fmt.Errorf("Rendezvous is enabled, but ClusterConfig.RendezvousNodes is empty")
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
} else if !c.Rendezvous {
|
|
|
|
return fmt.Errorf("Rendezvous is disabled, but ClusterConfig.RendezvousNodes is not empty")
|
2017-08-10 15:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-03-15 21:03:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error {
|
|
|
|
// Validate child structs
|
|
|
|
if err := c.UpstreamConfig.Validate(validate); err != nil {
|
2017-03-15 21:03:01 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := c.ClusterConfig.Validate(validate); err != nil {
|
2017-03-15 21:03:01 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := c.LightEthConfig.Validate(validate); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := c.WhisperConfig.Validate(validate); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := c.SwarmConfig.Validate(validate); err != nil {
|
2017-03-15 21:03:01 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-01-17 12:56:22 +00:00
|
|
|
if err := c.ShhextConfig.Validate(validate); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-04-29 12:05:49 +00:00
|
|
|
if c.IncentivisationConfig.Enabled {
|
|
|
|
if err := c.IncentivisationConfig.Validate(validate); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 21:03:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// Validate validates the UpstreamRPCConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *UpstreamRPCConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if !c.Enabled {
|
|
|
|
return nil
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
2017-08-15 10:27:12 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
2017-08-15 10:27:12 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if _, err := url.ParseRequestURI(c.URL); err != nil {
|
|
|
|
return fmt.Errorf("UpstreamRPCConfig.URL '%s' is invalid: %v", c.URL, err.Error())
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-05-16 03:24:56 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// Validate validates the ClusterConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *ClusterConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if !c.Enabled {
|
2017-05-16 03:24:56 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
2017-05-16 03:24:56 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
return nil
|
2017-10-16 21:54:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// Validate validates the LightEthConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *LightEthConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if !c.Enabled {
|
2017-08-15 10:27:12 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
2017-08-15 10:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// Validate validates the WhisperConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *WhisperConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if !c.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-09-13 16:31:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-25 14:03:35 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if c.EnableMailServer {
|
|
|
|
if c.DataDir == "" {
|
|
|
|
return fmt.Errorf("WhisperConfig.DataDir must be specified when WhisperConfig.EnableMailServer is true")
|
2018-03-19 16:22:09 +00:00
|
|
|
}
|
2019-01-04 11:44:01 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if c.MailServerPassword == "" && c.MailServerAsymKey == "" {
|
|
|
|
return fmt.Errorf("WhisperConfig.MailServerPassword or WhisperConfig.MailServerAsymKey must be specified when WhisperConfig.EnableMailServer is true")
|
2018-03-19 16:22:09 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
if c.MailServerAsymKey != "" {
|
|
|
|
if _, err := crypto.HexToECDSA(c.MailServerAsymKey); err != nil {
|
|
|
|
return fmt.Errorf("WhisperConfig.MailServerAsymKey is invalid: %s", c.MailServerAsymKey)
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// Validate validates the SwarmConfig struct and returns an error if inconsistent values are found
|
|
|
|
func (c *SwarmConfig) Validate(validate *validator.Validate) error {
|
|
|
|
if !c.Enabled {
|
|
|
|
return nil
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
if err := validate.Struct(c); err != nil {
|
|
|
|
return err
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
func getUpstreamURL(networkID uint64) string {
|
|
|
|
switch networkID {
|
|
|
|
case MainNetworkID:
|
|
|
|
return MainnetEthereumNetworkURL
|
|
|
|
case RopstenNetworkID:
|
|
|
|
return RopstenEthereumNetworkURL
|
|
|
|
case RinkebyNetworkID:
|
|
|
|
return RinkebyEthereumNetworkURL
|
2019-03-14 08:43:32 +00:00
|
|
|
case GoerliNetworkID:
|
|
|
|
return GoerliEthereumNetworkURL
|
2018-09-13 16:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save dumps configuration to the disk
|
|
|
|
func (c *NodeConfig) Save() error {
|
|
|
|
data, err := json.MarshalIndent(c, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-04-20 12:23:18 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
|
|
|
|
if err := os.MkdirAll(c.DataDir, os.ModePerm); err != nil {
|
|
|
|
return err
|
2018-04-20 12:23:18 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
|
|
|
|
configFilePath := filepath.Join(c.DataDir, "config.json")
|
|
|
|
if err := ioutil.WriteFile(configFilePath, data, os.ModePerm); err != nil {
|
|
|
|
return err
|
2018-08-24 11:20:50 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
|
|
|
|
c.log.Info("config file saved", "path", configFilePath)
|
|
|
|
return nil
|
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
|
|
|
|
2018-08-24 03:17:32 +00:00
|
|
|
// LesTopic returns discovery v5 topic derived from genesis of the provided network.
|
2018-08-27 09:32:14 +00:00
|
|
|
// 1 - mainnet, 3 - ropsten, 4 - rinkeby
|
2018-08-24 03:17:32 +00:00
|
|
|
func LesTopic(netid int) string {
|
|
|
|
switch netid {
|
|
|
|
case 1:
|
2018-08-27 09:32:14 +00:00
|
|
|
return LESDiscoveryIdentifier + common.Bytes2Hex(params.MainnetGenesisHash.Bytes()[:8])
|
2018-08-24 03:17:32 +00:00
|
|
|
case 3:
|
2018-08-27 09:32:14 +00:00
|
|
|
return LESDiscoveryIdentifier + common.Bytes2Hex(params.TestnetGenesisHash.Bytes()[:8])
|
|
|
|
case 4:
|
|
|
|
return LESDiscoveryIdentifier + common.Bytes2Hex(params.RinkebyGenesisHash.Bytes()[:8])
|
2018-08-24 03:17:32 +00:00
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|