github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/init_message.go (about) 1 package lnwire 2 3 import "io" 4 5 // Init is the first message reveals the features supported or required by this 6 // node. Nodes wait for receipt of the other's features to simplify error 7 // diagnosis where features are incompatible. Each node MUST wait to receive 8 // init before sending any other messages. 9 type Init struct { 10 // GlobalFeatures is a legacy feature vector used for backwards 11 // compatibility with older nodes. Any features defined here should be 12 // merged with those presented in Features. 13 GlobalFeatures *RawFeatureVector 14 15 // Features is a feature vector containing the features supported by 16 // the remote node. 17 // 18 // NOTE: Older nodes may place some features in GlobalFeatures, but all 19 // new features are to be added in Features. When handling an Init 20 // message, any GlobalFeatures should be merged into the unified 21 // Features field. 22 Features *RawFeatureVector 23 } 24 25 // NewInitMessage creates new instance of init message object. 26 func NewInitMessage(gf *RawFeatureVector, f *RawFeatureVector) *Init { 27 return &Init{ 28 GlobalFeatures: gf, 29 Features: f, 30 } 31 } 32 33 // A compile time check to ensure Init implements the lnwire.Message 34 // interface. 35 var _ Message = (*Init)(nil) 36 37 // Decode deserializes a serialized Init message stored in the passed 38 // io.Reader observing the specified protocol version. 39 // 40 // This is part of the lnwire.Message interface. 41 func (msg *Init) Decode(r io.Reader, pver uint32) error { 42 return ReadElements(r, 43 &msg.GlobalFeatures, 44 &msg.Features, 45 ) 46 } 47 48 // Encode serializes the target Init into the passed io.Writer observing 49 // the protocol version specified. 50 // 51 // This is part of the lnwire.Message interface. 52 func (msg *Init) Encode(w io.Writer, pver uint32) error { 53 return WriteElements(w, 54 msg.GlobalFeatures, 55 msg.Features, 56 ) 57 } 58 59 // MsgType returns the integer uniquely identifying this message type on the 60 // wire. 61 // 62 // This is part of the lnwire.Message interface. 63 func (msg *Init) MsgType() MessageType { 64 return MsgInit 65 } 66 67 // MaxPayloadLength returns the maximum allowed payload size for an Init 68 // complete message observing the specified protocol version. 69 // 70 // This is part of the lnwire.Message interface. 71 func (msg *Init) MaxPayloadLength(uint32) uint32 { 72 return 2 + 2 + maxAllowedSize + 2 + maxAllowedSize 73 }