github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/pong.go (about)

     1  package lnwire
     2  
     3  import "io"
     4  
     5  // PongPayload is a set of opaque bytes sent in response to a ping message.
     6  type PongPayload []byte
     7  
     8  // Pong defines a message which is the direct response to a received Ping
     9  // message. A Pong reply indicates that a connection is still active. The Pong
    10  // reply to a Ping message should contain the nonce carried in the original
    11  // Pong message.
    12  type Pong struct {
    13  	// PongBytes is a set of opaque bytes that corresponds to the
    14  	// NumPongBytes defined in the ping message that this pong is
    15  	// replying to.
    16  	PongBytes PongPayload
    17  }
    18  
    19  // NewPong returns a new Pong message.
    20  func NewPong(pongBytes []byte) *Pong {
    21  	return &Pong{
    22  		PongBytes: pongBytes,
    23  	}
    24  }
    25  
    26  // A compile time check to ensure Pong implements the lnwire.Message interface.
    27  var _ Message = (*Pong)(nil)
    28  
    29  // Decode deserializes a serialized Pong message stored in the passed io.Reader
    30  // observing the specified protocol version.
    31  //
    32  // This is part of the lnwire.Message interface.
    33  func (p *Pong) Decode(r io.Reader, pver uint32) error {
    34  	return ReadElements(r,
    35  		&p.PongBytes,
    36  	)
    37  }
    38  
    39  // Encode serializes the target Pong into the passed io.Writer observing the
    40  // protocol version specified.
    41  //
    42  // This is part of the lnwire.Message interface.
    43  func (p *Pong) Encode(w io.Writer, pver uint32) error {
    44  	return WriteElements(w,
    45  		p.PongBytes,
    46  	)
    47  }
    48  
    49  // MsgType returns the integer uniquely identifying this message type on the
    50  // wire.
    51  //
    52  // This is part of the lnwire.Message interface.
    53  func (p *Pong) MsgType() MessageType {
    54  	return MsgPong
    55  }
    56  
    57  // MaxPayloadLength returns the maximum allowed payload size for a Pong
    58  // complete message observing the specified protocol version.
    59  //
    60  // This is part of the lnwire.Message interface.
    61  func (p *Pong) MaxPayloadLength(uint32) uint32 {
    62  	return 65532
    63  }