@@ -41,26 +41,16 @@ const (
4141 LegacyHopDataSize = (RealmByteSize + AddressSize + AmtForwardSize +
4242 OutgoingCLTVSize + NumPaddingBytes + HMACSize )
4343
44- // MaxPayloadSize is the maximum size an `update_add_htlc` payload for a
45- // single hop can be. This is the worst case scenario of a single hop,
46- // consuming all available space. We need to know this in order to
47- // generate a sufficiently long stream of pseudo-random bytes when
48- // encrypting/decrypting the payload. This field is here for backwards
49- // compatibility. Throughout the code we use StandardRoutingInfoSize
50- // because of the more apt naming.
51- MaxPayloadSize = standardRoutingInfoSize
52- StandardRoutingInfoSize = standardRoutingInfoSize
53-
54- // standardRoutingInfoSize is the fixed size of the the routing info. This
55- // consists of an addressSize byte address and a HMACSize byte HMAC for
56- // each hop of the route, the first pair in cleartext and the following
57- // pairs increasingly obfuscated. If not all space is used up, the
58- // remainder is padded with null-bytes, also obfuscated.
59- standardRoutingInfoSize = 1300
60-
61- // JumboRoutingInfoSize is the size of the routing info for a jumbo
62- // onion packet.
63- JumboRoutingInfoSize = 32768
44+ // MaxRoutingPayloadSize is the maximum size an `update_add_htlc`
45+ // payload for a single hop can be. This is the worst case scenario of a
46+ // single hop, consuming all available space. We need to know this in
47+ // order to generate a sufficiently long stream of pseudo-random bytes
48+ // when encrypting/decrypting the payload.
49+ MaxRoutingPayloadSize = 1300
50+
51+ // MaxOnionMessagePayloadSize is the size of the routing info for a
52+ // onion messaging jumbo onion packet.
53+ MaxOnionMessagePayloadSize = 32768
6454
6555 // keyLen is the length of the keys used to generate cipher streams and
6656 // encrypt payloads. Since we use SHA256 to generate the keys, the
@@ -73,13 +63,13 @@ const (
7363
7464var (
7565 ErrStandardRoutingPayloadSizeExceeded = fmt .Errorf (
76- "max routing info size of %v bytes exceeded" ,
77- StandardRoutingInfoSize ,
66+ "max routing payload size of %v bytes exceeded" ,
67+ MaxRoutingPayloadSize ,
7868 )
7969
8070 ErrMessageRoutingPayloadSizeExceeded = fmt .Errorf (
81- "max onion message routing info size of %v bytes exceeded" ,
82- JumboRoutingInfoSize ,
71+ "max onion message routing payload size of %v bytes exceeded" ,
72+ MaxOnionMessagePayloadSize ,
8373 )
8474)
8575
@@ -212,16 +202,16 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
212202
213203 totalPayloadSize := paymentPath .TotalPayloadSize ()
214204
215- routingInfoLen := StandardRoutingInfoSize
216- maxRoutingInfoErr := ErrStandardRoutingPayloadSizeExceeded
217- if isOnionMessage && totalPayloadSize > StandardRoutingInfoSize {
218- routingInfoLen = JumboRoutingInfoSize
219- maxRoutingInfoErr = ErrMessageRoutingPayloadSizeExceeded
205+ routingPayloadLen := MaxRoutingPayloadSize
206+ maxRoutingPayloadErr := ErrStandardRoutingPayloadSizeExceeded
207+ if isOnionMessage && totalPayloadSize > MaxRoutingPayloadSize {
208+ routingPayloadLen = MaxOnionMessagePayloadSize
209+ maxRoutingPayloadErr = ErrMessageRoutingPayloadSizeExceeded
220210 }
221211
222212 // Check whether total payload size doesn't exceed the hard maximum.
223- if totalPayloadSize > routingInfoLen {
224- return nil , maxRoutingInfoErr
213+ if totalPayloadSize > routingPayloadLen {
214+ return nil , maxRoutingPayloadErr
225215 }
226216
227217 // Before we proceed, we'll check that the payload types of each hop
@@ -254,13 +244,13 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
254244
255245 // Generate the padding, called "filler strings" in the paper.
256246 filler := generateHeaderPadding (
257- "rho" , paymentPath , hopSharedSecrets , routingInfoLen ,
247+ "rho" , paymentPath , hopSharedSecrets , routingPayloadLen ,
258248 )
259249
260250 // Allocate zero'd out byte slices to store the final mix header packet
261251 // and the hmac for each hop.
262252 var (
263- mixHeader = make ([]byte , routingInfoLen )
253+ mixHeader = make ([]byte , routingPayloadLen )
264254 nextHmac [HMACSize ]byte
265255 hopPayloadBuf bytes.Buffer
266256 )
@@ -287,7 +277,7 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
287277 // Next, using the key dedicated for our stream cipher, we'll
288278 // generate enough bytes to obfuscate this layer of the onion
289279 // packet.
290- streamBytes := generateCipherStream (rhoKey , uint (routingInfoLen ))
280+ streamBytes := generateCipherStream (rhoKey , uint (routingPayloadLen ))
291281 payload := paymentPath [i ].HopPayload
292282
293283 // Before we assemble the packet, we'll shift the current
0 commit comments