2022-05-03 22:08:36 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
2022-05-05 01:34:44 +02:00
|
|
|
"math/rand"
|
2022-05-03 22:08:36 +02:00
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
)
|
|
|
|
|
2022-05-04 16:59:08 +01:00
|
|
|
var connection *websocket.Conn
|
2022-05-03 22:08:36 +02:00
|
|
|
|
2022-05-04 16:59:08 +01:00
|
|
|
// proxy-client
|
2022-05-03 22:08:36 +02:00
|
|
|
func Start_client(v string, w string) {
|
2022-05-04 16:59:08 +01:00
|
|
|
var err error
|
2022-05-05 01:34:44 +02:00
|
|
|
|
|
|
|
rand.Seed(time.Now().UnixMilli())
|
2022-05-03 22:08:36 +02:00
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
u := url.URL{Scheme: "wss", Host: v, Path: "/ws/" + w}
|
|
|
|
|
|
|
|
dialer := websocket.DefaultDialer
|
|
|
|
dialer.TLSClientConfig = &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
}
|
|
|
|
|
2022-05-11 23:31:19 +02:00
|
|
|
fmt.Println(time.Now().Format(time.Stamp), "Connected to node", v, "using wallet address", w)
|
2022-05-04 16:59:08 +01:00
|
|
|
connection, _, err = websocket.DefaultDialer.Dial(u.String(), nil)
|
2022-05-03 22:08:36 +02:00
|
|
|
if err != nil {
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
fmt.Println(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
msg_type, recv_data, err := connection.ReadMessage()
|
2022-05-05 01:34:44 +02:00
|
|
|
if err != nil {
|
2022-05-03 22:08:36 +02:00
|
|
|
break
|
2022-05-05 01:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if msg_type != websocket.TextMessage {
|
|
|
|
continue
|
2022-05-03 22:08:36 +02:00
|
|
|
}
|
|
|
|
|
2022-05-05 07:49:58 +02:00
|
|
|
go SendTemplatesToNode(recv_data)
|
|
|
|
}
|
2022-05-03 22:08:36 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-04 16:59:08 +01:00
|
|
|
|
|
|
|
func SendToDaemon(buffer []byte) {
|
|
|
|
connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
|
|
|
|
connection.WriteMessage(websocket.TextMessage, buffer)
|
2022-05-05 01:34:44 +02:00
|
|
|
}
|