AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc,
};
use lightning::onion_message::messenger::{
- CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger,
- PendingOnionMessage, Responder, ResponseInstruction,
+ CustomOnionMessageHandler, Destination, MessageRouter, MessageSendInstructions,
+ OnionMessagePath, OnionMessenger, Responder, ResponseInstruction,
};
use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
use lightning::onion_message::packet::OnionMessageContents;
buffer.read_to_limit(&mut buf, u64::MAX)?;
return Ok(Some(TestCustomMessage {}));
}
- fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
+ fn release_pending_custom_messages(&self) -> Vec<(TestCustomMessage, MessageSendInstructions)> {
vec![]
}
}
use crate::ln::wire;
use crate::ln::wire::{Encode, Type};
use crate::onion_message::async_payments::{AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc};
-use crate::onion_message::messenger::{CustomOnionMessageHandler, PendingOnionMessage, Responder, ResponseInstruction};
+use crate::onion_message::messenger::{CustomOnionMessageHandler, Responder, ResponseInstruction, MessageSendInstructions};
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
use crate::onion_message::packet::OnionMessageContents;
use crate::routing::gossip::{NodeId, NodeAlias};
fn read_custom_message<R: io::Read>(&self, _msg_type: u64, _buffer: &mut R) -> Result<Option<Infallible>, msgs::DecodeError> where Self: Sized {
Ok(None)
}
- fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Infallible>> {
+ fn release_pending_custom_messages(&self) -> Vec<(Infallible, MessageSendInstructions)> {
vec![]
}
}
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
use crate::util::test_utils;
use super::async_payments::{AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc};
-use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction, SendError, SendSuccess};
+use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, Responder, ResponseInstruction, MessageSendInstructions, SendError, SendSuccess};
use super::offers::{OffersMessage, OffersMessageHandler};
use super::packet::{OnionMessageContents, Packet};
_ => Ok(None),
}
}
- fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
+ fn release_pending_custom_messages(&self) -> Vec<(Self::CustomMessage, MessageSendInstructions)> {
vec![]
}
}
///
/// Typically, this is used for messages initiating a message flow rather than in response to
/// another message. The latter should use the return value of [`Self::handle_custom_message`].
- #[cfg(not(c_bindings))]
- fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>>;
-
- /// Releases any [`Self::CustomMessage`]s that need to be sent.
- ///
- /// Typically, this is used for messages initiating a message flow rather than in response to
- /// another message. The latter should use the return value of [`Self::handle_custom_message`].
- #[cfg(c_bindings)]
- fn release_pending_custom_messages(&self) -> Vec<(Self::CustomMessage, Destination, Option<BlindedMessagePath>)>;
+ fn release_pending_custom_messages(&self) -> Vec<(Self::CustomMessage, MessageSendInstructions)>;
}
/// A processed incoming onion message, containing either a Forward (another onion message)
)
}
+ fn send_onion_message_internal<T: OnionMessageContents>(
+ &self, message: T, instructions: MessageSendInstructions, log_suffix: fmt::Arguments,
+ ) -> Result<Option<SendSuccess>, SendError> {
+ let (destination, context) = match instructions {
+ MessageSendInstructions::WithReplyPath { destination, context } => (destination, Some(context)),
+ MessageSendInstructions::WithoutReplyPath { destination } => (destination, None),
+ };
+
+ let reply_path = if let Some(context) = context {
+ match self.create_blinded_path(context) {
+ Ok(reply_path) => Some(reply_path),
+ Err(err) => {
+ log_trace!(
+ self.logger,
+ "Failed to create reply path {}: {:?}",
+ log_suffix, err
+ );
+ return Err(err);
+ }
+ }
+ } else { None };
+
+ self.find_path_and_enqueue_onion_message(
+ message, destination, reply_path, log_suffix,
+ ).map(|result| Some(result))
+ }
+
fn find_path_and_enqueue_onion_message<T: OnionMessageContents>(
&self, contents: T, destination: Destination, reply_path: Option<BlindedMessagePath>,
log_suffix: fmt::Arguments
pub fn handle_onion_message_response<T: OnionMessageContents>(
&self, response: T, instructions: ResponseInstruction,
) -> Result<Option<SendSuccess>, SendError> {
- let (destination, context) = match instructions.into_instructions() {
- MessageSendInstructions::WithReplyPath { destination, context } => (destination, Some(context)),
- MessageSendInstructions::WithoutReplyPath { destination } => (destination, None),
- };
-
let message_type = response.msg_type();
- let reply_path = if let Some(context) = context {
- match self.create_blinded_path(context) {
- Ok(reply_path) => Some(reply_path),
- Err(err) => {
- log_trace!(
- self.logger,
- "Failed to create reply path when responding with {} to an onion message: {:?}",
- message_type, err
- );
- return Err(err);
- }
- }
- } else { None };
-
- self.find_path_and_enqueue_onion_message(
- response, destination, reply_path,
+ self.send_onion_message_internal(
+ response, instructions.into_instructions(),
format_args!(
"when responding with {} to an onion message",
message_type,
)
- ).map(|result| Some(result))
+ )
}
#[cfg(test)]
}
// Enqueue any initiating `CustomMessage`s to send.
- for message in self.custom_handler.release_pending_custom_messages() {
- #[cfg(not(c_bindings))]
- let PendingOnionMessage { contents, destination, reply_path } = message;
- #[cfg(c_bindings)]
- let (contents, destination, reply_path) = message;
- let _ = self.find_path_and_enqueue_onion_message(
- contents, destination, reply_path, format_args!("when sending CustomMessage")
+ for (message, instructions) in self.custom_handler.release_pending_custom_messages() {
+ let _ = self.send_onion_message_internal(
+ message, instructions, format_args!("when sending CustomMessage")
);
}