mirror of
https://github.com/8lecramm/derohe-proxy.git
synced 2025-01-10 13:57:56 +00:00
multi wallet support
- added suppport for more than one wallet - user-defined logging interval - other fixes
This commit is contained in:
parent
f30238e761
commit
50899d3907
@ -4,11 +4,12 @@ var command_line string = `derohe-proxy
|
||||
Proxy to combine all miners and to reduce network load
|
||||
|
||||
Usage:
|
||||
derohe-proxy [--listen-address=<127.0.0.1:10100>] --daemon-address=<1.2.3.4:10100>
|
||||
derohe-proxy [--listen-address=<127.0.0.1:10100>] [--log-interval=<60>] --daemon-address=<1.2.3.4:10100>
|
||||
|
||||
Options:
|
||||
--listen-address=<127.0.0.1:10100> bind to specific address:port, default is 0.0.0.0:10200
|
||||
--daemon-address=<1.2.3.4:10100> connect to this daemon
|
||||
--log-interval=<60> set logging interval in seconds (range 60 - 3600), default is 60 seconds
|
||||
|
||||
Example Mainnet: ./derohe-proxy --daemon-address=minernode1.dero.io:10100
|
||||
`
|
||||
@ -18,3 +19,6 @@ var Arguments = map[string]interface{}{}
|
||||
|
||||
var listen_addr string = "0.0.0.0:10200"
|
||||
var daemon_address string = "minernode1.dero.io:10100"
|
||||
|
||||
// logging interval in seconds
|
||||
var log_intervall int = 60
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"derohe-proxy/proxy"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/docopt/docopt-go"
|
||||
@ -37,6 +38,21 @@ func main() {
|
||||
daemon_address = Arguments["--daemon-address"].(string)
|
||||
}
|
||||
|
||||
if Arguments["--log-interval"] != nil {
|
||||
interval, err := strconv.ParseInt(Arguments["--log-interval"].(string), 10, 32)
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
if interval < 60 || interval > 3600 {
|
||||
log_intervall = 60
|
||||
} else {
|
||||
log_intervall = int(interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Logging every %d seconds\n", log_intervall)
|
||||
|
||||
go proxy.Start_server(listen_addr)
|
||||
|
||||
// Wait for first miner connection to grab wallet address
|
||||
@ -46,7 +62,12 @@ func main() {
|
||||
go proxy.Start_client(daemon_address, proxy.Address)
|
||||
|
||||
for {
|
||||
time.Sleep(time.Minute * 5)
|
||||
fmt.Printf("%v %4d miners connected\t\tBlocks:%4d\tMiniblocks:%4d\tRejected:%4d\n", time.Now().Format(time.Stamp), proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected)
|
||||
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)
|
||||
for i := range proxy.Wallet_count {
|
||||
if proxy.Wallet_count[i] > 0 {
|
||||
fmt.Printf("%v Wallet %v, %d miners\n", time.Now().Format(time.Stamp), i, proxy.Wallet_count[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func Start_client(v string, w string) {
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Connected to node", v, "using wallet address", w)
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Connected to node", v)
|
||||
connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/deroproject/derohe/rpc"
|
||||
)
|
||||
|
||||
func edit_blob(input []byte) (output []byte) {
|
||||
func edit_blob(input []byte, miner [32]byte) (output []byte) {
|
||||
var err error
|
||||
var params rpc.GetBlockTemplate_Result
|
||||
var mbl block.MiniBlock
|
||||
@ -30,6 +30,12 @@ func edit_blob(input []byte) (output []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
// Insert miner address
|
||||
if !mbl.Final {
|
||||
copy(mbl.KeyHash[:], miner[:])
|
||||
}
|
||||
|
||||
// Insert random nonce
|
||||
for i := range mbl.Nonce {
|
||||
mbl.Nonce[i] = rand.Uint32()
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ var client_list_mutex sync.Mutex
|
||||
var client_list = map[*websocket.Conn]*user_session{}
|
||||
|
||||
var miners_count int
|
||||
var Wallet_count map[string]uint
|
||||
var Address string
|
||||
|
||||
func Start_server(listen string) {
|
||||
@ -81,6 +82,8 @@ func Start_server(listen string) {
|
||||
return
|
||||
}
|
||||
|
||||
Wallet_count = make(map[string]uint)
|
||||
|
||||
server.Wait()
|
||||
defer server.Stop()
|
||||
|
||||
@ -103,7 +106,9 @@ func SendTemplateToNodes(input []byte) {
|
||||
break
|
||||
}
|
||||
|
||||
if nonce := edit_blob(input); nonce != nil {
|
||||
miner_address := rv.address_sum
|
||||
|
||||
if nonce := edit_blob(input, miner_address); nonce != nil {
|
||||
data = nonce
|
||||
} else {
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce")
|
||||
@ -151,8 +156,9 @@ func onWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
client_list_mutex.Lock()
|
||||
defer client_list_mutex.Unlock()
|
||||
client_list[wsConn] = &session
|
||||
Wallet_count[client_list[wsConn].address.String()]++
|
||||
Address = address
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Incoming connection from IP:", wsConn.RemoteAddr().String())
|
||||
fmt.Printf("%v Incoming connection: %v, Wallet: %v\n", time.Now().Format(time.Stamp), wsConn.RemoteAddr().String(), address)
|
||||
}
|
||||
|
||||
// forward results to daemon
|
||||
@ -169,14 +175,15 @@ func newUpgrader() *websocket.Upgrader {
|
||||
defer client_list_mutex.Unlock()
|
||||
|
||||
SendToDaemon(data)
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Submitting result from miner IP:", c.RemoteAddr().String())
|
||||
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) {
|
||||
client_list_mutex.Lock()
|
||||
defer client_list_mutex.Unlock()
|
||||
Wallet_count[client_list[c].address.String()]--
|
||||
fmt.Printf("%v Lost connection: %v, Wallet: %v\n", time.Now().Format(time.Stamp), c.RemoteAddr().String(), client_list[c].address.String())
|
||||
delete(client_list, c)
|
||||
fmt.Println(time.Now().Format(time.Stamp), "Interrupted or lost connection:", c.RemoteAddr().String())
|
||||
})
|
||||
|
||||
return u
|
||||
|
Loading…
x
Reference in New Issue
Block a user