OSDN Git Service

Dev simd (#1146)
[bytom/bytom.git] / cmd / bytomd / commands / run_node.go
index 5d41677..049cd88 100644 (file)
@@ -2,13 +2,12 @@ package commands
 
 import (
        "fmt"
-       "io/ioutil"
 
+       log "github.com/sirupsen/logrus"
        "github.com/spf13/cobra"
 
        "github.com/bytom/node"
-       "github.com/bytom/types"
-       cmn "github.com/tendermint/tmlibs/common"
+       "strings"
 )
 
 var runNodeCmd = &cobra.Command{
@@ -18,43 +17,64 @@ var runNodeCmd = &cobra.Command{
 }
 
 func init() {
+       runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile bytomd programs")
+       runNodeCmd.Flags().Bool("mining", config.Mining, "Enable mining")
+
+       runNodeCmd.Flags().Bool("simd.enable", config.Simd.Enable, "Enable SIMD mechan for tensority")
+
+       runNodeCmd.Flags().Bool("auth.disable", config.Auth.Disable, "Disable rpc access authenticate")
+
+       runNodeCmd.Flags().Bool("wallet.disable", config.Wallet.Disable, "Disable wallet")
+       runNodeCmd.Flags().Bool("wallet.rescan", config.Wallet.Rescan, "Rescan wallet")
+       runNodeCmd.Flags().Bool("vault_mode", config.VaultMode, "Run in the offline enviroment")
+       runNodeCmd.Flags().Bool("web.closed", config.Web.Closed, "Lanch web browser or not")
+       runNodeCmd.Flags().String("chain_id", config.ChainID, "Select network type")
+
+       // log level
+       runNodeCmd.Flags().String("log_level", config.LogLevel, "Select log level(debug, info, warn, error or fatal")
+
        // p2p flags
        runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
        runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
        runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
        runNodeCmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable Peer-Exchange ")
-       runNodeCmd.Flags().Bool("wallet.enable", config.Wallet.Enable, "Enable wallet")
+       runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers")
+       runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout")
+       runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout")
+
+       // log flags
+       runNodeCmd.Flags().String("log_file", config.LogFile, "Log output file")
 
        RootCmd.AddCommand(runNodeCmd)
 }
 
-func runNode(cmd *cobra.Command, args []string) error {
-       genDocFile := config.GenesisFile()
-       if cmn.FileExists(genDocFile) {
-               jsonBlob, err := ioutil.ReadFile(genDocFile)
-               if err != nil {
-                       return fmt.Errorf("Couldn't read GenesisDoc file: %v", err)
-               }
-               genDoc, err := types.GenesisDocFromJSON(jsonBlob)
-               if err != nil {
-                       return fmt.Errorf("Error reading GenesisDoc: %v", err)
-               }
-               if genDoc.ChainID == "" {
-                       return fmt.Errorf("Genesis doc %v must include non-empty chain_id", genDocFile)
-               }
-               config.ChainID = genDoc.ChainID
-               config.PrivateKey = genDoc.PrivateKey
-               config.Time = genDoc.GenesisTime
-       } else {
-               return fmt.Errorf("not find genesis.json")
+func getLogLevel(level string) log.Level {
+       switch strings.ToLower(level) {
+       case "debug":
+               return log.DebugLevel
+       case "info":
+               return log.InfoLevel
+       case "warn":
+               return log.WarnLevel
+       case "error":
+               return log.ErrorLevel
+       case "fatal":
+               return log.FatalLevel
+       default:
+               return log.InfoLevel
        }
+}
+
+func runNode(cmd *cobra.Command, args []string) error {
+       // Set log level by config.LogLevel
+       log.SetLevel(getLogLevel(config.LogLevel))
 
        // Create & start node
-       n := node.NewNodeDefault(config, logger.With("module", "node_p2p"))
+       n := node.NewNode(config)
        if _, err := n.Start(); err != nil {
                return fmt.Errorf("Failed to start node: %v", err)
        } else {
-               logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
+               log.Info("Start node ", n.SyncManager().NodeInfo())
        }
 
        // Trap signal, run forever.