@@ -15,7 +15,7 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
15
15
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
16
16
use bitcoin:: secp256k1:: { self , PublicKey , Scalar , Secp256k1 , SecretKey } ;
17
17
18
- use crate :: blinded_path:: { BlindedPath , Direction , IntroductionNode } ;
18
+ use crate :: blinded_path:: { BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
19
19
use crate :: blinded_path:: message:: { advance_path_by_one, ForwardTlvs , NextHop , ReceiveTlvs } ;
20
20
use crate :: blinded_path:: utils;
21
21
use crate :: events:: { Event , EventHandler , EventsProvider } ;
@@ -70,7 +70,7 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
70
70
/// # use bitcoin::hashes::_export::_core::time::Duration;
71
71
/// # use bitcoin::hashes::hex::FromHex;
72
72
/// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey, self};
73
- /// # use lightning::blinded_path::BlindedPath;
73
+ /// # use lightning::blinded_path::{ BlindedPath, EmptyNodeIdLookUp} ;
74
74
/// # use lightning::sign::{EntropySource, KeysManager};
75
75
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
76
76
/// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
@@ -111,14 +111,15 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
111
111
/// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
112
112
/// # let (hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1);
113
113
/// # let destination_node_id = hop_node_id1;
114
+ /// # let node_id_lookup = EmptyNodeIdLookUp {};
114
115
/// # let message_router = Arc::new(FakeMessageRouter {});
115
116
/// # let custom_message_handler = IgnoringMessageHandler {};
116
117
/// # let offers_message_handler = IgnoringMessageHandler {};
117
118
/// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
118
119
/// // ChannelManager.
119
120
/// let onion_messenger = OnionMessenger::new(
120
- /// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler ,
121
- /// &custom_message_handler
121
+ /// &keys_manager, &keys_manager, logger, &node_id_lookup, message_router ,
122
+ /// &offers_message_handler, & custom_message_handler
122
123
/// );
123
124
124
125
/// # #[derive(Debug)]
@@ -155,11 +156,12 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
155
156
///
156
157
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
157
158
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
158
- pub struct OnionMessenger < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref >
159
+ pub struct OnionMessenger < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref >
159
160
where
160
161
ES :: Target : EntropySource ,
161
162
NS :: Target : NodeSigner ,
162
163
L :: Target : Logger ,
164
+ NL :: Target : NodeIdLookUp ,
163
165
MR :: Target : MessageRouter ,
164
166
OMH :: Target : OffersMessageHandler ,
165
167
CMH :: Target : CustomOnionMessageHandler ,
@@ -169,6 +171,7 @@ where
169
171
logger : L ,
170
172
message_recipients : Mutex < HashMap < PublicKey , OnionMessageRecipient > > ,
171
173
secp_ctx : Secp256k1 < secp256k1:: All > ,
174
+ node_id_lookup : NL ,
172
175
message_router : MR ,
173
176
offers_handler : OMH ,
174
177
custom_handler : CMH ,
@@ -584,13 +587,15 @@ pub enum PeeledOnion<T: OnionMessageContents> {
584
587
///
585
588
/// Returns the node id of the peer to send the message to, the message itself, and any addresses
586
589
/// need to connect to the first node.
587
- pub fn create_onion_message < ES : Deref , NS : Deref , T : OnionMessageContents > (
588
- entropy_source : & ES , node_signer : & NS , secp_ctx : & Secp256k1 < secp256k1:: All > ,
589
- path : OnionMessagePath , contents : T , reply_path : Option < BlindedPath > ,
590
+ pub fn create_onion_message < ES : Deref , NS : Deref , NL : Deref , T : OnionMessageContents > (
591
+ entropy_source : & ES , node_signer : & NS , node_id_lookup : & NL ,
592
+ secp_ctx : & Secp256k1 < secp256k1:: All > , path : OnionMessagePath , contents : T ,
593
+ reply_path : Option < BlindedPath > ,
590
594
) -> Result < ( PublicKey , OnionMessage , Option < Vec < SocketAddress > > ) , SendError >
591
595
where
592
596
ES :: Target : EntropySource ,
593
597
NS :: Target : NodeSigner ,
598
+ NL :: Target : NodeIdLookUp ,
594
599
{
595
600
let OnionMessagePath { intermediate_nodes, mut destination, first_node_addresses } = path;
596
601
if let Destination :: BlindedPath ( BlindedPath { ref blinded_hops, .. } ) = destination {
@@ -614,7 +619,7 @@ where
614
619
let our_node_id = node_signer. get_node_id ( Recipient :: Node )
615
620
. map_err ( |( ) | SendError :: GetNodeIdFailed ) ?;
616
621
if introduction_node_id == our_node_id {
617
- advance_path_by_one ( blinded_path, node_signer, & secp_ctx)
622
+ advance_path_by_one ( blinded_path, node_signer, node_id_lookup , & secp_ctx)
618
623
. map_err ( |( ) | SendError :: BlindedPathAdvanceFailed ) ?;
619
624
}
620
625
}
@@ -746,21 +751,22 @@ where
746
751
}
747
752
}
748
753
749
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref >
750
- OnionMessenger < ES , NS , L , MR , OMH , CMH >
754
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref >
755
+ OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
751
756
where
752
757
ES :: Target : EntropySource ,
753
758
NS :: Target : NodeSigner ,
754
759
L :: Target : Logger ,
760
+ NL :: Target : NodeIdLookUp ,
755
761
MR :: Target : MessageRouter ,
756
762
OMH :: Target : OffersMessageHandler ,
757
763
CMH :: Target : CustomOnionMessageHandler ,
758
764
{
759
765
/// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
760
766
/// their respective handlers.
761
767
pub fn new (
762
- entropy_source : ES , node_signer : NS , logger : L , message_router : MR , offers_handler : OMH ,
763
- custom_handler : CMH
768
+ entropy_source : ES , node_signer : NS , logger : L , node_id_lookup : NL , message_router : MR ,
769
+ offers_handler : OMH , custom_handler : CMH
764
770
) -> Self {
765
771
let mut secp_ctx = Secp256k1 :: new ( ) ;
766
772
secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
@@ -770,6 +776,7 @@ where
770
776
message_recipients : Mutex :: new ( new_hash_map ( ) ) ,
771
777
secp_ctx,
772
778
logger,
779
+ node_id_lookup,
773
780
message_router,
774
781
offers_handler,
775
782
custom_handler,
@@ -846,7 +853,8 @@ where
846
853
log_trace ! ( self . logger, "Constructing onion message {}: {:?}" , log_suffix, contents) ;
847
854
848
855
let ( first_node_id, onion_message, addresses) = create_onion_message (
849
- & self . entropy_source , & self . node_signer , & self . secp_ctx , path, contents, reply_path
856
+ & self . entropy_source , & self . node_signer , & self . node_id_lookup , & self . secp_ctx , path,
857
+ contents, reply_path,
850
858
) ?;
851
859
852
860
let mut message_recipients = self . message_recipients . lock ( ) . unwrap ( ) ;
@@ -942,12 +950,13 @@ fn outbound_buffer_full(peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, On
942
950
false
943
951
}
944
952
945
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref > EventsProvider
946
- for OnionMessenger < ES , NS , L , MR , OMH , CMH >
953
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref > EventsProvider
954
+ for OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
947
955
where
948
956
ES :: Target : EntropySource ,
949
957
NS :: Target : NodeSigner ,
950
958
L :: Target : Logger ,
959
+ NL :: Target : NodeIdLookUp ,
951
960
MR :: Target : MessageRouter ,
952
961
OMH :: Target : OffersMessageHandler ,
953
962
CMH :: Target : CustomOnionMessageHandler ,
@@ -963,12 +972,13 @@ where
963
972
}
964
973
}
965
974
966
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref > OnionMessageHandler
967
- for OnionMessenger < ES , NS , L , MR , OMH , CMH >
975
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref > OnionMessageHandler
976
+ for OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
968
977
where
969
978
ES :: Target : EntropySource ,
970
979
NS :: Target : NodeSigner ,
971
980
L :: Target : Logger ,
981
+ NL :: Target : NodeIdLookUp ,
972
982
MR :: Target : MessageRouter ,
973
983
OMH :: Target : OffersMessageHandler ,
974
984
CMH :: Target : CustomOnionMessageHandler ,
@@ -1005,7 +1015,13 @@ where
1005
1015
Ok ( PeeledOnion :: Forward ( next_hop, onion_message) ) => {
1006
1016
let next_node_id = match next_hop {
1007
1017
NextHop :: NodeId ( pubkey) => pubkey,
1008
- NextHop :: ShortChannelId ( _) => todo ! ( ) ,
1018
+ NextHop :: ShortChannelId ( scid) => match self . node_id_lookup . next_node_id ( scid) {
1019
+ Some ( pubkey) => pubkey,
1020
+ None => {
1021
+ log_trace ! ( self . logger, "Dropping forwarded onion message to unresolved peer using SCID {}" , scid) ;
1022
+ return
1023
+ } ,
1024
+ } ,
1009
1025
} ;
1010
1026
1011
1027
let mut message_recipients = self . message_recipients . lock ( ) . unwrap ( ) ;
@@ -1137,6 +1153,7 @@ pub type SimpleArcOnionMessenger<M, T, F, L> = OnionMessenger<
1137
1153
Arc < KeysManager > ,
1138
1154
Arc < KeysManager > ,
1139
1155
Arc < L > ,
1156
+ Arc < SimpleArcChannelManager < M , T , F , L > > ,
1140
1157
Arc < DefaultMessageRouter < Arc < NetworkGraph < Arc < L > > > , Arc < L > , Arc < KeysManager > > > ,
1141
1158
Arc < SimpleArcChannelManager < M , T , F , L > > ,
1142
1159
IgnoringMessageHandler
@@ -1156,8 +1173,9 @@ pub type SimpleRefOnionMessenger<
1156
1173
& ' a KeysManager ,
1157
1174
& ' a KeysManager ,
1158
1175
& ' b L ,
1159
- & ' i DefaultMessageRouter < & ' g NetworkGraph < & ' b L > , & ' b L , & ' a KeysManager > ,
1160
- & ' j SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1176
+ & ' i SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1177
+ & ' j DefaultMessageRouter < & ' g NetworkGraph < & ' b L > , & ' b L , & ' a KeysManager > ,
1178
+ & ' i SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1161
1179
IgnoringMessageHandler
1162
1180
> ;
1163
1181
0 commit comments