github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/gossip_timestamp_range.go (about)

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