mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
logging every sent and receive onion message
Logs every sent + receive for P2P messages solves #2346
This commit is contained in:
parent
6b43153861
commit
ff5e5221d2
8 changed files with 38 additions and 17 deletions
|
@ -91,6 +91,7 @@ impl OffersMessageHandler for TestOffersMessageHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TestCustomMessage {}
|
||||
|
||||
const CUSTOM_MESSAGE_TYPE: u64 = 4242;
|
||||
|
@ -265,9 +266,10 @@ mod tests {
|
|||
{
|
||||
let log_entries = logger.lines.lock().unwrap();
|
||||
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
|
||||
"Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
|
||||
"Received an onion message with path_id None and a reply_path: Custom(TestCustomMessage)"
|
||||
.to_string())), Some(&1));
|
||||
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
|
||||
"Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
|
||||
"Sending onion message: TestCustomMessage".to_string())), Some(&1));
|
||||
}
|
||||
|
||||
let two_unblinded_hops_om = "\
|
||||
|
|
|
@ -720,8 +720,7 @@ impl Bolt12Invoice {
|
|||
self.contents.verify(TlvStream::new(&self.bytes), key, secp_ctx)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
|
||||
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
|
||||
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream) =
|
||||
self.contents.as_tlv_stream();
|
||||
let signature_tlv_stream = SignatureTlvStreamRef {
|
||||
|
@ -1143,7 +1142,6 @@ impl_writeable!(FallbackAddress, { version, program });
|
|||
type FullInvoiceTlvStream =
|
||||
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, InvoiceTlvStream, SignatureTlvStream);
|
||||
|
||||
#[cfg(test)]
|
||||
type FullInvoiceTlvStreamRef<'a> = (
|
||||
PayerTlvStreamRef<'a>,
|
||||
OfferTlvStreamRef<'a>,
|
||||
|
|
|
@ -608,8 +608,7 @@ impl InvoiceRequest {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
|
||||
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
|
||||
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream) =
|
||||
self.contents.as_tlv_stream();
|
||||
let signature_tlv_stream = SignatureTlvStreamRef {
|
||||
|
@ -811,7 +810,6 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST
|
|||
type FullInvoiceRequestTlvStream =
|
||||
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream);
|
||||
|
||||
#[cfg(test)]
|
||||
type FullInvoiceRequestTlvStreamRef<'a> = (
|
||||
PayerTlvStreamRef<'a>,
|
||||
OfferTlvStreamRef<'a>,
|
||||
|
|
|
@ -381,6 +381,7 @@ fn reply_path() {
|
|||
fn invalid_custom_message_type() {
|
||||
let nodes = create_nodes(2);
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InvalidCustomMessage{}
|
||||
impl OnionMessageContents for InvalidCustomMessage {
|
||||
fn tlv_type(&self) -> u64 {
|
||||
|
|
|
@ -71,7 +71,7 @@ use crate::prelude::*;
|
|||
/// # use std::sync::Arc;
|
||||
/// # struct FakeLogger;
|
||||
/// # impl Logger for FakeLogger {
|
||||
/// # fn log(&self, record: Record) { unimplemented!() }
|
||||
/// # fn log(&self, record: Record) { println!("{:?}" , record); }
|
||||
/// # }
|
||||
/// # struct FakeMessageRouter {}
|
||||
/// # impl MessageRouter for FakeMessageRouter {
|
||||
|
@ -97,7 +97,8 @@ use crate::prelude::*;
|
|||
/// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
|
||||
/// &custom_message_handler
|
||||
/// );
|
||||
///
|
||||
|
||||
/// # #[derive(Debug)]
|
||||
/// # struct YourCustomMessage {}
|
||||
/// impl Writeable for YourCustomMessage {
|
||||
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
|
||||
|
@ -517,6 +518,9 @@ where
|
|||
pub fn send_onion_message<T: OnionMessageContents>(
|
||||
&self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>
|
||||
) -> Result<(), SendError> {
|
||||
|
||||
log_trace!(self.logger, "Sending onion message: {:?}", contents);
|
||||
|
||||
let (first_node_id, onion_msg) = create_onion_message(
|
||||
&self.entropy_source, &self.node_signer, &self.secp_ctx, path, contents, reply_path
|
||||
)?;
|
||||
|
@ -570,7 +574,7 @@ where
|
|||
},
|
||||
};
|
||||
|
||||
log_trace!(self.logger, "Sending onion message {}", log_suffix);
|
||||
log_trace!(self.logger, "Sending onion message {}: {:?}", log_suffix, contents);
|
||||
|
||||
if let Err(e) = self.send_onion_message(path, contents, reply_path) {
|
||||
log_trace!(self.logger, "Failed sending onion message {}: {:?}", log_suffix, e);
|
||||
|
@ -629,9 +633,10 @@ where
|
|||
msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler
|
||||
) {
|
||||
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
|
||||
log_trace!(self.logger,
|
||||
"Received an onion message with path_id {:02x?} and {} reply_path",
|
||||
path_id, if reply_path.is_some() { "a" } else { "no" });
|
||||
log_trace!(
|
||||
self.logger,
|
||||
"Received an onion message with path_id {:02x?} and {} reply_path: {:?}",
|
||||
path_id, if reply_path.is_some() { "a" } else { "no" }, message);
|
||||
|
||||
match message {
|
||||
ParsedOnionMessageContents::Offers(msg) => {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
//! Message handling for BOLT 12 Offers.
|
||||
|
||||
use core::convert::TryFrom;
|
||||
use core::fmt;
|
||||
use crate::io::{self, Read};
|
||||
use crate::ln::msgs::DecodeError;
|
||||
use crate::offers::invoice_error::InvoiceError;
|
||||
|
@ -58,7 +59,7 @@ pub trait OffersMessageHandler {
|
|||
/// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`].
|
||||
///
|
||||
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone)]
|
||||
pub enum OffersMessage {
|
||||
/// A request for a [`Bolt12Invoice`] for a particular [`Offer`].
|
||||
///
|
||||
|
@ -92,6 +93,22 @@ impl OffersMessage {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for OffersMessage {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
OffersMessage::InvoiceRequest(message) => {
|
||||
write!(f, "{:?}", message.as_tlv_stream())
|
||||
}
|
||||
OffersMessage::Invoice(message) => {
|
||||
write!(f, "{:?}", message.as_tlv_stream())
|
||||
}
|
||||
OffersMessage::InvoiceError(message) => {
|
||||
write!(f, "{:?}", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OnionMessageContents for OffersMessage {
|
||||
fn tlv_type(&self) -> u64 {
|
||||
match self {
|
||||
|
|
|
@ -147,7 +147,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
|
|||
}
|
||||
|
||||
/// The contents of an onion message.
|
||||
pub trait OnionMessageContents: Writeable {
|
||||
pub trait OnionMessageContents: Writeable + core::fmt::Debug {
|
||||
/// Returns the TLV type identifying the message contents. MUST be >= 64.
|
||||
fn tlv_type(&self) -> u64;
|
||||
}
|
||||
|
|
|
@ -917,7 +917,7 @@ macro_rules! tlv_stream {
|
|||
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug)]
|
||||
pub(super) struct $nameref<'a> {
|
||||
pub(crate) struct $nameref<'a> {
|
||||
$(
|
||||
pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
|
||||
)*
|
||||
|
|
Loading…
Add table
Reference in a new issue