multi wallet support

- added suppport for more than one wallet
- user-defined logging interval
- other fixes
This commit is contained in:
8lecramm 2022-05-27 02:16:25 +02:00 committed by GitHub
parent f30238e761
commit 50899d3907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 9 deletions

View File

@ -4,11 +4,12 @@ var command_line string = `derohe-proxy
Proxy to combine all miners and to reduce network load Proxy to combine all miners and to reduce network load
Usage: 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: Options:
--listen-address=<127.0.0.1:10100> bind to specific address:port, default is 0.0.0.0:10200 --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 --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 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 listen_addr string = "0.0.0.0:10200"
var daemon_address string = "minernode1.dero.io:10100" var daemon_address string = "minernode1.dero.io:10100"
// logging interval in seconds
var log_intervall int = 60

View File

@ -4,6 +4,7 @@ import (
"derohe-proxy/proxy" "derohe-proxy/proxy"
"fmt" "fmt"
"net" "net"
"strconv"
"time" "time"
"github.com/docopt/docopt-go" "github.com/docopt/docopt-go"
@ -37,6 +38,21 @@ func main() {
daemon_address = Arguments["--daemon-address"].(string) 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) go proxy.Start_server(listen_addr)
// Wait for first miner connection to grab wallet address // Wait for first miner connection to grab wallet address
@ -46,7 +62,12 @@ func main() {
go proxy.Start_client(daemon_address, proxy.Address) go proxy.Start_client(daemon_address, proxy.Address)
for { for {
time.Sleep(time.Minute * 5) time.Sleep(time.Second * time.Duration(log_intervall))
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) 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])
}
}
} }
} }

View File

@ -32,7 +32,7 @@ func Start_client(v string, w string) {
InsecureSkipVerify: true, 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) connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil { if err != nil {
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)

View File

@ -11,7 +11,7 @@ import (
"github.com/deroproject/derohe/rpc" "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 err error
var params rpc.GetBlockTemplate_Result var params rpc.GetBlockTemplate_Result
var mbl block.MiniBlock var mbl block.MiniBlock
@ -30,6 +30,12 @@ func edit_blob(input []byte) (output []byte) {
return return
} }
// Insert miner address
if !mbl.Final {
copy(mbl.KeyHash[:], miner[:])
}
// Insert random nonce
for i := range mbl.Nonce { for i := range mbl.Nonce {
mbl.Nonce[i] = rand.Uint32() mbl.Nonce[i] = rand.Uint32()
} }

View File

@ -44,6 +44,7 @@ var client_list_mutex sync.Mutex
var client_list = map[*websocket.Conn]*user_session{} var client_list = map[*websocket.Conn]*user_session{}
var miners_count int var miners_count int
var Wallet_count map[string]uint
var Address string var Address string
func Start_server(listen string) { func Start_server(listen string) {
@ -81,6 +82,8 @@ func Start_server(listen string) {
return return
} }
Wallet_count = make(map[string]uint)
server.Wait() server.Wait()
defer server.Stop() defer server.Stop()
@ -103,7 +106,9 @@ func SendTemplateToNodes(input []byte) {
break break
} }
if nonce := edit_blob(input); nonce != nil { miner_address := rv.address_sum
if nonce := edit_blob(input, miner_address); nonce != nil {
data = nonce data = nonce
} else { } else {
fmt.Println(time.Now().Format(time.Stamp), "Failed to change nonce") 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() client_list_mutex.Lock()
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
client_list[wsConn] = &session client_list[wsConn] = &session
Wallet_count[client_list[wsConn].address.String()]++
Address = address 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 // forward results to daemon
@ -169,14 +175,15 @@ func newUpgrader() *websocket.Upgrader {
defer client_list_mutex.Unlock() defer client_list_mutex.Unlock()
SendToDaemon(data) 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) { u.OnClose(func(c *websocket.Conn, err error) {
client_list_mutex.Lock() client_list_mutex.Lock()
defer client_list_mutex.Unlock() 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) delete(client_list, c)
fmt.Println(time.Now().Format(time.Stamp), "Interrupted or lost connection:", c.RemoteAddr().String())
}) })
return u return u