github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/ping.go (about) 1 package lnwire 2 3 import "io" 4 5 // PingPayload is a set of opaque bytes used to pad out a ping message. 6 type PingPayload []byte 7 8 // Ping defines a message which is sent by peers periodically to determine if 9 // the connection is still valid. Each ping message carries the number of bytes 10 // to pad the pong response with, and also a number of bytes to be ignored at 11 // the end of the ping message (which is padding). 12 type Ping struct { 13 // NumPongBytes is the number of bytes the pong response to this 14 // message should carry. 15 NumPongBytes uint16 16 17 // PaddingBytes is a set of opaque bytes used to pad out this ping 18 // message. Using this field in conjunction to the one above, it's 19 // possible for node to generate fake cover traffic. 20 PaddingBytes PingPayload 21 } 22 23 // NewPing returns a new Ping message. 24 func NewPing(numBytes uint16) *Ping { 25 return &Ping{ 26 NumPongBytes: numBytes, 27 } 28 } 29 30 // A compile time check to ensure Ping implements the lnwire.Message interface. 31 var _ Message = (*Ping)(nil) 32 33 // Decode deserializes a serialized Ping message stored in the passed io.Reader 34 // observing the specified protocol version. 35 // 36 // This is part of the lnwire.Message interface. 37 func (p *Ping) Decode(r io.Reader, pver uint32) error { 38 return ReadElements(r, 39 &p.NumPongBytes, 40 &p.PaddingBytes) 41 } 42 43 // Encode serializes the target Ping into the passed io.Writer observing the 44 // protocol version specified. 45 // 46 // This is part of the lnwire.Message interface. 47 func (p *Ping) Encode(w io.Writer, pver uint32) error { 48 return WriteElements(w, 49 p.NumPongBytes, 50 p.PaddingBytes) 51 } 52 53 // MsgType returns the integer uniquely identifying this message type on the 54 // wire. 55 // 56 // This is part of the lnwire.Message interface. 57 func (p *Ping) MsgType() MessageType { 58 return MsgPing 59 } 60 61 // MaxPayloadLength returns the maximum allowed payload size for a Ping 62 // complete message observing the specified protocol version. 63 // 64 // This is part of the lnwire.Message interface. 65 func (p Ping) MaxPayloadLength(uint32) uint32 { 66 return 65532 67 }