diff --git a/node/node_handler.go b/node/node_handler.go index 69b68e612..54626dab7 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -75,7 +75,7 @@ func (node *Node) NodeHandler(conn net.Conn) { switch msgCategory { case proto.Identity: - actionType := proto_identity.IdentityMessageType(msgType) + actionType := proto_identity.IDMessageType(msgType) switch actionType { case proto_identity.Identity: messageType := proto_identity.MessageType(msgPayload[0]) @@ -90,7 +90,7 @@ func (node *Node) NodeHandler(conn net.Conn) { } } case proto.Consensus: - actionType := consensus.ConsensusMessageType(msgType) + actionType := consensus.ConMessageType(msgType) switch actionType { case consensus.Consensus: if consensusObj.IsLeader { @@ -189,7 +189,7 @@ func (node *Node) NodeHandler(conn net.Conn) { node.pongMessageHandler(msgPayload) } case proto.Client: - actionType := client.ClientMessageType(msgType) + actionType := client.MessageType(msgType) node.log.Info("NET: received message: Client/Transaction") switch actionType { case client.Transaction: diff --git a/proto/client/client.go b/proto/client/client.go index 5bcc08177..be7644cb8 100644 --- a/proto/client/client.go +++ b/proto/client/client.go @@ -8,28 +8,31 @@ import ( "github.com/harmony-one/harmony/proto" ) -// The specific types of message under Client category -type ClientMessageType byte +// MessageType is the specific types of message under Client category +type MessageType byte +// Message type supported by client const ( - Transaction ClientMessageType = iota + Transaction MessageType = iota // TODO: add more types ) -// The types of messages used for Client/Transaction +// TransactionMessageType defines the types of messages used for Client/Transaction type TransactionMessageType int +// The proof of accept or reject returned by the leader to the client tnat issued cross shard transactions const ( - ProofOfLock TransactionMessageType = iota // The proof of accept or reject returned by the leader to the client tnat issued cross shard transactions. + ProofOfLock TransactionMessageType = iota UtxoResponse ) +// FetchUtxoResponseMessage is the data structure of UTXO map type FetchUtxoResponseMessage struct { UtxoMap blockchain.UtxoMap ShardID uint32 } -// [leader] Constructs the proof of accept or reject message that will be sent to client +// ConstructProofOfAcceptOrRejectMessage constructs the proof of accept or reject message that will be sent to client func ConstructProofOfAcceptOrRejectMessage(proofs []blockchain.CrossShardTxProof) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)}) byteBuffer.WriteByte(byte(Transaction)) @@ -40,7 +43,7 @@ func ConstructProofOfAcceptOrRejectMessage(proofs []blockchain.CrossShardTxProof return byteBuffer.Bytes() } -// Constructs the response message to fetch utxo message +// ConstructFetchUtxoResponseMessage constructs the response message to fetch utxo message func ConstructFetchUtxoResponseMessage(utxoMap *blockchain.UtxoMap, shardID uint32) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)}) byteBuffer.WriteByte(byte(Transaction)) diff --git a/proto/common.go b/proto/common.go index be8100e0f..a552e98b3 100644 --- a/proto/common.go +++ b/proto/common.go @@ -21,7 +21,7 @@ n - 2 bytes - actual message payload ---- content end ----- */ -// The message category enum +// MessageCategory defines the message category enum type MessageCategory byte //Consensus and other message categories @@ -39,26 +39,26 @@ const MessageCategoryBytes = 1 // MessageTypeBytes is the number of bytes message type takes const MessageTypeBytes = 1 -// Get the message category from the p2p message content +// GetMessageCategory gets the message category from the p2p message content func GetMessageCategory(message []byte) (MessageCategory, error) { if len(message) < MessageCategoryBytes { - return 0, errors.New("Failed to get message category: no data available.") + return 0, errors.New("failed to get message category: no data available") } return MessageCategory(message[MessageCategoryBytes-1]), nil } -// Get the message type from the p2p message content +// GetMessageType gets the message type from the p2p message content func GetMessageType(message []byte) (byte, error) { if len(message) < MessageCategoryBytes+MessageTypeBytes { - return 0, errors.New("Failed to get message type: no data available.") + return 0, errors.New("failed to get message type: no data available") } return byte(message[MessageCategoryBytes+MessageTypeBytes-1]), nil } -// Get the node message payload from the p2p message content +// GetMessagePayload gets the node message payload from the p2p message content func GetMessagePayload(message []byte) ([]byte, error) { if len(message) < MessageCategoryBytes+MessageTypeBytes { - return []byte{}, errors.New("Failed to get message payload: no data available.") + return []byte{}, errors.New("failed to get message payload: no data available") } return message[MessageCategoryBytes+MessageTypeBytes:], nil } diff --git a/proto/consensus/consensus.go b/proto/consensus/consensus.go index d389dd4fb..94c086292 100644 --- a/proto/consensus/consensus.go +++ b/proto/consensus/consensus.go @@ -71,12 +71,12 @@ Response: // MessageTypeBytes is the number of bytes consensus message type occupies const MessageTypeBytes = 1 -// ConsensusMessageType is the specific types of message under Consensus category -type ConsensusMessageType byte +// ConMessageType is the specific types of message under Consensus category +type ConMessageType byte // Consensus message type constants. const ( - Consensus ConsensusMessageType = iota + Consensus ConMessageType = iota // TODO: add more types ) @@ -117,23 +117,23 @@ func (msgType MessageType) String() string { return names[msgType] } -// Get the consensus message type from the consensus message +// GetConsensusMessageType gets the consensus message type from the consensus message func GetConsensusMessageType(message []byte) (MessageType, error) { if len(message) < 1 { - return 0, errors.New("Failed to get consensus message type: no data available.") + return 0, errors.New("failed to get consensus message type: no data available") } return MessageType(message[0]), nil } -// Get the consensus message payload from the consensus message +// GetConsensusMessagePayload gets the consensus message payload from the consensus message func GetConsensusMessagePayload(message []byte) ([]byte, error) { if len(message) < 2 { - return []byte{}, errors.New("Failed to get consensus message payload: no data available.") + return []byte{}, errors.New("failed to get consensus message payload: no data available") } return message[MessageTypeBytes:], nil } -// Concatenate msgType as one byte with payload, and return the whole byte array +// ConstructConsensusMessage concatenates msgType as one byte with payload, and return the whole byte array func ConstructConsensusMessage(consensusMsgType MessageType, payload []byte) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.Consensus)}) byteBuffer.WriteByte(byte(Consensus)) diff --git a/proto/identity/identity.go b/proto/identity/identity.go index 716dfe165..cafba9cc3 100644 --- a/proto/identity/identity.go +++ b/proto/identity/identity.go @@ -10,12 +10,12 @@ import ( // IdentityMessageTypeBytes is the number of bytes consensus message type occupies const IdentityMessageTypeBytes = 1 -// IdentityMessageType is the identity message type. -type IdentityMessageType byte +// IDMessageType is the identity message type. +type IDMessageType byte // Constants of IdentityMessageType. const ( - Identity IdentityMessageType = iota + Identity IDMessageType = iota // TODO: add more types ) @@ -44,7 +44,7 @@ func (msgType MessageType) String() string { // GetIdentityMessageType Get the identity message type from the identity message func GetIdentityMessageType(message []byte) (MessageType, error) { if len(message) < 1 { - return 0, errors.New("Failed to get identity message type: no data available.") + return 0, errors.New("failed to get identity message type: no data available") } return MessageType(message[0]), nil } @@ -52,12 +52,12 @@ func GetIdentityMessageType(message []byte) (MessageType, error) { // GetIdentityMessagePayload message payload from the identity message func GetIdentityMessagePayload(message []byte) ([]byte, error) { if len(message) < 2 { - return []byte{}, errors.New("Failed to get identity message payload: no data available.") + return []byte{}, errors.New("failed to get identity message payload: no data available") } return message[IdentityMessageTypeBytes:], nil } -// Concatenate msgType as one byte with payload, and return the whole byte array +// ConstructIdentityMessage concatenates msgType as one byte with payload, and return the whole byte array func ConstructIdentityMessage(identityMessageType MessageType, payload []byte) []byte { byteBuffer := bytes.NewBuffer([]byte{byte(proto.Identity)}) byteBuffer.WriteByte(byte(Identity))