@@ -700,6 +700,103 @@ where
700
700
}
701
701
}
702
702
703
+ /// A [`MessageRouter`] that can only route to a directly connected [`Destination`],
704
+ /// and tries to create compact blinded path for that purpose.
705
+ ///
706
+ /// # Privacy
707
+ ///
708
+ /// Creating [`BlindedMessagePath`]s may affect privacy since, if a suitable path cannot be found,
709
+ /// it will create a one-hop path using the recipient as the introduction node if it is a announced
710
+ /// node. Otherwise, there is no way to find a path to the introduction node in order to send a
711
+ /// message, and thus an `Err` is returned.
712
+ pub struct CompactMessageRouter < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref >
713
+ where
714
+ L :: Target : Logger ,
715
+ ES :: Target : EntropySource ,
716
+ {
717
+ network_graph : G ,
718
+ entropy_source : ES ,
719
+ }
720
+
721
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref > CompactMessageRouter < G , L , ES >
722
+ where
723
+ L :: Target : Logger ,
724
+ ES :: Target : EntropySource ,
725
+ {
726
+ /// Creates a [`DefaultMessageRouter`] using the given [`NetworkGraph`].
727
+ pub fn new ( network_graph : G , entropy_source : ES ) -> Self {
728
+ Self { network_graph, entropy_source }
729
+ }
730
+ }
731
+
732
+ impl < G : Deref < Target = NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter
733
+ for CompactMessageRouter < G , L , ES >
734
+ where
735
+ L :: Target : Logger ,
736
+ ES :: Target : EntropySource ,
737
+ {
738
+ fn find_path (
739
+ & self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination ,
740
+ ) -> Result < OnionMessagePath , ( ) > {
741
+ DefaultMessageRouter :: < G , L , ES > :: find_path ( & self . network_graph , sender, peers, destination)
742
+ }
743
+
744
+ fn create_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
745
+ & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > ,
746
+ secp_ctx : & Secp256k1 < T > ,
747
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
748
+ DefaultMessageRouter :: create_blinded_paths_from_iter (
749
+ & self . network_graph ,
750
+ recipient,
751
+ context,
752
+ peers. into_iter ( ) ,
753
+ & self . entropy_source ,
754
+ secp_ctx,
755
+ true ,
756
+ )
757
+ }
758
+
759
+ fn create_compact_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
760
+ & self , recipient : PublicKey , context : MessageContext , peers : Vec < MessageForwardNode > ,
761
+ secp_ctx : & Secp256k1 < T > ,
762
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
763
+ DefaultMessageRouter :: create_blinded_paths_from_iter (
764
+ & self . network_graph ,
765
+ recipient,
766
+ context,
767
+ peers. into_iter ( ) ,
768
+ & self . entropy_source ,
769
+ secp_ctx,
770
+ true ,
771
+ )
772
+ }
773
+ }
774
+
775
+ /// A special [`MessageRouter`] that can doesn't route.
776
+ pub struct NullMessageRouter { }
777
+
778
+ impl MessageRouter for NullMessageRouter {
779
+ fn find_path (
780
+ & self , _sender : PublicKey , _peers : Vec < PublicKey > , _destination : Destination ,
781
+ ) -> Result < OnionMessagePath , ( ) > {
782
+ unreachable ! ( )
783
+ }
784
+
785
+ fn create_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
786
+ & self , _recipient : PublicKey , _context : MessageContext , _peers : Vec < MessageForwardNode > ,
787
+ _secp_ctx : & Secp256k1 < T > ,
788
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
789
+ Ok ( vec ! [ ] )
790
+ }
791
+
792
+ fn create_compact_blinded_paths < T : secp256k1:: Signing + secp256k1:: Verification > (
793
+ & self , _recipient : PublicKey , _context : MessageContext , _peers : Vec < MessageForwardNode > ,
794
+ _secp_ctx : & Secp256k1 < T > ,
795
+ ) -> Result < Vec < BlindedMessagePath > , ( ) > {
796
+ Ok ( vec ! [ ] )
797
+ }
798
+ }
799
+
703
800
/// A path for sending an [`OnionMessage`].
704
801
#[ derive( Clone ) ]
705
802
pub struct OnionMessagePath {
0 commit comments