]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass logger to onion payload decoder
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 2 Jun 2023 13:08:59 +0000 (08:08 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 13 Jun 2023 18:07:46 +0000 (13:07 -0500)
In an upcoming commit, messages for BOLT 12 offers are read from the
onion payload. Passing a logger allows for logging semantic errors when
parsing the messages.

lightning/src/onion_message/messenger.rs
lightning/src/onion_message/packet.rs

index 5171422cb895ac45ace605871fb44c0630104e41..865700609450380ad2314d8f26b36cb6401bc0c1 100644 (file)
@@ -301,7 +301,7 @@ fn outbound_buffer_full(peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, Ve
 impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessageHandler for OnionMessenger<ES, NS, L, CMH>
        where ES::Target: EntropySource,
                  NS::Target: NodeSigner,
-                 L::Target: Logger,
+                 L::Target: Logger + Sized,
                  CMH::Target: CustomOnionMessageHandler + Sized,
 {
        /// Handle an incoming onion message. Currently, if a message was destined for us we will log, but
@@ -331,9 +331,10 @@ impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessageHandler for OnionMe
                                }
                        }
                };
-               match onion_utils::decode_next_untagged_hop(onion_decode_ss, &msg.onion_routing_packet.hop_data[..],
-                       msg.onion_routing_packet.hmac, (control_tlvs_ss, &*self.custom_handler))
-               {
+               match onion_utils::decode_next_untagged_hop(
+                       onion_decode_ss, &msg.onion_routing_packet.hop_data[..], msg.onion_routing_packet.hmac,
+                       (control_tlvs_ss, &*self.custom_handler, &*self.logger)
+               ) {
                        Ok((Payload::Receive::<<<CMH as Deref>::Target as CustomOnionMessageHandler>::CustomMessage> {
                                message, control_tlvs: ReceiveControlTlvs::Unblinded(ReceiveTlvs { path_id }), reply_path,
                        }, None)) => {
index 2fb2407dbdd093bdbe4ae260e31f12fbe4722d8a..d4f08109cd9858e0b62c88fbaffe59249b07efee 100644 (file)
@@ -17,6 +17,7 @@ use crate::ln::msgs::DecodeError;
 use crate::ln::onion_utils;
 use super::messenger::CustomOnionMessageHandler;
 use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter};
+use crate::util::logger::Logger;
 use crate::util::ser::{BigSize, FixedLengthReader, LengthRead, LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer};
 
 use core::cmp;
@@ -201,9 +202,10 @@ impl<T: CustomOnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
 }
 
 // Uses the provided secret to simultaneously decode and decrypt the control TLVs and data TLV.
-impl<H: CustomOnionMessageHandler> ReadableArgs<(SharedSecret, &H)> for Payload<<H as CustomOnionMessageHandler>::CustomMessage> {
-       fn read<R: Read>(r: &mut R, args: (SharedSecret, &H)) -> Result<Self, DecodeError> {
-               let (encrypted_tlvs_ss, handler) = args;
+impl<H: CustomOnionMessageHandler, L: Logger>
+ReadableArgs<(SharedSecret, &H, &L)> for Payload<<H as CustomOnionMessageHandler>::CustomMessage> {
+       fn read<R: Read>(r: &mut R, args: (SharedSecret, &H, &L)) -> Result<Self, DecodeError> {
+               let (encrypted_tlvs_ss, handler, _logger) = args;
 
                let v: BigSize = Readable::read(r)?;
                let mut rd = FixedLengthReader::new(r, v.0);