diff --git a/common/message.go b/common/message.go index f8c8da6b1..c1a303a02 100644 --- a/common/message.go +++ b/common/message.go @@ -24,18 +24,13 @@ n - 2 bytes - actual message payload */ -// NODE_TYPE_BYTES is # of bytes message category -const NODE_TYPE_BYTES = 1 +// MESSAGE_CATEGORY_BYTES is the number of bytes message category takes +const MESSAGE_CATEGORY_BYTES = 1 -// ACTION_TYPE_BYTES is # of bytes for message type which can be -// - for CONSENSUS category -// 0x00: consensus -// 0x01: sharding ... -// - for NODE category -// 0x00: transaction ... -const ACTION_TYPE_BYTES = 1 +// MESSAGE_TYPE_BYTES is the number of bytes message type takes +const MESSAGE_TYPE_BYTES = 1 -// The CATEGORY of messages +// The message category enum type MessageCategory byte const ( @@ -47,24 +42,24 @@ const ( // Get the message category from the p2p message content func GetMessageCategory(message []byte) (MessageCategory, error) { - if len(message) < NODE_TYPE_BYTES { - return 0, errors.New("Failed to get node type: no data available.") + if len(message) < MESSAGE_CATEGORY_BYTES { + return 0, errors.New("Failed to get message category: no data available.") } - return MessageCategory(message[NODE_TYPE_BYTES-1]), nil + return MessageCategory(message[MESSAGE_CATEGORY_BYTES-1]), nil } // Get the message type from the p2p message content func GetMessageType(message []byte) (byte, error) { - if len(message) < NODE_TYPE_BYTES+ACTION_TYPE_BYTES { - return 0, errors.New("Failed to get action type: no data available.") + if len(message) < MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES { + return 0, errors.New("Failed to get message type: no data available.") } - return byte(message[NODE_TYPE_BYTES+ACTION_TYPE_BYTES-1]), nil + return byte(message[MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES-1]), nil } // Get the node message payload from the p2p message content func GetMessagePayload(message []byte) ([]byte, error) { - if len(message) < NODE_TYPE_BYTES+ACTION_TYPE_BYTES { + if len(message) < MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES { return []byte{}, errors.New("Failed to get message payload: no data available.") } - return message[NODE_TYPE_BYTES+ACTION_TYPE_BYTES:], nil + return message[MESSAGE_CATEGORY_BYTES+MESSAGE_TYPE_BYTES:], nil }