-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_node.go
84 lines (67 loc) · 2.63 KB
/
run_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package commands
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/bytom/node"
"strings"
)
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("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().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 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.NewNode(config)
if _, err := n.Start(); err != nil {
return fmt.Errorf("Failed to start node: %v", err)
} else {
log.Info("Start node ", n.SyncManager().NodeInfo())
}
// Trap signal, run forever.
n.RunForever()
return nil
}