@@ -812,15 +812,7 @@ pub trait CustomOnionMessageHandler {
812
812
///
813
813
/// Typically, this is used for messages initiating a message flow rather than in response to
814
814
/// another message. The latter should use the return value of [`Self::handle_custom_message`].
815
- #[ cfg( not( c_bindings) ) ]
816
- fn release_pending_custom_messages ( & self ) -> Vec < PendingOnionMessage < Self :: CustomMessage > > ;
817
-
818
- /// Releases any [`Self::CustomMessage`]s that need to be sent.
819
- ///
820
- /// Typically, this is used for messages initiating a message flow rather than in response to
821
- /// another message. The latter should use the return value of [`Self::handle_custom_message`].
822
- #[ cfg( c_bindings) ]
823
- fn release_pending_custom_messages ( & self ) -> Vec < ( Self :: CustomMessage , Destination , Option < BlindedMessagePath > ) > ;
815
+ fn release_pending_custom_messages ( & self ) -> Vec < ( Self :: CustomMessage , MessageSendInstructions ) > ;
824
816
}
825
817
826
818
/// A processed incoming onion message, containing either a Forward (another onion message)
@@ -1170,6 +1162,33 @@ where
1170
1162
)
1171
1163
}
1172
1164
1165
+ fn handle_onion_message_send < T : OnionMessageContents > (
1166
+ & self , response_message : T , response : MessageSendInstructions , log_suffix : fmt:: Arguments ,
1167
+ ) -> Result < Option < SendSuccess > , SendError > {
1168
+ let ( destination, context) = match response {
1169
+ MessageSendInstructions :: WithReplyPath { destination, context } => ( destination, Some ( context) ) ,
1170
+ MessageSendInstructions :: WithoutReplyPath { destination } => ( destination, None ) ,
1171
+ } ;
1172
+
1173
+ let reply_path = if let Some ( context) = context {
1174
+ match self . create_blinded_path ( context) {
1175
+ Ok ( reply_path) => Some ( reply_path) ,
1176
+ Err ( err) => {
1177
+ log_trace ! (
1178
+ self . logger,
1179
+ "Failed to create reply path {}: {:?}" ,
1180
+ log_suffix, err
1181
+ ) ;
1182
+ return Err ( err) ;
1183
+ }
1184
+ }
1185
+ } else { None } ;
1186
+
1187
+ self . find_path_and_enqueue_onion_message (
1188
+ response_message, destination, reply_path, log_suffix,
1189
+ ) . map ( |result| Some ( result) )
1190
+ }
1191
+
1173
1192
fn find_path_and_enqueue_onion_message < T : OnionMessageContents > (
1174
1193
& self , contents : T , destination : Destination , reply_path : Option < BlindedMessagePath > ,
1175
1194
log_suffix : fmt:: Arguments
@@ -1322,35 +1341,16 @@ where
1322
1341
/// generating the response asynchronously. Subsequently, when the response is prepared and
1323
1342
/// ready for sending, that task can invoke this method to enqueue the response for delivery.
1324
1343
pub fn handle_onion_message_response < T : OnionMessageContents > (
1325
- & self , response_message : T , response : MessageSendInstructions ,
1344
+ & self , response_message : T , instructions : MessageSendInstructions ,
1326
1345
) -> Result < Option < SendSuccess > , SendError > {
1327
- let ( destination, context) = match response {
1328
- MessageSendInstructions :: WithReplyPath { destination, context } => ( destination, Some ( context) ) ,
1329
- MessageSendInstructions :: WithoutReplyPath { destination } => ( destination, None ) ,
1330
- } ;
1331
-
1332
1346
let message_type = response_message. msg_type ( ) ;
1333
- let reply_path = if let Some ( context) = context {
1334
- match self . create_blinded_path ( context) {
1335
- Ok ( reply_path) => Some ( reply_path) ,
1336
- Err ( err) => {
1337
- log_trace ! (
1338
- self . logger,
1339
- "Failed to create reply path when responding with {} to an onion message: {:?}" ,
1340
- message_type, err
1341
- ) ;
1342
- return Err ( err) ;
1343
- }
1344
- }
1345
- } else { None } ;
1346
-
1347
- self . find_path_and_enqueue_onion_message (
1348
- response_message, destination, reply_path,
1347
+ self . handle_onion_message_send (
1348
+ response_message, instructions,
1349
1349
format_args ! (
1350
1350
"when responding with {} to an onion message" ,
1351
1351
message_type,
1352
1352
)
1353
- ) . map ( |result| Some ( result ) )
1353
+ )
1354
1354
}
1355
1355
1356
1356
#[ cfg( test) ]
@@ -1730,13 +1730,9 @@ where
1730
1730
}
1731
1731
1732
1732
// Enqueue any initiating `CustomMessage`s to send.
1733
- for message in self . custom_handler . release_pending_custom_messages ( ) {
1734
- #[ cfg( not( c_bindings) ) ]
1735
- let PendingOnionMessage { contents, destination, reply_path } = message;
1736
- #[ cfg( c_bindings) ]
1737
- let ( contents, destination, reply_path) = message;
1738
- let _ = self . find_path_and_enqueue_onion_message (
1739
- contents, destination, reply_path, format_args ! ( "when sending CustomMessage" )
1733
+ for ( message, instructions) in self . custom_handler . release_pending_custom_messages ( ) {
1734
+ let _ = self . handle_onion_message_send (
1735
+ message, instructions, format_args ! ( "when sending CustomMessage" )
1740
1736
) ;
1741
1737
}
1742
1738
0 commit comments