2017-03-28 09:04:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-03 22:07:13 +00:00
|
|
|
"flag"
|
2017-03-28 09:04:52 +00:00
|
|
|
"fmt"
|
2017-11-03 22:07:13 +00:00
|
|
|
"log"
|
2017-03-28 09:04:52 +00:00
|
|
|
"os"
|
|
|
|
"runtime"
|
2017-11-03 22:07:13 +00:00
|
|
|
"strings"
|
2017-03-28 09:04:52 +00:00
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/api"
|
2017-03-28 09:04:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-11-03 22:07:13 +00:00
|
|
|
gitCommit = "N/A" // rely on linker: -ldflags -X main.GitCommit"
|
|
|
|
buildStamp = "N/A" // rely on linker: -ldflags -X main.buildStamp"
|
2017-03-28 09:04:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-11-03 22:07:13 +00:00
|
|
|
prodMode = flag.Bool("production", false, "Whether production settings should be loaded")
|
|
|
|
nodeKeyFile = flag.String("nodekey", "", "P2P node key file (private key)")
|
|
|
|
dataDir = flag.String("datadir", params.DataDir, "Data directory for the databases and keystore")
|
|
|
|
networkID = flag.Int("networkid", params.RopstenNetworkID, "Network identifier (integer, 1=Homestead, 3=Ropsten, 4=Rinkeby, 777=StatusChain)")
|
|
|
|
whisperEnabled = flag.Bool("shh", false, "SHH protocol enabled")
|
|
|
|
swarmEnabled = flag.Bool("swarm", false, "Swarm protocol enabled")
|
|
|
|
httpEnabled = flag.Bool("http", false, "HTTP RPC endpoint 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")
|
|
|
|
version = flag.Bool("version", false, "Print version")
|
|
|
|
)
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
func main() {
|
|
|
|
flag.Usage = printUsage
|
|
|
|
flag.Parse()
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
config, err := makeNodeConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Making config failed: %v", err)
|
|
|
|
return
|
2017-05-16 03:24:56 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
if *version {
|
|
|
|
printVersion(config, gitCommit, buildStamp)
|
|
|
|
return
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
backend := api.NewStatusBackend()
|
|
|
|
started, err := backend.StartNode(config)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Node start failed: %v", err)
|
|
|
|
return
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// wait till node is started
|
|
|
|
<-started
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// wait till node has been stopped
|
|
|
|
node, err := backend.NodeManager().Node()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Getting node failed: %v", err)
|
|
|
|
return
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
node.Wait()
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
|
|
|
func makeNodeConfig() (*params.NodeConfig, error) {
|
|
|
|
devMode := !*prodMode
|
|
|
|
nodeConfig, err := params.NewNodeConfig(*dataDir, uint64(*networkID), devMode)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-09-01 18:44:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// TODO(divan): move this logic into params package
|
|
|
|
if *nodeKeyFile != "" {
|
|
|
|
nodeConfig.NodeKeyFile = *nodeKeyFile
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
if *logLevel != "" {
|
|
|
|
nodeConfig.LogLevel = *logLevel
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-11-03 22:07:13 +00:00
|
|
|
if *logFile != "" {
|
|
|
|
nodeConfig.LogFile = *logFile
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
nodeConfig.LightEthConfig.Enabled = true
|
|
|
|
nodeConfig.RPCEnabled = *httpEnabled
|
|
|
|
nodeConfig.WhisperConfig.Enabled = *whisperEnabled
|
|
|
|
nodeConfig.SwarmConfig.Enabled = *swarmEnabled
|
2017-03-28 09:04:52 +00:00
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// RPC configuration
|
|
|
|
if !*httpEnabled {
|
|
|
|
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-11-03 22:07:13 +00:00
|
|
|
nodeConfig.HTTPPort = *httpPort
|
|
|
|
nodeConfig.IPCEnabled = *ipcEnabled
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
// printVersion prints verbose output about version and config.
|
|
|
|
func printVersion(config *params.NodeConfig, gitCommit, buildStamp string) {
|
|
|
|
if gitCommit != "" && len(gitCommit) > 8 {
|
|
|
|
params.Version += "-" + gitCommit[:8]
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
fmt.Println(strings.Title(params.ClientIdentifier))
|
|
|
|
fmt.Println("Version:", params.Version)
|
|
|
|
if gitCommit != "" {
|
|
|
|
fmt.Println("Git Commit:", gitCommit)
|
2017-09-01 18:44:50 +00:00
|
|
|
}
|
2017-11-03 22:07:13 +00:00
|
|
|
if buildStamp != "" {
|
|
|
|
fmt.Println("Build Stamp:", buildStamp)
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
fmt.Println("Network Id:", config.NetworkID)
|
|
|
|
fmt.Println("Go Version:", runtime.Version())
|
|
|
|
fmt.Println("OS:", runtime.GOOS)
|
|
|
|
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
|
|
|
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
|
|
|
|
|
|
|
|
config.LightEthConfig.Genesis = "SKIP"
|
|
|
|
fmt.Println("Loaded Config: ", config)
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:13 +00:00
|
|
|
func printUsage() {
|
|
|
|
fmt.Fprintln(os.Stderr, "Usage: statusd [options]")
|
|
|
|
fmt.Fprintf(os.Stderr, `
|
|
|
|
Examples:
|
|
|
|
statusd # run status node with defaults
|
|
|
|
statusd -networkid 4 # run node on Rinkeby network
|
|
|
|
statusd -datadir /dir # specify different dir for data
|
|
|
|
statusd -ipc # enable IPC for usage with "geth attach"
|
|
|
|
|
|
|
|
Options:
|
|
|
|
`)
|
|
|
|
flag.PrintDefaults()
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|