use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use std::{cmp, fmt};
+use std::fmt::Debug;
use std::io::Read;
use util::events::MessageSendEventsProvider;
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;
/// An error in decoding a message or struct.
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub enum DecodeError {
/// A version byte specified something we don't know how to handle.
/// Includes unknown realm byte in an OnionHopData packet
/// A length descriptor in the packet didn't describe the later data correctly
BadLengthDescriptor,
/// Error from std::io
- Io(::std::io::Error),
+ Io(::std::io::ErrorKind),
}
/// An init message to be sent or received from a peer
},
}
impl NetAddress {
- fn get_id(&self) -> u8 {
- match self {
- &NetAddress::IPv4 {..} => { 1 },
- &NetAddress::IPv6 {..} => { 2 },
- &NetAddress::OnionV2 {..} => { 3 },
- &NetAddress::OnionV3 {..} => { 4 },
- }
- }
-
/// Strict byte-length of address descriptor, 1-byte type not recorded
fn len(&self) -> u16 {
match self {
pub first_blocknum: u32,
/// The number of blocks included in the range of the reply
pub number_of_blocks: u32,
- /// Indicates if the query recipient maintains up-to-date channel
- /// information for the chain_hash
- pub full_information: bool,
+ /// True when this is the final reply for a query
+ pub sync_complete: bool,
/// The short_channel_ids in the channel range
pub short_channel_ids: Vec<u64>,
}
}
/// An Err type for failure to process messages.
+#[derive(Clone)]
pub struct LightningError {
/// A human-readable message describing the error
pub err: String,
if e.kind() == ::std::io::ErrorKind::UnexpectedEof {
DecodeError::ShortRead
} else {
- DecodeError::Io(e)
+ DecodeError::Io(e.kind())
}
}
}
w.write_all(&self.rgb)?;
self.alias.write(w)?;
- let mut addrs_to_encode = self.addresses.clone();
- addrs_to_encode.sort_by(|a, b| { a.get_id().cmp(&b.get_id()) });
let mut addr_len = 0;
- for addr in &addrs_to_encode {
+ for addr in self.addresses.iter() {
addr_len += 1 + addr.len();
}
(addr_len + self.excess_address_data.len() as u16).write(w)?;
- for addr in addrs_to_encode {
+ for addr in self.addresses.iter() {
addr.write(w)?;
}
w.write_all(&self.excess_address_data[..])?;
let addr_len: u16 = Readable::read(r)?;
let mut addresses: Vec<NetAddress> = Vec::new();
- let mut highest_addr_type = 0;
let mut addr_readpos = 0;
let mut excess = false;
let mut excess_byte = 0;
if addr_len <= addr_readpos { break; }
match Readable::read(r) {
Ok(Ok(addr)) => {
- if addr.get_id() < highest_addr_type {
- // Addresses must be sorted in increasing order
- return Err(DecodeError::InvalidValue);
- }
- highest_addr_type = addr.get_id();
if addr_len < addr_readpos + 1 + addr.len() {
return Err(DecodeError::BadLengthDescriptor);
}
let chain_hash: BlockHash = Readable::read(r)?;
let first_blocknum: u32 = Readable::read(r)?;
let number_of_blocks: u32 = Readable::read(r)?;
- let full_information: bool = Readable::read(r)?;
+ let sync_complete: bool = Readable::read(r)?;
// We expect the encoding_len to always includes the 1-byte
// encoding_type and that short_channel_ids are 8-bytes each
chain_hash,
first_blocknum,
number_of_blocks,
- full_information,
+ sync_complete,
short_channel_ids
})
}
self.chain_hash.write(w)?;
self.first_blocknum.write(w)?;
self.number_of_blocks.write(w)?;
- self.full_information.write(w)?;
+ self.sync_complete.write(w)?;
encoding_len.write(w)?;
(EncodingType::Uncompressed as u8).write(w)?;
chain_hash: expected_chain_hash,
first_blocknum: 756230,
number_of_blocks: 1500,
- full_information: true,
+ sync_complete: true,
short_channel_ids: vec![0x000000000000008e, 0x0000000000003c69, 0x000000000045a6c4],
};
assert_eq!(reply_channel_range.chain_hash, expected_chain_hash);
assert_eq!(reply_channel_range.first_blocknum, 756230);
assert_eq!(reply_channel_range.number_of_blocks, 1500);
- assert_eq!(reply_channel_range.full_information, true);
+ assert_eq!(reply_channel_range.sync_complete, true);
assert_eq!(reply_channel_range.short_channel_ids[0], 0x000000000000008e);
assert_eq!(reply_channel_range.short_channel_ids[1], 0x0000000000003c69);
assert_eq!(reply_channel_range.short_channel_ids[2], 0x000000000045a6c4);