X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fmsgs.rs;h=6aa9e05b242fd7a53018c70cb05dd170d5d49432;hb=587af43eca7dc254bf0feb96d4732fd56cf6fcc3;hp=f87e3722f999d239934241e8aa5ee046872d8fd8;hpb=c43e535bc03404bad16e3d30e5b2fc7215e6ca15;p=rust-lightning diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index f87e3722..6aa9e05b 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -1,12 +1,14 @@ //! Wire messages, traits representing wire message handlers, and a few error types live here. +//! //! For a normal node you probably don't need to use anything here, however, if you wish to split a //! node into an internet-facing route/message socket handling daemon and a separate daemon (or //! server entirely) which handles only channel-related messages you may wish to implement //! ChannelMessageHandler yourself and use it to re-serialize messages and pass them across //! daemons/servers. +//! //! Note that if you go with such an architecture (instead of passing raw socket events to a //! non-internet-facing system) you trust the frontend internet-facing system to not lie about the -//! source node_id of the mssage, however this does allow you to significantly reduce bandwidth +//! source node_id of the message, however this does allow you to significantly reduce bandwidth //! between the systems as routing messages can represent a significant chunk of bandwidth usage //! (especially for non-channel-publicly-announcing nodes). As an alternate design which avoids //! this issue, if you have sufficient bidirectional bandwidth between your systems, you may send @@ -14,9 +16,9 @@ //! track the network on the less-secure system. use secp256k1::key::PublicKey; -use secp256k1::{Secp256k1, Signature}; +use secp256k1::Signature; use secp256k1; -use bitcoin::util::hash::Sha256dHash; +use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin::blockdata::script::Script; use std::error::Error; @@ -24,9 +26,11 @@ use std::{cmp, fmt}; use std::io::Read; use std::result::Result; -use util::{byte_utils, events}; +use util::events; use util::ser::{Readable, Writeable, Writer}; +use ln::channelmanager::{PaymentPreimage, PaymentHash}; + /// An error in decoding a message or struct. #[derive(Debug)] pub enum DecodeError { @@ -43,7 +47,6 @@ pub enum DecodeError { /// 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), @@ -88,32 +91,26 @@ impl LocalFeatures { } pub(crate) 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; + self.flags.iter().enumerate().any(|(idx, &byte)| { + ( idx != 0 && (byte & 0x55) != 0 ) || ( idx == 0 && (byte & 0x14) != 0 ) + }) } pub(crate) 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; + self.flags.iter().enumerate().any(|(idx, &byte)| { + ( idx != 0 && byte != 0 ) || ( idx == 0 && (byte & 0xc4) != 0 ) + }) } } /// Tracks globalfeatures which are in init messages and routing announcements -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug)] pub struct GlobalFeatures { + #[cfg(not(test))] flags: Vec, + // Used to test encoding of diverse msgs + #[cfg(test)] + pub flags: Vec } impl GlobalFeatures { @@ -149,6 +146,7 @@ pub struct Init { } /// An error message to be sent or received from a peer +#[derive(Clone)] pub struct ErrorMessage { pub(crate) channel_id: [u8; 32], pub(crate) data: String, @@ -166,6 +164,7 @@ pub struct Pong { } /// An open_channel message to be sent or received from a peer +#[derive(Clone)] pub struct OpenChannel { pub(crate) chain_hash: Sha256dHash, pub(crate) temporary_channel_id: [u8; 32], @@ -185,10 +184,11 @@ pub struct OpenChannel { pub(crate) htlc_basepoint: PublicKey, pub(crate) first_per_commitment_point: PublicKey, pub(crate) channel_flags: u8, - pub(crate) shutdown_scriptpubkey: Option