2022-05-03 22:08:36 +02:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"fmt"
|
|
|
|
"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-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,
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Connect 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()
|
|
|
|
if msg_type != websocket.TextMessage || err != nil {
|
|
|
|
break
|
|
|
|
} else {
|
2022-05-04 16:59:08 +01:00
|
|
|
fmt.Println(string(recv_data))
|
|
|
|
//edit_blob(recv_data)
|
2022-05-03 22:08:36 +02:00
|
|
|
go SendTemplatesToNode(recv_data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
return
|
|
|
|
}
|