HAR-84: fix golint warnings on proto/ directory

Signed-off-by: Leo Chen <leo@harmony.one>
pull/115/head
Leo Chen 6 years ago committed by Minh Doan
parent 162866d1b4
commit 94fdb1e20c
  1. 6
      node/node_handler.go
  2. 17
      proto/client/client.go
  3. 14
      proto/common.go
  4. 16
      proto/consensus/consensus.go
  5. 12
      proto/identity/identity.go

@ -75,7 +75,7 @@ func (node *Node) NodeHandler(conn net.Conn) {
switch msgCategory { switch msgCategory {
case proto.Identity: case proto.Identity:
actionType := proto_identity.IdentityMessageType(msgType) actionType := proto_identity.IDMessageType(msgType)
switch actionType { switch actionType {
case proto_identity.Identity: case proto_identity.Identity:
messageType := proto_identity.MessageType(msgPayload[0]) messageType := proto_identity.MessageType(msgPayload[0])
@ -90,7 +90,7 @@ func (node *Node) NodeHandler(conn net.Conn) {
} }
} }
case proto.Consensus: case proto.Consensus:
actionType := consensus.ConsensusMessageType(msgType) actionType := consensus.ConMessageType(msgType)
switch actionType { switch actionType {
case consensus.Consensus: case consensus.Consensus:
if consensusObj.IsLeader { if consensusObj.IsLeader {
@ -189,7 +189,7 @@ func (node *Node) NodeHandler(conn net.Conn) {
node.pongMessageHandler(msgPayload) node.pongMessageHandler(msgPayload)
} }
case proto.Client: case proto.Client:
actionType := client.ClientMessageType(msgType) actionType := client.MessageType(msgType)
node.log.Info("NET: received message: Client/Transaction") node.log.Info("NET: received message: Client/Transaction")
switch actionType { switch actionType {
case client.Transaction: case client.Transaction:

@ -8,28 +8,31 @@ import (
"github.com/harmony-one/harmony/proto" "github.com/harmony-one/harmony/proto"
) )
// The specific types of message under Client category // MessageType is the specific types of message under Client category
type ClientMessageType byte type MessageType byte
// Message type supported by client
const ( const (
Transaction ClientMessageType = iota Transaction MessageType = iota
// TODO: add more types // 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 type TransactionMessageType int
// The proof of accept or reject returned by the leader to the client tnat issued cross shard transactions
const ( 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 UtxoResponse
) )
// FetchUtxoResponseMessage is the data structure of UTXO map
type FetchUtxoResponseMessage struct { type FetchUtxoResponseMessage struct {
UtxoMap blockchain.UtxoMap UtxoMap blockchain.UtxoMap
ShardID uint32 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 { func ConstructProofOfAcceptOrRejectMessage(proofs []blockchain.CrossShardTxProof) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)})
byteBuffer.WriteByte(byte(Transaction)) byteBuffer.WriteByte(byte(Transaction))
@ -40,7 +43,7 @@ func ConstructProofOfAcceptOrRejectMessage(proofs []blockchain.CrossShardTxProof
return byteBuffer.Bytes() 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 { func ConstructFetchUtxoResponseMessage(utxoMap *blockchain.UtxoMap, shardID uint32) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.Client)})
byteBuffer.WriteByte(byte(Transaction)) byteBuffer.WriteByte(byte(Transaction))

@ -21,7 +21,7 @@ n - 2 bytes - actual message payload
---- content end ----- ---- content end -----
*/ */
// The message category enum // MessageCategory defines the message category enum
type MessageCategory byte type MessageCategory byte
//Consensus and other message categories //Consensus and other message categories
@ -39,26 +39,26 @@ const MessageCategoryBytes = 1
// MessageTypeBytes is the number of bytes message type takes // MessageTypeBytes is the number of bytes message type takes
const MessageTypeBytes = 1 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) { func GetMessageCategory(message []byte) (MessageCategory, error) {
if len(message) < MessageCategoryBytes { 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 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) { func GetMessageType(message []byte) (byte, error) {
if len(message) < MessageCategoryBytes+MessageTypeBytes { 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 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) { func GetMessagePayload(message []byte) ([]byte, error) {
if len(message) < MessageCategoryBytes+MessageTypeBytes { 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 return message[MessageCategoryBytes+MessageTypeBytes:], nil
} }

@ -71,12 +71,12 @@ Response:
// MessageTypeBytes is the number of bytes consensus message type occupies // MessageTypeBytes is the number of bytes consensus message type occupies
const MessageTypeBytes = 1 const MessageTypeBytes = 1
// ConsensusMessageType is the specific types of message under Consensus category // ConMessageType is the specific types of message under Consensus category
type ConsensusMessageType byte type ConMessageType byte
// Consensus message type constants. // Consensus message type constants.
const ( const (
Consensus ConsensusMessageType = iota Consensus ConMessageType = iota
// TODO: add more types // TODO: add more types
) )
@ -117,23 +117,23 @@ func (msgType MessageType) String() string {
return names[msgType] 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) { func GetConsensusMessageType(message []byte) (MessageType, error) {
if len(message) < 1 { 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 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) { func GetConsensusMessagePayload(message []byte) ([]byte, error) {
if len(message) < 2 { 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 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 { func ConstructConsensusMessage(consensusMsgType MessageType, payload []byte) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Consensus)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.Consensus)})
byteBuffer.WriteByte(byte(Consensus)) byteBuffer.WriteByte(byte(Consensus))

@ -10,12 +10,12 @@ import (
// IdentityMessageTypeBytes is the number of bytes consensus message type occupies // IdentityMessageTypeBytes is the number of bytes consensus message type occupies
const IdentityMessageTypeBytes = 1 const IdentityMessageTypeBytes = 1
// IdentityMessageType is the identity message type. // IDMessageType is the identity message type.
type IdentityMessageType byte type IDMessageType byte
// Constants of IdentityMessageType. // Constants of IdentityMessageType.
const ( const (
Identity IdentityMessageType = iota Identity IDMessageType = iota
// TODO: add more types // TODO: add more types
) )
@ -44,7 +44,7 @@ func (msgType MessageType) String() string {
// GetIdentityMessageType Get the identity message type from the identity message // GetIdentityMessageType Get the identity message type from the identity message
func GetIdentityMessageType(message []byte) (MessageType, error) { func GetIdentityMessageType(message []byte) (MessageType, error) {
if len(message) < 1 { 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 return MessageType(message[0]), nil
} }
@ -52,12 +52,12 @@ func GetIdentityMessageType(message []byte) (MessageType, error) {
// GetIdentityMessagePayload message payload from the identity message // GetIdentityMessagePayload message payload from the identity message
func GetIdentityMessagePayload(message []byte) ([]byte, error) { func GetIdentityMessagePayload(message []byte) ([]byte, error) {
if len(message) < 2 { 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 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 { func ConstructIdentityMessage(identityMessageType MessageType, payload []byte) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Identity)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.Identity)})
byteBuffer.WriteByte(byte(Identity)) byteBuffer.WriteByte(byte(Identity))

Loading…
Cancel
Save