mirror of
https://github.com/8lecramm/derohe-proxy.git
synced 2025-01-10 13:57:56 +00:00
Merge pull request #1 from Hansen333/main
Send Hashrate to Hansen33 Nodes
This commit is contained in:
commit
e1c0552834
BIN
derohe-proxy
Executable file
BIN
derohe-proxy
Executable file
Binary file not shown.
@ -70,10 +70,27 @@ func main() {
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
go proxy.Start_client(daemon_address, proxy.Address, minimal, nonce)
|
||||
go proxy.SendUpdateToDaemon()
|
||||
|
||||
for {
|
||||
time.Sleep(time.Second * time.Duration(log_intervall))
|
||||
fmt.Printf("%v %d miners connected, Bl: %d, Mbl: %d, Rej: %d\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected)
|
||||
|
||||
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])
|
||||
|
@ -8,14 +8,41 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/deroproject/derohe/rpc"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type (
|
||||
GetBlockTemplate_Params struct {
|
||||
Wallet_Address string `json:"wallet_address"`
|
||||
Block bool `json:"block"`
|
||||
Miner string `json:"miner"`
|
||||
}
|
||||
GetBlockTemplate_Result struct {
|
||||
JobID string `json:"jobid"`
|
||||
Blocktemplate_blob string `json:"blocktemplate_blob,omitempty"`
|
||||
Blockhashing_blob string `json:"blockhashing_blob,omitempty"`
|
||||
Difficulty string `json:"difficulty"`
|
||||
Difficultyuint64 uint64 `json:"difficultyuint64"`
|
||||
Height uint64 `json:"height"`
|
||||
Prev_Hash string `json:"prev_hash"`
|
||||
EpochMilli uint64 `json:"epochmilli"`
|
||||
Blocks uint64 `json:"blocks"` // number of blocks found
|
||||
MiniBlocks uint64 `json:"miniblocks"` // number of miniblocks found
|
||||
Rejected uint64 `json:"rejected"` // reject count
|
||||
LastError string `json:"lasterror"` // last error
|
||||
Status string `json:"status"`
|
||||
Orphans uint64 `json:"orphans"`
|
||||
Hansen33Mod bool `json:"hansen33_mod"`
|
||||
}
|
||||
)
|
||||
|
||||
var connection *websocket.Conn
|
||||
var Blocks uint64
|
||||
var Minis uint64
|
||||
var Rejected uint64
|
||||
var Orphans uint64
|
||||
var ModdedNode bool = false
|
||||
var Hashrate float64
|
||||
|
||||
// proxy-client
|
||||
func Start_client(v string, w string, min_jobs bool, nonce bool) {
|
||||
@ -42,7 +69,7 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
var params rpc.GetBlockTemplate_Result
|
||||
var params GetBlockTemplate_Result
|
||||
|
||||
for {
|
||||
msg_type, recv_data, err := connection.ReadMessage()
|
||||
@ -61,7 +88,18 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
|
||||
Blocks = params.Blocks
|
||||
Minis = params.MiniBlocks
|
||||
Rejected = params.Rejected
|
||||
Orphans = params.Orphans
|
||||
|
||||
if ModdedNode != params.Hansen33Mod {
|
||||
if params.Hansen33Mod {
|
||||
fmt.Print("Hansen33 Mod Mining Node Detected - Happy Mining\n")
|
||||
}
|
||||
}
|
||||
ModdedNode = params.Hansen33Mod
|
||||
|
||||
if !ModdedNode {
|
||||
fmt.Print("Official Mining Node Detected - Happy Mining\n")
|
||||
}
|
||||
if min_jobs {
|
||||
if params.Height != last_height || params.Difficultyuint64 != last_diff {
|
||||
last_height = params.Height
|
||||
@ -75,6 +113,23 @@ func Start_client(v string, w string, min_jobs bool, nonce bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func SendUpdateToDaemon() {
|
||||
|
||||
var count = 0
|
||||
for {
|
||||
if ModdedNode {
|
||||
if count == 0 {
|
||||
time.Sleep(60 * time.Second)
|
||||
}
|
||||
|
||||
connection.WriteJSON(MinerInfo_Params{Wallet_Address: Address, Miner_Tag: "", Miner_Hashrate: Hashrate})
|
||||
|
||||
count++
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func SendToDaemon(buffer []byte) {
|
||||
connection.WriteMessage(websocket.TextMessage, buffer)
|
||||
}
|
||||
|
@ -8,12 +8,11 @@ import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/deroproject/derohe/block"
|
||||
"github.com/deroproject/derohe/rpc"
|
||||
)
|
||||
|
||||
func edit_blob(input []byte, miner [32]byte, nonce bool) (output []byte) {
|
||||
var err error
|
||||
var params rpc.GetBlockTemplate_Result
|
||||
var params GetBlockTemplate_Result
|
||||
var mbl block.MiniBlock
|
||||
var raw_hex []byte
|
||||
var out bytes.Buffer
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@ -36,10 +37,22 @@ type user_session struct {
|
||||
miniblocks uint64
|
||||
lasterr string
|
||||
address rpc.Address
|
||||
orphans uint64
|
||||
hashrate float64
|
||||
valid_address bool
|
||||
address_sum [32]byte
|
||||
}
|
||||
|
||||
type ( // array without name containing block template in hex
|
||||
MinerInfo_Params struct {
|
||||
Wallet_Address string `json:"wallet_address"`
|
||||
Miner_Tag string `json:"miner_tag"`
|
||||
Miner_Hashrate float64 `json:"miner_hashrate"`
|
||||
}
|
||||
MinerInfo_Result struct {
|
||||
}
|
||||
)
|
||||
|
||||
var client_list_mutex sync.Mutex
|
||||
var client_list = map[*websocket.Conn]*user_session{}
|
||||
|
||||
@ -175,8 +188,27 @@ func newUpgrader() *websocket.Upgrader {
|
||||
client_list_mutex.Lock()
|
||||
defer client_list_mutex.Unlock()
|
||||
|
||||
SendToDaemon(data)
|
||||
fmt.Printf("%v Submitting result from miner: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String())
|
||||
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 {
|
||||
go SendToDaemon(data)
|
||||
fmt.Printf("%v Submitting result from miner: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String())
|
||||
}
|
||||
})
|
||||
|
||||
u.OnClose(func(c *websocket.Conn, err error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user