projects
/
rust-lightning
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f986626
)
Make the custom message traits cloneable as they're deep in nested structs
author
Matt Corallo
<git@bluematt.me>
Fri, 24 Sep 2021 18:44:32 +0000
(18:44 +0000)
committer
Matt Corallo
<git@bluematt.me>
Tue, 24 Oct 2023 04:16:34 +0000
(
04:16
+0000)
lightning/src/ln/wire.rs
patch
|
blob
|
history
lightning/src/onion_message/functional_tests.rs
patch
|
blob
|
history
lightning/src/onion_message/messenger.rs
patch
|
blob
|
history
lightning/src/onion_message/packet.rs
patch
|
blob
|
history
diff --git
a/lightning/src/ln/wire.rs
b/lightning/src/ln/wire.rs
index 88e2ad7c1daee03ef245c795f0119eb229a10520..e982a2aec0da3b504a32dbc10b9b5f9662cfb229 100644
(file)
--- a/
lightning/src/ln/wire.rs
+++ b/
lightning/src/ln/wire.rs
@@
-45,9
+45,9
@@
impl<T> TestEq for T {}
/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
/// variant contains a message from [`msgs`] or otherwise the message type if unknown.
#[allow(missing_docs)]
/// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
/// variant contains a message from [`msgs`] or otherwise the message type if unknown.
#[allow(missing_docs)]
-#[derive(Debug)]
+#[derive(
Clone,
Debug)]
#[cfg_attr(test, derive(PartialEq))]
#[cfg_attr(test, derive(PartialEq))]
-pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
+pub(crate) enum Message<T> where T:
Clone +
core::fmt::Debug + Type + TestEq {
Init(msgs::Init),
Error(msgs::ErrorMessage),
Warning(msgs::WarningMessage),
Init(msgs::Init),
Error(msgs::ErrorMessage),
Warning(msgs::WarningMessage),
@@
-383,13
+383,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`].
/// 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)]
/// 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;
}
fn type_id(&self) -> u16;
}
@@
-399,12
+399,12
@@
impl Type for () {
}
#[cfg(test)]
}
#[cfg(test)]
-impl<T: core::fmt::Debug + Writeable + PartialEq> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable +
Clone +
PartialEq> Type for T where T: Encode {
fn type_id(&self) -> u16 { T::TYPE }
}
#[cfg(not(test))]
fn type_id(&self) -> u16 { T::TYPE }
}
#[cfg(not(test))]
-impl<T: core::fmt::Debug + Writeable> Type for T where T: Encode {
+impl<T: core::fmt::Debug + Writeable
+ Clone
> Type for T where T: Encode {
fn type_id(&self) -> u16 { T::TYPE }
}
fn type_id(&self) -> u16 { T::TYPE }
}
@@
-734,7
+734,7
@@
mod tests {
}
}
}
}
- #[derive(Eq, PartialEq, Debug)]
+ #[derive(
Clone,
Eq, PartialEq, Debug)]
struct TestCustomMessage {}
const CUSTOM_MESSAGE_TYPE : u16 = 9000;
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 0193001b30c0d5ca4fc0421b27470a9fab81d0de..283aa027f01fb00934575faffeeb76e91931d4b2 100644
(file)
--- a/
lightning/src/onion_message/functional_tests.rs
+++ b/
lightning/src/onion_message/functional_tests.rs
@@
-380,6
+380,7
@@
fn reply_path() {
fn invalid_custom_message_type() {
let nodes = create_nodes(2);
fn invalid_custom_message_type() {
let nodes = create_nodes(2);
+ #[derive(Clone)]
struct InvalidCustomMessage{}
impl OnionMessageContents for InvalidCustomMessage {
fn tlv_type(&self) -> u64 {
struct InvalidCustomMessage{}
impl OnionMessageContents for InvalidCustomMessage {
fn tlv_type(&self) -> u64 {
diff --git
a/lightning/src/onion_message/messenger.rs
b/lightning/src/onion_message/messenger.rs
index 0bd7b0f511ff5461048bd4dd656c700cbc2fb795..06985758e10c18d00b6eca3d3dffc43c44172dab 100644
(file)
--- a/
lightning/src/onion_message/messenger.rs
+++ b/
lightning/src/onion_message/messenger.rs
@@
-98,6
+98,7
@@
use crate::prelude::*;
/// &custom_message_handler
/// );
///
/// &custom_message_handler
/// );
///
+/// # #[derive(Clone)]
/// # struct YourCustomMessage {}
/// impl Writeable for YourCustomMessage {
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
/// # struct YourCustomMessage {}
/// impl Writeable for YourCustomMessage {
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
diff --git
a/lightning/src/onion_message/packet.rs
b/lightning/src/onion_message/packet.rs
index ba90c717b34181783506f0ab5018fc15ec8093de..1dbe5706eefdb23791b1b3d70c69fd343c7c35c1 100644
(file)
--- a/
lightning/src/onion_message/packet.rs
+++ b/
lightning/src/onion_message/packet.rs
@@
-117,7
+117,7
@@
pub(super) enum Payload<T: OnionMessageContents> {
/// The contents of an [`OnionMessage`] as read from the wire.
///
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
/// The contents of an [`OnionMessage`] as read from the wire.
///
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
-#[derive(Debug)]
+#[derive(
Clone,
Debug)]
pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
/// A message related to BOLT 12 Offers.
Offers(OffersMessage),
pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
/// A message related to BOLT 12 Offers.
Offers(OffersMessage),
@@
-147,7
+147,7
@@
impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
}
/// The contents of an onion message.
}
/// The contents of an onion message.
-pub trait OnionMessageContents: Writeable {
+pub trait OnionMessageContents: Writeable
+ Clone
{
/// Returns the TLV type identifying the message contents. MUST be >= 64.
fn tlv_type(&self) -> u64;
}
/// Returns the TLV type identifying the message contents. MUST be >= 64.
fn tlv_type(&self) -> u64;
}