package commands import ( "fmt" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/bytom/node" ) var runNodeCmd = &cobra.Command{ Use: "node", Short: "Run the bytomd", RunE: runNode, } 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("auth.disable", config.Auth.Disable, "Disable rpc access authenticate") runNodeCmd.Flags().Bool("wallet.disable", config.Wallet.Disable, "Disable 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") // 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().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") RootCmd.AddCommand(runNodeCmd) } func runNode(cmd *cobra.Command, args []string) error { // Create & start node n := node.NewNode(config) if _, err := n.Start(); err != nil { return fmt.Errorf("Failed to start node: %v", err) } else { log.WithField("nodeInfo", n.SyncManager().Switch().NodeInfo()).Info("Started node") } // Trap signal, run forever. n.RunForever() return nil }