X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fmsgs.rs;h=dd60efa03c1a480d8cb41d00d6a7d28fb2529462;hb=HEAD;hp=b4432c7084d9ebf8340b547ec2ca515700650ca0;hpb=97488ad36e4e22cc1d6ae3832a0cb6c1bcb1dc94;p=rust-lightning diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs deleted file mode 100644 index b4432c70..00000000 --- a/src/ln/msgs.rs +++ /dev/null @@ -1,2330 +0,0 @@ -use secp256k1::key::PublicKey; -use secp256k1::{Secp256k1, Signature}; -use secp256k1; -use bitcoin::util::hash::Sha256dHash; -use bitcoin::network::serialize::{deserialize,serialize}; -use bitcoin::blockdata::script::Script; - -use std::error::Error; -use std::{cmp, fmt}; -use std::result::Result; - -use util::{byte_utils, internal_traits, events}; -use util::ser::{Readable, Reader, Writeable, Writer}; - -pub trait MsgEncodable { - fn encode(&self) -> Vec; - #[inline] - fn encoded_len(&self) -> usize { self.encode().len() } - #[inline] - fn encode_with_len(&self) -> Vec { - let enc = self.encode(); - let mut res = Vec::with_capacity(enc.len() + 2); - res.extend_from_slice(&byte_utils::be16_to_array(enc.len() as u16)); - res.extend_from_slice(&enc); - res - } -} -#[derive(Debug)] -pub enum DecodeError { - /// Unknown realm byte in an OnionHopData packet - UnknownRealmByte, - /// Unknown feature mandating we fail to parse message - UnknownRequiredFeature, - /// Failed to decode a public key (ie it's invalid) - BadPublicKey, - /// Failed to decode a signature (ie it's invalid) - BadSignature, - /// Value expected to be text wasn't decodable as text - BadText, - /// Buffer too short - ShortRead, - /// node_announcement included more than one address of a given type! - ExtraAddressesPerType, - /// A length descriptor in the packet didn't describe the later data correctly - /// (currently only generated in node_announcement) - BadLengthDescriptor, - /// Error from std::io - Io(::std::io::Error), - /// 1 or 0 is not found for boolean value - InvalidValue, -} -pub trait MsgDecodable: Sized { - fn decode(v: &[u8]) -> Result; -} - -/// Tracks localfeatures which are only in init messages -#[derive(Clone, PartialEq)] -pub struct LocalFeatures { - flags: Vec, -} - -impl LocalFeatures { - pub fn new() -> LocalFeatures { - LocalFeatures { - flags: Vec::new(), - } - } - - pub fn supports_data_loss_protect(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & 3) != 0 - } - pub fn requires_data_loss_protect(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & 1) != 0 - } - - pub fn initial_routing_sync(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0 - } - pub fn set_initial_routing_sync(&mut self) { - if self.flags.len() == 0 { - self.flags.resize(1, 1 << 3); - } else { - self.flags[0] |= 1 << 3; - } - } - - pub fn supports_upfront_shutdown_script(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (3 << 4)) != 0 - } - pub fn requires_upfront_shutdown_script(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (1 << 4)) != 0 - } - - pub fn requires_unknown_bits(&self) -> bool { - for (idx, &byte) in self.flags.iter().enumerate() { - if idx != 0 && (byte & 0x55) != 0 { - return true; - } else if idx == 0 && (byte & 0x14) != 0 { - return true; - } - } - return false; - } - - pub fn supports_unknown_bits(&self) -> bool { - for (idx, &byte) in self.flags.iter().enumerate() { - if idx != 0 && byte != 0 { - return true; - } else if idx == 0 && (byte & 0xc4) != 0 { - return true; - } - } - return false; - } -} - -/// Tracks globalfeatures which are in init messages and routing announcements -#[derive(Clone, PartialEq)] -pub struct GlobalFeatures { - flags: Vec, -} - -impl GlobalFeatures { - pub fn new() -> GlobalFeatures { - GlobalFeatures { - flags: Vec::new(), - } - } - - pub fn requires_unknown_bits(&self) -> bool { - for &byte in self.flags.iter() { - if (byte & 0x55) != 0 { - return true; - } - } - return false; - } - - pub fn supports_unknown_bits(&self) -> bool { - for &byte in self.flags.iter() { - if byte != 0 { - return true; - } - } - return false; - } -} - -pub struct Init { - pub global_features: GlobalFeatures, - pub local_features: LocalFeatures, -} - -pub struct ErrorMessage { - pub channel_id: [u8; 32], - pub data: String, -} - -pub struct Ping { - pub ponglen: u16, - pub byteslen: u16, -} - -pub struct Pong { - pub byteslen: u16, -} - -pub struct OpenChannel { - pub chain_hash: Sha256dHash, - pub temporary_channel_id: [u8; 32], - pub funding_satoshis: u64, - pub push_msat: u64, - pub dust_limit_satoshis: u64, - pub max_htlc_value_in_flight_msat: u64, - pub channel_reserve_satoshis: u64, - pub htlc_minimum_msat: u64, - pub feerate_per_kw: u32, - pub to_self_delay: u16, - pub max_accepted_htlcs: u16, - pub funding_pubkey: PublicKey, - pub revocation_basepoint: PublicKey, - pub payment_basepoint: PublicKey, - pub delayed_payment_basepoint: PublicKey, - pub htlc_basepoint: PublicKey, - pub first_per_commitment_point: PublicKey, - pub channel_flags: u8, - pub shutdown_scriptpubkey: Option