//! 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 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 //! raw socket events into your non-internet-facing system and then send routing events back to //! track the network on the less-secure system. use secp256k1::key::PublicKey; use secp256k1::Signature; use secp256k1; use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin::blockdata::script::Script; use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use std::error::Error; use std::{cmp, fmt}; use std::io::Read; use std::result::Result; use util::events; use util::ser::{Readable, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedVarInt}; use ln::channelmanager::{PaymentPreimage, PaymentHash, PaymentSecret}; /// 21 million * 10^8 * 1000 pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; /// An error in decoding a message or struct. #[derive(Debug)] pub enum DecodeError { /// A version byte specified something we don't know how to handle. /// Includes unknown realm byte in an OnionHopData packet UnknownVersion, /// Unknown feature mandating we fail to parse message (eg TLV with an even, unknown type) UnknownRequiredFeature, /// Value was invalid, eg a byte which was supposed to be a bool was something other than a 0 /// or 1, a public key/private key/signature was invalid, text wasn't UTF-8, TLV was /// syntactically incorrect, etc InvalidValue, /// Buffer too short ShortRead, /// A length descriptor in the packet didn't describe the later data correctly BadLengthDescriptor, /// Error from std::io Io(::std::io::Error), } /// 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 #[derive(Clone)] pub struct ErrorMessage { pub(crate) channel_id: [u8; 32], pub(crate) data: String, } /// A ping message to be sent or received from a peer pub struct Ping { pub(crate) ponglen: u16, pub(crate) byteslen: u16, } /// A pong message to be sent or received from a peer pub struct Pong { pub(crate) byteslen: u16, } /// 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], pub(crate) funding_satoshis: u64, pub(crate) push_msat: u64, pub(crate) dust_limit_satoshis: u64, pub(crate) max_htlc_value_in_flight_msat: u64, pub(crate) channel_reserve_satoshis: u64, pub(crate) htlc_minimum_msat: u64, pub(crate) feerate_per_kw: u32, pub(crate) to_self_delay: u16, pub(crate) max_accepted_htlcs: u16, pub(crate) funding_pubkey: PublicKey, pub(crate) revocation_basepoint: PublicKey, pub(crate) payment_basepoint: PublicKey, pub(crate) delayed_payment_basepoint: PublicKey, pub(crate) htlc_basepoint: PublicKey, pub(crate) first_per_commitment_point: PublicKey, pub(crate) channel_flags: u8, pub(crate) shutdown_scriptpubkey: OptionalField