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

     1  /*
     2   * @file
     3   * @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package p2pcommon
     7  
     8  // MsgReadWriter read byte stream, parse stream with respect to protocol version and return message object used in p2p module
     9  // It also write Message to stream with serialized form and have Close() to close underlying io stream.
    10  // The implementations should be safe for concurrent read and write, but not concurrent reads or writes.
    11  type MsgReadWriter interface {
    12  	ReadMsg() (Message, error)
    13  	WriteMsg(msg Message) error
    14  	Close() error
    15  
    16  	AddIOListener(l MsgIOListener)
    17  }
    18  
    19  // MsgIOListener listen read and write of p2p message. The concrete implementations must consume much of times.
    20  type MsgIOListener interface {
    21  	OnRead(protocol SubProtocol, read int)
    22  	OnWrite(protocol SubProtocol, write int)
    23  }
    24  
    25  //go:generate mockgen -source=msgio.go -package=p2pmock -destination=../p2pmock/mock_msgio.go