forked from aergoio/aergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
126 lines (107 loc) · 2.85 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
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package config
import (
"runtime"
"github.com/aergoio/aergo-lib/config"
"github.com/aergoio/aergo/types"
)
type ServerContext struct {
config.BaseContext
}
func NewServerContext(homePath string, configFilePath string) *ServerContext {
serverCxt := &ServerContext{}
serverCxt.BaseContext = config.NewBaseContext(serverCxt, homePath, configFilePath, EnvironmentPrefix)
return serverCxt
}
func (ctx *ServerContext) GetHomePath() string {
return defaultAergoHomePath
}
func (ctx *ServerContext) GetConfigFileName() string {
return defaultAergoConfigFileName
}
func (ctx *ServerContext) GetTemplate() string {
return tomlConfigFileTemplate
}
func (ctx *ServerContext) GetDefaultConfig() interface{} {
return &Config{
BaseConfig: ctx.GetDefaultBaseConfig(),
RPC: ctx.GetDefaultRPCConfig(),
REST: ctx.GetDefaultRESTConfig(),
P2P: ctx.GetDefaultP2PConfig(),
Blockchain: ctx.GetDefaultBlockchainConfig(),
Mempool: ctx.GetDefaultMempoolConfig(),
Consensus: ctx.GetDefaultConsensusConfig(),
Monitor: ctx.GetDefaultMonitorConfig(),
}
}
func (ctx *ServerContext) GetDefaultBaseConfig() BaseConfig {
return BaseConfig{
DataDir: ctx.ExpandPathEnv("$HOME/data"),
DbType: "badgerdb",
EnableProfile: false,
ProfilePort: 6060,
EnableRest: false,
EnableTestmode: false,
Personal: true,
}
}
func (ctx *ServerContext) GetDefaultRPCConfig() *RPCConfig {
return &RPCConfig{
NetServiceAddr: "127.0.0.1",
NetServicePort: 7845,
NetServiceTrace: false,
NSKey: "",
}
}
func (ctx *ServerContext) GetDefaultRESTConfig() *RESTConfig {
return &RESTConfig{
RestPort: 8080,
}
}
func (ctx *ServerContext) GetDefaultP2PConfig() *P2PConfig {
return &P2PConfig{
NetProtocolAddr: "",
NetProtocolPort: 7846,
NPBindAddr: "",
NPBindPort: -1,
NPEnableTLS: false,
NPCert: "",
NPKey: "",
NPAddPeers: nil,
NPMaxPeers: 100,
NPPeerPool: 100,
NPUsePolaris: true,
}
}
func (ctx *ServerContext) GetDefaultBlockchainConfig() *BlockchainConfig {
return &BlockchainConfig{
MaxBlockSize: types.DefaultMaxBlockSize,
CoinbaseAccount: "",
MaxAnchorCount: 20,
UseFastSyncer: false,
VerifierCount: types.DefaultVerifierCnt,
}
}
func (ctx *ServerContext) GetDefaultMempoolConfig() *MempoolConfig {
return &MempoolConfig{
ShowMetrics: false,
EnableFadeout: false,
FadeoutPeriod: types.DefaultEvictPeriod,
VerifierNumber: runtime.NumCPU(),
DumpFilePath: ctx.ExpandPathEnv("$HOME/mempool.dump"),
}
}
func (ctx *ServerContext) GetDefaultConsensusConfig() *ConsensusConfig {
return &ConsensusConfig{
BlockInterval: 1,
}
}
func (ctx *ServerContext) GetDefaultMonitorConfig() *MonitorConfig {
return &MonitorConfig{
ServerProtocol: "",
ServerEndpoint: "",
}
}