2017-11-03 22:07:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-12-07 16:58:11 +00:00
|
|
|
"bytes"
|
2017-11-03 22:07:13 +00:00
|
|
|
"errors"
|
2017-12-04 16:11:14 +00:00
|
|
|
"flag"
|
2017-11-03 22:07:13 +00:00
|
|
|
"fmt"
|
2017-12-07 16:58:11 +00:00
|
|
|
"io/ioutil"
|
2017-11-03 22:07:13 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
)
|
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
var (
|
|
|
|
prodMode = flag.Bool("production", false, "Whether production settings should be loaded")
|
|
|
|
dataDir = flag.String("datadir", "wnode-data", "Data directory for the databases and keystore")
|
|
|
|
networkID = flag.Int("networkid", params.RopstenNetworkID, "Network identifier (integer, 1=Homestead, 3=Ropsten, 4=Rinkeby)")
|
|
|
|
listenAddr = flag.String("listenaddr", params.ListenAddr, "IP address and port of this node (e.g. 127.0.0.1:30303)")
|
|
|
|
httpEnabled = flag.Bool("http", false, "HTTP RPC enpoint enabled (default: false)")
|
|
|
|
httpPort = flag.Int("httpport", params.HTTPPort, "HTTP RPC server's listening port")
|
|
|
|
ipcEnabled = flag.Bool("ipc", false, "IPC RPC endpoint enabled")
|
|
|
|
logLevel = flag.String("log", "INFO", `Log level, one of: "ERROR", "WARN", "INFO", "DEBUG", and "TRACE"`)
|
|
|
|
logFile = flag.String("logfile", "", "Path to the log file")
|
|
|
|
|
|
|
|
// Whisper
|
|
|
|
identity = flag.String("identity", "", "Protocol identity file (private key used for asymmetric encryption)")
|
|
|
|
passwordFile = flag.String("passwordfile", "", "Password file (password is used for symmetric encryption)")
|
2017-12-07 12:07:45 +00:00
|
|
|
standalone = flag.Bool("standalone", true, "Don't actively connect to peers, wait for incoming connections")
|
2017-12-04 16:11:14 +00:00
|
|
|
minPow = flag.Float64("pow", params.WhisperMinimumPoW, "PoW for messages to be added to queue, in float format")
|
|
|
|
ttl = flag.Int("ttl", params.WhisperTTL, "Time to live for messages, in seconds")
|
|
|
|
|
|
|
|
// MailServer
|
|
|
|
enableMailServer = flag.Bool("mailserver", false, "Delivers expired messages on demand")
|
|
|
|
|
|
|
|
// Push Notification
|
|
|
|
enablePN = flag.Bool("notify", false, "Node is capable of sending Push Notifications")
|
|
|
|
firebaseAuth = flag.String("firebaseauth", "", "FCM Authorization Key used for sending Push Notifications")
|
|
|
|
|
|
|
|
// Tesing and debug
|
|
|
|
injectAccounts = flag.Bool("injectaccounts", false, "Whether test account should be injected or not")
|
|
|
|
)
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// makeNodeConfig creates node configuration object from flags
|
|
|
|
func makeNodeConfig() (*params.NodeConfig, error) {
|
|
|
|
devMode := !*prodMode
|
|
|
|
nodeConfig, err := params.NewNodeConfig(*dataDir, uint64(*networkID), devMode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
nodeConfig.ListenAddr = *listenAddr
|
2017-11-03 22:07:13 +00:00
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
nodeConfig.LogLevel = *logLevel
|
|
|
|
if filepath.IsAbs(*logFile) {
|
|
|
|
nodeConfig.LogFile = *logFile
|
|
|
|
} else if *logFile != "" {
|
|
|
|
nodeConfig.LogFile = filepath.Join(*dataDir, *logFile)
|
|
|
|
}
|
2017-11-03 22:07:13 +00:00
|
|
|
|
|
|
|
// disable les and swarm for wnode
|
|
|
|
nodeConfig.LightEthConfig.Enabled = false
|
|
|
|
nodeConfig.SwarmConfig.Enabled = false
|
|
|
|
|
|
|
|
// whisper configuration
|
|
|
|
whisperConfig := nodeConfig.WhisperConfig
|
|
|
|
whisperConfig.Enabled = true
|
|
|
|
whisperConfig.IdentityFile = *identity
|
2017-12-04 16:11:14 +00:00
|
|
|
whisperConfig.EnablePushNotification = *enablePN
|
|
|
|
whisperConfig.EnableMailServer = *enableMailServer
|
|
|
|
whisperConfig.MinimumPoW = *minPow
|
2017-11-03 22:07:13 +00:00
|
|
|
whisperConfig.TTL = *ttl
|
|
|
|
|
2017-12-04 16:11:14 +00:00
|
|
|
if whisperConfig.EnablePushNotification && whisperConfig.IdentityFile == "" {
|
|
|
|
return nil, errors.New("notification server requires -identity file to be specified")
|
2017-11-03 22:07:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if whisperConfig.IdentityFile != "" {
|
2017-12-04 16:11:14 +00:00
|
|
|
if _, err := whisperConfig.ReadIdentityFile(); err != nil {
|
2017-11-03 22:07:13 +00:00
|
|
|
return nil, fmt.Errorf("read identity file: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:58:11 +00:00
|
|
|
if whisperConfig.EnableMailServer {
|
|
|
|
if *passwordFile == "" {
|
|
|
|
return nil, errors.New("passwordfile should be specified if MailServer is enabled")
|
|
|
|
}
|
|
|
|
|
|
|
|
password, err := readFile(*passwordFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("password file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
whisperConfig.Password = string(password)
|
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// firebase configuration
|
|
|
|
firebaseConfig := whisperConfig.FirebaseConfig
|
|
|
|
firebaseConfig.AuthorizationKeyFile = *firebaseAuth
|
2017-12-04 16:11:14 +00:00
|
|
|
if firebaseConfig.AuthorizationKeyFile != "" {
|
2017-11-03 22:07:13 +00:00
|
|
|
if _, err := firebaseConfig.ReadAuthorizationKeyFile(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RPC configuration
|
2017-12-04 16:11:14 +00:00
|
|
|
// TODO(adam): clarify all these IPC/RPC/HTTPHost
|
2017-11-03 22:07:13 +00:00
|
|
|
if !*httpEnabled {
|
|
|
|
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
|
|
|
}
|
|
|
|
nodeConfig.HTTPPort = *httpPort
|
|
|
|
nodeConfig.IPCEnabled = *ipcEnabled
|
2017-12-04 16:11:14 +00:00
|
|
|
nodeConfig.RPCEnabled = *httpEnabled
|
2017-11-03 22:07:13 +00:00
|
|
|
|
2017-12-07 12:07:45 +00:00
|
|
|
if *standalone {
|
|
|
|
nodeConfig.BootClusterConfig.Enabled = false
|
|
|
|
nodeConfig.BootClusterConfig.BootNodes = nil
|
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
2017-12-07 16:58:11 +00:00
|
|
|
|
|
|
|
func readFile(path string) ([]byte, error) {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
data = bytes.TrimRight(data, "\n")
|
|
|
|
|
|
|
|
if len(data) == 0 {
|
|
|
|
return nil, errors.New("file is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|