Skip to content

Commit d577b24

Browse files
committed
Add a MessageSendInstructions::ForReply
In order to allow onion message handlers to reply asynchronously without introducing a circular dependency graph, the message handlers need to be able to send replies described by `MessageSendInstructions`. This allows them to send replies via the normal message queuing (i.e. without making a function call to `OnionMessenger`). Here we enable that by adding a `MessageSendInstructions::ForReply` variant which holds `ReplyInstruction`s. Fixes #3178
1 parent d2cc904 commit d577b24

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lightning/src/onion_message/messenger.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl Responder {
367367
/// Use when the recipient doesn't need to send back a reply to us.
368368
pub fn respond(self) -> ResponseInstruction {
369369
ResponseInstruction {
370-
send_path: self.reply_path,
370+
destination: Destination::BlindedPath(self.reply_path),
371371
context: None,
372372
}
373373
}
@@ -377,7 +377,7 @@ impl Responder {
377377
/// Use when the recipient needs to send back a reply to us.
378378
pub fn respond_with_reply_path(self, context: MessageContext) -> ResponseInstruction {
379379
ResponseInstruction {
380-
send_path: self.reply_path,
380+
destination: Destination::BlindedPath(self.reply_path),
381381
context: Some(context),
382382
}
383383
}
@@ -386,17 +386,13 @@ impl Responder {
386386
/// Instructions for how and where to send the response to an onion message.
387387
#[derive(Clone)]
388388
pub struct ResponseInstruction {
389-
send_path: BlindedMessagePath,
389+
destination: Destination,
390390
context: Option<MessageContext>,
391391
}
392392

393393
impl ResponseInstruction {
394394
fn into_instructions(self) -> MessageSendInstructions {
395-
let destination = Destination::BlindedPath(self.send_path);
396-
match self.context {
397-
Some(context) => MessageSendInstructions::WithReplyPath { destination, context },
398-
None => MessageSendInstructions::WithoutReplyPath { destination },
399-
}
395+
MessageSendInstructions::ForReply { instructions: self }
400396
}
401397
}
402398

@@ -425,7 +421,11 @@ pub enum MessageSendInstructions {
425421
WithoutReplyPath {
426422
/// The desination where we need to send our message.
427423
destination: Destination,
428-
}
424+
},
425+
/// Indicates that a message is being sent as a reply to a received message.
426+
ForReply {
427+
instructions: ResponseInstruction,
428+
},
429429
}
430430

431431
/// A trait defining behavior for routing an [`OnionMessage`].
@@ -1169,7 +1169,8 @@ where
11691169
let (destination, reply_path) = match instructions {
11701170
MessageSendInstructions::WithSpecifiedReplyPath { destination, reply_path } =>
11711171
(destination, Some(reply_path)),
1172-
MessageSendInstructions::WithReplyPath { destination, context } => {
1172+
MessageSendInstructions::WithReplyPath { destination, context }|
1173+
MessageSendInstructions::ForReply { instructions: ResponseInstruction { destination, context: Some(context) } } => {
11731174
match self.create_blinded_path(context) {
11741175
Ok(reply_path) => (destination, Some(reply_path)),
11751176
Err(err) => {
@@ -1182,7 +1183,8 @@ where
11821183
}
11831184
}
11841185
},
1185-
MessageSendInstructions::WithoutReplyPath { destination } =>
1186+
MessageSendInstructions::WithoutReplyPath { destination }|
1187+
MessageSendInstructions::ForReply { instructions: ResponseInstruction { destination, context: None } } =>
11861188
(destination, None),
11871189
};
11881190

0 commit comments

Comments
 (0)