New feature: random nonces

This commit is contained in:
mmarcel 2022-05-05 01:34:44 +02:00
parent 8ac12d5baa
commit 7d67f1b17d

View File

@ -1,11 +1,17 @@
package proxy package proxy
import ( import (
"bytes"
"crypto/tls" "crypto/tls"
"encoding/hex"
"encoding/json"
"fmt" "fmt"
"math/rand"
"net/url" "net/url"
"time" "time"
"github.com/deroproject/derohe/block"
"github.com/deroproject/derohe/rpc"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
) )
@ -14,6 +20,9 @@ var connection *websocket.Conn
// proxy-client // proxy-client
func Start_client(v string, w string) { func Start_client(v string, w string) {
var err error var err error
var rand_nonce []byte
rand.Seed(time.Now().UnixMilli())
for { for {
@ -34,14 +43,20 @@ func Start_client(v string, w string) {
for { for {
msg_type, recv_data, err := connection.ReadMessage() msg_type, recv_data, err := connection.ReadMessage()
if msg_type != websocket.TextMessage || err != nil { if err != nil {
break break
}
if msg_type != websocket.TextMessage {
continue
} else {
if rand_nonce = edit_blob(recv_data); rand_nonce != nil {
go SendTemplatesToNode(rand_nonce)
} else { } else {
fmt.Println(string(recv_data))
//edit_blob(recv_data)
go SendTemplatesToNode(recv_data) go SendTemplatesToNode(recv_data)
} }
} }
}
} }
} }
@ -49,5 +64,39 @@ func Start_client(v string, w string) {
func SendToDaemon(buffer []byte) { func SendToDaemon(buffer []byte) {
connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond))
connection.WriteMessage(websocket.TextMessage, buffer) connection.WriteMessage(websocket.TextMessage, buffer)
}
func edit_blob(input []byte) (output []byte) {
var err error
var params rpc.GetBlockTemplate_Result
var mbl block.MiniBlock
var raw_hex []byte
var out bytes.Buffer
if err = json.Unmarshal(input, &params); err != nil {
return
}
if raw_hex, err = hex.DecodeString(params.Blockhashing_blob); err != nil {
return
}
if mbl.Deserialize(raw_hex); err != nil {
return
}
for i := range mbl.Nonce {
mbl.Nonce[i] = rand.Uint32()
}
params.Blockhashing_blob = fmt.Sprintf("%x", mbl.Serialize())
encoder := json.NewEncoder(&out)
if err = encoder.Encode(params); err != nil {
return
}
output = out.Bytes()
return return
} }