-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.go
317 lines (259 loc) · 8.33 KB
/
config.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package config
import (
"strings"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/urfave/cli/v2"
)
// Config represents the configuration.
type Config struct {
Global global
RPC rpc
P2P p2p
}
type global struct {
NodeIdentityKeyPassphrase string
LogPathLine bool
LogLevel string
DataDir string
KeystoreDir string
Validator bool
ValidatorKeypath string
ValidatorPass string
SearchEngine bool
SearchEngineResultCount int
ShowStorageCapacity bool
Storage bool
StoragePublic bool
StorageNodeLocation string
StorageDir string
StorageToken string
StorageFeesPerByte string
StorageFileMerkleTreeTotalSegments int
StorageFileSegmentsEncryptionPercentage int
DataVerifier bool
DataVerifierVerificationFees string
DataVerifierTransactionFees string
DataDownloadsPath string
SuperLightNode bool
Debug bool
VerifyBlocks bool
GeoLiteDBPath string
AllowFeesOverride bool
}
type p2p struct {
GossipMaxMessageSize int
MinPeers int
MaxPeers int
ListenPort int
ListenAddress string
Bootstraper bootstraper
}
type bootstraper struct {
Nodes []string
Frequency int
}
type rpc struct {
Whitelist []string
EnabledServices []string
DisabledMethods []string
HTTP httpWSConfig
Websocket httpWSConfig
Socket unixDomainSocket
}
type httpWSConfig struct {
Enabled bool
ListenPort int
ListenAddress string
CrossOriginValue string
}
type unixDomainSocket struct {
Enabled bool
Path string
}
// New creates a new configuration.
func New(ctx *cli.Context) *Config {
conf := &Config{
Global: global{
SearchEngineResultCount: 100,
StorageFileMerkleTreeTotalSegments: 1024,
StorageFileSegmentsEncryptionPercentage: 1,
},
RPC: rpc{
Whitelist: []string{},
EnabledServices: []string{},
DisabledMethods: []string{},
HTTP: httpWSConfig{
Enabled: false,
ListenPort: 8090,
ListenAddress: "127.0.0.1",
CrossOriginValue: "*",
},
Websocket: httpWSConfig{
Enabled: false,
ListenPort: 8091,
ListenAddress: "127.0.0.1",
CrossOriginValue: "*",
},
Socket: unixDomainSocket{
Enabled: false,
Path: "",
},
},
P2P: p2p{
GossipMaxMessageSize: 10 * pubsub.DefaultMaxMessageSize,
MinPeers: 100,
MaxPeers: 400,
ListenPort: 10209,
ListenAddress: "127.0.0.1",
},
}
conf.applyFlags(ctx)
return conf
}
func (conf *Config) applyFlags(ctx *cli.Context) {
// there is default value for data directory
conf.Global.DataDir = ctx.String(DataDirFlag.Name)
conf.Global.KeystoreDir = ctx.String(KeystoreDirFlag.Name)
if ctx.IsSet(NodeIdentityKeyPassphrase.Name) {
conf.Global.NodeIdentityKeyPassphrase = ctx.String(NodeIdentityKeyPassphrase.Name)
}
if ctx.IsSet(LogPathLine.Name) {
conf.Global.LogPathLine = ctx.Bool(LogPathLine.Name)
}
if ctx.IsSet(LogLevelFlag.Name) {
conf.Global.LogLevel = ctx.String(LogLevelFlag.Name)
}
if ctx.IsSet(ValidatorFlag.Name) {
conf.Global.Validator = ctx.Bool(ValidatorFlag.Name)
}
if ctx.IsSet(ValidatorKeypath.Name) {
conf.Global.ValidatorKeypath = ctx.String(ValidatorKeypath.Name)
}
if ctx.IsSet(ValidatorPass.Name) {
conf.Global.ValidatorPass = ctx.String(ValidatorPass.Name)
}
if ctx.IsSet(SearchEngine.Name) {
conf.Global.SearchEngine = ctx.Bool(SearchEngine.Name)
}
if ctx.IsSet(SearchEngineResultCount.Name) {
conf.Global.SearchEngineResultCount = ctx.Int(SearchEngineResultCount.Name)
}
if ctx.IsSet(StorageCapacity.Name) {
conf.Global.ShowStorageCapacity = ctx.Bool(StorageCapacity.Name)
}
if ctx.IsSet(Storage.Name) {
conf.Global.Storage = ctx.Bool(Storage.Name)
}
if ctx.IsSet(StoragePublic.Name) {
conf.Global.StoragePublic = ctx.Bool(StoragePublic.Name)
}
if ctx.IsSet(StorageNodeLocation.Name) {
conf.Global.StorageNodeLocation = ctx.String(StorageNodeLocation.Name)
}
if ctx.IsSet(StorageDir.Name) {
conf.Global.StorageDir = ctx.String(StorageDir.Name)
}
if ctx.IsSet(StorageToken.Name) {
conf.Global.StorageToken = ctx.String(StorageToken.Name)
}
if ctx.IsSet(StorageFeesPerByte.Name) {
conf.Global.StorageFeesPerByte = ctx.String(StorageFeesPerByte.Name)
}
if ctx.IsSet(StorageFileMerkleTreeTotalSegments.Name) {
conf.Global.StorageFileMerkleTreeTotalSegments = ctx.Int(StorageFileMerkleTreeTotalSegments.Name)
}
if ctx.IsSet(StorageFileSegmentsEncryptionPercentage.Name) {
conf.Global.StorageFileSegmentsEncryptionPercentage = ctx.Int(StorageFileSegmentsEncryptionPercentage.Name)
}
if ctx.IsSet(DataVerifier.Name) {
conf.Global.DataVerifier = ctx.Bool(DataVerifier.Name)
}
if ctx.IsSet(DataVerifierVerificationFees.Name) {
conf.Global.DataVerifierVerificationFees = ctx.String(DataVerifierVerificationFees.Name)
}
if ctx.IsSet(DataVerifierTransactionFees.Name) {
conf.Global.DataVerifierTransactionFees = ctx.String(DataVerifierTransactionFees.Name)
}
if ctx.IsSet(DataDownloadsPath.Name) {
conf.Global.DataDownloadsPath = ctx.String(DataDownloadsPath.Name)
}
if ctx.IsSet(SuperLightNode.Name) {
conf.Global.SuperLightNode = ctx.Bool(SuperLightNode.Name)
}
if ctx.IsSet(DebugMode.Name) {
conf.Global.Debug = ctx.Bool(DebugMode.Name)
}
if ctx.IsSet(VerifyBlocks.Name) {
conf.Global.VerifyBlocks = ctx.Bool(VerifyBlocks.Name)
}
if ctx.IsSet(GeoLiteDBPath.Name) {
conf.Global.GeoLiteDBPath = ctx.String(GeoLiteDBPath.Name)
}
if ctx.IsSet(AllowFeesOverride.Name) {
conf.Global.AllowFeesOverride = ctx.Bool(AllowFeesOverride.Name)
}
if ctx.IsSet(RPCServicesFlag.Name) {
conf.RPC.EnabledServices = strings.Split(ctx.String(RPCServicesFlag.Name), ",")
}
if ctx.IsSet(RPCDisabledMethodsFlag.Name) {
conf.RPC.DisabledMethods = strings.Split(ctx.String(RPCDisabledMethodsFlag.Name), ",")
}
if ctx.IsSet(RPCWhitelistFlag.Name) {
conf.RPC.Whitelist = strings.Split(ctx.String(RPCWhitelistFlag.Name), ",")
}
// RPC:SOCKET
if ctx.IsSet(RPCSocketEnabledFlag.Name) {
conf.RPC.Socket.Enabled = ctx.Bool(RPCSocketEnabledFlag.Name)
}
if ctx.IsSet(RPCSocketPathFlag.Name) {
conf.RPC.Socket.Path = ctx.String(RPCSocketPathFlag.Name)
}
// RPC:HTTP
if ctx.IsSet(RPCHTTPEnabledFlag.Name) {
conf.RPC.HTTP.Enabled = ctx.Bool(RPCHTTPEnabledFlag.Name)
}
if ctx.IsSet(RPCHTTPPortFlag.Name) {
conf.RPC.HTTP.ListenPort = ctx.Int(RPCHTTPPortFlag.Name)
}
if ctx.IsSet(RPCHTTPAddrFlag.Name) {
conf.RPC.HTTP.ListenAddress = ctx.String(RPCHTTPAddrFlag.Name)
}
if ctx.IsSet(RPCHTTPCrossOriginFlag.Name) {
conf.RPC.HTTP.CrossOriginValue = ctx.String(RPCHTTPCrossOriginFlag.Name)
}
// RPC:WS
if ctx.IsSet(RPCWSEnabledFlag.Name) {
conf.RPC.Websocket.Enabled = ctx.Bool(RPCWSEnabledFlag.Name)
}
if ctx.IsSet(RPCWSPortFlag.Name) {
conf.RPC.Websocket.ListenPort = ctx.Int(RPCWSPortFlag.Name)
}
if ctx.IsSet(RPCWSAddrFlag.Name) {
conf.RPC.Websocket.ListenAddress = ctx.String(RPCWSAddrFlag.Name)
}
if ctx.IsSet(RPCWSCrossOriginFlag.Name) {
conf.RPC.Websocket.CrossOriginValue = ctx.String(RPCWSCrossOriginFlag.Name)
}
// P2P
if ctx.IsSet(P2PMaxGossipSize.Name) {
conf.P2P.GossipMaxMessageSize = ctx.Int(P2PMaxGossipSize.Name)
}
if ctx.IsSet(MaxPeersFlag.Name) {
conf.P2P.MaxPeers = ctx.Int(MaxPeersFlag.Name)
}
if ctx.IsSet(P2PListenPortFlag.Name) {
conf.P2P.ListenPort = ctx.Int(P2PListenPortFlag.Name)
}
if ctx.IsSet(P2PListenAddrFlag.Name) {
conf.P2P.ListenAddress = ctx.String(P2PListenAddrFlag.Name)
}
if ctx.IsSet(P2PMinPeersFlag.Name) {
conf.P2P.MinPeers = ctx.Int(P2PMinPeersFlag.Name)
}
if ctx.IsSet(P2PBootstraperFlag.Name) {
conf.P2P.Bootstraper.Nodes = strings.Split(ctx.String(P2PBootstraperFlag.Name), ",")
}
if ctx.IsSet(P2PFrequencyFlag.Name) {
conf.P2P.Bootstraper.Frequency = ctx.Int(P2PFrequencyFlag.Name)
}
}