Skip to content

Commit 0caa098

Browse files
committed
Pull the guts of ResponseInstruction into a new enum
In the coming commits we'll use the `ResponseInstruction` enum's contents for all messages, allowing message senders to rely on the in-`OnionMessegner` reply path selection logic. In order to do so and avoid users confusing the new `MessageSendInstructions` for `ResponseInstruction`, we leave `ResponseInstruction` as a now-unconstructible struct which wraps a `MessageSendInstructions`.
1 parent 2bf2572 commit 0caa098

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ impl OnionMessageRecipient {
342342
}
343343

344344

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.
347347
#[derive(Clone, Debug, Eq, PartialEq)]
348348
pub struct Responder {
349349
/// The path along which a response can be sent.
@@ -362,41 +362,59 @@ impl Responder {
362362
}
363363
}
364364

365-
/// Creates a [`ResponseInstruction::WithoutReplyPath`] for a given response.
365+
/// Creates a [`ResponseInstruction`] for responding without including a reply path.
366366
///
367367
/// Use when the recipient doesn't need to send back a reply to us.
368368
pub fn respond(self) -> ResponseInstruction {
369-
ResponseInstruction::WithoutReplyPath {
369+
ResponseInstruction {
370370
send_path: self.reply_path,
371+
context: None,
371372
}
372373
}
373374

374-
/// Creates a [`ResponseInstruction::WithReplyPath`] for a given response.
375+
/// Creates a [`ResponseInstruction`] for responding including a reply path.
375376
///
376377
/// Use when the recipient needs to send back a reply to us.
377378
pub fn respond_with_reply_path(self, context: MessageContext) -> ResponseInstruction {
378-
ResponseInstruction::WithReplyPath {
379+
ResponseInstruction {
379380
send_path: self.reply_path,
380-
context: context,
381+
context: Some(context),
381382
}
382383
}
383384
}
384385

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.
389407
WithReplyPath {
390-
/// The path over which we'll send our reply.
408+
/// The destination where we need to send our message.
391409
send_path: BlindedMessagePath,
392410
/// The context to include in the reply path we'll give the recipient so they can respond
393411
/// to us.
394412
context: MessageContext,
395413
},
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.
398416
WithoutReplyPath {
399-
/// The path over which we'll send our reply.
417+
/// The destination where we need to send our message.
400418
send_path: BlindedMessagePath,
401419
}
402420
}
@@ -1323,9 +1341,9 @@ where
13231341
pub fn handle_onion_message_response<T: OnionMessageContents>(
13241342
&self, response: T, instructions: ResponseInstruction,
13251343
) -> 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),
13291347
};
13301348

13311349
let message_type = response.msg_type();

0 commit comments

Comments
 (0)