github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/cmd/bytomd/commands/run_node.go (about) 1 package commands 2 3 import ( 4 "strings" 5 6 log "github.com/sirupsen/logrus" 7 "github.com/spf13/cobra" 8 9 "github.com/bytom/bytom/node" 10 ) 11 12 const logModule = "cmd" 13 14 var runNodeCmd = &cobra.Command{ 15 Use: "node", 16 Short: "Run the bytomd", 17 RunE: runNode, 18 } 19 20 func init() { 21 runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile bytomd programs") 22 runNodeCmd.Flags().Bool("mining", config.Mining, "Enable mining") 23 24 runNodeCmd.Flags().Bool("auth.disable", config.Auth.Disable, "Disable rpc access authenticate") 25 26 runNodeCmd.Flags().Bool("wallet.disable", config.Wallet.Disable, "Disable wallet") 27 runNodeCmd.Flags().Bool("wallet.rescan", config.Wallet.Rescan, "Rescan wallet") 28 runNodeCmd.Flags().Bool("wallet.txindex", config.Wallet.TxIndex, "Save global tx index") 29 runNodeCmd.Flags().Bool("vault_mode", config.VaultMode, "Run in the offline enviroment") 30 runNodeCmd.Flags().Bool("web.closed", config.Web.Closed, "Lanch web browser or not") 31 runNodeCmd.Flags().String("chain_id", config.ChainID, "Select network type") 32 33 // log level 34 runNodeCmd.Flags().String("log_level", config.LogLevel, "Select log level(debug, info, warn, error or fatal)") 35 36 // p2p flags 37 runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)") 38 runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes") 39 runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration") 40 runNodeCmd.Flags().Bool("p2p.lan_discoverable", config.P2P.LANDiscover, "Whether the node can be discovered by nodes in the LAN") 41 runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers") 42 runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout") 43 runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout") 44 runNodeCmd.Flags().String("p2p.proxy_address", config.P2P.ProxyAddress, "Connect via SOCKS5 proxy (eg. 127.0.0.1:1086)") 45 runNodeCmd.Flags().String("p2p.proxy_username", config.P2P.ProxyUsername, "Username for proxy server") 46 runNodeCmd.Flags().String("p2p.proxy_password", config.P2P.ProxyPassword, "Password for proxy server") 47 runNodeCmd.Flags().String("p2p.keep_dial", config.P2P.KeepDial, "Peers addresses try keeping connecting to, separated by ',' (for example \"1.1.1.1:46657;2.2.2.2:46658\")") 48 49 // log flags 50 runNodeCmd.Flags().String("log_file", config.LogFile, "Log output file") 51 52 // websocket flags 53 runNodeCmd.Flags().Int("ws.max_num_websockets", config.Websocket.MaxNumWebsockets, "Max number of websocket connections") 54 runNodeCmd.Flags().Int("ws.max_num_concurrent_reqs", config.Websocket.MaxNumConcurrentReqs, "Max number of concurrent websocket requests that may be processed concurrently") 55 56 RootCmd.AddCommand(runNodeCmd) 57 } 58 59 func setLogLevel(level string) { 60 switch strings.ToLower(level) { 61 case "debug": 62 log.SetLevel(log.DebugLevel) 63 case "info": 64 log.SetLevel(log.InfoLevel) 65 case "warn": 66 log.SetLevel(log.WarnLevel) 67 case "error": 68 log.SetLevel(log.ErrorLevel) 69 case "fatal": 70 log.SetLevel(log.FatalLevel) 71 default: 72 log.SetLevel(log.InfoLevel) 73 } 74 } 75 76 func runNode(cmd *cobra.Command, args []string) error { 77 // startTime := time.Now() 78 setLogLevel(config.LogLevel) 79 80 // Create & start node 81 n := node.NewNode(config) 82 if err := n.Start(); err != nil { 83 log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("failed to start node") 84 } 85 86 // nodeInfo := n.NodeInfo() 87 // log.WithFields(log.Fields{ 88 // "module": logModule, 89 // "version": nodeInfo, 90 // "network": nodeInfo.Network, 91 // "duration": time.Since(startTime), 92 // }).Info("start node complete") 93 94 // Trap signal, run forever. 95 n.RunForever() 96 return nil 97 }