From b9b43ce5c8cb3216d1459944c6f0d48d8c37243f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 24 Sep 2021 18:44:32 +0000 Subject: [PATCH] Make the custom message traits cloneable as they're deep in nested structs --- lightning/src/ln/wire.rs | 10 +++++----- lightning/src/onion_message/functional_tests.rs | 1 + lightning/src/onion_message/messenger.rs | 1 + lightning/src/onion_message/packet.rs | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index deec15a5..1ceb38c7 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -276,13 +276,13 @@ pub(crate) use self::encode::Encode; /// Defines a type identifier for sending messages over the wire. /// /// Messages implementing this trait specify a type and must be [`Writeable`]. -pub trait Type: core::fmt::Debug + Writeable { +pub trait Type: core::fmt::Debug + Writeable + Clone { /// Returns the type identifying the message payload. fn type_id(&self) -> u16; } #[cfg(test)] -pub trait Type: core::fmt::Debug + Writeable + PartialEq { +pub trait Type: core::fmt::Debug + Writeable + Clone + PartialEq { fn type_id(&self) -> u16; } @@ -292,12 +292,12 @@ impl Type for () { } #[cfg(test)] -impl Type for T where T: Encode { +impl Type for T where T: Encode { fn type_id(&self) -> u16 { T::TYPE } } #[cfg(not(test))] -impl Type for T where T: Encode { +impl Type for T where T: Encode { fn type_id(&self) -> u16 { T::TYPE } } @@ -583,7 +583,7 @@ mod tests { } } - #[derive(Eq, PartialEq, Debug)] + #[derive(Clone, Eq, PartialEq, Debug)] struct TestCustomMessage {} const CUSTOM_MESSAGE_TYPE : u16 = 9000; diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index efa6507b..c4faffab 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -220,6 +220,7 @@ fn reply_path() { fn invalid_custom_message_type() { let nodes = create_nodes(2); + #[derive(Clone)] struct InvalidCustomMessage{} impl CustomOnionMessageContents for InvalidCustomMessage { fn tlv_type(&self) -> u64 { diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 6284c47c..78e8ccd1 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -71,6 +71,7 @@ use crate::prelude::*; /// // ChannelManager. /// let onion_messenger = OnionMessenger::new(&keys_manager, logger, your_custom_message_handler); /// +/// # #[derive(Clone)] /// # struct YourCustomMessage {} /// impl Writeable for YourCustomMessage { /// fn write(&self, w: &mut W) -> Result<(), io::Error> { diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 3bc42f50..440d5006 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -134,7 +134,7 @@ impl Writeable for OnionMessageContents { } /// The contents of a custom onion message. -pub trait CustomOnionMessageContents: Writeable { +pub trait CustomOnionMessageContents: Writeable + Clone { /// Returns the TLV type identifying the message contents. MUST be >= 64. fn tlv_type(&self) -> u64; } -- 2.30.2