flags.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @authors
  16. * Jeffrey Wilcke <i@jev.io>
  17. */
  18. package main
  19. import (
  20. "crypto/ecdsa"
  21. "flag"
  22. "fmt"
  23. "log"
  24. "os"
  25. "path"
  26. "runtime"
  27. "github.com/ethereum/go-ethereum/crypto"
  28. "github.com/ethereum/go-ethereum/ethutil"
  29. "github.com/ethereum/go-ethereum/logger"
  30. "github.com/ethereum/go-ethereum/p2p/nat"
  31. "github.com/ethereum/go-ethereum/vm"
  32. )
  33. var (
  34. Identifier string
  35. KeyRing string
  36. KeyStore string
  37. StartRpc bool
  38. RpcListenAddress string
  39. RpcPort int
  40. OutboundPort string
  41. ShowGenesis bool
  42. AddPeer string
  43. MaxPeer int
  44. GenAddr bool
  45. BootNodes string
  46. NodeKey *ecdsa.PrivateKey
  47. NAT nat.Interface
  48. SecretFile string
  49. ExportDir string
  50. NonInteractive bool
  51. Datadir string
  52. LogFile string
  53. ConfigFile string
  54. DebugFile string
  55. LogLevel int
  56. VmType int
  57. MinerThreads int
  58. )
  59. // flags specific to gui client
  60. var AssetPath string
  61. var defaultConfigFile = path.Join(ethutil.DefaultDataDir(), "conf.ini")
  62. func Init() {
  63. // TODO: move common flag processing to cmd/utils
  64. flag.Usage = func() {
  65. fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
  66. flag.PrintDefaults()
  67. }
  68. flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
  69. flag.StringVar(&Identifier, "id", "", "Custom client identifier")
  70. flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
  71. flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file")
  72. flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
  73. flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
  74. flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")
  75. flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
  76. flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
  77. flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
  78. flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
  79. flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
  80. flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
  81. flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
  82. flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
  83. flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5 (= silent,error,warn,info,debug,debug detail)")
  84. flag.StringVar(&AssetPath, "asset_path", ethutil.DefaultAssetPath(), "absolute path to GUI assets directory")
  85. // Network stuff
  86. var (
  87. nodeKeyFile = flag.String("nodekey", "", "network private key file")
  88. nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)")
  89. natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
  90. )
  91. flag.StringVar(&OutboundPort, "port", "30303", "listening port")
  92. flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
  93. flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
  94. flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
  95. flag.Parse()
  96. var err error
  97. if NAT, err = nat.Parse(*natstr); err != nil {
  98. log.Fatalf("-nat: %v", err)
  99. }
  100. switch {
  101. case *nodeKeyFile != "" && *nodeKeyHex != "":
  102. log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")
  103. case *nodeKeyFile != "":
  104. if NodeKey, err = crypto.LoadECDSA(*nodeKeyFile); err != nil {
  105. log.Fatalf("-nodekey: %v", err)
  106. }
  107. case *nodeKeyHex != "":
  108. if NodeKey, err = crypto.HexToECDSA(*nodeKeyHex); err != nil {
  109. log.Fatalf("-nodekeyhex: %v", err)
  110. }
  111. }
  112. if VmType >= int(vm.MaxVmTy) {
  113. log.Fatal("Invalid VM type ", VmType)
  114. }
  115. }