2016-11-11 02:09:14 +01:00
|
|
|
package lnwire
|
|
|
|
|
2017-01-15 02:52:05 +01:00
|
|
|
import "io"
|
2016-11-11 02:09:14 +01:00
|
|
|
|
2017-04-17 03:19:03 +02:00
|
|
|
// PongPayload is a set of opaque bytes sent in response to a ping message.
|
2017-04-17 03:11:39 +02:00
|
|
|
type PongPayload []byte
|
|
|
|
|
2017-04-17 00:48:41 +02:00
|
|
|
// Pong defines a message which is the direct response to a received Ping
|
|
|
|
// message. A Pong reply indicates that a connection is still active. The Pong
|
|
|
|
// reply to a Ping message should contain the nonce carried in the original
|
|
|
|
// Pong message.
|
|
|
|
type Pong struct {
|
2017-04-17 03:11:39 +02:00
|
|
|
// PongBytes is a set of opaque bytes that corresponds to the
|
2018-04-18 04:03:27 +02:00
|
|
|
// NumPongBytes defined in the ping message that this pong is
|
2017-04-17 03:11:39 +02:00
|
|
|
// replying to.
|
|
|
|
PongBytes PongPayload
|
2016-11-11 02:09:14 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 03:11:39 +02:00
|
|
|
// NewPong returns a new Pong message.
|
|
|
|
func NewPong(pongBytes []byte) *Pong {
|
2017-04-17 00:48:41 +02:00
|
|
|
return &Pong{
|
2017-04-17 03:11:39 +02:00
|
|
|
PongBytes: pongBytes,
|
2016-11-11 02:09:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:41 +02:00
|
|
|
// A compile time check to ensure Pong implements the lnwire.Message interface.
|
|
|
|
var _ Message = (*Pong)(nil)
|
2016-11-11 02:09:14 +01:00
|
|
|
|
2017-04-17 00:48:41 +02:00
|
|
|
// Decode deserializes a serialized Pong message stored in the passed io.Reader
|
2016-11-11 02:09:14 +01:00
|
|
|
// observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 00:48:41 +02:00
|
|
|
func (p *Pong) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-04-17 03:11:39 +02:00
|
|
|
&p.PongBytes,
|
2016-11-11 02:09:14 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:41 +02:00
|
|
|
// Encode serializes the target Pong into the passed io.Writer observing the
|
2016-11-11 02:09:14 +01:00
|
|
|
// protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 00:48:41 +02:00
|
|
|
func (p *Pong) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return WriteElements(w,
|
2017-04-17 03:11:39 +02:00
|
|
|
p.PongBytes,
|
2016-11-11 02:09:14 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2016-11-11 02:09:14 +01:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (p *Pong) MsgType() MessageType {
|
|
|
|
return MsgPong
|
2016-11-11 02:09:14 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 00:48:41 +02:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a Pong
|
2016-11-11 02:09:14 +01:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 00:48:41 +02:00
|
|
|
func (p *Pong) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 03:11:39 +02:00
|
|
|
return 65532
|
2016-11-11 02:09:14 +01:00
|
|
|
}
|