@@ -151,7 +151,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
151
151
/// # use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext};
152
152
/// # use lightning::sign::{EntropySource, KeysManager};
153
153
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
154
- /// # use lightning::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger};
154
+ /// # use lightning::onion_message::messenger::{BlindedPathType, Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger};
155
155
/// # use lightning::onion_message::packet::OnionMessageContents;
156
156
/// # use lightning::util::logger::{Logger, Record};
157
157
/// # use lightning::util::ser::{Writeable, Writer};
@@ -175,7 +175,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
175
175
/// # })
176
176
/// # }
177
177
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
178
- /// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>
178
+ /// # &self, _recipient: PublicKey, _context: MessageContext, _blinded_path: BlindedPathType, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>
179
179
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
180
180
/// # unreachable!()
181
181
/// # }
@@ -449,14 +449,9 @@ pub trait MessageRouter {
449
449
450
450
/// Creates [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are assumed to
451
451
/// be direct peers with the `recipient`.
452
- fn create_blinded_paths <
453
- T : secp256k1:: Signing + secp256k1:: Verification
454
- > (
455
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > , secp_ctx : & Secp256k1 < T > ,
456
- ) -> Result < Vec < BlindedMessagePath > , ( ) > ;
457
-
458
- /// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
459
- /// assumed to be direct peers with the `recipient`.
452
+ ///
453
+ /// # Note of compact blinded path:
454
+ /// User can decide to create compact blinded path by specifying the appropirate [`BlindedPathType`].
460
455
///
461
456
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
462
457
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
@@ -465,24 +460,12 @@ pub trait MessageRouter {
465
460
/// Implementations using additional intermediate nodes are responsible for using a
466
461
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
467
462
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
468
- ///
469
- /// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
470
- /// ignoring the short channel ids.
471
- fn create_compact_blinded_paths <
463
+ fn create_blinded_paths <
472
464
T : secp256k1:: Signing + secp256k1:: Verification
473
465
> (
474
- & self , recipient : PublicKey , context : MessageContext ,
466
+ & self , recipient : PublicKey , context : MessageContext , blinded_path : BlindedPathType ,
475
467
peers : Vec < MessageForwardNode > , secp_ctx : & Secp256k1 < T > ,
476
- ) -> Result < Vec < BlindedMessagePath > , ( ) > {
477
- let peers = peers
478
- . into_iter ( )
479
- . map ( |mut node| {
480
- node. short_channel_id = None ;
481
- node
482
- } )
483
- . collect ( ) ;
484
- self . create_blinded_paths ( recipient, context, peers, secp_ctx)
485
- }
468
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > ;
486
469
}
487
470
488
471
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -516,8 +499,8 @@ where
516
499
I : ExactSizeIterator < Item = MessageForwardNode > ,
517
500
T : secp256k1:: Signing + secp256k1:: Verification
518
501
> (
519
- network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
520
- entropy_source : & ES , secp_ctx : & Secp256k1 < T > , compact_paths : bool ,
502
+ network_graph : & G , recipient : PublicKey , context : MessageContext , blinded_path : BlindedPathType ,
503
+ peers : I , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
521
504
) -> Result < Vec < BlindedMessagePath > , ( ) > {
522
505
// Limit the number of blinded paths that are computed.
523
506
const MAX_PATHS : usize = 3 ;
@@ -573,10 +556,13 @@ where
573
556
} ,
574
557
} ?;
575
558
576
- if compact_paths {
577
- for path in & mut paths {
578
- path. use_compact_introduction_node ( & network_graph) ;
559
+ match blinded_path {
560
+ BlindedPathType :: Compact => {
561
+ for path in & mut paths {
562
+ path. use_compact_introduction_node ( & network_graph) ;
563
+ }
579
564
}
565
+ BlindedPathType :: Full => { }
580
566
}
581
567
582
568
Ok ( paths)
@@ -618,25 +604,10 @@ where
618
604
pub ( crate ) fn create_blinded_paths <
619
605
T : secp256k1:: Signing + secp256k1:: Verification
620
606
> (
621
- network_graph : & G , recipient : PublicKey , context : MessageContext ,
607
+ network_graph : & G , recipient : PublicKey , context : MessageContext , blinded_path : BlindedPathType ,
622
608
peers : Vec < MessageForwardNode > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
623
609
) -> Result < Vec < BlindedMessagePath > , ( ) > {
624
- let peers = peers
625
- . into_iter ( )
626
- . map ( |mut node| {
627
- node. short_channel_id = None ;
628
- node
629
- } ) ;
630
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, false )
631
- }
632
-
633
- pub ( crate ) fn create_compact_blinded_paths <
634
- T : secp256k1:: Signing + secp256k1:: Verification
635
- > (
636
- network_graph : & G , recipient : PublicKey , context : MessageContext ,
637
- peers : Vec < MessageForwardNode > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
638
- ) -> Result < Vec < BlindedMessagePath > , ( ) > {
639
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, true )
610
+ Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, blinded_path, peers. into_iter ( ) , entropy_source, secp_ctx)
640
611
}
641
612
}
642
613
@@ -654,19 +625,11 @@ where
654
625
fn create_blinded_paths <
655
626
T : secp256k1:: Signing + secp256k1:: Verification
656
627
> (
657
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > , secp_ctx : & Secp256k1 < T > ,
658
- ) -> Result < Vec < BlindedMessagePath > , ( ) > {
659
- Self :: create_blinded_paths ( & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
660
- }
661
-
662
- fn create_compact_blinded_paths <
663
- T : secp256k1:: Signing + secp256k1:: Verification
664
- > (
665
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > , secp_ctx : & Secp256k1 < T > ,
628
+ & self , recipient : PublicKey , context : MessageContext , blinded_path : BlindedPathType ,
629
+ peers : Vec < MessageForwardNode > , secp_ctx : & Secp256k1 < T > ,
666
630
) -> Result < Vec < BlindedMessagePath > , ( ) > {
667
- Self :: create_compact_blinded_paths ( & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
631
+ Self :: create_blinded_paths ( & self . network_graph , recipient, context, blinded_path , peers, & self . entropy_source , secp_ctx)
668
632
}
669
-
670
633
}
671
634
672
635
/// A path for sending an [`OnionMessage`].
@@ -1266,7 +1229,7 @@ where
1266
1229
. collect :: < Vec < _ > > ( ) ;
1267
1230
1268
1231
self . message_router
1269
- . create_blinded_paths ( recipient, context, peers, secp_ctx)
1232
+ . create_blinded_paths ( recipient, context, BlindedPathType :: Full , peers, secp_ctx)
1270
1233
. and_then ( |paths| paths. into_iter ( ) . next ( ) . ok_or ( ( ) ) )
1271
1234
. map_err ( |_| SendError :: PathNotFound )
1272
1235
}
0 commit comments