@@ -151,7 +151,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
151
151
/// # use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext};
152
152
/// # use lightning::sign::{EntropySource, KeysManager};
153
153
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
154
- /// # use lightning::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger};
154
+ /// # use lightning::onion_message::messenger::{BlindedPathParams, Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger};
155
155
/// # use lightning::onion_message::packet::OnionMessageContents;
156
156
/// # use lightning::util::logger::{Logger, Record};
157
157
/// # use lightning::util::ser::{Writeable, Writer};
@@ -175,7 +175,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
175
175
/// # })
176
176
/// # }
177
177
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
178
- /// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
178
+ /// # &self, _params: BlindedPathParams , _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
179
179
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
180
180
/// # unreachable!()
181
181
/// # }
@@ -475,7 +475,7 @@ pub trait MessageRouter {
475
475
fn create_blinded_paths <
476
476
T : secp256k1:: Signing + secp256k1:: Verification
477
477
> (
478
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
478
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
479
479
) -> Result < Vec < BlindedMessagePath > , ( ) > ;
480
480
481
481
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
@@ -501,7 +501,9 @@ pub trait MessageRouter {
501
501
. into_iter ( )
502
502
. map ( |MessageForwardNode { node_id, short_channel_id : _ } | node_id)
503
503
. collect ( ) ;
504
- self . create_blinded_paths ( recipient, context, peers, secp_ctx)
504
+
505
+ let params = BlindedPathParams :: new ( true ) ;
506
+ self . create_blinded_paths ( params, recipient, context, peers, secp_ctx)
505
507
}
506
508
}
507
509
@@ -536,12 +538,9 @@ where
536
538
I : ExactSizeIterator < Item = MessageForwardNode > ,
537
539
T : secp256k1:: Signing + secp256k1:: Verification
538
540
> (
539
- network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
540
- entropy_source : & ES , secp_ctx : & Secp256k1 < T > , compact_paths : bool ,
541
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext , peers : I ,
542
+ entropy_source : & ES , secp_ctx : & Secp256k1 < T >
541
543
) -> Result < Vec < BlindedMessagePath > , ( ) > {
542
- // Limit the number of blinded paths that are computed.
543
- const MAX_PATHS : usize = 3 ;
544
-
545
544
// Ensure peers have at least three channels so that it is more difficult to infer the
546
545
// recipient's node_id.
547
546
const MIN_PEER_CHANNELS : usize = 3 ;
@@ -578,7 +577,7 @@ where
578
577
. map ( |( peer, _, _) | {
579
578
BlindedMessagePath :: new ( & [ peer] , recipient, context. clone ( ) , & * * entropy_source, secp_ctx)
580
579
} )
581
- . take ( MAX_PATHS )
580
+ . take ( params . paths )
582
581
. collect :: < Result < Vec < _ > , _ > > ( ) ;
583
582
584
583
let mut paths = match paths {
@@ -593,7 +592,7 @@ where
593
592
} ,
594
593
} ?;
595
594
596
- if compact_paths {
595
+ if params . is_compact {
597
596
for path in & mut paths {
598
597
path. use_compact_introduction_node ( & network_graph) ;
599
598
}
@@ -638,13 +637,13 @@ where
638
637
pub ( crate ) fn create_blinded_paths <
639
638
T : secp256k1:: Signing + secp256k1:: Verification
640
639
> (
641
- network_graph : & G , recipient : PublicKey , context : MessageContext ,
640
+ params : BlindedPathParams , network_graph : & G , recipient : PublicKey , context : MessageContext ,
642
641
peers : Vec < PublicKey > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
643
642
) -> Result < Vec < BlindedMessagePath > , ( ) > {
644
643
let peers = peers
645
644
. into_iter ( )
646
645
. map ( |node_id| MessageForwardNode { node_id, short_channel_id : None } ) ;
647
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, false )
646
+ Self :: create_blinded_paths_from_iter ( params , network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
648
647
}
649
648
650
649
pub ( crate ) fn create_compact_blinded_paths <
@@ -653,7 +652,8 @@ where
653
652
network_graph : & G , recipient : PublicKey , context : MessageContext ,
654
653
peers : Vec < MessageForwardNode > , entropy_source : & ES , secp_ctx : & Secp256k1 < T > ,
655
654
) -> Result < Vec < BlindedMessagePath > , ( ) > {
656
- Self :: create_blinded_paths_from_iter ( network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx, true )
655
+ let params = BlindedPathParams :: new ( true ) ;
656
+ Self :: create_blinded_paths_from_iter ( params, network_graph, recipient, context, peers. into_iter ( ) , entropy_source, secp_ctx)
657
657
}
658
658
}
659
659
@@ -671,9 +671,9 @@ where
671
671
fn create_blinded_paths <
672
672
T : secp256k1:: Signing + secp256k1:: Verification
673
673
> (
674
- & self , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
674
+ & self , params : BlindedPathParams , recipient : PublicKey , context : MessageContext , peers : Vec < PublicKey > , secp_ctx : & Secp256k1 < T > ,
675
675
) -> Result < Vec < BlindedMessagePath > , ( ) > {
676
- Self :: create_blinded_paths ( & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
676
+ Self :: create_blinded_paths ( params , & self . network_graph , recipient, context, peers, & self . entropy_source , secp_ctx)
677
677
}
678
678
679
679
fn create_compact_blinded_paths <
@@ -1200,7 +1200,8 @@ where
1200
1200
MessageSendInstructions :: WithReplyPath { destination, context }
1201
1201
|MessageSendInstructions :: ForReply { instructions : ResponseInstruction { destination, context : Some ( context) } } =>
1202
1202
{
1203
- match self . create_blinded_path ( context) {
1203
+ let params = BlindedPathParams :: new ( false ) ;
1204
+ match self . create_blinded_path ( params, context) {
1204
1205
Ok ( reply_path) => ( destination, Some ( reply_path) ) ,
1205
1206
Err ( err) => {
1206
1207
log_trace ! (
@@ -1265,7 +1266,7 @@ where
1265
1266
. map_err ( |_| SendError :: PathNotFound )
1266
1267
}
1267
1268
1268
- fn create_blinded_path ( & self , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1269
+ fn create_blinded_path ( & self , params : BlindedPathParams , context : MessageContext ) -> Result < BlindedMessagePath , SendError > {
1269
1270
let recipient = self . node_signer
1270
1271
. get_node_id ( Recipient :: Node )
1271
1272
. map_err ( |_| SendError :: GetNodeIdFailed ) ?;
@@ -1278,7 +1279,7 @@ where
1278
1279
. collect :: < Vec < _ > > ( ) ;
1279
1280
1280
1281
self . message_router
1281
- . create_blinded_paths ( recipient, context, peers, secp_ctx)
1282
+ . create_blinded_paths ( params , recipient, context, peers, secp_ctx)
1282
1283
. and_then ( |paths| paths. into_iter ( ) . next ( ) . ok_or ( ( ) ) )
1283
1284
. map_err ( |_| SendError :: PathNotFound )
1284
1285
}
0 commit comments