forked from 8lecramm/derohe-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
derohe-proxy.go
156 lines (134 loc) · 4.33 KB
/
derohe-proxy.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
package main
import (
"derohe-proxy/config"
"derohe-proxy/proxy"
"fmt"
"net"
"strconv"
"time"
"github.com/docopt/docopt-go"
)
var proxyConfig = config.ProxyConfig{
ListenAddr: "0.0.0.0:10200",
DaemonAddr: "minernode1.dero.io:10100",
LogInterval: 60,
Minimal: false,
NonceEdit: false,
Global: false,
ZeroNonce: false,
Verbose: false,
JobRate: (500 * time.Millisecond),
WalletFile: false,
Quantum: false,
}
func main() {
var err error
config.Arguments, err = docopt.Parse(config.CommandLine, nil, true, "pre-alpha", false)
if err != nil {
return
}
if config.Arguments["--listen-address"] != nil {
addr, err := net.ResolveTCPAddr("tcp", config.Arguments["--listen-address"].(string))
if err != nil {
return
} else {
if addr.Port == 0 {
return
} else {
proxyConfig.ListenAddr = addr.String()
}
}
}
if config.Arguments["--daemon-address"] == nil {
return
} else {
proxyConfig.DaemonAddr = config.Arguments["--daemon-address"].(string)
}
if config.Arguments["--log-interval"] != nil {
interval, err := strconv.ParseInt(config.Arguments["--log-interval"].(string), 10, 32)
if err != nil {
return
} else {
if interval < 60 || interval > 3600 {
proxyConfig.LogInterval = 60
} else {
proxyConfig.LogInterval = int(interval)
}
}
}
if config.Arguments["--jobrate"] != nil {
job_rate, err := time.ParseDuration(config.Arguments["--jobrate"].(string))
if err != nil {
return
} else {
proxyConfig.JobRate = job_rate
}
}
if config.Arguments["--minimal"].(bool) {
proxyConfig.Minimal = true
fmt.Printf("%v Forward only 2 jobs per block\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--nonce"].(bool) {
proxyConfig.NonceEdit = true
fmt.Printf("%v Nonce editing is enabled\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--zero"].(bool) {
proxyConfig.ZeroNonce = true
fmt.Printf("%v Flags/Nonce2 zeroing are enabled\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--global"].(bool) {
proxyConfig.Global = true
fmt.Printf("%v Global Nonce targeting is enabled\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--walletfile"].(bool) {
proxyConfig.WalletFile = true
fmt.Printf("%v Global Wallet List Enabled\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--quantum"].(bool) {
proxyConfig.Quantum = true
fmt.Printf("%v Quantum Random Data Enabled...will fallback to crypto/rand if unavailable\n", time.Now().Format(time.Stamp))
}
if config.Arguments["--verbose"].(bool) {
proxyConfig.Verbose = true
fmt.Printf("%v Verbose nonce output is enabled\n", time.Now().Format(time.Stamp))
}
fmt.Printf("%v Logging every %d seconds\n", time.Now().Format(time.Stamp), proxyConfig.LogInterval)
fmt.Printf("%v Job Dispatch Rate: %s\n", time.Now().Format(time.Stamp), proxyConfig.JobRate.String())
if proxyConfig.NonceEdit {
go proxy.RandomGenerator(&proxyConfig)
fmt.Print("Building random data for 10 sec...\n")
time.Sleep(time.Second * 10)
}
go proxy.Start_server(&proxyConfig)
// Wait for first miner connection to grab wallet address
for proxy.CountMiners() < 1 {
time.Sleep(time.Second * 1)
}
go proxy.Start_client(proxy.Address)
go proxy.SendUpdateToDaemon()
for {
time.Sleep(time.Second * time.Duration(proxyConfig.LogInterval))
hash_rate_string := ""
switch {
case proxy.Hashrate > 1000000000000:
hash_rate_string = fmt.Sprintf("%.3f TH/s", float64(proxy.Hashrate)/1000000000000.0)
case proxy.Hashrate > 1000000000:
hash_rate_string = fmt.Sprintf("%.3f GH/s", float64(proxy.Hashrate)/1000000000.0)
case proxy.Hashrate > 1000000:
hash_rate_string = fmt.Sprintf("%.3f MH/s", float64(proxy.Hashrate)/1000000.0)
case proxy.Hashrate > 1000:
hash_rate_string = fmt.Sprintf("%.3f KH/s", float64(proxy.Hashrate)/1000.0)
case proxy.Hashrate > 0:
hash_rate_string = fmt.Sprintf("%d H/s", int(proxy.Hashrate))
}
fmt.Printf("%v %d miners connected, IB:%d MB:%d MBR:%d MBO:%d - MINING @ %s\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans, hash_rate_string)
for i := range proxy.Wallet_count {
if proxy.Wallet_count[i] > 1 {
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, proxy.Wallet_count[i])
}
}
if proxyConfig.WalletFile {
proxy.LoadWalletsFile()
}
}
}