github.com/aergoio/aergo@v1.3.1/p2p/p2pcommon/internalmsg.go (about)

     1  /*
     2   * @file
     3   * @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package p2pcommon
     7  
     8  import (
     9  	"github.com/aergoio/aergo/types"
    10  	"github.com/aergoio/etcd/raft/raftpb"
    11  )
    12  
    13  //go:generate mockgen -source=internalmsg.go -package=p2pmock -destination=../p2pmock/mock_msgorder.go
    14  
    15  // MsgOrder is abstraction of information about the message that will be sent to peer.
    16  // Some type of msgOrder, such as notice mo, should thread-safe and re-entrant
    17  type MsgOrder interface {
    18  	GetMsgID() MsgID
    19  	// Timestamp is unit time value
    20  	Timestamp() int64
    21  	IsRequest() bool
    22  	IsNeedSign() bool
    23  	GetProtocolID() SubProtocol
    24  
    25  	// SendTo send message to remote peer. it return err if write fails, or nil if write is successful or ignored.
    26  	SendTo(p RemotePeer) error
    27  	CancelSend(pi RemotePeer)
    28  }
    29  
    30  type MoFactory interface {
    31  	NewMsgRequestOrder(expectResponse bool, protocolID SubProtocol, message MessageBody) MsgOrder
    32  	NewMsgBlockRequestOrder(respReceiver ResponseReceiver, protocolID SubProtocol, message MessageBody) MsgOrder
    33  	NewMsgResponseOrder(reqID MsgID, protocolID SubProtocol, message MessageBody) MsgOrder
    34  	NewMsgBlkBroadcastOrder(noticeMsg *types.NewBlockNotice) MsgOrder
    35  	NewMsgTxBroadcastOrder(noticeMsg *types.NewTransactionsNotice) MsgOrder
    36  	NewMsgBPBroadcastOrder(noticeMsg *types.BlockProducedNotice) MsgOrder
    37  	NewRaftMsgOrder(msgType raftpb.MessageType, raftMsg *raftpb.Message) MsgOrder
    38  }
    39