@@ -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
@@ -235,16 +225,16 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
235225
236226 totalPayloadSize := paymentPath .TotalPayloadSize ()
237227
238- routingInfoLen := StandardRoutingInfoSize
239- maxRoutingInfoErr := ErrStandardRoutingPayloadSizeExceeded
240- if cfg .isOnionMessage && totalPayloadSize > StandardRoutingInfoSize {
241- routingInfoLen = JumboRoutingInfoSize
242- maxRoutingInfoErr = ErrMessageRoutingPayloadSizeExceeded
228+ routingPayloadLen := MaxRoutingPayloadSize
229+ maxRoutingPayloadErr := ErrStandardRoutingPayloadSizeExceeded
230+ if cfg .isOnionMessage && totalPayloadSize > MaxRoutingPayloadSize {
231+ routingPayloadLen = MaxOnionMessagePayloadSize
232+ maxRoutingPayloadErr = ErrMessageRoutingPayloadSizeExceeded
243233 }
244234
245235 // Check whether total payload size doesn't exceed the hard maximum.
246- if totalPayloadSize > routingInfoLen {
247- return nil , maxRoutingInfoErr
236+ if totalPayloadSize > routingPayloadLen {
237+ return nil , maxRoutingPayloadErr
248238 }
249239
250240 // Before we proceed, we'll check that the payload types of each hop
@@ -277,13 +267,13 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
277267
278268 // Generate the padding, called "filler strings" in the paper.
279269 filler := generateHeaderPadding (
280- "rho" , paymentPath , hopSharedSecrets , routingInfoLen ,
270+ "rho" , paymentPath , hopSharedSecrets , routingPayloadLen ,
281271 )
282272
283273 // Allocate zero'd out byte slices to store the final mix header packet
284274 // and the hmac for each hop.
285275 var (
286- mixHeader = make ([]byte , routingInfoLen )
276+ mixHeader = make ([]byte , routingPayloadLen )
287277 nextHmac [HMACSize ]byte
288278 hopPayloadBuf bytes.Buffer
289279 )
@@ -310,7 +300,7 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
310300 // Next, using the key dedicated for our stream cipher, we'll
311301 // generate enough bytes to obfuscate this layer of the onion
312302 // packet.
313- streamBytes := generateCipherStream (rhoKey , uint (routingInfoLen ))
303+ streamBytes := generateCipherStream (rhoKey , uint (routingPayloadLen ))
314304 payload := paymentPath [i ].HopPayload
315305
316306 // Before we assemble the packet, we'll shift the current
0 commit comments