-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
220 lines (215 loc) · 6.14 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
// Package node
//
// @author: xwc1125
package node
var (
ConfPathName = "conf"
DataPathName = "chaindata"
P2pPathName = "p2p"
KeystorePathName = "keystore"
CertsPathName = "certs"
IPCPathName = "chain5j.ipc"
// sn配置
isSNVerify = true
snPubKey = ""
)
//type ChainDirConfig struct {
// RootDir string // 根目录
// ConfDir string // 配置目录
// DBDir string // 数据目录
// P2PDir string // 数据目录
// KeystoreDir string // 密码目录
// IPCPath string // IPC path
// CertsDir string // 证书目录
//}
//
//func GetDataDir() *ChainDirConfig {
// if chainDirConfig != nil {
// return chainDirConfig
// }
// var dataDir = "./"
// //if cli.RootCli != nil {
// // dataDir = cli.RootCli.DataDir
// //}
// return SetDataDir(dataDir)
//}
//
//func SetDataDir(rootDir string) *ChainDirConfig {
// rootDir = strings.TrimSuffix(rootDir, "/")
// confPath := filepath.Join(rootDir, ConfPathName)
// dataPath := filepath.Join(rootDir, DataPathName)
// p2pPath := filepath.Join(rootDir, P2pPathName)
// keystorePath := filepath.Join(rootDir, KeystorePathName)
// certsPath := filepath.Join(rootDir, CertsPathName)
// ipcPath := filepath.Join(rootDir, IPCPathName)
//
// if !ioutil.PathExists(confPath) {
// ioutil.MakeDirAll(confPath)
// }
// if !ioutil.PathExists(dataPath) {
// ioutil.MakeDirAll(dataPath)
// }
// if !ioutil.PathExists(p2pPath) {
// ioutil.MakeDirAll(p2pPath)
// }
// if !ioutil.PathExists(certsPath) {
// ioutil.MakeDirAll(certsPath)
// }
// if !ioutil.PathExists(keystorePath) {
// ioutil.MakeDirAll(keystorePath)
// }
// chainDirConfig = &ChainDirConfig{
// RootDir: rootDir,
// ConfDir: confPath,
// DBDir: dataPath,
// P2PDir: p2pPath,
// CertsDir: certsPath,
// KeystoreDir: keystorePath,
// IPCPath: ipcPath,
// }
//
// logger.Info("chainDirConfig", "path", chainDirConfig)
// return chainDirConfig
//}
//// 节点配置
//type NodeConfig struct {
// IpcConfig rpc.IpcConfig `json:"ipc" mapstructure:"ipc"` // ipc
// TlsConfig network.TlsConfig `json:"tls" mapstructure:"tls"` // tls
// HttpConfig rpc.HttpConfig `json:"http" mapstructure:"http"` // http
// WSConfig rpc.WSConfig `json:"ws" mapstructure:"ws"` // websocket
// P2P models.P2PConfig `json:"p2p" mapstructure:"p2p"` // p2p
// DBPath string `json:"db_path" mapstructure:"db_path"` // db 路径
// EnableWorker bool `json:"enable_worker" mapstructure:"enable_worker"` // 是否启动worker
//}
//
//func GetNodeConfig() (*NodeConfig, error) {
// var err error
// // ipc
// {
// ipcName := viper.Sub("ipc").GetString("ipc_name")
// if ipcName != "" && strings.HasSuffix(ipcName, ".ipc") {
// IPCPathName = ipcName
// }
// }
// // tls
// tlsConfig := network.TlsConfig{}
// {
// err = viper.UnmarshalKey("tls", &tlsConfig)
// if err != nil {
// logger.Error("viper.UnmarshalKey(tls, &tlsConfig) err", "err", err)
// }
// if tlsConfig.KeyFile != "" && !filepath.IsAbs(tlsConfig.KeyFile) {
// tlsConfig.KeyFile = filepath.Join(GetDataDir().RootDir, tlsConfig.KeyFile)
// }
// if tlsConfig.CertFile != "" && !filepath.IsAbs(tlsConfig.CertFile) {
// tlsConfig.CertFile = filepath.Join(GetDataDir().RootDir, tlsConfig.CertFile)
// }
// for i, root := range tlsConfig.CaRoots {
// if root != "" && !filepath.IsAbs(root) {
// tlsConfig.CaRoots[i] = filepath.Join(GetDataDir().RootDir, root)
// }
// }
// }
// // http
// httpConfig := rpc.HttpConfig{}
// {
// err = viper.UnmarshalKey("http", &httpConfig)
// if err != nil {
// logger.Error("viper.UnmarshalKey(http, &httpConfig) err", "err", err)
// }
//
// // 解析cmd中的参数
// host := viper.GetString("rpchost")
// if host == "" {
// httpConfig.Host = host
// }
// if httpConfig.Host == "" {
// httpConfig.Host = "0.0.0.0"
// }
// port := viper.GetInt("rpcport")
// if port != 9545 {
// httpConfig.Port = port
// }
// if httpConfig.Port == 0 {
// httpConfig.Port = port
// }
// }
// // ws
// wsConfig := rpc.WSConfig{}
// {
// err = viper.UnmarshalKey("ws", &wsConfig)
// if err != nil {
// logger.Error("viper.UnmarshalKey(ws, &wsConfig) err", "err", err)
// }
// }
// // p2p2
// p2pConfig := models.P2PConfig{}
// {
// err = viper.UnmarshalKey("p2p", &p2pConfig)
// if err != nil {
// logger.Error("viper.UnmarshalKey(p2p, &p2pConfig) err", "err", err)
// }
// if p2pConfig.MaxPeers == 0 {
// p2pConfig.MaxPeers = p2p.MaxPeers
// }
// if !filepath.IsAbs(p2pConfig.KeyPath) {
// p2pConfig.KeyPath = filepath.Join(GetDataDir().RootDir, p2pConfig.KeyPath)
// }
// if !filepath.IsAbs(p2pConfig.CertPath) {
// p2pConfig.CertPath = filepath.Join(GetDataDir().RootDir, p2pConfig.CertPath)
// }
// if p2pConfig.CaRoots != nil && len(p2pConfig.CaRoots) > 0 {
// for i, root := range p2pConfig.CaRoots {
// if !filepath.IsAbs(root) {
// root = filepath.Join(GetDataDir().RootDir, root)
// }
// caRootBytes, err := nioutil.ReadFile(root)
// if err != nil {
// return nil, err
// }
// p2pConfig.CaRoots[i] = string(caRootBytes)
// }
// }
// }
//
// return &NodeConfig{
// IpcConfig: rpc.IpcConfig{
// Path: GetDataDir().IPCPath,
// },
// TlsConfig: tlsConfig,
// HttpConfig: httpConfig,
// WSConfig: wsConfig,
// P2P: p2pConfig,
// DBPath: GetDataDir().DBDir,
// EnableWorker: viper.GetBool("mine"),
// }, nil
//}
//
//func RegisterSNPubkey(pubKey string) {
// snPubKey = pubKey
//}
//func GetLicense() (*license2.SN, error) {
// input := viper.GetString("license")
// if len(input) == 0 {
// return &license2.SN{}, nil
// }
//
// //logger.Info("load license", "input", input)
// jsonBytes, err := base64.StdEncoding.DecodeString(input)
// if err != nil {
// return nil, err
// }
// logger.Info("load license", "license", string(jsonBytes))
//
// var sn license2.SN
// err = json.Unmarshal(jsonBytes, &sn)
// if err != nil {
// return nil, errors.New("invalid license")
// }
//
// if !license2.Verify(sn.GetSignJson(), sn.Signature, []byte(snPubKey)) {
// return nil, errors.New("invalid license")
// }
//
// return &sn, nil
//}