-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.go
73 lines (61 loc) · 2.44 KB
/
main.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
package main
import (
"blockEmulator/build"
"blockEmulator/params"
"fmt"
"log"
"github.com/spf13/pflag"
)
var (
// network config
shardNum int
nodeNum int
shardID int
nodeID int
// supervisor or not
isSupervisor bool
// batch running config
isGen bool
isGenerateForExeFile bool
)
func main() {
// Read basic configs
params.ReadConfigFile()
// Generate bat files
pflag.BoolVarP(&isGen, "gen", "g", false, "isGen is a bool value, which indicates whether to generate a batch file")
pflag.BoolVarP(&isGenerateForExeFile, "shellForExe", "f", false, "isGenerateForExeFile is a bool value, which is effective only if 'isGen' is true; True to generate for an executable, False for 'go run'. ")
// Start a node.
pflag.IntVarP(&shardNum, "shardNum", "S", params.ShardNum, "shardNum is an Integer, which indicates that how many shards are deployed. ")
pflag.IntVarP(&nodeNum, "nodeNum", "N", params.NodesInShard, "nodeNum is an Integer, which indicates how many nodes of each shard are deployed. ")
pflag.IntVarP(&shardID, "shardID", "s", -1, "shardID is an Integer, which indicates the ID of the shard to which this node belongs. Value range: [0, shardNum). ")
pflag.IntVarP(&nodeID, "nodeID", "n", -1, "nodeID is an Integer, which indicates the ID of this node. Value range: [0, nodeNum).")
pflag.BoolVarP(&isSupervisor, "supervisor", "c", false, "isSupervisor is a bool value, which indicates whether this node is a supervisor.")
pflag.Parse()
params.ShardNum = shardNum
params.NodesInShard = nodeNum
if isGen {
if isGenerateForExeFile {
// Generate the corresponding .bat file or .sh file based on the detected operating system.
if err := build.GenerateExeBatchByIpTable(nodeNum, shardNum); err != nil {
fmt.Println(err.Error())
}
} else {
// Generate a .bat file or .sh file for running `go run`.
if err := build.GenerateBatchByIpTable(nodeNum, shardNum); err != nil {
fmt.Println(err.Error())
}
}
return
}
if isSupervisor {
build.BuildSupervisor(uint64(nodeNum), uint64(shardNum))
} else {
if shardID >= shardNum || shardID < 0 {
log.Panicf("Wrong ShardID. This ShardID is %d, but only %d shards in the current config. ", shardID, shardNum)
}
if nodeID >= nodeNum || nodeID < 0 {
log.Panicf("Wrong NodeID. This NodeID is %d, but only %d nodes in the current config. ", nodeID, nodeNum)
}
build.BuildNewPbftNode(uint64(nodeID), uint64(nodeNum), uint64(shardID), uint64(shardNum))
}
}