@@ -830,15 +830,7 @@ pub trait CustomOnionMessageHandler {
830
830
///
831
831
/// Typically, this is used for messages initiating a message flow rather than in response to
832
832
/// another message. The latter should use the return value of [`Self::handle_custom_message`].
833
- #[ cfg( not( c_bindings) ) ]
834
- fn release_pending_custom_messages ( & self ) -> Vec < PendingOnionMessage < Self :: CustomMessage > > ;
835
-
836
- /// Releases any [`Self::CustomMessage`]s that need to be sent.
837
- ///
838
- /// Typically, this is used for messages initiating a message flow rather than in response to
839
- /// another message. The latter should use the return value of [`Self::handle_custom_message`].
840
- #[ cfg( c_bindings) ]
841
- fn release_pending_custom_messages ( & self ) -> Vec < ( Self :: CustomMessage , Destination , Option < BlindedMessagePath > ) > ;
833
+ fn release_pending_custom_messages ( & self ) -> Vec < ( Self :: CustomMessage , MessageSendInstructions ) > ;
842
834
}
843
835
844
836
/// A processed incoming onion message, containing either a Forward (another onion message)
@@ -1188,6 +1180,33 @@ where
1188
1180
)
1189
1181
}
1190
1182
1183
+ fn send_onion_message_internal < T : OnionMessageContents > (
1184
+ & self , message : T , instructions : MessageSendInstructions , log_suffix : fmt:: Arguments ,
1185
+ ) -> Result < Option < SendSuccess > , SendError > {
1186
+ let ( destination, context) = match instructions {
1187
+ MessageSendInstructions :: WithReplyPath { destination, context } => ( destination, Some ( context) ) ,
1188
+ MessageSendInstructions :: WithoutReplyPath { destination } => ( destination, None ) ,
1189
+ } ;
1190
+
1191
+ let reply_path = if let Some ( context) = context {
1192
+ match self . create_blinded_path ( context) {
1193
+ Ok ( reply_path) => Some ( reply_path) ,
1194
+ Err ( err) => {
1195
+ log_trace ! (
1196
+ self . logger,
1197
+ "Failed to create reply path {}: {:?}" ,
1198
+ log_suffix, err
1199
+ ) ;
1200
+ return Err ( err) ;
1201
+ }
1202
+ }
1203
+ } else { None } ;
1204
+
1205
+ self . find_path_and_enqueue_onion_message (
1206
+ message, destination, reply_path, log_suffix,
1207
+ ) . map ( |result| Some ( result) )
1208
+ }
1209
+
1191
1210
fn find_path_and_enqueue_onion_message < T : OnionMessageContents > (
1192
1211
& self , contents : T , destination : Destination , reply_path : Option < BlindedMessagePath > ,
1193
1212
log_suffix : fmt:: Arguments
@@ -1342,33 +1361,14 @@ where
1342
1361
pub fn handle_onion_message_response < T : OnionMessageContents > (
1343
1362
& self , response : T , instructions : ResponseInstruction ,
1344
1363
) -> Result < Option < SendSuccess > , SendError > {
1345
- let ( destination, context) = match instructions. into_instructions ( ) {
1346
- MessageSendInstructions :: WithReplyPath { destination, context } => ( destination, Some ( context) ) ,
1347
- MessageSendInstructions :: WithoutReplyPath { destination } => ( destination, None ) ,
1348
- } ;
1349
-
1350
1364
let message_type = response. msg_type ( ) ;
1351
- let reply_path = if let Some ( context) = context {
1352
- match self . create_blinded_path ( context) {
1353
- Ok ( reply_path) => Some ( reply_path) ,
1354
- Err ( err) => {
1355
- log_trace ! (
1356
- self . logger,
1357
- "Failed to create reply path when responding with {} to an onion message: {:?}" ,
1358
- message_type, err
1359
- ) ;
1360
- return Err ( err) ;
1361
- }
1362
- }
1363
- } else { None } ;
1364
-
1365
- self . find_path_and_enqueue_onion_message (
1366
- response, destination, reply_path,
1365
+ self . send_onion_message_internal (
1366
+ response, instructions. into_instructions ( ) ,
1367
1367
format_args ! (
1368
1368
"when responding with {} to an onion message" ,
1369
1369
message_type,
1370
1370
)
1371
- ) . map ( |result| Some ( result ) )
1371
+ )
1372
1372
}
1373
1373
1374
1374
#[ cfg( test) ]
@@ -1748,13 +1748,9 @@ where
1748
1748
}
1749
1749
1750
1750
// Enqueue any initiating `CustomMessage`s to send.
1751
- for message in self . custom_handler . release_pending_custom_messages ( ) {
1752
- #[ cfg( not( c_bindings) ) ]
1753
- let PendingOnionMessage { contents, destination, reply_path } = message;
1754
- #[ cfg( c_bindings) ]
1755
- let ( contents, destination, reply_path) = message;
1756
- let _ = self . find_path_and_enqueue_onion_message (
1757
- contents, destination, reply_path, format_args ! ( "when sending CustomMessage" )
1751
+ for ( message, instructions) in self . custom_handler . release_pending_custom_messages ( ) {
1752
+ let _ = self . send_onion_message_internal (
1753
+ message, instructions, format_args ! ( "when sending CustomMessage" )
1758
1754
) ;
1759
1755
}
1760
1756
0 commit comments