2017-02-16 15:31:19 +03:00
|
|
|
package lnwire
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
import "io"
|
2017-02-16 15:31:19 +03: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 {
|
|
|
|
// GlobalFeatures is feature vector which affects HTLCs and thus are
|
|
|
|
// also advertised to other nodes.
|
2017-10-11 21:37:54 +03:00
|
|
|
GlobalFeatures *RawFeatureVector
|
2017-02-16 15:31:19 +03:00
|
|
|
|
|
|
|
// LocalFeatures is feature vector which only affect the protocol
|
|
|
|
// between two nodes.
|
2017-10-11 21:37:54 +03:00
|
|
|
LocalFeatures *RawFeatureVector
|
2017-02-16 15:31:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewInitMessage creates new instance of init message object.
|
2017-10-11 21:37:54 +03:00
|
|
|
func NewInitMessage(gf *RawFeatureVector, lf *RawFeatureVector) *Init {
|
2017-02-16 15:31:19 +03:00
|
|
|
return &Init{
|
|
|
|
GlobalFeatures: gf,
|
|
|
|
LocalFeatures: lf,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// A compile time check to ensure Init implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*Init)(nil)
|
|
|
|
|
2017-02-16 15:31:19 +03: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 05:27:41 +03:00
|
|
|
return ReadElements(r,
|
2017-02-16 15:31:19 +03:00
|
|
|
&msg.GlobalFeatures,
|
2017-11-18 00:26:39 +03:00
|
|
|
&msg.LocalFeatures,
|
2017-02-16 15:31:19 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target Init into the passed io.Writer observing
|
|
|
|
// the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (msg *Init) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return WriteElements(w,
|
2017-02-16 15:31:19 +03:00
|
|
|
msg.GlobalFeatures,
|
2017-11-18 00:26:39 +03:00
|
|
|
msg.LocalFeatures,
|
2017-02-16 15:31:19 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 15:31:19 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (msg *Init) MsgType() MessageType {
|
|
|
|
return MsgInit
|
2017-02-16 15:31:19 +03:00
|
|
|
}
|
|
|
|
|
2018-04-18 05:02:04 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for an Init
|
2017-02-16 15:31:19 +03:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (msg *Init) MaxPayloadLength(uint32) uint32 {
|
|
|
|
return 2 + maxAllowedSize + 2 + maxAllowedSize
|
|
|
|
}
|