diff --git a/proxy/client.go b/proxy/client.go index d5b2e43..d40fc9b 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -1,11 +1,17 @@ package proxy import ( + "bytes" "crypto/tls" + "encoding/hex" + "encoding/json" "fmt" + "math/rand" "net/url" "time" + "github.com/deroproject/derohe/block" + "github.com/deroproject/derohe/rpc" "github.com/gorilla/websocket" ) @@ -14,6 +20,9 @@ var connection *websocket.Conn // proxy-client func Start_client(v string, w string) { var err error + var rand_nonce []byte + + rand.Seed(time.Now().UnixMilli()) for { @@ -34,12 +43,18 @@ func Start_client(v string, w string) { for { msg_type, recv_data, err := connection.ReadMessage() - if msg_type != websocket.TextMessage || err != nil { + if err != nil { break + } + + if msg_type != websocket.TextMessage { + continue } else { - fmt.Println(string(recv_data)) - //edit_blob(recv_data) - go SendTemplatesToNode(recv_data) + if rand_nonce = edit_blob(recv_data); rand_nonce != nil { + go SendTemplatesToNode(rand_nonce) + } else { + go SendTemplatesToNode(recv_data) + } } } @@ -49,5 +64,39 @@ func Start_client(v string, w string) { func SendToDaemon(buffer []byte) { connection.SetWriteDeadline(time.Now().Add(100 * time.Millisecond)) 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, ¶ms); 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 }