@@ -365,30 +365,24 @@ impl Responder {
365
365
/// Creates a [`ResponseInstruction::WithoutReplyPath`] for a given response.
366
366
///
367
367
/// Use when the recipient doesn't need to send back a reply to us.
368
- pub fn respond < T : OnionMessageContents > ( self , response : T ) -> ResponseInstruction < T > {
369
- ResponseInstruction :: WithoutReplyPath ( OnionMessageResponse {
370
- message : response,
371
- reply_path : self . reply_path ,
372
- } )
368
+ pub fn respond < T : OnionMessageContents > ( self , response : T ) -> Option < ( T , ResponseInstruction ) > {
369
+ Some ( ( response, ResponseInstruction :: WithoutReplyPath {
370
+ send_path : self . reply_path ,
371
+ } ) )
373
372
}
374
373
375
374
/// Creates a [`ResponseInstruction::WithReplyPath`] for a given response.
376
375
///
377
376
/// Use when the recipient needs to send back a reply to us.
378
- pub fn respond_with_reply_path < T : OnionMessageContents > ( self , response : T , context : MessageContext ) -> ResponseInstruction < T > {
379
- ResponseInstruction :: WithReplyPath ( OnionMessageResponse {
380
- message : response ,
381
- reply_path : self . reply_path ,
382
- } , context )
377
+ pub fn respond_with_reply_path < T : OnionMessageContents > ( self , response : T , context : MessageContext ) -> Option < ( T , ResponseInstruction ) > {
378
+ Some ( ( response , ResponseInstruction :: WithReplyPath {
379
+ send_path : self . reply_path ,
380
+ context : context ,
381
+ } ) )
383
382
}
384
383
}
385
384
386
- /// This struct contains the information needed to reply to a received message.
387
- pub struct OnionMessageResponse < T : OnionMessageContents > {
388
- message : T ,
389
- reply_path : BlindedMessagePath ,
390
- }
391
-
385
+ /*#[cfg(not(c_bindings))]
392
386
/// `ResponseInstruction` represents instructions for responding to received messages.
393
387
pub enum ResponseInstruction<T: OnionMessageContents> {
394
388
/// Indicates that a response should be sent including a reply path for
@@ -401,6 +395,26 @@ pub enum ResponseInstruction<T: OnionMessageContents> {
401
395
NoResponse,
402
396
}
403
397
398
+ #[cfg(c_bindings)]*/
399
+ /// `ResponseInstruction` represents instructions for responding to received messages.
400
+ pub enum ResponseInstruction {
401
+ /// Indicates that a response should be sent including a reply path for
402
+ /// the recipient to respond back.
403
+ WithReplyPath {
404
+ /// The path over which we'll send our reply.
405
+ send_path : BlindedMessagePath ,
406
+ /// The context to include in the reply path we'll give the recipient so they can respond
407
+ /// to us.
408
+ context : MessageContext ,
409
+ } ,
410
+ /// Indicates that a response should be sent without including a reply path
411
+ /// for the recipient to respond back.
412
+ WithoutReplyPath {
413
+ /// The path over which we'll send our reply.
414
+ send_path : BlindedMessagePath ,
415
+ }
416
+ }
417
+
404
418
/// An [`OnionMessage`] for [`OnionMessenger`] to send.
405
419
///
406
420
/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are
@@ -799,7 +813,9 @@ pub trait CustomOnionMessageHandler {
799
813
/// Called with the custom message that was received, returning a response to send, if any.
800
814
///
801
815
/// The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
802
- fn handle_custom_message ( & self , message : Self :: CustomMessage , context : Option < Vec < u8 > > , responder : Option < Responder > ) -> ResponseInstruction < Self :: CustomMessage > ;
816
+ fn handle_custom_message (
817
+ & self , message : Self :: CustomMessage , context : Option < Vec < u8 > > , responder : Option < Responder >
818
+ ) -> Option < ( Self :: CustomMessage , ResponseInstruction ) > ;
803
819
804
820
/// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
805
821
/// message type is unknown.
@@ -1320,15 +1336,14 @@ where
1320
1336
/// the response is prepared and ready for sending, that task can invoke this method to enqueue
1321
1337
/// the response for delivery.
1322
1338
pub fn handle_onion_message_response < T : OnionMessageContents > (
1323
- & self , response : ResponseInstruction < T >
1339
+ & self , response_message : T , response : ResponseInstruction ,
1324
1340
) -> Result < Option < SendSuccess > , SendError > {
1325
- let ( response, context) = match response {
1326
- ResponseInstruction :: WithReplyPath ( response, context) => ( response, Some ( context) ) ,
1327
- ResponseInstruction :: WithoutReplyPath ( response) => ( response, None ) ,
1328
- ResponseInstruction :: NoResponse => return Ok ( None ) ,
1341
+ let ( response_path, context) = match response {
1342
+ ResponseInstruction :: WithReplyPath { send_path, context } => ( send_path, Some ( context) ) ,
1343
+ ResponseInstruction :: WithoutReplyPath { send_path } => ( send_path, None ) ,
1329
1344
} ;
1330
1345
1331
- let message_type = response . message . msg_type ( ) ;
1346
+ let message_type = response_message . msg_type ( ) ;
1332
1347
let reply_path = if let Some ( context) = context {
1333
1348
match self . create_blinded_path ( context) {
1334
1349
Ok ( reply_path) => Some ( reply_path) ,
@@ -1344,7 +1359,7 @@ where
1344
1359
} else { None } ;
1345
1360
1346
1361
self . find_path_and_enqueue_onion_message (
1347
- response . message , Destination :: BlindedPath ( response . reply_path ) , reply_path,
1362
+ response_message , Destination :: BlindedPath ( response_path ) , reply_path,
1348
1363
format_args ! (
1349
1364
"when responding with {} to an onion message" ,
1350
1365
message_type,
@@ -1564,14 +1579,18 @@ where
1564
1579
}
1565
1580
} ;
1566
1581
let response_instructions = self . offers_handler . handle_message ( msg, context, responder) ;
1567
- let _ = self . handle_onion_message_response ( response_instructions) ;
1582
+ if let Some ( ( msg, instructions) ) = response_instructions {
1583
+ let _ = self . handle_onion_message_response ( msg, instructions) ;
1584
+ }
1568
1585
} ,
1569
1586
#[ cfg( async_payments) ]
1570
1587
ParsedOnionMessageContents :: AsyncPayments ( AsyncPaymentsMessage :: HeldHtlcAvailable ( msg) ) => {
1571
1588
let response_instructions = self . async_payments_handler . held_htlc_available (
1572
1589
msg, responder
1573
1590
) ;
1574
- let _ = self . handle_onion_message_response ( response_instructions) ;
1591
+ if let Some ( ( msg, instructions) ) = response_instructions {
1592
+ let _ = self . handle_onion_message_response ( msg, instructions) ;
1593
+ }
1575
1594
} ,
1576
1595
#[ cfg( async_payments) ]
1577
1596
ParsedOnionMessageContents :: AsyncPayments ( AsyncPaymentsMessage :: ReleaseHeldHtlc ( msg) ) => {
@@ -1587,7 +1606,9 @@ where
1587
1606
}
1588
1607
} ;
1589
1608
let response_instructions = self . custom_handler . handle_custom_message ( msg, context, responder) ;
1590
- let _ = self . handle_onion_message_response ( response_instructions) ;
1609
+ if let Some ( ( msg, instructions) ) = response_instructions {
1610
+ let _ = self . handle_onion_message_response ( msg, instructions) ;
1611
+ }
1591
1612
} ,
1592
1613
}
1593
1614
} ,
0 commit comments