@@ -364,51 +364,12 @@ where
364
364
pub fn new ( network_graph : G , entropy_source : ES ) -> Self {
365
365
Self { network_graph, entropy_source }
366
366
}
367
- }
368
-
369
- impl < G : Deref < Target =NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter for DefaultMessageRouter < G , L , ES >
370
- where
371
- L :: Target : Logger ,
372
- ES :: Target : EntropySource ,
373
- {
374
- fn find_path (
375
- & self , sender : PublicKey , peers : Vec < PublicKey > , mut destination : Destination
376
- ) -> Result < OnionMessagePath , ( ) > {
377
- let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
378
- destination. resolve ( & network_graph) ;
379
367
380
- let first_node = match destination. first_node ( ) {
381
- Some ( first_node) => first_node,
382
- None => return Err ( ( ) ) ,
383
- } ;
384
-
385
- if peers. contains ( & first_node) || sender == first_node {
386
- Ok ( OnionMessagePath {
387
- intermediate_nodes : vec ! [ ] , destination, first_node_addresses : None
388
- } )
389
- } else {
390
- let node_announcement = network_graph
391
- . node ( & NodeId :: from_pubkey ( & first_node) )
392
- . and_then ( |node_info| node_info. announcement_info . as_ref ( ) )
393
- . and_then ( |announcement_info| announcement_info. announcement_message . as_ref ( ) )
394
- . map ( |node_announcement| & node_announcement. contents ) ;
395
-
396
- match node_announcement {
397
- Some ( node_announcement) if node_announcement. features . supports_onion_messages ( ) => {
398
- let first_node_addresses = Some ( node_announcement. addresses . clone ( ) ) ;
399
- Ok ( OnionMessagePath {
400
- intermediate_nodes : vec ! [ ] , destination, first_node_addresses
401
- } )
402
- } ,
403
- _ => Err ( ( ) ) ,
404
- }
405
- }
406
- }
407
-
408
- fn create_blinded_paths <
368
+ fn create_blinded_paths_from_iter <
369
+ I : Iterator < Item = ForwardNode > ,
409
370
T : secp256k1:: Signing + secp256k1:: Verification
410
371
> (
411
- & self , recipient : PublicKey , peers : Vec < ForwardNode > , secp_ctx : & Secp256k1 < T > ,
372
+ & self , recipient : PublicKey , peers : I , secp_ctx : & Secp256k1 < T > ,
412
373
) -> Result < Vec < BlindedPath > , ( ) > {
413
374
// Limit the number of blinded paths that are computed.
414
375
const MAX_PATHS : usize = 3 ;
@@ -421,7 +382,7 @@ where
421
382
let is_recipient_announced =
422
383
network_graph. nodes ( ) . contains_key ( & NodeId :: from_pubkey ( & recipient) ) ;
423
384
424
- let mut peer_info = peers. into_iter ( )
385
+ let mut peer_info = peers
425
386
// Limit to peers with announced channels
426
387
. filter_map ( |peer|
427
388
network_graph
@@ -464,6 +425,54 @@ where
464
425
}
465
426
}
466
427
428
+ impl < G : Deref < Target =NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter for DefaultMessageRouter < G , L , ES >
429
+ where
430
+ L :: Target : Logger ,
431
+ ES :: Target : EntropySource ,
432
+ {
433
+ fn find_path (
434
+ & self , sender : PublicKey , peers : Vec < PublicKey > , mut destination : Destination
435
+ ) -> Result < OnionMessagePath , ( ) > {
436
+ let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
437
+ destination. resolve ( & network_graph) ;
438
+
439
+ let first_node = match destination. first_node ( ) {
440
+ Some ( first_node) => first_node,
441
+ None => return Err ( ( ) ) ,
442
+ } ;
443
+
444
+ if peers. contains ( & first_node) || sender == first_node {
445
+ Ok ( OnionMessagePath {
446
+ intermediate_nodes : vec ! [ ] , destination, first_node_addresses : None
447
+ } )
448
+ } else {
449
+ let node_announcement = network_graph
450
+ . node ( & NodeId :: from_pubkey ( & first_node) )
451
+ . and_then ( |node_info| node_info. announcement_info . as_ref ( ) )
452
+ . and_then ( |announcement_info| announcement_info. announcement_message . as_ref ( ) )
453
+ . map ( |node_announcement| & node_announcement. contents ) ;
454
+
455
+ match node_announcement {
456
+ Some ( node_announcement) if node_announcement. features . supports_onion_messages ( ) => {
457
+ let first_node_addresses = Some ( node_announcement. addresses . clone ( ) ) ;
458
+ Ok ( OnionMessagePath {
459
+ intermediate_nodes : vec ! [ ] , destination, first_node_addresses
460
+ } )
461
+ } ,
462
+ _ => Err ( ( ) ) ,
463
+ }
464
+ }
465
+ }
466
+
467
+ fn create_blinded_paths <
468
+ T : secp256k1:: Signing + secp256k1:: Verification
469
+ > (
470
+ & self , recipient : PublicKey , peers : Vec < ForwardNode > , secp_ctx : & Secp256k1 < T > ,
471
+ ) -> Result < Vec < BlindedPath > , ( ) > {
472
+ self . create_blinded_paths_from_iter ( recipient, peers. into_iter ( ) , secp_ctx)
473
+ }
474
+ }
475
+
467
476
/// A path for sending an [`OnionMessage`].
468
477
#[ derive( Clone ) ]
469
478
pub struct OnionMessagePath {
0 commit comments