X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-custom-message%2Fsrc%2Flib.rs;h=a0948f23b5fb383d0b82c5156346e5822baa4fdc;hb=a9dcfaf952584ed835d733cb4688d5f96e86349d;hp=a6e43978d47ded2e1c9efd58c50fe234d7a02564;hpb=5e9e68ad689bc0a4278a31bf5241c90648dcbe1d;p=rust-lightning diff --git a/lightning-custom-message/src/lib.rs b/lightning-custom-message/src/lib.rs index a6e43978..a0948f23 100644 --- a/lightning-custom-message/src/lib.rs +++ b/lightning-custom-message/src/lib.rs @@ -12,6 +12,7 @@ //! `Foo` and `Bar` messages, and further composing it with a handler for `Baz` messages. //! //!``` +//! # fn main() {} // Avoid #[macro_export] generating an in-function warning //! # extern crate bitcoin; //! extern crate lightning; //! #[macro_use] @@ -19,7 +20,8 @@ //! //! # use bitcoin::secp256k1::PublicKey; //! # use lightning::io; -//! # use lightning::ln::msgs::{DecodeError, LightningError}; +//! # use lightning::ln::msgs::{DecodeError, Init, LightningError}; +//! # use lightning::ln::features::{InitFeatures, NodeFeatures}; //! use lightning::ln::peer_handler::CustomMessageHandler; //! use lightning::ln::wire::{CustomMessageReader, self}; //! use lightning::util::ser::Writeable; @@ -66,6 +68,18 @@ //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } +//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # unimplemented!() +//! # } +//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # unimplemented!() +//! # } +//! # fn provided_node_features(&self) -> NodeFeatures { +//! # unimplemented!() +//! # } +//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # unimplemented!() +//! # } //! } //! //! #[derive(Debug)] @@ -106,6 +120,18 @@ //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } +//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # unimplemented!() +//! # } +//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # unimplemented!() +//! # } +//! # fn provided_node_features(&self) -> NodeFeatures { +//! # unimplemented!() +//! # } +//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # unimplemented!() +//! # } //! } //! //! #[derive(Debug)] @@ -146,9 +172,20 @@ //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } +//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # unimplemented!() +//! # } +//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # unimplemented!() +//! # } +//! # fn provided_node_features(&self) -> NodeFeatures { +//! # unimplemented!() +//! # } +//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # unimplemented!() +//! # } //! } //! -//! # fn main() { //! // The first crate may define a handler composing `FooHandler` and `BarHandler` and export the //! // corresponding message type ids as a macro to use in further composition. //! @@ -188,7 +225,6 @@ //! macro_rules! foo_bar_baz_type_ids { //! () => { foo_bar_type_ids!() | baz_type_id!() } //! } -//! # } //!``` //! //! [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md @@ -268,6 +304,38 @@ macro_rules! composite_custom_message_handler { )* .collect() } + + fn peer_disconnected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey) { + $( + self.$field.peer_disconnected(their_node_id); + )* + } + + fn peer_connected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey, msg: &$crate::lightning::ln::msgs::Init, inbound: bool) -> Result<(), ()> { + let mut result = Ok(()); + $( + if let Err(e) = self.$field.peer_connected(their_node_id, msg, inbound) { + result = Err(e); + } + )* + result + } + + fn provided_node_features(&self) -> $crate::lightning::ln::features::NodeFeatures { + $crate::lightning::ln::features::NodeFeatures::empty() + $( + | self.$field.provided_node_features() + )* + } + + fn provided_init_features( + &self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey + ) -> $crate::lightning::ln::features::InitFeatures { + $crate::lightning::ln::features::InitFeatures::empty() + $( + | self.$field.provided_init_features(their_node_id) + )* + } } impl $crate::lightning::ln::wire::CustomMessageReader for $handler {