|
|
|
@ -1,10 +1,9 @@ |
|
|
|
|
package node |
|
|
|
|
package proto |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"encoding/gob" |
|
|
|
|
"harmony-benchmark/blockchain" |
|
|
|
|
"harmony-benchmark/proto" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// The specific types of message under NODE category
|
|
|
|
@ -43,7 +42,7 @@ const ( |
|
|
|
|
|
|
|
|
|
// Constructs serialized transactions
|
|
|
|
|
func ConstructTransactionListMessage(transactions []*blockchain.Transaction) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(NODE)}) |
|
|
|
|
byteBuffer.WriteByte(byte(TRANSACTION)) |
|
|
|
|
byteBuffer.WriteByte(byte(SEND)) |
|
|
|
|
encoder := gob.NewEncoder(byteBuffer) |
|
|
|
@ -58,7 +57,7 @@ func ConstructTransactionListMessage(transactions []*blockchain.Transaction) []b |
|
|
|
|
|
|
|
|
|
// Constructs serialized transactions
|
|
|
|
|
func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(NODE)}) |
|
|
|
|
byteBuffer.WriteByte(byte(TRANSACTION)) |
|
|
|
|
byteBuffer.WriteByte(byte(REQUEST)) |
|
|
|
|
for _, txId := range transactionIds { |
|
|
|
@ -69,7 +68,7 @@ func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte { |
|
|
|
|
|
|
|
|
|
// Constructs STOP message for node to stop
|
|
|
|
|
func ConstructStopMessage() []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(NODE)}) |
|
|
|
|
byteBuffer.WriteByte(byte(CONTROL)) |
|
|
|
|
byteBuffer.WriteByte(byte(STOP)) |
|
|
|
|
return byteBuffer.Bytes() |
|
|
|
@ -77,7 +76,7 @@ func ConstructStopMessage() []byte { |
|
|
|
|
|
|
|
|
|
// Constructs blocks sync message to send blocks to other nodes
|
|
|
|
|
func ConstructBlocksSyncMessage(blocks []blockchain.Block) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(NODE)}) |
|
|
|
|
byteBuffer.WriteByte(byte(BLOCK)) |
|
|
|
|
byteBuffer.WriteByte(byte(SYNC)) |
|
|
|
|
encoder := gob.NewEncoder(byteBuffer) |