2016-11-11 04:09:14 +03:00
|
|
|
package lnwire
|
|
|
|
|
2017-01-15 04:52:05 +03:00
|
|
|
import "io"
|
2016-11-11 04:09:14 +03:00
|
|
|
|
2017-04-17 04:19:03 +03:00
|
|
|
// PongPayload is a set of opaque bytes sent in response to a ping message.
|
2017-04-17 04:11:39 +03:00
|
|
|
type PongPayload []byte
|
|
|
|
|
2017-04-17 01:48:41 +03: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 04:11:39 +03:00
|
|
|
// PongBytes is a set of opaque bytes that corresponds to the
|
|
|
|
// NumPongBytes defined in the ping message that this this pong is
|
|
|
|
// replying to.
|
|
|
|
PongBytes PongPayload
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 04:11:39 +03:00
|
|
|
// NewPong returns a new Pong message.
|
|
|
|
func NewPong(pongBytes []byte) *Pong {
|
2017-04-17 01:48:41 +03:00
|
|
|
return &Pong{
|
2017-04-17 04:11:39 +03:00
|
|
|
PongBytes: pongBytes,
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 01:48:41 +03:00
|
|
|
// A compile time check to ensure Pong implements the lnwire.Message interface.
|
|
|
|
var _ Message = (*Pong)(nil)
|
2016-11-11 04:09:14 +03:00
|
|
|
|
2017-04-17 01:48:41 +03:00
|
|
|
// Decode deserializes a serialized Pong message stored in the passed io.Reader
|
2016-11-11 04:09:14 +03:00
|
|
|
// observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 01:48:41 +03:00
|
|
|
func (p *Pong) Decode(r io.Reader, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return readElements(r,
|
2017-04-17 04:11:39 +03:00
|
|
|
&p.PongBytes,
|
2016-11-11 04:09:14 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-17 01:48:41 +03:00
|
|
|
// Encode serializes the target Pong into the passed io.Writer observing the
|
2016-11-11 04:09:14 +03:00
|
|
|
// protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 01:48:41 +03:00
|
|
|
func (p *Pong) Encode(w io.Writer, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return writeElements(w,
|
2017-04-17 04:11:39 +03:00
|
|
|
p.PongBytes,
|
2016-11-11 04:09:14 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 01:48:41 +03:00
|
|
|
func (p *Pong) Command() uint32 {
|
|
|
|
return CmdPong
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-17 01:48:41 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a Pong
|
2016-11-11 04:09:14 +03:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 01:48:41 +03:00
|
|
|
func (p *Pong) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 04:11:39 +03:00
|
|
|
return 65532
|
2016-11-11 04:09:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate performs any necessary sanity checks to ensure all fields present
|
2017-04-17 01:48:41 +03:00
|
|
|
// on the Pong are valid.
|
2016-11-11 04:09:14 +03:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-17 01:48:41 +03:00
|
|
|
func (p *Pong) Validate() error {
|
2016-11-11 04:09:14 +03:00
|
|
|
return nil
|
|
|
|
}
|