From: Wilmer Paulino Date: Thu, 18 May 2023 16:36:18 +0000 (-0700) Subject: Implement enqueue_message trait requirements on Message enum X-Git-Tag: v0.0.116-alpha1~27^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=55a7a03248cbd1a1b952c37ea7722a711b24403e;p=rust-lightning Implement enqueue_message trait requirements on Message enum The inner structs of each enum variant already implemented them and we plan to pass in `Message`s to `enqueue_message` in a future commit. --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 3cb6a55f2..059ccde48 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -26,7 +26,7 @@ use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager use crate::util::ser::{VecWriter, Writeable, Writer}; use crate::ln::peer_channel_encryptor::{PeerChannelEncryptor,NextNoiseStep}; use crate::ln::wire; -use crate::ln::wire::Encode; +use crate::ln::wire::{Encode, Type}; use crate::onion_message::{CustomOnionMessageContents, CustomOnionMessageHandler, SimpleArcOnionMessenger, SimpleRefOnionMessenger}; use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, NodeAlias}; use crate::util::atomic_counter::AtomicCounter; diff --git a/lightning/src/ln/wire.rs b/lightning/src/ln/wire.rs index 1a01e3382..88e2ad7c1 100644 --- a/lightning/src/ln/wire.rs +++ b/lightning/src/ln/wire.rs @@ -96,9 +96,59 @@ pub(crate) enum Message where T: core::fmt::Debug + Type + TestEq { Custom(T), } -impl Message where T: core::fmt::Debug + Type + TestEq { +impl Writeable for Message where T: core::fmt::Debug + Type + TestEq { + fn write(&self, writer: &mut W) -> Result<(), io::Error> { + match self { + &Message::Init(ref msg) => msg.write(writer), + &Message::Error(ref msg) => msg.write(writer), + &Message::Warning(ref msg) => msg.write(writer), + &Message::Ping(ref msg) => msg.write(writer), + &Message::Pong(ref msg) => msg.write(writer), + &Message::OpenChannel(ref msg) => msg.write(writer), + &Message::OpenChannelV2(ref msg) => msg.write(writer), + &Message::AcceptChannel(ref msg) => msg.write(writer), + &Message::AcceptChannelV2(ref msg) => msg.write(writer), + &Message::FundingCreated(ref msg) => msg.write(writer), + &Message::FundingSigned(ref msg) => msg.write(writer), + &Message::TxAddInput(ref msg) => msg.write(writer), + &Message::TxAddOutput(ref msg) => msg.write(writer), + &Message::TxRemoveInput(ref msg) => msg.write(writer), + &Message::TxRemoveOutput(ref msg) => msg.write(writer), + &Message::TxComplete(ref msg) => msg.write(writer), + &Message::TxSignatures(ref msg) => msg.write(writer), + &Message::TxInitRbf(ref msg) => msg.write(writer), + &Message::TxAckRbf(ref msg) => msg.write(writer), + &Message::TxAbort(ref msg) => msg.write(writer), + &Message::ChannelReady(ref msg) => msg.write(writer), + &Message::Shutdown(ref msg) => msg.write(writer), + &Message::ClosingSigned(ref msg) => msg.write(writer), + &Message::OnionMessage(ref msg) => msg.write(writer), + &Message::UpdateAddHTLC(ref msg) => msg.write(writer), + &Message::UpdateFulfillHTLC(ref msg) => msg.write(writer), + &Message::UpdateFailHTLC(ref msg) => msg.write(writer), + &Message::UpdateFailMalformedHTLC(ref msg) => msg.write(writer), + &Message::CommitmentSigned(ref msg) => msg.write(writer), + &Message::RevokeAndACK(ref msg) => msg.write(writer), + &Message::UpdateFee(ref msg) => msg.write(writer), + &Message::ChannelReestablish(ref msg) => msg.write(writer), + &Message::AnnouncementSignatures(ref msg) => msg.write(writer), + &Message::ChannelAnnouncement(ref msg) => msg.write(writer), + &Message::NodeAnnouncement(ref msg) => msg.write(writer), + &Message::ChannelUpdate(ref msg) => msg.write(writer), + &Message::QueryShortChannelIds(ref msg) => msg.write(writer), + &Message::ReplyShortChannelIdsEnd(ref msg) => msg.write(writer), + &Message::QueryChannelRange(ref msg) => msg.write(writer), + &Message::ReplyChannelRange(ref msg) => msg.write(writer), + &Message::GossipTimestampFilter(ref msg) => msg.write(writer), + &Message::Unknown(_) => { Ok(()) }, + &Message::Custom(ref msg) => msg.write(writer), + } + } +} + +impl Type for Message where T: core::fmt::Debug + Type + TestEq { /// Returns the type that was used to decode the message payload. - pub fn type_id(&self) -> u16 { + fn type_id(&self) -> u16 { match self { &Message::Init(ref msg) => msg.type_id(), &Message::Error(ref msg) => msg.type_id(), @@ -145,7 +195,9 @@ impl Message where T: core::fmt::Debug + Type + TestEq { &Message::Custom(ref msg) => msg.type_id(), } } +} +impl Message where T: core::fmt::Debug + Type + TestEq { /// Returns whether the message's type is even, indicating both endpoints must support it. pub fn is_even(&self) -> bool { (self.type_id() & 1) == 0