github.com/decred/dcrlnd@v0.7.6/lnwire/gossip_timestamp_range.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  
     7  	"github.com/decred/dcrd/chaincfg/chainhash"
     8  )
     9  
    10  // GossipTimestampRange is a message that allows the sender to restrict the set
    11  // of future gossip announcements sent by the receiver. Nodes should send this
    12  // if they have the gossip-queries feature bit active. Nodes are able to send
    13  // new GossipTimestampRange messages to replace the prior window.
    14  type GossipTimestampRange struct {
    15  	// ChainHash denotes the chain that the sender wishes to restrict the
    16  	// set of received announcements of.
    17  	ChainHash chainhash.Hash
    18  
    19  	// FirstTimestamp is the timestamp of the earliest announcement message
    20  	// that should be sent by the receiver.
    21  	FirstTimestamp uint32
    22  
    23  	// TimestampRange is the horizon beyond the FirstTimestamp that any
    24  	// announcement messages should be sent for. The receiving node MUST
    25  	// NOT send any announcements that have a timestamp greater than
    26  	// FirstTimestamp + TimestampRange.
    27  	TimestampRange uint32
    28  
    29  	// ExtraData is the set of data that was appended to this message to
    30  	// fill out the full maximum transport message size. These fields can
    31  	// be used to specify optional data such as custom TLV fields.
    32  	ExtraData ExtraOpaqueData
    33  }
    34  
    35  // NewGossipTimestampRange creates a new empty GossipTimestampRange message.
    36  func NewGossipTimestampRange() *GossipTimestampRange {
    37  	return &GossipTimestampRange{}
    38  }
    39  
    40  // A compile time check to ensure GossipTimestampRange implements the
    41  // lnwire.Message interface.
    42  var _ Message = (*GossipTimestampRange)(nil)
    43  
    44  // Decode deserializes a serialized GossipTimestampRange message stored in the
    45  // passed io.Reader observing the specified protocol version.
    46  //
    47  // This is part of the lnwire.Message interface.
    48  func (g *GossipTimestampRange) Decode(r io.Reader, pver uint32) error {
    49  	return ReadElements(r,
    50  		g.ChainHash[:],
    51  		&g.FirstTimestamp,
    52  		&g.TimestampRange,
    53  		&g.ExtraData,
    54  	)
    55  }
    56  
    57  // Encode serializes the target GossipTimestampRange into the passed io.Writer
    58  // observing the protocol version specified.
    59  //
    60  // This is part of the lnwire.Message interface.
    61  func (g *GossipTimestampRange) Encode(w *bytes.Buffer, pver uint32) error {
    62  	if err := WriteBytes(w, g.ChainHash[:]); err != nil {
    63  		return err
    64  	}
    65  
    66  	if err := WriteUint32(w, g.FirstTimestamp); err != nil {
    67  		return err
    68  	}
    69  
    70  	if err := WriteUint32(w, g.TimestampRange); err != nil {
    71  		return err
    72  	}
    73  
    74  	return WriteBytes(w, g.ExtraData)
    75  }
    76  
    77  // MsgType returns the integer uniquely identifying this message type on the
    78  // wire.
    79  //
    80  // This is part of the lnwire.Message interface.
    81  func (g *GossipTimestampRange) MsgType() MessageType {
    82  	return MsgGossipTimestampRange
    83  }