@@ -704,6 +704,114 @@ where
704
704
}
705
705
}
706
706
707
+ /// This message router is similar to [`DefaultMessageRouter`], but it always creates
708
+ /// full-length blinded paths, using the peer's [`NodeId`].
709
+ ///
710
+ /// This message router can only route to a directly connected [`Destination`].
711
+ ///
712
+ /// # Privacy
713
+ ///
714
+ /// Creating [`BlindedMessagePath`]s may affect privacy since, if a suitable path cannot be found,
715
+ /// it will create a one-hop path using the recipient as the introduction node if it is a announced
716
+ /// node. Otherwise, there is no way to find a path to the introduction node in order to send a
717
+ /// message, and thus an `Err` is returned.
718
+ pub struct NodeIdMessageRouter < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref >
719
+ where
720
+ L :: Target : Logger ,
721
+ ES :: Target : EntropySource ,
722
+ {
723
+ network_graph : G ,
724
+ entropy_source : ES ,
725
+ }
726
+
727
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref > NodeIdMessageRouter < G , L , ES >
728
+ where
729
+ L :: Target : Logger ,
730
+ ES :: Target : EntropySource ,
731
+ {
732
+ /// Creates a [`DefaultMessageRouter`] using the given [`NetworkGraph`].
733
+ pub fn new ( network_graph : G , entropy_source : ES ) -> Self {
734
+ Self { network_graph, entropy_source }
735
+ }
736
+ }
737
+
738
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter
739
+ for NodeIdMessageRouter < G , L , ES >
740
+ where
741
+ L :: Target : Logger ,
742
+ ES :: Target : EntropySource ,
743
+ {
744
+ fn find_path (
745
+ & self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination ,
746
+ ) -> Result < OnionMessagePath , ( ) > {
747
+ DefaultMessageRouter :: < G , L , ES > :: find_path ( & self . network_graph , sender, peers, destination)
748
+ }
749
+
750
+ fn create_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
751
+ & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > ,
752
+ secp_ctx : & Secp256k1 < T > ,
753
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
754
+ DefaultMessageRouter :: create_blinded_paths_from_iter (
755
+ & self . network_graph ,
756
+ recipient,
757
+ context,
758
+ peers. into_iter ( ) ,
759
+ & self . entropy_source ,
760
+ secp_ctx,
761
+ false ,
762
+ )
763
+ }
764
+
765
+ fn create_compact_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
766
+ & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > ,
767
+ secp_ctx : & Secp256k1 < T > ,
768
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
769
+ DefaultMessageRouter :: create_blinded_paths_from_iter (
770
+ & self . network_graph ,
771
+ recipient,
772
+ context,
773
+ peers. into_iter ( ) ,
774
+ & self . entropy_source ,
775
+ secp_ctx,
776
+ false ,
777
+ )
778
+ }
779
+ }
780
+
781
+ /// A special [`MessageRouter`] implementation that performs no routing.
782
+ ///
783
+ /// # Note
784
+ /// [`NullMessageRouter`] **must not** be used with [`ChannelManager`] as a parameter.
785
+ ///
786
+ /// # Reason
787
+ /// [`ChannelManager`] requires a functioning [`MessageRouter`] to create blinded paths,
788
+ /// which are necessary for constructing reply paths in onion message communication.
789
+ ///
790
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
791
+ pub struct NullMessageRouter { }
792
+
793
+ impl MessageRouter for NullMessageRouter {
794
+ fn find_path (
795
+ & self , _sender : PublicKey , _peers : Vec < PublicKey > , _destination : Destination ,
796
+ ) -> Result < OnionMessagePath , ( ) > {
797
+ unreachable ! ( )
798
+ }
799
+
800
+ fn create_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
801
+ & self , _recipient : PublicKey , _context : MessageContext , _peers : Vec < MessageForwardNode > ,
802
+ _secp_ctx : & Secp256k1 < T > ,
803
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
804
+ Ok ( vec ! [ ] )
805
+ }
806
+
807
+ fn create_compact_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
808
+ & self , _recipient : PublicKey , _context : MessageContext , _peers : Vec < MessageForwardNode > ,
809
+ _secp_ctx : & Secp256k1 < T > ,
810
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
811
+ Ok ( vec ! [ ] )
812
+ }
813
+ }
814
+
707
815
/// A path for sending an [`OnionMessage`].
708
816
#[ derive( Clone ) ]
709
817
pub struct OnionMessagePath {
0 commit comments