Merge pull request #2590 from Crypt-iQ/init_message_payload_fix

lnwire: features "maxAllowedSize" fix
This commit is contained in:
Olaoluwa Osuntokun 2019-03-21 20:58:29 -07:00 committed by GitHub
commit e58fa33ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View File

@ -49,16 +49,14 @@ const (
// maxAllowedSize is a maximum allowed size of feature vector. // maxAllowedSize is a maximum allowed size of feature vector.
// //
// NOTE: Within the protocol, the maximum allowed message size is 65535 // NOTE: Within the protocol, the maximum allowed message size is 65535
// bytes. Adding the overhead from the crypto protocol (the 2-byte // bytes for all messages. Accounting for the overhead within the feature
// packet length and 16-byte MAC), we arrive at 65569 bytes. Accounting // message to signal the type of message, that leaves us with 65533 bytes
// for the overhead within the feature message to signal the type of // for the init message itself. Next, we reserve 4 bytes to encode the
// the message, that leaves 65567 bytes for the init message itself. // lengths of both the local and global feature vectors, so 65529 bytes
// Next, we reserve 4-bytes to encode the lengths of both the local and // for the local and global features. Knocking off one byte for the sake
// global feature vectors, so 65563 for the global and local features. // of the calculation, that leads us to 32764 bytes for each feature
// Knocking off one byte for the sake of the calculation, that leads to // vector, or 131056 different features.
// a max allowed size of 32781 bytes for each feature vector, or 131124 maxAllowedSize = 32764
// different features.
maxAllowedSize = 32781
) )
// LocalFeatures is a mapping of known connection-local feature bits to a // LocalFeatures is a mapping of known connection-local feature bits to a

View File

@ -63,5 +63,5 @@ func (msg *Init) MsgType() MessageType {
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (msg *Init) MaxPayloadLength(uint32) uint32 { func (msg *Init) MaxPayloadLength(uint32) uint32 {
return 2 + maxAllowedSize + 2 + maxAllowedSize return 2 + 2 + maxAllowedSize + 2 + maxAllowedSize
} }