/
factomParams.go
244 lines (222 loc) · 9.74 KB
/
factomParams.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package engine
import (
"flag"
"os"
"github.com/FactomProject/factomd/common/primitives"
)
type FactomParams struct {
AckbalanceHash bool
EnableNet bool
WaitEntries bool
ListenTo int
Cnt int
Net string
Fnet string
DropRate int
Journal string
Journaling bool
Follower bool
Leader bool
Db string
CloneDB string
PortOverride int
Peers string
NetworkName string
NetworkPortOverride int
ControlPanelPortOverride int
LogPort string
BlkTime int
FaultTimeout int
RuntimeLog bool
Netdebug int
Exclusive bool
prefix string
rotate bool
timeOffset int
keepMismatch bool
StartDelay int64
deadline int
customNet []byte
rpcUser string
rpcPassword string
factomdTLS bool
factomdLocations string
memProfileRate int
fast bool
fastLocation string
loglvl string
logjson bool
svm bool
pluginPath string
torManage bool
torUpload bool
Sim_Stdin bool
exposeProfiling bool
useLogstash bool
logstashURL string
Sync2 int
DebugConsole bool
}
func (f *FactomParams) Init() {
f.AckbalanceHash = true
f.EnableNet = true
f.WaitEntries = false
f.ListenTo = 0
f.Cnt = 1
f.Net = "tree"
f.Fnet = ""
f.DropRate = 0
f.Journal = ""
f.Journaling = false
f.Follower = false
f.Leader = true
f.Db = ""
f.CloneDB = ""
f.PortOverride = 0
f.Peers = ""
f.NetworkName = ""
f.NetworkPortOverride = 0
f.ControlPanelPortOverride = 0
f.LogPort = "6060"
f.BlkTime = 0
f.FaultTimeout = 60
f.RuntimeLog = false
f.Netdebug = 0
f.Exclusive = false
f.prefix = ""
f.rotate = false
f.timeOffset = 0
f.keepMismatch = false
f.StartDelay = 10
f.deadline = 1000
f.customNet = primitives.Sha([]byte("")).Bytes()[:4]
f.rpcUser = ""
f.rpcPassword = ""
f.factomdTLS = false
f.factomdLocations = ""
f.memProfileRate = 512 * 1024
f.fast = true
f.fastLocation = ""
f.loglvl = "node"
f.logjson = false
f.svm = false
f.pluginPath = ""
f.torManage = false
f.torUpload = false
f.Sim_Stdin = true
f.exposeProfiling = false
f.Sync2 = -1
f.DebugConsole = false
}
func ParseCmdLine(args []string) *FactomParams {
p := new(FactomParams)
ackBalanceHashPtr := flag.Bool("balancehash", true, "If false, then don't pass around balance hashes")
enablenetPtr := flag.Bool("enablenet", true, "Enable or disable networking")
waitEntriesPtr := flag.Bool("waitentries", false, "Wait for Entries to be validated prior to execution of messages")
listenToPtr := flag.Int("node", 0, "Node Number the simulator will set as the focus")
cntPtr := flag.Int("count", 1, "The number of nodes to generate")
netPtr := flag.String("net", "tree", "The default algorithm to build the network connections")
fnetPtr := flag.String("fnet", "", "Read the given file to build the network connections")
dropPtr := flag.Int("drop", 0, "Number of messages to drop out of every thousand")
journalPtr := flag.String("journal", "", "Rerun a Journal of messages")
journalingPtr := flag.Bool("journaling", false, "Write a journal of all messages recieved. Default is off.")
followerPtr := flag.Bool("follower", false, "If true, force node to be a follower. Only used when replaying a journal.")
leaderPtr := flag.Bool("leader", true, "If true, force node to be a leader. Only used when replaying a journal.")
dbPtr := flag.String("db", "", "Override the Database in the Config file and use this Database implementation. Options Map, LDB, or Bolt")
cloneDBPtr := flag.String("clonedb", "", "Override the main node and use this database for the clones in a Network.")
networkNamePtr := flag.String("network", "", "Network to join: MAIN, TEST or LOCAL")
peersPtr := flag.String("peers", "", "Array of peer addresses. ")
blkTimePtr := flag.Int("blktime", 0, "Seconds per block. Production is 600.")
faultTimeoutPtr := flag.Int("faulttimeout", 60, "Seconds before considering Federated servers at-fault. Default is 60.")
runtimeLogPtr := flag.Bool("runtimeLog", false, "If true, maintain runtime logs of messages passed.")
netdebugPtr := flag.Int("netdebug", 0, "0-5: 0 = quiet, >0 = increasing levels of logging")
exclusivePtr := flag.Bool("exclusive", false, "If true, we only dial out to special/trusted peers.")
prefixNodePtr := flag.String("prefix", "", "Prefix the Factom Node Names with this value; used to create leaderless networks.")
rotatePtr := flag.Bool("rotate", false, "If true, responsiblity is owned by one leader, and rotated over the leaders.")
timeOffsetPtr := flag.Int("timedelta", 0, "Maximum timeDelta in milliseconds to offset each node. Simulates deltas in system clocks over a network.")
keepMismatchPtr := flag.Bool("keepmismatch", false, "If true, do not discard DBStates even when a majority of DBSignatures have a different hash")
startDelayPtr := flag.Int("startdelay", 10, "Delay to start processing messages, in seconds")
deadlinePtr := flag.Int("deadline", 1000, "Timeout Delay in milliseconds used on Reads and Writes to the network comm")
customNetPtr := flag.String("customnet", "", "This string specifies a custom blockchain network ID.")
rpcUserflag := flag.String("rpcuser", "", "Username to protect factomd local API with simple HTTP authentication")
rpcPasswordflag := flag.String("rpcpass", "", "Password to protect factomd local API. Ignored if rpcuser is blank")
factomdTLSflag := flag.Bool("tls", false, "Set to true to require encrypted connections to factomd API and Control Panel") //to get tls, run as "factomd -tls=true"
factomdLocationsflag := flag.String("selfaddr", "", "comma seperated IPAddresses and DNS names of this factomd to use when creating a cert file")
memProfileRate := flag.Int("mpr", 512*1024, "Set the Memory Profile Rate to update profiling per X bytes allocated. Default 512K, set to 1 to profile everything, 0 to disable.")
exposeProfilePtr := flag.Bool("exposeprofiler", false, "Setting this exposes the profiling port to outside localhost.")
factomHomePtr := flag.String("factomhome", "", "Set the factom home directory. The .factom folder will be placed here if set, otherwise it will default to $HOME")
logportPtr := flag.String("logPort", "6060", "Port for pprof logging")
portOverridePtr := flag.Int("port", 0, "Port where we serve WSAPI; default 8088")
ControlPanelPortOverridePtr := flag.Int("ControlPanelPort", 0, "Port for control panel webserver; Default 8090")
networkPortOverridePtr := flag.Int("networkPort", 0, "Port for p2p network; default 8110")
fastPtr := flag.Bool("fast", true, "If true, factomd will fast-boot from a file.")
fastLocationPtr := flag.String("fastlocation", "", "Directory to put the fast-boot file in.")
logLvlPtr := flag.String("loglvl", "none", "Set log level to either: none, debug, info, warning, error, fatal or panic")
logJsonPtr := flag.Bool("logjson", false, "Use to set logging to use a json formatting")
sim_stdinPtr := flag.Bool("sim_stdin", true, "If true, sim control reads from stdin.")
// Plugins
pluginPath := flag.String("plugin", "", "Input the path to any plugin binaries")
// Torrent Plugin
tormanager := flag.Bool("tormanage", false, "Use torrent dbstate manager. Must have plugin binary installed and in $PATH")
torUploader := flag.Bool("torupload", false, "Be a torrent uploader")
// Logstash connection (if used)
logstash := flag.Bool("logstash", false, "If true, use Logstash")
logstashURL := flag.String("logurl", "localhost:8345", "Endpoint URL for Logstash")
sync2Ptr := flag.Int("sync2", -1, "Set the initial blockheight for the second Sync pass. Used to force a total sync, or skip unnecessary syncing of entries.")
DebugConsolePtr := flag.Bool("DebugConsole", false, "Enable DebugConsole")
flag.CommandLine.Parse(args)
p.AckbalanceHash = *ackBalanceHashPtr
p.EnableNet = *enablenetPtr
p.WaitEntries = *waitEntriesPtr
p.ListenTo = *listenToPtr
p.Cnt = *cntPtr
p.Net = *netPtr
p.Fnet = *fnetPtr
p.DropRate = *dropPtr
p.Journal = *journalPtr
p.Journaling = *journalingPtr
p.Follower = *followerPtr
p.Leader = *leaderPtr
p.Db = *dbPtr
p.CloneDB = *cloneDBPtr
p.PortOverride = *portOverridePtr
p.Peers = *peersPtr
p.NetworkName = *networkNamePtr
p.NetworkPortOverride = *networkPortOverridePtr
p.ControlPanelPortOverride = *ControlPanelPortOverridePtr
p.LogPort = *logportPtr
p.BlkTime = *blkTimePtr
p.FaultTimeout = *faultTimeoutPtr
p.RuntimeLog = *runtimeLogPtr
p.Netdebug = *netdebugPtr
p.Exclusive = *exclusivePtr
p.prefix = *prefixNodePtr
p.rotate = *rotatePtr
p.timeOffset = *timeOffsetPtr
p.keepMismatch = *keepMismatchPtr
p.StartDelay = int64(*startDelayPtr)
p.deadline = *deadlinePtr
p.customNet = primitives.Sha([]byte(*customNetPtr)).Bytes()[:4]
p.rpcUser = *rpcUserflag
p.rpcPassword = *rpcPasswordflag
p.factomdTLS = *factomdTLSflag
p.factomdLocations = *factomdLocationsflag
p.memProfileRate = *memProfileRate
p.fast = *fastPtr
p.fastLocation = *fastLocationPtr
p.loglvl = *logLvlPtr
p.logjson = *logJsonPtr
p.Sim_Stdin = *sim_stdinPtr
p.exposeProfiling = *exposeProfilePtr
p.pluginPath = *pluginPath
p.torManage = *tormanager
p.torUpload = *torUploader
p.useLogstash = *logstash
p.logstashURL = *logstashURL
p.Sync2 = *sync2Ptr
p.DebugConsole = *DebugConsolePtr
if *factomHomePtr != "" {
os.Setenv("FACTOM_HOME", *factomHomePtr)
}
return p
}