2017-02-16 13:31:19 +01:00
|
|
|
package lnwire
|
|
|
|
|
2021-06-17 08:17:30 +02:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
)
|
2017-02-16 13:31:19 +01:00
|
|
|
|
|
|
|
// Init is the first message reveals the features supported or required by this
|
|
|
|
// node. Nodes wait for receipt of the other's features to simplify error
|
|
|
|
// diagnosis where features are incompatible. Each node MUST wait to receive
|
|
|
|
// init before sending any other messages.
|
|
|
|
type Init struct {
|
2019-11-08 14:31:47 +01:00
|
|
|
// GlobalFeatures is a legacy feature vector used for backwards
|
|
|
|
// compatibility with older nodes. Any features defined here should be
|
|
|
|
// merged with those presented in Features.
|
2017-10-11 20:37:54 +02:00
|
|
|
GlobalFeatures *RawFeatureVector
|
2017-02-16 13:31:19 +01:00
|
|
|
|
2020-11-25 22:12:29 +01:00
|
|
|
// Features is a feature vector containing the features supported by
|
2019-11-08 14:31:47 +01:00
|
|
|
// the remote node.
|
|
|
|
//
|
|
|
|
// NOTE: Older nodes may place some features in GlobalFeatures, but all
|
|
|
|
// new features are to be added in Features. When handling an Init
|
|
|
|
// message, any GlobalFeatures should be merged into the unified
|
|
|
|
// Features field.
|
|
|
|
Features *RawFeatureVector
|
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
|
2017-02-16 13:31:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewInitMessage creates new instance of init message object.
|
2019-11-08 14:31:47 +01:00
|
|
|
func NewInitMessage(gf *RawFeatureVector, f *RawFeatureVector) *Init {
|
2017-02-16 13:31:19 +01:00
|
|
|
return &Init{
|
|
|
|
GlobalFeatures: gf,
|
2019-11-08 14:31:47 +01:00
|
|
|
Features: f,
|
2020-01-28 02:25:36 +01:00
|
|
|
ExtraData: make([]byte, 0),
|
2017-02-16 13:31:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// A compile time check to ensure Init implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*Init)(nil)
|
|
|
|
|
2017-02-16 13:31:19 +01:00
|
|
|
// Decode deserializes a serialized Init message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (msg *Init) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-02-16 13:31:19 +01:00
|
|
|
&msg.GlobalFeatures,
|
2019-11-08 14:31:47 +01:00
|
|
|
&msg.Features,
|
2020-01-28 02:25:36 +01:00
|
|
|
&msg.ExtraData,
|
2017-02-16 13:31:19 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target Init 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 (msg *Init) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 09:03:43 +02:00
|
|
|
if err := WriteRawFeatureVector(w, msg.GlobalFeatures); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteRawFeatureVector(w, msg.Features); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, msg.ExtraData)
|
2017-02-16 13:31:19 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 13:31:19 +01:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (msg *Init) MsgType() MessageType {
|
|
|
|
return MsgInit
|
2017-02-16 13:31:19 +01:00
|
|
|
}
|