X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=ec2c98cb93cdd0b6733937a176868624ee05c162;hb=32c245b08fca6330a3a8373184d025332feab157;hp=875354251c5022c760d2ebe301a17478d90e3ea0;hpb=09d2a71352f738de1f4f36248a735e6383ee0d8d;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 87535425..ec2c98cb 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -56,7 +56,10 @@ pub enum DecodeError { /// An init message to be sent or received from a peer pub struct Init { + #[cfg(not(feature = "fuzztarget"))] pub(crate) features: InitFeatures, + #[cfg(feature = "fuzztarget")] + pub features: InitFeatures, } /// An error message to be sent or received from a peer @@ -571,7 +574,7 @@ pub trait ChannelMessageHandler : events::MessageSendEventsProvider + Send + Syn fn peer_disconnected(&self, their_node_id: &PublicKey, no_connection_possible: bool); /// Handle a peer reconnecting, possibly generating channel_reestablish message(s). - fn peer_connected(&self, their_node_id: &PublicKey); + fn peer_connected(&self, their_node_id: &PublicKey, msg: &Init); /// Handle an incoming channel_reestablish message from the given peer. fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &ChannelReestablish); @@ -603,22 +606,20 @@ pub trait RoutingMessageHandler : Send + Sync { fn get_next_node_announcements(&self, starting_point: Option<&PublicKey>, batch_amount: u8) -> Vec; } -pub(crate) struct OnionRealm0HopData { - pub(crate) short_channel_id: u64, - pub(crate) amt_to_forward: u64, - pub(crate) outgoing_cltv_value: u32, - // 12 bytes of 0-padding -} - mod fuzzy_internal_msgs { // These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize // them from untrusted input): - use super::OnionRealm0HopData; + pub(crate) enum OnionHopDataFormat { + Legacy, // aka Realm-0 + } + pub struct OnionHopData { - pub(crate) realm: u8, - pub(crate) data: OnionRealm0HopData, - pub(crate) hmac: [u8; 32], + pub(crate) format: OnionHopDataFormat, + pub(crate) short_channel_id: u64, + pub(crate) amt_to_forward: u64, + pub(crate) outgoing_cltv_value: u32, + // 12 bytes of 0-padding } pub struct DecodedOnionErrorPacket { @@ -955,9 +956,12 @@ impl_writeable!(UpdateAddHTLC, 32+8+8+32+4+1366, { onion_routing_packet }); -impl Writeable for OnionRealm0HopData { +impl Writeable for OnionHopData { fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - w.size_hint(32); + w.size_hint(33); + match self.format { + OnionHopDataFormat::Legacy => 0u8.write(w)?, + } self.short_channel_id.write(w)?; self.amt_to_forward.write(w)?; self.outgoing_cltv_value.write(w)?; @@ -966,42 +970,23 @@ impl Writeable for OnionRealm0HopData { } } -impl Readable for OnionRealm0HopData { - fn read(r: &mut R) -> Result { - Ok(OnionRealm0HopData { - short_channel_id: Readable::read(r)?, - amt_to_forward: Readable::read(r)?, - outgoing_cltv_value: { - let v: u32 = Readable::read(r)?; - r.read_exact(&mut [0; 12])?; - v - } - }) - } -} - -impl Writeable for OnionHopData { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - w.size_hint(65); - self.realm.write(w)?; - self.data.write(w)?; - self.hmac.write(w)?; - Ok(()) - } -} - impl Readable for OnionHopData { fn read(r: &mut R) -> Result { Ok(OnionHopData { - realm: { + format: { let r: u8 = Readable::read(r)?; if r != 0 { return Err(DecodeError::UnknownVersion); } - r + OnionHopDataFormat::Legacy + }, + short_channel_id: Readable::read(r)?, + amt_to_forward: Readable::read(r)?, + outgoing_cltv_value: { + let v: u32 = Readable::read(r)?; + r.read_exact(&mut [0; 12])?; + v }, - data: Readable::read(r)?, - hmac: Readable::read(r)?, }) } }