derohe-proxy/derohe-proxy.go

144 lines
4.0 KiB
Go
Raw Normal View History

2022-05-24 17:17:12 +01:00
package main
import (
2022-10-03 15:35:05 +01:00
"derohe-proxy/config"
2022-05-24 17:17:12 +01:00
"derohe-proxy/proxy"
"fmt"
"net"
"strconv"
2022-12-28 18:33:42 +00:00
"strings"
2022-05-24 17:17:12 +01:00
"time"
2022-11-16 23:54:30 +00:00
"github.com/deroproject/derohe/globals"
2022-05-24 17:17:12 +01:00
"github.com/docopt/docopt-go"
)
func main() {
var err error
2022-10-03 15:35:05 +01:00
config.Arguments, err = docopt.Parse(config.Command_line, nil, true, "pre-alpha", false)
2022-05-24 17:17:12 +01:00
if err != nil {
return
}
2022-10-03 15:35:05 +01:00
if config.Arguments["--listen-address"] != nil {
addr, err := net.ResolveTCPAddr("tcp", config.Arguments["--listen-address"].(string))
2022-05-24 17:17:12 +01:00
if err != nil {
return
} else {
if addr.Port == 0 {
return
} else {
2022-10-03 15:35:05 +01:00
config.Listen_addr = addr.String()
2022-05-24 17:17:12 +01:00
}
}
}
2022-10-03 15:35:05 +01:00
if config.Arguments["--daemon-address"] == nil {
2022-05-24 17:17:12 +01:00
return
} else {
2022-10-03 15:35:05 +01:00
config.Daemon_address = config.Arguments["--daemon-address"].(string)
2022-05-24 17:17:12 +01:00
}
2022-10-03 15:35:05 +01:00
if config.Arguments["--wallet-address"] != nil {
2022-12-28 18:33:42 +00:00
// check for worker suffix
var parseWorker []string
var address string
if strings.Contains(config.Arguments["--wallet-address"].(string), ".") {
parseWorker = strings.Split(config.Arguments["--wallet-address"].(string), ".")
config.Worker = parseWorker[1]
address = parseWorker[0]
} else {
address = config.Arguments["--wallet-address"].(string)
}
addr, err := globals.ParseValidateAddress(address)
2022-11-16 23:54:30 +00:00
if err != nil {
fmt.Printf("%v Wallet address is invalid!\n", time.Now().Format(time.Stamp))
}
config.WalletAddr = addr.String()
2022-12-28 18:33:42 +00:00
if config.Worker != "" {
fmt.Printf("%v Using wallet %s and name %s for all connections\n", time.Now().Format(time.Stamp), config.WalletAddr, config.Worker)
} else {
fmt.Printf("%v Using wallet %s for all connections\n", time.Now().Format(time.Stamp), config.WalletAddr)
}
2022-10-03 15:35:05 +01:00
}
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 {
2022-10-03 15:35:05 +01:00
config.Log_intervall = 60
} else {
2022-10-03 15:35:05 +01:00
config.Log_intervall = int(interval)
}
}
}
/*if config.Arguments["--minimal"].(bool) {
2022-10-03 15:35:05 +01:00
config.Minimal = true
2022-06-08 00:03:38 +01:00
fmt.Printf("%v Forward only 2 jobs per block\n", time.Now().Format(time.Stamp))
}*/
2022-05-28 11:52:52 +01:00
2022-10-03 15:35:05 +01:00
if config.Arguments["--nonce"].(bool) {
config.Nonce = true
2022-06-08 00:03:38 +01:00
fmt.Printf("%v Nonce editing is enabled\n", time.Now().Format(time.Stamp))
}
2022-10-03 15:35:05 +01:00
if config.Arguments["--pool"].(bool) {
config.Pool_mode = true
config.Minimal = false
fmt.Printf("%v Pool mode is enabled\n", time.Now().Format(time.Stamp))
}
fmt.Printf("%v Logging every %d seconds\n", time.Now().Format(time.Stamp), config.Log_intervall)
2022-10-03 15:35:05 +01:00
go proxy.Start_server()
2022-05-24 17:17:12 +01:00
// Wait for first miner connection to grab wallet address
for proxy.CountMiners() < 1 {
time.Sleep(time.Second * 1)
}
2022-12-28 18:33:42 +00:00
if config.Worker == "" {
go proxy.Start_client(proxy.Address)
} else {
go proxy.Start_client(proxy.Address + "." + config.Worker)
}
2022-05-24 17:17:12 +01:00
for {
2022-10-03 15:35:05 +01:00
time.Sleep(time.Second * time.Duration(config.Log_intervall))
2022-07-19 21:50:35 +01:00
2023-03-27 22:13:50 +01:00
miners := proxy.CountMiners()
2022-07-19 21:50:35 +01:00
hash_rate_string := ""
2023-03-27 22:13:50 +01:00
if miners > 0 {
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))
}
2022-07-19 21:50:35 +01:00
}
2022-10-03 15:35:05 +01:00
if !config.Pool_mode {
2023-03-27 22:13:50 +01:00
fmt.Printf("%v %d miners connected, IB:%d MB:%d MBR:%d MBO:%d\n", time.Now().Format(time.Stamp), miners, proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans)
2022-10-03 15:35:05 +01:00
} else {
2023-03-27 22:13:50 +01:00
fmt.Printf("%v %d miners connected, Pool stats: IB:%d MB:%d MBR:%d MBO:%d\n", time.Now().Format(time.Stamp), miners, proxy.Blocks, proxy.Minis, proxy.Rejected, proxy.Orphans)
fmt.Printf("%v Shares submitted: %d, Hashrate: %s\n", time.Now().Format(time.Stamp), proxy.Shares, hash_rate_string)
}
2023-03-27 22:13:50 +01:00
proxy.CountWallets()
2022-05-24 17:17:12 +01:00
}
}