diff --git a/derohe-proxy.go b/derohe-proxy.go index cc3c4e3..091dd8c 100644 --- a/derohe-proxy.go +++ b/derohe-proxy.go @@ -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,38 +109,35 @@ 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 := "" - 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)) + 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)) + } } 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() } } diff --git a/proxy/client.go b/proxy/client.go index a72031b..59956d7 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -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)) - } - } else { - if !noRepeat { - noRepeat = true - fmt.Printf("%v Official Mining Node Detected - Happy Mining\n", time.Now().Format(time.Stamp)) - } + if config.Pool_mode { + difficulty = params.Difficultyuint64 } - 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() diff --git a/proxy/server.go b/proxy/server.go index 8a345e7..49fd024 100644 --- a/proxy/server.go +++ b/proxy/server.go @@ -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 {