forked from hacash/miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
72 lines (62 loc) · 2.43 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
package minerrelayservice
import (
"fmt"
"github.com/hacash/core/sys"
"net"
"os"
)
type MinerRelayServiceConfig struct {
ServerAddress *net.TCPAddr
IsReportHashrate bool // Whether to report calculation force statistics
IsAcceptHashrate bool // Whether to accept calculation force statistics
ServerTcpListenPort int // TCP server listening port
MaxWorkerConnect int // TCP Max connections
HttpApiListenPort int // HTTP API data interface service
// Data storage
StoreEnable bool // Storage on
DataDir string // catalogue
SaveMiningBlockStuff bool // Save mining block information
SaveMiningHash bool // Whether to save the submitted block hash value
SaveMiningNonce bool // Save submitted nonce value
}
func NewEmptyMinerRelayServiceConfig() *MinerRelayServiceConfig {
cnf := &MinerRelayServiceConfig{}
return cnf
}
//////////////////////////////////////////////////
func NewMinerRelayServiceConfig(cnffile *sys.Inicnf) *MinerRelayServiceConfig {
cnf := NewEmptyMinerRelayServiceConfig()
cnfsection := cnffile.Section("")
// pool
addr, err := net.ResolveTCPAddr("tcp", cnfsection.Key("server_connect").MustString(""))
if err != nil {
fmt.Println(err)
panic("pool ip:port is error.")
}
cnf.ServerAddress = addr
// IsReportHashrate or IsAcceptHashrate
cnf.IsReportHashrate = cnfsection.Key("report_hashrate").MustBool(false)
cnf.IsAcceptHashrate = cnfsection.Key("accept_hashrate").MustBool(true)
// max
cnf.MaxWorkerConnect = cnfsection.Key("max_connect").MustInt(200)
cnf.ServerTcpListenPort = cnfsection.Key("server_listen_port").MustInt(19991)
if cnf.ServerTcpListenPort == 0 {
panic("Relay service:server listen port is zero")
}
cnf.HttpApiListenPort = cnfsection.Key("http_api_listen_port").MustInt(8080)
// store
storesection := cnffile.Section("store")
cnf.StoreEnable = storesection.Key("enable").MustBool(false)
if cnf.StoreEnable {
cnf.DataDir = storesection.Key("data_dir").MustString("./hacash_relay_service_data")
cnf.SaveMiningBlockStuff = storesection.Key("save_mining_block_stuff").MustBool(false)
cnf.SaveMiningHash = storesection.Key("save_mining_hash").MustBool(false)
cnf.SaveMiningNonce = storesection.Key("save_mining_nonce").MustBool(false)
if !cnf.SaveMiningHash && !cnf.SaveMiningNonce {
fmt.Println("[Miner Relay Service Config] Error: SaveMiningHash and SaveMiningNonce cannot be both false!")
os.Exit(0)
}
}
// ok
return cnf
}