Skip to content

Commit f9e4b83

Browse files
committed
Introduce ResponseInstructions for OnionMessage Handling
- Currently, handle_message (or handle_custom_message) only exposes the generated response for an OnionMessage, lacking the necessary reply_path for asynchronous responses. - This commit introduces a new flow for OnionMessage handling. - Instead of solely taking the message as input, handle_message now accepts an Optional `responder`, returning a `ResponseInstruction` containing both the response and the reply_path. - `ResponseInstruction` utilizes different enum variants to indicate how `handle_onion_message_response` should handle the response. - This enhancement enables exposing the reply_path alongside the response and allows for more complex response mechanisms, such as responding with an added reply_path. - The commit introduces the foundational framework (structs & enums) for this new flow.
1 parent 6d11111 commit f9e4b83

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,46 @@ impl OnionMessageRecipient {
243243
}
244244
}
245245

246+
247+
/// The `Responder` struct creates an appropriate [`ResponseInstruction`]
248+
/// for a response based on our ability to respond.
249+
pub struct Responder {
250+
/// The path along which the response can be sent.
251+
reply_path: BlindedPath,
252+
}
253+
254+
impl Responder {
255+
/// Creates a new [`Responder`] instance with the provided reply path.
256+
pub fn new(reply_path: BlindedPath) -> Self {
257+
Responder {
258+
reply_path,
259+
}
260+
}
261+
262+
/// Creates the appropriate [`ResponseInstruction`] for a given response.
263+
pub fn respond<T: OnionMessageContents>(self, response: T) -> ResponseInstruction<T> {
264+
ResponseInstruction::WithoutReplyPath(OnionMessageResponse {
265+
message: response,
266+
reply_path: self.reply_path
267+
})
268+
}
269+
}
270+
271+
/// This struct contains the information needed to reply to a received message.
272+
#[allow(unused)]
273+
pub struct OnionMessageResponse<T: OnionMessageContents> {
274+
message: T,
275+
reply_path: BlindedPath,
276+
}
277+
278+
/// `ResponseInstruction` represents instructions for responding to received messages.
279+
pub enum ResponseInstruction<T: OnionMessageContents> {
280+
/// Indicates that a response should be sent without including a reply path for the receiver to respond back.
281+
WithoutReplyPath(OnionMessageResponse<T>),
282+
/// Indicates that there's no response to send back.
283+
NoResponse,
284+
}
285+
246286
/// An [`OnionMessage`] for [`OnionMessenger`] to send.
247287
///
248288
/// These are obtained when released from [`OnionMessenger`]'s handlers after which they are

0 commit comments

Comments
 (0)