bugfix: send results to daemon instead to all miners

This commit is contained in:
mmarcel 2022-05-04 16:59:08 +01:00
parent 4a60c94000
commit 8ac12d5baa
2 changed files with 17 additions and 17 deletions

View File

@ -7,14 +7,13 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/lesismal/nbio/nbhttp"
)
var client *nbhttp.Client
//var connection *websocket.Conn
var connection *websocket.Conn
// proxy-client
func Start_client(v string, w string) {
var err error
for {
@ -26,7 +25,7 @@ func Start_client(v string, w string) {
}
fmt.Println("Connect to node", v, "using wallet address", w)
connection, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
time.Sleep(5 * time.Second)
fmt.Println(err)
@ -38,9 +37,17 @@ func Start_client(v string, w string) {
if msg_type != websocket.TextMessage || err != nil {
break
} else {
fmt.Println(string(recv_data))
//edit_blob(recv_data)
go SendTemplatesToNode(recv_data)
}
}
}
}
func SendToDaemon(buffer []byte) {
connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
connection.WriteMessage(websocket.TextMessage, buffer)
return
}

View File

@ -93,6 +93,7 @@ func CountMiners() int {
return miners_count
}
// forward all incoming templates from daemon to all miners
func SendTemplatesToNode(data []byte) {
for rk, rv := range client_list {
@ -113,6 +114,7 @@ func SendTemplatesToNode(data []byte) {
}
// handling for incoming miner connections
func onWebsocket(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, "/ws/") {
http.NotFound(w, r)
@ -145,6 +147,7 @@ func onWebsocket(w http.ResponseWriter, r *http.Request) {
Address = address
}
// forward results to daemon
func newUpgrader() *websocket.Upgrader {
u := websocket.NewUpgrader()
@ -157,18 +160,8 @@ func newUpgrader() *websocket.Upgrader {
client_list_mutex.Lock()
defer client_list_mutex.Unlock()
for rk, rv := range client_list {
go func(k *websocket.Conn, v *user_session) {
defer globals.Recover(2)
k.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
k.WriteMessage(websocket.TextMessage, data)
fmt.Println("Submit result to node from miner: ", v.address)
}(rk, rv)
}
SendToDaemon(data)
fmt.Println("Submit result to node")
})
u.OnClose(func(c *websocket.Conn, err error) {