2022-05-24 18:17:12 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/deroproject/derohe/rpc"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
|
|
|
|
var connection *websocket.Conn
|
|
|
|
var Blocks uint64
|
|
|
|
var Minis uint64
|
|
|
|
var Rejected uint64
|
|
|
|
|
|
|
|
// proxy-client
|
2022-06-08 01:03:38 +02:00
|
|
|
func Start_client(v string, w string, min_jobs bool, nonce bool) {
|
2022-05-24 18:17:12 +02:00
|
|
|
var err error
|
2022-05-28 12:52:52 +02:00
|
|
|
var last_diff uint64
|
|
|
|
var last_height uint64
|
2022-05-24 18:17:12 +02:00
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
u := url.URL{Scheme: "wss", Host: v, Path: "/ws/" + w}
|
|
|
|
|
|
|
|
dialer := websocket.DefaultDialer
|
|
|
|
dialer.TLSClientConfig = &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
}
|
|
|
|
|
2022-05-27 02:16:25 +02:00
|
|
|
fmt.Println(time.Now().Format(time.Stamp), "Connected to node", v)
|
2022-05-24 18:17:12 +02:00
|
|
|
connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
|
|
|
|
if err != nil {
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
fmt.Println(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var params rpc.GetBlockTemplate_Result
|
|
|
|
|
|
|
|
for {
|
|
|
|
msg_type, recv_data, err := connection.ReadMessage()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg_type != websocket.TextMessage {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = json.Unmarshal(recv_data, ¶ms); err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
Blocks = params.Blocks
|
|
|
|
Minis = params.MiniBlocks
|
|
|
|
Rejected = params.Rejected
|
|
|
|
|
2022-05-28 12:52:52 +02:00
|
|
|
if min_jobs {
|
|
|
|
if params.Height != last_height || params.Difficultyuint64 != last_diff {
|
|
|
|
last_height = params.Height
|
|
|
|
last_diff = params.Difficultyuint64
|
2022-06-08 01:03:38 +02:00
|
|
|
go SendTemplateToNodes(recv_data, nonce)
|
2022-05-28 12:52:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-08 01:03:38 +02:00
|
|
|
go SendTemplateToNodes(recv_data, nonce)
|
2022-05-28 12:52:52 +02:00
|
|
|
}
|
2022-05-24 18:17:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SendToDaemon(buffer []byte) {
|
|
|
|
connection.WriteMessage(websocket.TextMessage, buffer)
|
|
|
|
}
|