@@ -342,8 +342,8 @@ impl OnionMessageRecipient {
342
342
}
343
343
344
344
345
- /// The `Responder` struct creates an appropriate [`ResponseInstruction`]
346
- /// for responding to a message.
345
+ /// The `Responder` struct creates an appropriate [`ResponseInstruction`] for responding to a
346
+ /// message.
347
347
#[ derive( Clone , Debug , Eq , PartialEq ) ]
348
348
pub struct Responder {
349
349
/// The path along which a response can be sent.
@@ -362,41 +362,59 @@ impl Responder {
362
362
}
363
363
}
364
364
365
- /// Creates a [`ResponseInstruction::WithoutReplyPath `] for a given response .
365
+ /// Creates a [`ResponseInstruction`] for responding without including a reply path .
366
366
///
367
367
/// Use when the recipient doesn't need to send back a reply to us.
368
368
pub fn respond ( self ) -> ResponseInstruction {
369
- ResponseInstruction :: WithoutReplyPath {
369
+ ResponseInstruction {
370
370
send_path : self . reply_path ,
371
+ context : None ,
371
372
}
372
373
}
373
374
374
- /// Creates a [`ResponseInstruction::WithReplyPath `] for a given response .
375
+ /// Creates a [`ResponseInstruction`] for responding including a reply path .
375
376
///
376
377
/// Use when the recipient needs to send back a reply to us.
377
378
pub fn respond_with_reply_path ( self , context : MessageContext ) -> ResponseInstruction {
378
- ResponseInstruction :: WithReplyPath {
379
+ ResponseInstruction {
379
380
send_path : self . reply_path ,
380
- context : context,
381
+ context : Some ( context) ,
381
382
}
382
383
}
383
384
}
384
385
385
- /// `ResponseInstruction` represents instructions for responding to received messages.
386
- pub enum ResponseInstruction {
387
- /// Indicates that a response should be sent including a reply path for
388
- /// the recipient to respond back.
386
+ /// Instructions for how and where to send the response to an onion message.
387
+ pub struct ResponseInstruction {
388
+ send_path : BlindedMessagePath ,
389
+ context : Option < MessageContext > ,
390
+ }
391
+
392
+ impl ResponseInstruction {
393
+ fn into_instructions ( self ) -> MessageSendInstructions {
394
+ let send_path = self . send_path ;
395
+ match self . context {
396
+ Some ( context) => MessageSendInstructions :: WithReplyPath { send_path, context } ,
397
+ None => MessageSendInstructions :: WithoutReplyPath { send_path } ,
398
+ }
399
+ }
400
+ }
401
+
402
+ /// Instructions for how and where to send a message.
403
+ #[ derive( Clone ) ]
404
+ pub enum MessageSendInstructions {
405
+ /// Indicates that a message should be sent including a reply path for the recipient to
406
+ /// respond.
389
407
WithReplyPath {
390
- /// The path over which we'll send our reply .
408
+ /// The destination where we need to send our message .
391
409
send_path : BlindedMessagePath ,
392
410
/// The context to include in the reply path we'll give the recipient so they can respond
393
411
/// to us.
394
412
context : MessageContext ,
395
413
} ,
396
- /// Indicates that a response should be sent without including a reply path
397
- /// for the recipient to respond back .
414
+ /// Indicates that a message should be sent without including a reply path, preventing the
415
+ /// recipient from responding .
398
416
WithoutReplyPath {
399
- /// The path over which we'll send our reply .
417
+ /// The destination where we need to send our message .
400
418
send_path : BlindedMessagePath ,
401
419
}
402
420
}
@@ -1323,9 +1341,9 @@ where
1323
1341
pub fn handle_onion_message_response < T : OnionMessageContents > (
1324
1342
& self , response : T , instructions : ResponseInstruction ,
1325
1343
) -> Result < Option < SendSuccess > , SendError > {
1326
- let ( response_path, context) = match instructions {
1327
- ResponseInstruction :: WithReplyPath { send_path, context } => ( send_path, Some ( context) ) ,
1328
- ResponseInstruction :: WithoutReplyPath { send_path } => ( send_path, None ) ,
1344
+ let ( response_path, context) = match instructions. into_instructions ( ) {
1345
+ MessageSendInstructions :: WithReplyPath { send_path, context } => ( send_path, Some ( context) ) ,
1346
+ MessageSendInstructions :: WithoutReplyPath { send_path } => ( send_path, None ) ,
1329
1347
} ;
1330
1348
1331
1349
let message_type = response. msg_type ( ) ;
0 commit comments