2018-04-17 03:46:54 +02:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2021-06-17 08:17:30 +02:00
|
|
|
"bytes"
|
2018-04-17 03:46:54 +02:00
|
|
|
"io"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2018-04-17 03:46:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// GossipTimestampRange is a message that allows the sender to restrict the set
|
|
|
|
// of future gossip announcements sent by the receiver. Nodes should send this
|
|
|
|
// if they have the gossip-queries feature bit active. Nodes are able to send
|
|
|
|
// new GossipTimestampRange messages to replace the prior window.
|
|
|
|
type GossipTimestampRange struct {
|
|
|
|
// ChainHash denotes the chain that the sender wishes to restrict the
|
|
|
|
// set of received announcements of.
|
|
|
|
ChainHash chainhash.Hash
|
|
|
|
|
|
|
|
// FirstTimestamp is the timestamp of the earliest announcement message
|
|
|
|
// that should be sent by the receiver.
|
|
|
|
FirstTimestamp uint32
|
|
|
|
|
|
|
|
// TimestampRange is the horizon beyond the FirstTimestamp that any
|
|
|
|
// announcement messages should be sent for. The receiving node MUST
|
|
|
|
// NOT send any announcements that have a timestamp greater than
|
|
|
|
// FirstTimestamp + TimestampRange.
|
|
|
|
TimestampRange uint32
|
2020-01-28 02:25:36 +01:00
|
|
|
|
|
|
|
// ExtraData is the set of data that was appended to this message to
|
|
|
|
// fill out the full maximum transport message size. These fields can
|
|
|
|
// be used to specify optional data such as custom TLV fields.
|
|
|
|
ExtraData ExtraOpaqueData
|
2018-04-17 03:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewGossipTimestampRange creates a new empty GossipTimestampRange message.
|
|
|
|
func NewGossipTimestampRange() *GossipTimestampRange {
|
|
|
|
return &GossipTimestampRange{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure GossipTimestampRange implements the
|
|
|
|
// lnwire.Message interface.
|
|
|
|
var _ Message = (*GossipTimestampRange)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized GossipTimestampRange message stored in the
|
|
|
|
// passed io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (g *GossipTimestampRange) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2018-04-17 03:46:54 +02:00
|
|
|
g.ChainHash[:],
|
|
|
|
&g.FirstTimestamp,
|
|
|
|
&g.TimestampRange,
|
2020-01-28 02:25:36 +01:00
|
|
|
&g.ExtraData,
|
2018-04-17 03:46:54 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target GossipTimestampRange into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 08:17:30 +02:00
|
|
|
func (g *GossipTimestampRange) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 09:03:43 +02:00
|
|
|
if err := WriteBytes(w, g.ChainHash[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteUint32(w, g.FirstTimestamp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteUint32(w, g.TimestampRange); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, g.ExtraData)
|
2018-04-17 03:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (g *GossipTimestampRange) MsgType() MessageType {
|
|
|
|
return MsgGossipTimestampRange
|
|
|
|
}
|