X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmsgs.rs;h=eec1a053802fd7476ce1b43f0518b4ef339c1dfb;hb=58a4f6c4ad3c262f7ed7009f6c99d36936e958b4;hp=3c1a549ada269adb56220aa3c021be3b9ec2b202;hpb=3a0356fe308ba29916d00f3376cd57ce6613f3d0;p=rust-lightning diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 3c1a549a..eec1a053 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -32,6 +32,7 @@ use bitcoin::hash_types::{Txid, BlockHash}; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; +use prelude::*; use core::{cmp, fmt}; use core::fmt::Debug; use std::io::Read; @@ -482,6 +483,17 @@ impl Readable for Result { } } +impl Readable for NetAddress { + fn read(reader: &mut R) -> Result { + match Readable::read(reader) { + Ok(Ok(res)) => Ok(res), + Ok(Err(_)) => Err(DecodeError::UnknownVersion), + Err(e) => Err(e), + } + } +} + + /// The unsigned part of a node_announcement #[derive(Clone, Debug, PartialEq)] pub struct UnsignedNodeAnnouncement { @@ -867,6 +879,7 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider { } mod fuzzy_internal_msgs { + use prelude::*; use ln::PaymentSecret; // These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize @@ -1285,20 +1298,17 @@ impl Writeable for OnionHopData { (2, HighZeroBytesDroppedVarInt(self.amt_to_forward)), (4, HighZeroBytesDroppedVarInt(self.outgoing_cltv_value)), (6, short_channel_id) - }); + }, { }); }, - OnionHopDataFormat::FinalNode { payment_data: Some(ref final_data) } => { - if final_data.total_msat > MAX_VALUE_MSAT { panic!("We should never be sending infinite/overflow onion payments"); } - encode_varint_length_prefixed_tlv!(w, { - (2, HighZeroBytesDroppedVarInt(self.amt_to_forward)), - (4, HighZeroBytesDroppedVarInt(self.outgoing_cltv_value)), - (8, final_data) - }); - }, - OnionHopDataFormat::FinalNode { payment_data: None } => { + OnionHopDataFormat::FinalNode { ref payment_data } => { + if let Some(final_data) = payment_data { + if final_data.total_msat > MAX_VALUE_MSAT { panic!("We should never be sending infinite/overflow onion payments"); } + } encode_varint_length_prefixed_tlv!(w, { (2, HighZeroBytesDroppedVarInt(self.amt_to_forward)), (4, HighZeroBytesDroppedVarInt(self.outgoing_cltv_value)) + }, { + (8, payment_data) }); }, } @@ -1844,6 +1854,7 @@ mod tests { use bitcoin::secp256k1::key::{PublicKey,SecretKey}; use bitcoin::secp256k1::{Secp256k1, Message}; + use prelude::*; use std::io::Cursor; #[test]