@@ -64,9 +64,9 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
64
64
/// # extern crate bitcoin;
65
65
/// # use bitcoin::hashes::_export::_core::time::Duration;
66
66
/// # use bitcoin::hashes::hex::FromHex;
67
- /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
67
+ /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey, self };
68
68
/// # use lightning::blinded_path::BlindedPath;
69
- /// # use lightning::sign::KeysManager;
69
+ /// # use lightning::sign::{EntropySource, KeysManager} ;
70
70
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
71
71
/// # use lightning::onion_message::{OnionMessageContents, Destination, MessageRouter, OnionMessagePath, OnionMessenger};
72
72
/// # use lightning::util::logger::{Logger, Record};
@@ -90,6 +90,11 @@ pub(super) const MAX_TIMER_TICKS: usize = 2;
90
90
/// # first_node_addresses: None,
91
91
/// # })
92
92
/// # }
93
+ /// # fn create_blinded_paths<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
94
+ /// # &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
95
+ /// # ) -> Result<Vec<BlindedPath>, ()> {
96
+ /// # unreachable!()
97
+ /// # }
93
98
/// # }
94
99
/// # let seed = [42u8; 32];
95
100
/// # let time = Duration::from_secs(123456);
@@ -270,6 +275,15 @@ pub trait MessageRouter {
270
275
fn find_path (
271
276
& self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination
272
277
) -> Result < OnionMessagePath , ( ) > ;
278
+
279
+ /// Creates [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed to be
280
+ /// direct peers with the `recipient`.
281
+ fn create_blinded_paths <
282
+ ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
283
+ > (
284
+ & self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
285
+ secp_ctx : & Secp256k1 < T >
286
+ ) -> Result < Vec < BlindedPath > , ( ) > ;
273
287
}
274
288
275
289
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -321,6 +335,35 @@ where
321
335
}
322
336
}
323
337
}
338
+
339
+ fn create_blinded_paths <
340
+ ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
341
+ > (
342
+ & self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
343
+ secp_ctx : & Secp256k1 < T >
344
+ ) -> Result < Vec < BlindedPath > , ( ) > {
345
+ // Limit the number of blinded paths that are computed.
346
+ const MAX_PATHS : usize = 3 ;
347
+
348
+ // Ensure peers have at least three channels so that it is more difficult to infer the
349
+ // recipient's node_id.
350
+ const MIN_PEER_CHANNELS : usize = 3 ;
351
+
352
+ let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
353
+ peers. into_iter ( )
354
+ // Limit to peers with announced channels
355
+ . filter ( |pubkey|
356
+ network_graph
357
+ . node ( & NodeId :: from_pubkey ( & pubkey) )
358
+ . map ( |info| & info. channels [ ..] )
359
+ . map ( |channels| channels. len ( ) >= MIN_PEER_CHANNELS )
360
+ . unwrap_or ( false )
361
+ )
362
+ . map ( |pubkey| vec ! [ pubkey, recipient] )
363
+ . map ( |node_pks| BlindedPath :: new_for_message ( & node_pks, entropy_source, secp_ctx) )
364
+ . take ( MAX_PATHS )
365
+ . collect ( )
366
+ }
324
367
}
325
368
326
369
/// A path for sending an [`OnionMessage`].
0 commit comments