Refactor node/message.go to proto/node.go, p2p/message.go to p2p.message_reader.go

pull/50/head
Rongjian Lan 6 years ago
parent 3d37dae7ca
commit 737732150f
  1. 0
      p2p/message_reader.go
  2. 1
      proto/common.go
  3. 11
      proto/node.go

@ -4,7 +4,6 @@ import (
"errors" "errors"
) )
// TODO: Fix the comments below.
/* /*
The message structure of any message in Harmony network The message structure of any message in Harmony network

@ -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)
Loading…
Cancel
Save