mirror of
https://github.com/8lecramm/derohe-proxy.git
synced 2025-01-10 05:47:56 +00:00
Hashrate support for --pool mode
This commit is contained in:
parent
735376ef60
commit
698736108e
@ -7,7 +7,6 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/deroproject/derohe/globals"
|
||||
@ -16,7 +15,6 @@ import (
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
var rwmutex sync.RWMutex
|
||||
|
||||
config.Arguments, err = docopt.Parse(config.Command_line, nil, true, "pre-alpha", false)
|
||||
|
||||
@ -111,13 +109,15 @@ func main() {
|
||||
} else {
|
||||
go proxy.Start_client(proxy.Address + "." + config.Worker)
|
||||
}
|
||||
//go proxy.SendUpdateToDaemon()
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * time.Duration(config.Log_intervall))
|
||||
|
||||
miners := proxy.CountMiners()
|
||||
|
||||
hash_rate_string := ""
|
||||
|
||||
if miners > 0 {
|
||||
switch {
|
||||
case proxy.Hashrate > 1000000000000:
|
||||
hash_rate_string = fmt.Sprintf("%.3f TH/s", float64(proxy.Hashrate)/1000000000000.0)
|
||||
@ -130,19 +130,14 @@ func main() {
|
||||
case proxy.Hashrate > 0:
|
||||
hash_rate_string = fmt.Sprintf("%d H/s", int(proxy.Hashrate))
|
||||
}
|
||||
}
|
||||
|
||||
if !config.Pool_mode {
|
||||
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)
|
||||
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)
|
||||
} else {
|
||||
fmt.Printf("%v %d miners connected, Pool stats: 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)
|
||||
fmt.Printf("%v Shares submitted: %d\n", time.Now().Format(time.Stamp), proxy.Shares)
|
||||
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)
|
||||
}
|
||||
rwmutex.RLock()
|
||||
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])
|
||||
}
|
||||
}
|
||||
rwmutex.RUnlock()
|
||||
proxy.CountWallets()
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,10 @@ var Blocks uint64
|
||||
var Minis uint64
|
||||
var Rejected uint64
|
||||
var Orphans uint64
|
||||
var ModdedNode bool = false
|
||||
var noRepeat bool
|
||||
var Hashrate float64
|
||||
|
||||
var Hashrate uint64
|
||||
var Connected int64
|
||||
var difficulty uint64
|
||||
|
||||
// proxy-client
|
||||
func Start_client(w string) {
|
||||
@ -103,17 +104,9 @@ func Start_client(w string) {
|
||||
Rejected = params.Rejected
|
||||
Orphans = params.Orphans
|
||||
|
||||
if ModdedNode != params.Hansen33Mod {
|
||||
if params.Hansen33Mod {
|
||||
fmt.Printf("%v Hansen33 Mod Mining Node Detected - Happy Mining\n", time.Now().Format(time.Stamp))
|
||||
if config.Pool_mode {
|
||||
difficulty = params.Difficultyuint64
|
||||
}
|
||||
} else {
|
||||
if !noRepeat {
|
||||
noRepeat = true
|
||||
fmt.Printf("%v Official Mining Node Detected - Happy Mining\n", time.Now().Format(time.Stamp))
|
||||
}
|
||||
}
|
||||
ModdedNode = params.Hansen33Mod
|
||||
|
||||
if config.Minimal {
|
||||
if params.Height != last_height || params.Difficultyuint64 != last_diff {
|
||||
@ -128,23 +121,6 @@ func Start_client(w string) {
|
||||
}
|
||||
}
|
||||
|
||||
func SendUpdateToDaemon() {
|
||||
|
||||
var count = 0
|
||||
for {
|
||||
if ModdedNode {
|
||||
if count == 0 {
|
||||
time.Sleep(60 * time.Second)
|
||||
}
|
||||
|
||||
connection.conn.WriteJSON(MinerInfo_Params{Wallet_Address: Address, Miner_Tag: "", Miner_Hashrate: Hashrate})
|
||||
|
||||
count++
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func SendToDaemon(buffer []byte) {
|
||||
connection.Lock()
|
||||
defer connection.Unlock()
|
||||
|
@ -60,9 +60,12 @@ var client_list = map[*websocket.Conn]*user_session{}
|
||||
|
||||
var miners_count int
|
||||
var Shares uint64
|
||||
var shareValue uint64
|
||||
var Wallet_count map[string]uint
|
||||
var Address string
|
||||
|
||||
var rwmutex sync.RWMutex
|
||||
|
||||
func Start_server() {
|
||||
var err error
|
||||
|
||||
@ -198,6 +201,10 @@ func onWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("%v Incoming connection: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker, address)
|
||||
} else {
|
||||
fmt.Printf("%v Incoming connection: %v (%v)\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), worker)
|
||||
if len(client_list) == 1 {
|
||||
Connected = time.Now().UnixMilli()
|
||||
shareValue = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,31 +221,15 @@ func newUpgrader() *websocket.Upgrader {
|
||||
client_list_mutex.Lock()
|
||||
defer client_list_mutex.Unlock()
|
||||
|
||||
/*
|
||||
var x MinerInfo_Params
|
||||
if json.Unmarshal(data, &x); len(x.Wallet_Address) > 0 {
|
||||
|
||||
if x.Miner_Hashrate > 0 {
|
||||
sess := client_list[c]
|
||||
sess.hashrate = x.Miner_Hashrate
|
||||
client_list[c] = sess
|
||||
}
|
||||
|
||||
var NewHashRate float64
|
||||
for _, s := range client_list {
|
||||
NewHashRate += s.hashrate
|
||||
}
|
||||
Hashrate = NewHashRate
|
||||
|
||||
// Update miners information
|
||||
return
|
||||
} else {
|
||||
*/
|
||||
SendToDaemon(data)
|
||||
if !config.Pool_mode {
|
||||
fmt.Printf("%v Submitting result from miner: %v (%v), Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].worker, client_list[c].address.String())
|
||||
} else {
|
||||
Shares++
|
||||
shareValue += difficulty
|
||||
if Connected > 0 {
|
||||
Hashrate = shareValue / (uint64(time.Now().UnixMilli()-Connected) / 1000)
|
||||
}
|
||||
}
|
||||
//}
|
||||
})
|
||||
@ -254,6 +245,18 @@ func newUpgrader() *websocket.Upgrader {
|
||||
return u
|
||||
}
|
||||
|
||||
func CountWallets() {
|
||||
|
||||
rwmutex.RLock()
|
||||
defer rwmutex.RUnlock()
|
||||
|
||||
for i := range Wallet_count {
|
||||
if Wallet_count[i] > 1 {
|
||||
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, Wallet_count[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// taken unmodified from derohe repo
|
||||
// cert handling
|
||||
func generate_random_tls_cert() tls.Certificate {
|
||||
|
Loading…
Reference in New Issue
Block a user