mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
lnwire: create new ExtraOpaqueData type for parsing TLV extensions
In this commit, we create a new `ExtraOpaqueData` based on the field with the same name that's present in all the announcement related messages. In later commits, we'll embed this new type in each message, so we'll have a generic way to add/parse TLV extensions from messages.
This commit is contained in:
committed by
Johan T. Halseth
parent
dd6f0ba931
commit
a603ac4938
@@ -18,9 +18,16 @@ import (
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
)
|
||||
|
||||
// MaxSliceLength is the maximum allowed length for any opaque byte slices in
|
||||
// the wire protocol.
|
||||
const MaxSliceLength = 65535
|
||||
const (
|
||||
// MaxSliceLength is the maximum allowed length for any opaque byte
|
||||
// slices in the wire protocol.
|
||||
MaxSliceLength = 65535
|
||||
|
||||
// MaxMsgBody is the largest payload any message is allowed to provide.
|
||||
// This is two less than the MaxSliceLength as each message has a 2
|
||||
// byte type that precedes the message body.
|
||||
MaxMsgBody = 65533
|
||||
)
|
||||
|
||||
// PkScript is simple type definition which represents a raw serialized public
|
||||
// key script.
|
||||
@@ -418,6 +425,10 @@ func WriteElement(w io.Writer, element interface{}) error {
|
||||
if _, err := w.Write(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case ExtraOpaqueData:
|
||||
return e.Encode(w)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown type in WriteElement: %T", e)
|
||||
}
|
||||
@@ -824,6 +835,10 @@ func ReadElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
*e = addrBytes[:length]
|
||||
|
||||
case *ExtraOpaqueData:
|
||||
return e.Decode(r)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown type in ReadElement: %T", e)
|
||||
}
|
||||
|
Reference in New Issue
Block a user