X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fln%2Fmsgs.rs;h=f00dc34a50024a48d36c9a0ebf3c0dc695567f3b;hb=788bd915c40bbdd1fa7bbbfef22f46805d8c42d1;hp=c43a5dc9c4d4ff5c0b379d6cdc94f31c904bdc12;hpb=9373c5993fcc4943f31e20fb0e0367d2bddec596;p=rust-lightning diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index c43a5dc9..f00dc34a 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -1,5 +1,22 @@ +//! 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::{Secp256k1, Signature}; +use secp256k1::Signature; use secp256k1; use bitcoin::util::hash::Sha256dHash; use bitcoin::blockdata::script::Script; @@ -9,32 +26,30 @@ 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 { - /// Unknown realm byte in an OnionHopData packet - UnknownRealmByte, + /// 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 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, + /// 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, etc + InvalidValue, /// 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, } /// Tracks localfeatures which are only in init messages @@ -130,25 +145,32 @@ impl GlobalFeatures { } } +/// An init message to be sent or received from a peer pub struct Init { pub(crate) global_features: GlobalFeatures, pub(crate) local_features: LocalFeatures, } +/// 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], @@ -168,9 +190,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