diff --git a/identitychain/identitychain.go b/identitychain/identitychain.go index d1a9fa012..c84cb412d 100644 --- a/identitychain/identitychain.go +++ b/identitychain/identitychain.go @@ -30,7 +30,7 @@ type IdentityChain struct { CurrentEpochStartTime int64 NumberOfShards int NumberOfNodesInShard int - PowMap map[p2p.Peer]uint32 + PowMap map[p2p.Peer]string } func seekRandomNumber(EpochNum int, SelectedIdentitites []*node.Node) int { @@ -171,6 +171,6 @@ func New(Peer p2p.Peer) *IdentityChain { IDC := IdentityChain{} IDC.Peer = Peer IDC.log = log.New() - IDC.PowMap = make(map[p2p.Peer]uint32) + IDC.PowMap = make(map[p2p.Peer]string) return &IDC } diff --git a/identitychain/identitychain_handler.go b/identitychain/identitychain_handler.go index 4e8ac8820..7b004fd2e 100644 --- a/identitychain/identitychain_handler.go +++ b/identitychain/identitychain_handler.go @@ -2,7 +2,6 @@ package identitychain import ( "bytes" - "encoding/binary" "fmt" "math/rand" "net" @@ -80,8 +79,7 @@ func (IDC *IdentityChain) registerIdentity(msgPayload []byte) { proof := payload[offset : offset+32] offset = offset + 32 Node := node.DeserializeWaitNode(payload[offset:]) - id := int(IDC.PowMap[Node.Self]) - req := pow.NewRequest(5, []byte(strconv.Itoa(id))) + req := IDC.PowMap[Node.Self] ok, err := pow.Check(req, string(proof), []byte("")) fmt.Println(err) if ok { @@ -102,30 +100,23 @@ func (IDC *IdentityChain) acceptNewConnection(msgPayload []byte) { fmt.Println("accepted new connection") } fmt.Println("Sleeping for 2 secs ...") - time.Sleep(5 * time.Second) + time.Sleep(2 * time.Second) Node := node.DeserializeWaitNode(identityPayload) buffer := bytes.NewBuffer([]byte{}) src := rand.NewSource(time.Now().UnixNano()) rnd := rand.New(src) - challengeNonce := uint32(rnd.Int31()) - //challengeNonce := uint32(rand.Intn(1000)) //fix so that different nonce is sent everytime. - fmt.Println("Challenge Nonce Sent:") - fmt.Println(challengeNonce) - IDC.PowMap[Node.Self] = challengeNonce - // 4 byte length of challengeNonce - - fourBytes := make([]byte, 4) - binary.BigEndian.PutUint32(fourBytes, challengeNonce) - buffer.Write(fourBytes) + challengeNonce := int((rnd.Int31())) + req := pow.NewRequest(5, []byte(strconv.Itoa(challengeNonce))) + IDC.PowMap[Node.Self] = req + fmt.Println(req) + buffer.Write([]byte(req)) // 32 byte block hash // buffer.Write(prevBlockHash) // The message is missing previous BlockHash, this is because we don't actively maintain a identitychain // This canbe included in the fulfill request. - // Message should be encrypted and then signed to follow PKE. //IDC should accept node publickey, encrypt the nonce and blockhash // Then sign the message by own private key and send the message back. - fmt.Println("Done sleeping. Ready or not here i come!") msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.REGISTER, buffer.Bytes()) p2p.SendMessage(Node.Self, msgToSend) } diff --git a/node/node.go b/node/node.go index 3676725c0..35fc1f7a6 100644 --- a/node/node.go +++ b/node/node.go @@ -2,11 +2,9 @@ package node import ( "bytes" - "encoding/binary" "encoding/gob" "fmt" "net" - "strconv" "sync" "github.com/simple-rules/harmony-benchmark/crypto/pki" @@ -155,7 +153,7 @@ func NewNodefromIDC(node Node, consensus *consensus.Consensus, db *db.LDBDatabas node.blockchain = genesisBlock // UTXO pool from Genesis block - node.UtxoPool = blockchain.CreateUTXOPoolFromGenesisBlockChain(node.blockchain) + //node.UtxoPool = blockchain.CreateUTXOPoolFromGenesisBlockChain(node.blockchain) // Initialize level db. node.db = db @@ -173,12 +171,9 @@ func (node *Node) processPOWMessage(message []byte) { fmt.Println("Could not read payload") } IDCPeer := node.IDCPeer - offset := 0 // 4 byte challengeNonce id - challengeNonce := int(binary.BigEndian.Uint32(payload[offset : offset+4])) - offset += 4 - fmt.Println(challengeNonce) - req := pow.NewRequest(5, []byte(strconv.Itoa(challengeNonce))) + req := string(payload) + fmt.Println(req) proof, _ := pow.Fulfil(req, []byte("")) //"This could be blockhasdata" buffer := bytes.NewBuffer([]byte{}) proofBytes := make([]byte, 32) //proof seems to be 32 byte here