Skip to content

Commit 9bd8ae5

Browse files
committed
Introduce custom data in handle_custom_message
1 parent 4d60755 commit 9bd8ae5

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

fuzz/src/onion_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
161161
type CustomMessage = TestCustomMessage;
162162
fn handle_custom_message(
163163
&self, message: Self::CustomMessage, _context: Option<Vec<u8>>,
164-
responder: Option<Responder>,
164+
_custom_data: Option<Vec<u8>>, responder: Option<Responder>,
165165
) -> Option<(Self::CustomMessage, ResponseInstruction)> {
166166
match responder {
167167
Some(responder) => Some((message, responder.respond())),

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12296,7 +12296,7 @@ where
1229612296
let nonce = Nonce::from_entropy_source(&*self.entropy_source);
1229712297
let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
1229812298
let context = MessageContext::Offers(OffersContext::InboundPayment { payment_hash, nonce, hmac });
12299-
Some((OffersMessage::Invoice(invoice), responder.respond_with_reply_path(context)))
12299+
Some((OffersMessage::Invoice(invoice), responder.respond_with_reply_path(context, None)))
1230012300
},
1230112301
Err(error) => Some((OffersMessage::InvoiceError(error.into()), responder.respond())),
1230212302
}

lightning/src/ln/peer_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl DNSResolverMessageHandler for IgnoringMessageHandler {
169169
}
170170
impl CustomOnionMessageHandler for IgnoringMessageHandler {
171171
type CustomMessage = Infallible;
172-
fn handle_custom_message(&self, _message: Infallible, _context: Option<Vec<u8>>, _responder: Option<Responder>) -> Option<(Infallible, ResponseInstruction)> {
172+
fn handle_custom_message(&self, _message: Infallible, _context: Option<Vec<u8>>, _custom_data: Option<Vec<u8>>, _responder: Option<Responder>) -> Option<(Infallible, ResponseInstruction)> {
173173
// Since we always return `None` in the read the handle method should never be called.
174174
unreachable!();
175175
}

lightning/src/onion_message/functional_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Drop for TestCustomMessageHandler {
188188
impl CustomOnionMessageHandler for TestCustomMessageHandler {
189189
type CustomMessage = TestCustomMessage;
190190
fn handle_custom_message(
191-
&self, msg: Self::CustomMessage, context: Option<Vec<u8>>, responder: Option<Responder>,
191+
&self, msg: Self::CustomMessage, context: Option<Vec<u8>>, custom_data: Option<Vec<u8>>, responder: Option<Responder>,
192192
) -> Option<(Self::CustomMessage, ResponseInstruction)> {
193193
let expectation = self.get_next_expectation();
194194
assert_eq!(msg, expectation.expect);
@@ -206,7 +206,7 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
206206
match responder {
207207
Some(responder) if expectation.include_reply_path => {
208208
let context = MessageContext::Custom(context.unwrap_or_else(Vec::new));
209-
let reply = responder.respond_with_reply_path(context);
209+
let reply = responder.respond_with_reply_path(context, custom_data);
210210
Some((response, reply))
211211
},
212212
Some(responder) => Some((response, responder.respond())),
@@ -502,7 +502,7 @@ fn async_response_over_one_blinded_hop() {
502502
// 5. Expect Alice to receive the message and create a response instruction for it.
503503
alice.custom_message_handler.expect_message(message.clone());
504504
let response_instruction =
505-
nodes[0].custom_message_handler.handle_custom_message(message, None, responder);
505+
nodes[0].custom_message_handler.handle_custom_message(message, None, None, responder);
506506

507507
// 6. Simulate Alice asynchronously responding back to Bob with a response.
508508
let (msg, instructions) = response_instruction.unwrap();
@@ -543,7 +543,7 @@ fn async_response_with_reply_path_succeeds() {
543543
let responder = Responder::new(reply_path);
544544
alice.custom_message_handler.expect_message_and_response(message.clone());
545545
let response_instruction =
546-
alice.custom_message_handler.handle_custom_message(message, None, Some(responder));
546+
alice.custom_message_handler.handle_custom_message(message, None, None, Some(responder));
547547

548548
let (msg, instructions) = response_instruction.unwrap();
549549
assert_eq!(
@@ -589,7 +589,7 @@ fn async_response_with_reply_path_fails() {
589589
let responder = Responder::new(reply_path);
590590
alice.custom_message_handler.expect_message_and_response(message.clone());
591591
let response_instruction =
592-
alice.custom_message_handler.handle_custom_message(message, None, Some(responder));
592+
alice.custom_message_handler.handle_custom_message(message, None, None, Some(responder));
593593

594594
let (msg, instructions) = response_instruction.unwrap();
595595
assert_eq!(

lightning/src/onion_message/messenger.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,17 +418,17 @@ impl Responder {
418418
pub fn respond(self) -> ResponseInstruction {
419419
ResponseInstruction {
420420
destination: Destination::BlindedPath(self.reply_path),
421-
context: None,
421+
reply_data: (None, None)
422422
}
423423
}
424424

425425
/// Creates a [`ResponseInstruction`] for responding including a reply path.
426426
///
427427
/// Use when the recipient needs to send back a reply to us.
428-
pub fn respond_with_reply_path(self, context: MessageContext) -> ResponseInstruction {
428+
pub fn respond_with_reply_path(self, context: MessageContext, custom_data: Option<Vec<u8>>) -> ResponseInstruction {
429429
ResponseInstruction {
430430
destination: Destination::BlindedPath(self.reply_path),
431-
context: Some(context),
431+
reply_data: (Some(context), custom_data),
432432
}
433433
}
434434
}
@@ -440,7 +440,7 @@ pub struct ResponseInstruction {
440440
/// [`Destination`] rather than an explicit [`BlindedMessagePath`] simplifies the logic in
441441
/// [`OnionMessenger::send_onion_message_internal`] somewhat.
442442
destination: Destination,
443-
context: Option<MessageContext>,
443+
reply_data: (Option<MessageContext>, Option<Vec<u8>>)
444444
}
445445

446446
impl ResponseInstruction {
@@ -469,7 +469,7 @@ pub enum MessageSendInstructions {
469469
destination: Destination,
470470
/// The context to include in the reply path we'll give the recipient so they can respond
471471
/// to us.
472-
context: MessageContext,
472+
reply_data: (MessageContext, Option<Vec<u8>>),
473473
},
474474
/// Indicates that a message should be sent without including a reply path, preventing the
475475
/// recipient from responding.
@@ -874,7 +874,7 @@ pub trait CustomOnionMessageHandler {
874874
///
875875
/// The returned [`Self::CustomMessage`], if any, is enqueued to be sent by [`OnionMessenger`].
876876
fn handle_custom_message(
877-
&self, message: Self::CustomMessage, context: Option<Vec<u8>>, responder: Option<Responder>,
877+
&self, message: Self::CustomMessage, context: Option<Vec<u8>>, custom_data: Option<Vec<u8>>, responder: Option<Responder>,
878878
) -> Option<(Self::CustomMessage, ResponseInstruction)>;
879879

880880
/// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
@@ -1315,10 +1315,10 @@ where
13151315
MessageSendInstructions::WithSpecifiedReplyPath { destination, reply_path } => {
13161316
(destination, Some(reply_path))
13171317
},
1318-
MessageSendInstructions::WithReplyPath { destination, context }
1318+
MessageSendInstructions::WithReplyPath { destination, reply_data: (context, custom_data) }
13191319
| MessageSendInstructions::ForReply {
1320-
instructions: ResponseInstruction { destination, context: Some(context) },
1321-
} => match self.create_blinded_path(context) {
1320+
instructions: ResponseInstruction { destination, reply_data: (Some(context), custom_data) },
1321+
} => match self.create_blinded_path(context, custom_data) {
13221322
Ok(reply_path) => (destination, Some(reply_path)),
13231323
Err(err) => {
13241324
log_trace!(
@@ -1332,7 +1332,7 @@ where
13321332
},
13331333
MessageSendInstructions::WithoutReplyPath { destination }
13341334
| MessageSendInstructions::ForReply {
1335-
instructions: ResponseInstruction { destination, context: None },
1335+
instructions: ResponseInstruction { destination, reply_data: (None, _) },
13361336
} => (destination, None),
13371337
};
13381338

@@ -1390,7 +1390,7 @@ where
13901390
}
13911391

13921392
fn create_blinded_path(
1393-
&self, context: MessageContext,
1393+
&self, context: MessageContext, custom_data: Option<Vec<u8>>,
13941394
) -> Result<BlindedMessagePath, SendError> {
13951395
let recipient = self
13961396
.node_signer
@@ -1409,7 +1409,7 @@ where
14091409

14101410
let recipient_tlvs = ReceiveTlvs {
14111411
context: Some(context),
1412-
custom_data: None,
1412+
custom_data,
14131413
};
14141414

14151415
self.message_router
@@ -1915,7 +1915,7 @@ where
19151915
},
19161916
};
19171917
let response_instructions =
1918-
self.custom_handler.handle_custom_message(msg, context, responder);
1918+
self.custom_handler.handle_custom_message(msg, context, custom_data, responder);
19191919
if let Some((msg, instructions)) = response_instructions {
19201920
let _ = self.handle_onion_message_response(msg, instructions);
19211921
}

0 commit comments

Comments
 (0)