refactor reading of socket into a function

This commit is contained in:
Tim Williams 2018-07-27 15:01:34 -04:00
parent 8cc8da8ea5
commit bd83244bba

View file

@ -3,7 +3,6 @@ package main
//@NOTE SHYFT main func for api, sets up router and spins up a server //@NOTE SHYFT main func for api, sets up router and spins up a server
//to run server 'go run shyftRingWalletConn/*.go' //to run server 'go run shyftRingWalletConn/*.go'
import ( import (
//"bytes"
"bufio" "bufio"
"fmt" "fmt"
"github.com/ShyftNetwork/go-empyrean/common/hexutil" "github.com/ShyftNetwork/go-empyrean/common/hexutil"
@ -53,7 +52,33 @@ func main() {
// Handles incoming requests. // Handles incoming requests.
func handleRequest(conn net.Conn) { func handleRequest(conn net.Conn) {
go func() { go readerConn(conn)
key, _ := crypto.HexToECDSA(testPrivHex)
f_msg := "Hello World"
first_message := []byte(f_msg)
new_msg2 := crypto.Keccak256(first_message)
fmt.Println("HASH IS ::", hexutil.Encode(new_msg2))
//send_message := append(new_msg2, []byte{byte(10)}...)
new_sig, err := crypto.Sign(new_msg2, key)
if err != nil {
fmt.Println("The crypto.Sign err is ", err)
}
hex_sig := hexutil.Encode(new_sig)
fmt.Println("HEX SIG ::", hex_sig)
conn.Write([]byte("Broadcasting Message"))
conn.Write([]byte("\n"))
conn.Write([]byte(f_msg))
conn.Write([]byte("\n"))
conn.Write(new_sig)
conn.Write([]byte("\n"))
}
func readerConn(conn net.Conn) {
var prevMsg []byte var prevMsg []byte
var addressOfClient []byte var addressOfClient []byte
var signatureFromClient []byte var signatureFromClient []byte
@ -116,28 +141,4 @@ func handleRequest(conn net.Conn) {
fmt.Println("ADDRESS IS ::", recoveredAddr.Hex()) fmt.Println("ADDRESS IS ::", recoveredAddr.Hex())
} }
} }
}()
key, _ := crypto.HexToECDSA(testPrivHex)
f_msg := "Hello World"
first_message := []byte(f_msg)
new_msg2 := crypto.Keccak256(first_message)
fmt.Println("HASH IS ::", hexutil.Encode(new_msg2))
//send_message := append(new_msg2, []byte{byte(10)}...)
new_sig, err := crypto.Sign(new_msg2, key)
if err != nil {
fmt.Println("The crypto.Sign err is ", err)
}
hex_sig := hexutil.Encode(new_sig)
fmt.Println("HEX SIG ::", hex_sig)
conn.Write([]byte("Broadcasting Message"))
conn.Write([]byte("\n"))
conn.Write([]byte(f_msg))
conn.Write([]byte("\n"))
conn.Write(new_sig)
conn.Write([]byte("\n"))
} }