2017-03-28 09:04:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth"
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
"gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
gitCommit = "rely on linker: -ldflags -X main.GitCommit"
|
|
|
|
buildStamp = "rely on linker: -ldflags -X main.buildStamp"
|
|
|
|
app = makeApp(gitCommit)
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-05-03 14:24:48 +00:00
|
|
|
// NodeKeyFileFlag is a node key file to be used as node's private key
|
2017-04-09 22:16:05 +00:00
|
|
|
NodeKeyFileFlag = cli.StringFlag{
|
|
|
|
Name: "nodekey",
|
|
|
|
Usage: "P2P node key file (private key)",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// DataDirFlag defines data directory for the node
|
2017-03-28 09:04:52 +00:00
|
|
|
DataDirFlag = cli.StringFlag{
|
|
|
|
Name: "datadir",
|
|
|
|
Usage: "Data directory for the databases and keystore",
|
2017-04-09 22:16:05 +00:00
|
|
|
Value: params.DataDir,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// NetworkIDFlag defines network ID
|
|
|
|
NetworkIDFlag = cli.IntFlag{
|
2017-03-28 09:04:52 +00:00
|
|
|
Name: "networkid",
|
|
|
|
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten)",
|
2017-05-03 14:24:48 +00:00
|
|
|
Value: params.TestNetworkID,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// LightEthEnabledFlag flags whether LES is enabled or not
|
2017-03-28 09:04:52 +00:00
|
|
|
LightEthEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "les",
|
|
|
|
Usage: "LES protocol enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// WhisperEnabledFlag flags whether Whisper is enabled or not
|
2017-03-28 09:04:52 +00:00
|
|
|
WhisperEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "shh",
|
|
|
|
Usage: "SHH protocol enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// SwarmEnabledFlag flags whether Swarm is enabled or not
|
2017-03-28 09:04:52 +00:00
|
|
|
SwarmEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "swarm",
|
|
|
|
Usage: "Swarm protocol enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// HTTPEnabledFlag defines whether HTTP RPC endpoint should be opened or not
|
2017-03-28 09:04:52 +00:00
|
|
|
HTTPEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "http",
|
|
|
|
Usage: "HTTP RPC enpoint enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// HTTPPortFlag defines HTTP RPC port to use (if HTTP RPC is enabled)
|
2017-03-28 09:04:52 +00:00
|
|
|
HTTPPortFlag = cli.IntFlag{
|
|
|
|
Name: "httpport",
|
|
|
|
Usage: "HTTP RPC server's listening port",
|
2017-04-09 22:16:05 +00:00
|
|
|
Value: params.HTTPPort,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// IPCEnabledFlag flags whether IPC is enabled or not
|
2017-03-28 09:04:52 +00:00
|
|
|
IPCEnabledFlag = cli.BoolFlag{
|
|
|
|
Name: "ipc",
|
|
|
|
Usage: "IPC RPC enpoint enabled",
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
|
|
|
|
// LogLevelFlag defines a log reporting level
|
2017-03-28 09:04:52 +00:00
|
|
|
LogLevelFlag = cli.StringFlag{
|
|
|
|
Name: "log",
|
2017-05-02 14:35:37 +00:00
|
|
|
Usage: `Log level, one of: ""ERROR", "WARNING", "INFO", "DEBUG", and "TRACE"`,
|
2017-03-28 09:04:52 +00:00
|
|
|
Value: "INFO",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// setup the app
|
|
|
|
app.Action = statusd
|
|
|
|
app.HideVersion = true // separate command prints version
|
|
|
|
app.Commands = []cli.Command{
|
2017-04-09 22:16:05 +00:00
|
|
|
versionCommand,
|
|
|
|
wnodeCommand,
|
2017-03-28 09:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.Flags = []cli.Flag{
|
2017-04-09 22:16:05 +00:00
|
|
|
NodeKeyFileFlag,
|
2017-03-28 09:04:52 +00:00
|
|
|
DataDirFlag,
|
2017-05-03 14:24:48 +00:00
|
|
|
NetworkIDFlag,
|
2017-03-28 09:04:52 +00:00
|
|
|
LightEthEnabledFlag,
|
|
|
|
WhisperEnabledFlag,
|
|
|
|
SwarmEnabledFlag,
|
|
|
|
HTTPEnabledFlag,
|
|
|
|
HTTPPortFlag,
|
|
|
|
IPCEnabledFlag,
|
|
|
|
LogLevelFlag,
|
|
|
|
}
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// statusd runs Status node
|
|
|
|
func statusd(ctx *cli.Context) error {
|
|
|
|
config, err := makeNodeConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "can not parse config: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := geth.CreateAndRunNode(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait till node has been stopped
|
|
|
|
geth.NodeManagerInstance().Node().GethStack().Wait()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
|
|
|
func makeNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
2017-05-03 14:24:48 +00:00
|
|
|
nodeConfig, err := params.NewNodeConfig(ctx.GlobalString(DataDirFlag.Name), ctx.GlobalUint64(NetworkIDFlag.Name))
|
2017-03-28 09:04:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-09 22:16:05 +00:00
|
|
|
nodeConfig.NodeKeyFile = ctx.GlobalString(NodeKeyFileFlag.Name)
|
2017-03-28 09:04:52 +00:00
|
|
|
if !ctx.GlobalBool(HTTPEnabledFlag.Name) {
|
|
|
|
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
|
|
|
}
|
|
|
|
nodeConfig.IPCEnabled = ctx.GlobalBool(IPCEnabledFlag.Name)
|
|
|
|
nodeConfig.LightEthConfig.Enabled = ctx.GlobalBool(LightEthEnabledFlag.Name)
|
|
|
|
nodeConfig.WhisperConfig.Enabled = ctx.GlobalBool(WhisperEnabledFlag.Name)
|
|
|
|
nodeConfig.SwarmConfig.Enabled = ctx.GlobalBool(SwarmEnabledFlag.Name)
|
|
|
|
nodeConfig.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name)
|
|
|
|
|
|
|
|
if logLevel := ctx.GlobalString(LogLevelFlag.Name); len(logLevel) > 0 {
|
|
|
|
nodeConfig.LogEnabled = true
|
|
|
|
nodeConfig.LogLevel = logLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeApp creates an app with sane defaults.
|
|
|
|
func makeApp(gitCommit string) *cli.App {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = filepath.Base(os.Args[0])
|
|
|
|
app.Author = ""
|
|
|
|
//app.Authors = nil
|
|
|
|
app.Email = ""
|
|
|
|
app.Version = params.Version
|
|
|
|
if gitCommit != "" {
|
|
|
|
app.Version += "-" + gitCommit[:8]
|
|
|
|
}
|
|
|
|
app.Usage = "Status CLI"
|
|
|
|
return app
|
|
|
|
}
|