@@ -17,7 +17,10 @@ use super::async_payments::AsyncPaymentsMessage;
17
17
use super :: dns_resolution:: DNSResolverMessage ;
18
18
use super :: messenger:: CustomOnionMessageHandler ;
19
19
use super :: offers:: OffersMessage ;
20
- use crate :: blinded_path:: message:: { BlindedMessagePath , ForwardTlvs , NextMessageHop , ReceiveTlvs } ;
20
+ use crate :: blinded_path:: message:: {
21
+ BlindedMessagePath , DummyTlv , ForwardTlvs , NextMessageHop , PrimaryDummyTlv , ReceiveTlvs ,
22
+ UnauthenticatedDummyTlv ,
23
+ } ;
21
24
use crate :: crypto:: streams:: { ChaChaPolyReadAdapter , ChaChaPolyWriteAdapter } ;
22
25
use crate :: ln:: msgs:: DecodeError ;
23
26
use crate :: ln:: onion_utils;
@@ -111,6 +114,8 @@ impl LengthReadable for Packet {
111
114
pub ( super ) enum Payload < T : OnionMessageContents > {
112
115
/// This payload is for an intermediate hop.
113
116
Forward ( ForwardControlTlvs ) ,
117
+ /// This payload is dummy, and is inteded to be peeled.
118
+ Dummy ( DummyControlTlvs ) ,
114
119
/// This payload is for the final hop.
115
120
Receive { control_tlvs : ReceiveControlTlvs , reply_path : Option < BlindedMessagePath > , message : T } ,
116
121
}
@@ -204,6 +209,11 @@ pub(super) enum ForwardControlTlvs {
204
209
Unblinded ( ForwardTlvs ) ,
205
210
}
206
211
212
+ pub ( super ) enum DummyControlTlvs {
213
+ /// See [`ForwardControlTlvs::Unblinded`]
214
+ Unblinded ( DummyTlv ) ,
215
+ }
216
+
207
217
/// Receive control TLVs in their blinded and unblinded form.
208
218
pub ( super ) enum ReceiveControlTlvs {
209
219
/// See [`ForwardControlTlvs::Blinded`].
@@ -234,6 +244,10 @@ impl<T: OnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
234
244
let write_adapter = ChaChaPolyWriteAdapter :: new ( self . 1 , & control_tlvs) ;
235
245
_encode_varint_length_prefixed_tlv ! ( w, { ( 4 , write_adapter, required) } )
236
246
} ,
247
+ Payload :: Dummy ( DummyControlTlvs :: Unblinded ( control_tlvs) ) => {
248
+ let write_adapter = ChaChaPolyWriteAdapter :: new ( self . 1 , & control_tlvs) ;
249
+ _encode_varint_length_prefixed_tlv ! ( w, { ( 4 , write_adapter, required) } )
250
+ } ,
237
251
Payload :: Receive {
238
252
control_tlvs : ReceiveControlTlvs :: Unblinded ( control_tlvs) ,
239
253
reply_path,
@@ -310,6 +324,9 @@ impl<H: CustomOnionMessageHandler + ?Sized, L: Logger + ?Sized> ReadableArgs<(Sh
310
324
}
311
325
Ok ( Payload :: Forward ( ForwardControlTlvs :: Unblinded ( tlvs) ) )
312
326
} ,
327
+ Some ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Dummy ( tlvs) } ) => {
328
+ Ok ( Payload :: Dummy ( DummyControlTlvs :: Unblinded ( tlvs) ) )
329
+ } ,
313
330
Some ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Receive ( tlvs) } ) => {
314
331
Ok ( Payload :: Receive {
315
332
control_tlvs : ReceiveControlTlvs :: Unblinded ( tlvs) ,
@@ -328,6 +345,8 @@ impl<H: CustomOnionMessageHandler + ?Sized, L: Logger + ?Sized> ReadableArgs<(Sh
328
345
pub ( crate ) enum ControlTlvs {
329
346
/// This onion message is intended to be forwarded.
330
347
Forward ( ForwardTlvs ) ,
348
+ /// This onion message is a dummy, and is intended to be peeled.
349
+ Dummy ( DummyTlv ) ,
331
350
/// This onion message is intended to be received.
332
351
Receive ( ReceiveTlvs ) ,
333
352
}
@@ -343,6 +362,8 @@ impl Readable for ControlTlvs {
343
362
( 4 , next_node_id, option) ,
344
363
( 8 , next_blinding_override, option) ,
345
364
( 65537 , context, option) ,
365
+ ( 65539 , authentication, option) ,
366
+ ( 65541 , dummy_tlv, option) ,
346
367
} ) ;
347
368
348
369
let next_hop = match ( short_channel_id, next_node_id) {
@@ -352,18 +373,18 @@ impl Readable for ControlTlvs {
352
373
( None , None ) => None ,
353
374
} ;
354
375
355
- let valid_fwd_fmt = next_hop . is_some ( ) ;
356
- let valid_recv_fmt = next_hop . is_none ( ) && next_blinding_override . is_none ( ) ;
357
-
358
- let payload_fmt = if valid_fwd_fmt {
359
- ControlTlvs :: Forward ( ForwardTlvs {
360
- next_hop : next_hop . unwrap ( ) ,
361
- next_blinding_override ,
362
- } )
363
- } else if valid_recv_fmt {
364
- ControlTlvs :: Receive ( ReceiveTlvs { context } )
365
- } else {
366
- return Err ( DecodeError :: InvalidValue ) ;
376
+ let payload_fmt = match ( dummy_tlv , next_hop , next_blinding_override , authentication ) {
377
+ ( None , Some ( hop ) , _ , None ) => {
378
+ ControlTlvs :: Forward ( ForwardTlvs { next_hop : hop , next_blinding_override } )
379
+ } ,
380
+ ( None , None , None , None ) => ControlTlvs :: Receive ( ReceiveTlvs { context } ) ,
381
+ ( Some ( ( ) ) , None , None , Some ( auth ) ) => {
382
+ let tlv =
383
+ PrimaryDummyTlv { dummy_tlv : UnauthenticatedDummyTlv { } , authentication : auth } ;
384
+ ControlTlvs :: Dummy ( DummyTlv :: Primary ( tlv ) )
385
+ } ,
386
+ ( Some ( ( ) ) , None , None , None ) => ControlTlvs :: Dummy ( DummyTlv :: Subsequent ) ,
387
+ _ => return Err ( DecodeError :: InvalidValue ) ,
367
388
} ;
368
389
369
390
Ok ( payload_fmt)
@@ -374,6 +395,7 @@ impl Writeable for ControlTlvs {
374
395
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
375
396
match self {
376
397
Self :: Forward ( tlvs) => tlvs. write ( w) ,
398
+ Self :: Dummy ( tlvs) => tlvs. write ( w) ,
377
399
Self :: Receive ( tlvs) => tlvs. write ( w) ,
378
400
}
379
401
}
0 commit comments