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