From b77dd1a7cbd52540e5dde7821b2cf208dd8904f3 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Mon, 5 Nov 2018 15:41:45 -0800 Subject: [PATCH] fix style, change constant --- node/node_handler.go | 8 ++++---- proto/common.go | 20 ++++++++++---------- proto/node/node.go | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/node/node_handler.go b/node/node_handler.go index 59d4908d5..b40014d62 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -243,7 +243,7 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) { node.log.Error("Failed to deserialize transaction list", "error", err) } node.addPendingTransactions(*txList) - case proto_node.REQUEST: + case proto_node.Request: reader := bytes.NewBuffer(msgPayload[1:]) var txIDs map[[32]byte]bool buf := make([]byte, 32) // 32 byte hash Id @@ -265,15 +265,15 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) { } } // TODO: return the transaction list to requester - case proto_node.UNLOCK: - txAndProofDecoder := gob.NewDecoder(bytes.NewReader(msgPayload[1:])) // skip the UNLOCK messge type + case proto_node.Unlock: + txAndProofDecoder := gob.NewDecoder(bytes.NewReader(msgPayload[1:])) // skip the Unlock messge type txAndProofs := new([]*blockchain.Transaction) err := txAndProofDecoder.Decode(&txAndProofs) if err != nil { node.log.Error("Failed deserializing transaction and proofs list", "node", node) } - node.log.Debug("RECEIVED UNLOCK MESSAGE", "num", len(*txAndProofs)) + node.log.Debug("RECEIVED Unlock MESSAGE", "num", len(*txAndProofs)) node.addPendingTransactions(*txAndProofs) } diff --git a/proto/common.go b/proto/common.go index c3b2f5f1a..4d9fd099a 100644 --- a/proto/common.go +++ b/proto/common.go @@ -33,32 +33,32 @@ const ( // TODO: add more types ) -// MESSAGE_CATEGORY_BYTES is the number of bytes message category takes -const MESSAGE_CATEGORY_BYTES = 1 +// MessageCategoryBytes is the number of bytes message category takes +const MessageCategoryBytes = 1 -// MESSAGE_TYPE_BYTES is the number of bytes message type takes -const MESSAGE_TYPE_BYTES = 1 +// MessageTypeBytes is the number of bytes message type takes +const MessageTypeBytes = 1 // Get the message category from the p2p message content func GetMessageCategory(message []byte) (MessageCategory, error) { - if len(message) < MESSAGE_CATEGORY_BYTES { + if len(message) < MessageCategoryBytes { return 0, errors.New("Failed to get message category: no data available.") } - return MessageCategory(message[MESSAGE_CATEGORY_BYTES-1]), nil + return MessageCategory(message[MessageCategoryBytes-1]), nil } // Get the message type from the p2p message content func GetMessageType(message []byte) (byte, error) { - if len(message) < MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES { + if len(message) < MessageCategoryBytes+MessageTypeBytes { return 0, errors.New("Failed to get message type: no data available.") } - return byte(message[MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES-1]), nil + return byte(message[MessageCategoryBytes+MessageTypeBytes-1]), nil } // Get the node message payload from the p2p message content func GetMessagePayload(message []byte) ([]byte, error) { - if len(message) < MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES { + if len(message) < MessageCategoryBytes+MessageTypeBytes { return []byte{}, errors.New("Failed to get message payload: no data available.") } - return message[MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES:], nil + return message[MessageCategoryBytes+MessageTypeBytes:], nil } diff --git a/proto/node/node.go b/proto/node/node.go index 79441861b..ffdc25525 100644 --- a/proto/node/node.go +++ b/proto/node/node.go @@ -42,8 +42,8 @@ type TransactionMessageType int const ( Send TransactionMessageType = iota - REQUEST - UNLOCK + Request + Unlock ) // BlockMessageType represents the types of messages used for NODE/BLOCK @@ -101,7 +101,7 @@ func DeserializeBlockchainSyncMessage(d []byte) (*BlockchainSyncMessage, error) func ConstructUnlockToCommitOrAbortMessage(txsAndProofs []*blockchain.Transaction) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) byteBuffer.WriteByte(byte(Transaction)) - byteBuffer.WriteByte(byte(UNLOCK)) + byteBuffer.WriteByte(byte(Unlock)) encoder := gob.NewEncoder(byteBuffer) encoder.Encode(txsAndProofs) return byteBuffer.Bytes() @@ -161,7 +161,7 @@ func GenerateBlockchainSyncMessage(payload []byte) *BlockchainSyncMessage { func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.NODE)}) byteBuffer.WriteByte(byte(Transaction)) - byteBuffer.WriteByte(byte(REQUEST)) + byteBuffer.WriteByte(byte(Request)) for _, txID := range transactionIds { byteBuffer.Write(txID) }