@@ -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 , IntroductionNode } ;
18
+ use crate :: blinded_path:: { BlindedPath , 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 ,
@@ -579,13 +582,15 @@ pub enum PeeledOnion<T: OnionMessageContents> {
579
582
///
580
583
/// Returns the node id of the peer to send the message to, the message itself, and any addresses
581
584
/// need to connect to the first node.
582
- pub fn create_onion_message < ES : Deref , NS : Deref , T : OnionMessageContents > (
583
- entropy_source : & ES , node_signer : & NS , secp_ctx : & Secp256k1 < secp256k1:: All > ,
584
- path : OnionMessagePath , contents : T , reply_path : Option < BlindedPath > ,
585
+ pub fn create_onion_message < ES : Deref , NS : Deref , NL : Deref , T : OnionMessageContents > (
586
+ entropy_source : & ES , node_signer : & NS , node_id_lookup : & NL ,
587
+ secp_ctx : & Secp256k1 < secp256k1:: All > , path : OnionMessagePath , contents : T ,
588
+ reply_path : Option < BlindedPath > ,
585
589
) -> Result < ( PublicKey , OnionMessage , Option < Vec < SocketAddress > > ) , SendError >
586
590
where
587
591
ES :: Target : EntropySource ,
588
592
NS :: Target : NodeSigner ,
593
+ NL :: Target : NodeIdLookUp ,
589
594
{
590
595
let OnionMessagePath { intermediate_nodes, mut destination, first_node_addresses } = path;
591
596
if let Destination :: BlindedPath ( BlindedPath { ref blinded_hops, .. } ) = destination {
@@ -609,7 +614,7 @@ where
609
614
let our_node_id = node_signer. get_node_id ( Recipient :: Node )
610
615
. map_err ( |( ) | SendError :: GetNodeIdFailed ) ?;
611
616
if introduction_node_id == our_node_id {
612
- advance_path_by_one ( blinded_path, node_signer, & secp_ctx)
617
+ advance_path_by_one ( blinded_path, node_signer, node_id_lookup , & secp_ctx)
613
618
. map_err ( |( ) | SendError :: BlindedPathAdvanceFailed ) ?;
614
619
}
615
620
}
@@ -741,21 +746,22 @@ where
741
746
}
742
747
}
743
748
744
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref >
745
- OnionMessenger < ES , NS , L , MR , OMH , CMH >
749
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref >
750
+ OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
746
751
where
747
752
ES :: Target : EntropySource ,
748
753
NS :: Target : NodeSigner ,
749
754
L :: Target : Logger ,
755
+ NL :: Target : NodeIdLookUp ,
750
756
MR :: Target : MessageRouter ,
751
757
OMH :: Target : OffersMessageHandler ,
752
758
CMH :: Target : CustomOnionMessageHandler ,
753
759
{
754
760
/// Constructs a new `OnionMessenger` to send, forward, and delegate received onion messages to
755
761
/// their respective handlers.
756
762
pub fn new (
757
- entropy_source : ES , node_signer : NS , logger : L , message_router : MR , offers_handler : OMH ,
758
- custom_handler : CMH
763
+ entropy_source : ES , node_signer : NS , logger : L , node_id_lookup : NL , message_router : MR ,
764
+ offers_handler : OMH , custom_handler : CMH
759
765
) -> Self {
760
766
let mut secp_ctx = Secp256k1 :: new ( ) ;
761
767
secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
@@ -765,6 +771,7 @@ where
765
771
message_recipients : Mutex :: new ( new_hash_map ( ) ) ,
766
772
secp_ctx,
767
773
logger,
774
+ node_id_lookup,
768
775
message_router,
769
776
offers_handler,
770
777
custom_handler,
@@ -847,7 +854,8 @@ where
847
854
log_trace ! ( self . logger, "Constructing onion message {}: {:?}" , log_suffix, contents) ;
848
855
849
856
let ( first_node_id, onion_message, addresses) = create_onion_message (
850
- & self . entropy_source , & self . node_signer , & self . secp_ctx , path, contents, reply_path
857
+ & self . entropy_source , & self . node_signer , & self . node_id_lookup , & self . secp_ctx , path,
858
+ contents, reply_path,
851
859
) ?;
852
860
853
861
let mut message_recipients = self . message_recipients . lock ( ) . unwrap ( ) ;
@@ -943,12 +951,13 @@ fn outbound_buffer_full(peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, On
943
951
false
944
952
}
945
953
946
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref > EventsProvider
947
- for OnionMessenger < ES , NS , L , MR , OMH , CMH >
954
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref > EventsProvider
955
+ for OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
948
956
where
949
957
ES :: Target : EntropySource ,
950
958
NS :: Target : NodeSigner ,
951
959
L :: Target : Logger ,
960
+ NL :: Target : NodeIdLookUp ,
952
961
MR :: Target : MessageRouter ,
953
962
OMH :: Target : OffersMessageHandler ,
954
963
CMH :: Target : CustomOnionMessageHandler ,
@@ -964,12 +973,13 @@ where
964
973
}
965
974
}
966
975
967
- impl < ES : Deref , NS : Deref , L : Deref , MR : Deref , OMH : Deref , CMH : Deref > OnionMessageHandler
968
- for OnionMessenger < ES , NS , L , MR , OMH , CMH >
976
+ impl < ES : Deref , NS : Deref , L : Deref , NL : Deref , MR : Deref , OMH : Deref , CMH : Deref > OnionMessageHandler
977
+ for OnionMessenger < ES , NS , L , NL , MR , OMH , CMH >
969
978
where
970
979
ES :: Target : EntropySource ,
971
980
NS :: Target : NodeSigner ,
972
981
L :: Target : Logger ,
982
+ NL :: Target : NodeIdLookUp ,
973
983
MR :: Target : MessageRouter ,
974
984
OMH :: Target : OffersMessageHandler ,
975
985
CMH :: Target : CustomOnionMessageHandler ,
@@ -1007,7 +1017,13 @@ where
1007
1017
Ok ( PeeledOnion :: Forward ( next_hop, onion_message) ) => {
1008
1018
let next_node_id = match next_hop {
1009
1019
NextHop :: NodeId ( pubkey) => pubkey,
1010
- NextHop :: ShortChannelId ( _) => todo ! ( ) ,
1020
+ NextHop :: ShortChannelId ( scid) => match self . node_id_lookup . next_node_id ( scid) {
1021
+ Some ( pubkey) => pubkey,
1022
+ None => {
1023
+ log_trace ! ( self . logger, "Dropping forwarded onion message to unresolved peer using SCID {}" , scid) ;
1024
+ return
1025
+ } ,
1026
+ } ,
1011
1027
} ;
1012
1028
1013
1029
let mut message_recipients = self . message_recipients . lock ( ) . unwrap ( ) ;
@@ -1145,6 +1161,7 @@ pub type SimpleArcOnionMessenger<M, T, F, L> = OnionMessenger<
1145
1161
Arc < KeysManager > ,
1146
1162
Arc < KeysManager > ,
1147
1163
Arc < L > ,
1164
+ Arc < SimpleArcChannelManager < M , T , F , L > > ,
1148
1165
Arc < DefaultMessageRouter < Arc < NetworkGraph < Arc < L > > > , Arc < L > , Arc < KeysManager > > > ,
1149
1166
Arc < SimpleArcChannelManager < M , T , F , L > > ,
1150
1167
IgnoringMessageHandler
@@ -1164,8 +1181,9 @@ pub type SimpleRefOnionMessenger<
1164
1181
& ' a KeysManager ,
1165
1182
& ' a KeysManager ,
1166
1183
& ' b L ,
1167
- & ' i DefaultMessageRouter < & ' g NetworkGraph < & ' b L > , & ' b L , & ' a KeysManager > ,
1168
- & ' j SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1184
+ & ' i SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1185
+ & ' j DefaultMessageRouter < & ' g NetworkGraph < & ' b L > , & ' b L , & ' a KeysManager > ,
1186
+ & ' i SimpleRefChannelManager < ' a , ' b , ' c , ' d , ' e , ' f , ' g , ' h , M , T , F , L > ,
1169
1187
IgnoringMessageHandler
1170
1188
> ;
1171
1189
0 commit comments