@@ -449,50 +449,12 @@ where
449
449
pub fn new ( network_graph : G , entropy_source : ES ) -> Self {
450
450
Self { network_graph, entropy_source }
451
451
}
452
- }
453
-
454
- impl < G : Deref < Target =NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter for DefaultMessageRouter < G , L , ES >
455
- where
456
- L :: Target : Logger ,
457
- ES :: Target : EntropySource ,
458
- {
459
- fn find_path (
460
- & self , sender : PublicKey , peers : Vec < PublicKey > , mut destination : Destination
461
- ) -> Result < OnionMessagePath , ( ) > {
462
- let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
463
- destination. resolve ( & network_graph) ;
464
-
465
- let first_node = match destination. first_node ( ) {
466
- Some ( first_node) => first_node,
467
- None => return Err ( ( ) ) ,
468
- } ;
469
-
470
- if peers. contains ( & first_node) || sender == first_node {
471
- Ok ( OnionMessagePath {
472
- intermediate_nodes : vec ! [ ] , destination, first_node_addresses : None
473
- } )
474
- } else {
475
- let node_details = network_graph
476
- . node ( & NodeId :: from_pubkey ( & first_node) )
477
- . and_then ( |node_info| node_info. announcement_info . as_ref ( ) )
478
- . map ( |announcement_info| ( announcement_info. features ( ) , announcement_info. addresses ( ) ) ) ;
479
-
480
- match node_details {
481
- Some ( ( features, addresses) ) if features. supports_onion_messages ( ) && addresses. len ( ) > 0 => {
482
- let first_node_addresses = Some ( addresses. clone ( ) ) ;
483
- Ok ( OnionMessagePath {
484
- intermediate_nodes : vec ! [ ] , destination, first_node_addresses
485
- } )
486
- } ,
487
- _ => Err ( ( ) ) ,
488
- }
489
- }
490
- }
491
452
492
- fn create_blinded_paths <
453
+ fn create_blinded_paths_from_iter <
454
+ I : Iterator < Item = ForwardNode > ,
493
455
T : secp256k1:: Signing + secp256k1:: Verification
494
456
> (
495
- & self , recipient : PublicKey , peers : Vec < ForwardNode > , secp_ctx : & Secp256k1 < T > ,
457
+ & self , recipient : PublicKey , peers : I , secp_ctx : & Secp256k1 < T > ,
496
458
) -> Result < Vec < BlindedPath > , ( ) > {
497
459
// Limit the number of blinded paths that are computed.
498
460
const MAX_PATHS : usize = 3 ;
@@ -505,7 +467,7 @@ where
505
467
let is_recipient_announced =
506
468
network_graph. nodes ( ) . contains_key ( & NodeId :: from_pubkey ( & recipient) ) ;
507
469
508
- let mut peer_info = peers. into_iter ( )
470
+ let mut peer_info = peers
509
471
// Limit to peers with announced channels
510
472
. filter_map ( |peer|
511
473
network_graph
@@ -548,6 +510,53 @@ where
548
510
}
549
511
}
550
512
513
+ impl < G : Deref < Target =NetworkGraph < L > > , L : Deref , ES : Deref > MessageRouter for DefaultMessageRouter < G , L , ES >
514
+ where
515
+ L :: Target : Logger ,
516
+ ES :: Target : EntropySource ,
517
+ {
518
+ fn find_path (
519
+ & self , sender : PublicKey , peers : Vec < PublicKey > , mut destination : Destination
520
+ ) -> Result < OnionMessagePath , ( ) > {
521
+ let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
522
+ destination. resolve ( & network_graph) ;
523
+
524
+ let first_node = match destination. first_node ( ) {
525
+ Some ( first_node) => first_node,
526
+ None => return Err ( ( ) ) ,
527
+ } ;
528
+
529
+ if peers. contains ( & first_node) || sender == first_node {
530
+ Ok ( OnionMessagePath {
531
+ intermediate_nodes : vec ! [ ] , destination, first_node_addresses : None
532
+ } )
533
+ } else {
534
+ let node_details = network_graph
535
+ . node ( & NodeId :: from_pubkey ( & first_node) )
536
+ . and_then ( |node_info| node_info. announcement_info . as_ref ( ) )
537
+ . map ( |announcement_info| ( announcement_info. features ( ) , announcement_info. addresses ( ) ) ) ;
538
+
539
+ match node_details {
540
+ Some ( ( features, addresses) ) if features. supports_onion_messages ( ) && addresses. len ( ) > 0 => {
541
+ let first_node_addresses = Some ( addresses. clone ( ) ) ;
542
+ Ok ( OnionMessagePath {
543
+ intermediate_nodes : vec ! [ ] , destination, first_node_addresses
544
+ } )
545
+ } ,
546
+ _ => Err ( ( ) ) ,
547
+ }
548
+ }
549
+ }
550
+
551
+ fn create_blinded_paths <
552
+ T : secp256k1:: Signing + secp256k1:: Verification
553
+ > (
554
+ & self , recipient : PublicKey , peers : Vec < ForwardNode > , secp_ctx : & Secp256k1 < T > ,
555
+ ) -> Result < Vec < BlindedPath > , ( ) > {
556
+ self . create_blinded_paths_from_iter ( recipient, peers. into_iter ( ) , secp_ctx)
557
+ }
558
+ }
559
+
551
560
/// A path for sending an [`OnionMessage`].
552
561
#[ derive( Clone ) ]
553
562
pub struct OnionMessagePath {
0 commit comments