mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 14:48:14 +01:00
brontide: exclude MAC length from cipher text packet length prefix
Pervasively we would include the length of the MAC in the length prefix for cipher text packets. As a result, the MAC would eat into the total payload size. To remedy this, we now exclude the MAC from the length prefix for cipher text packets, and instead account for the length of the MAC on the packet when reading messages.
This commit is contained in:
@@ -117,14 +117,13 @@ func (c *Conn) Read(b []byte) (n int, err error) {
|
||||
func (c *Conn) Write(b []byte) (n int, err error) {
|
||||
// If the message doesn't require any chunking, then we can go ahead
|
||||
// with a single write.
|
||||
if len(b)+macSize <= math.MaxUint16 {
|
||||
if len(b) <= math.MaxUint16 {
|
||||
return len(b), c.noise.WriteMessage(c.conn, b)
|
||||
}
|
||||
|
||||
// If we need to split the message into fragments, then we'll write
|
||||
// chunks which maximize usage of the available payload. To do so, we
|
||||
// subtract the added overhead of the MAC at the end of the message.
|
||||
chunkSize := math.MaxUint16 - macSize
|
||||
// chunks which maximize usage of the available payload.
|
||||
chunkSize := math.MaxUint16
|
||||
|
||||
bytesToWrite := len(b)
|
||||
bytesWritten := 0
|
||||
|
||||
Reference in New Issue
Block a user