Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ members = [
"lightning-persister",
"lightning-background-processor",
"lightning-rapid-gossip-sync",
"lightning-custom-message",
"lightning-macros",
"lightning-dns-resolver",
"lightning-liquidity",
Expand Down
4 changes: 0 additions & 4 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ cargo test -p lightning-persister --quiet --color always --features tokio
cargo check -p lightning-persister --quiet --color always --features tokio
cargo doc -p lightning-persister --quiet --document-private-items --features tokio

echo -e "\n\nTest Custom Message Macros"
cargo test -p lightning-custom-message --quiet --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean

echo -e "\n\nTest backtrace-debug builds"
cargo test -p lightning --quiet --color always --features backtrace

Expand Down
23 changes: 0 additions & 23 deletions lightning-custom-message/Cargo.toml

This file was deleted.

4 changes: 2 additions & 2 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ use bitcoin::hashes::{Hash, HashEngine};
///
/// [BOLT 1] specifies a custom message type range for use with experimental or application-specific
/// messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
/// [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
/// [`util::custom_message`] module for tools useful in composing more than one custom handler.
///
/// [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
/// [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
/// [`util::custom_message`]: crate::util::custom_message
pub trait CustomMessageHandler: wire::CustomMessageReader {
/// Handles the given message sent from `sender_node_id`, possibly producing messages for
/// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// This file is Copyright its original authors, visible in version control
// history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.

//! Utilities for supporting custom peer-to-peer messages in LDK.
//!
//! [BOLT 1] specifies a custom message type range for use with experimental or application-specific
//! messages. While a [`CustomMessageHandler`] can be defined to support more than one message type,
//! defining such a handler requires a significant amount of boilerplate and can be error prone.
//!
//! This crate provides the [`composite_custom_message_handler`] macro for easily composing
//! This module provides the [`composite_custom_message_handler!`](crate::composite_custom_message_handler!) macro for easily composing
//! pre-defined custom message handlers into one handler. The resulting handler can be further
//! composed with other custom message handlers using the same macro.
//!
Expand All @@ -13,14 +22,10 @@
//!
//!```
//! # fn main() {} // Avoid #[macro_export] generating an in-function warning
//! # extern crate bitcoin;
//! extern crate lightning;
//! #[macro_use]
//! extern crate lightning_custom_message;
//!
//! # use bitcoin::secp256k1::PublicKey;
//! # use lightning::io;
//! # use lightning::ln::msgs::{DecodeError, Init, LightningError};
//! use lightning::composite_custom_message_handler;
//! use lightning::ln::peer_handler::CustomMessageHandler;
//! use lightning::ln::wire::{CustomMessageReader, self};
//! # use lightning::types::features::{InitFeatures, NodeFeatures};
Expand Down Expand Up @@ -228,12 +233,7 @@
//!```
//!
//! [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
//! [`CustomMessageHandler`]: crate::lightning::ln::peer_handler::CustomMessageHandler

#![doc(test(no_crate_inject, attr(deny(warnings))))]

pub extern crate bitcoin;
pub extern crate lightning;
//! [`CustomMessageHandler`]: crate::ln::peer_handler::CustomMessageHandler

/// Defines a composite type implementing [`CustomMessageHandler`] (and therefore also implementing
/// [`CustomMessageReader`]), along with a corresponding enumerated custom message [`Type`], from
Expand All @@ -244,13 +244,12 @@ pub extern crate lightning;
/// though using OR-ed literal patterns is preferred in order to catch unreachable code for
/// conflicting handlers.
///
/// See [crate documentation] for example usage.
/// See [module documentation](self) for example usage.
///
/// [`CustomMessageHandler`]: crate::lightning::ln::peer_handler::CustomMessageHandler
/// [`CustomMessageReader`]: crate::lightning::ln::wire::CustomMessageReader
/// [`Type`]: crate::lightning::ln::wire::Type
/// [`PeerManager`]: crate::lightning::ln::peer_handler::PeerManager
/// [crate documentation]: self
/// [`CustomMessageHandler`]: crate::ln::peer_handler::CustomMessageHandler
/// [`CustomMessageReader`]: crate::ln::wire::CustomMessageReader
/// [`Type`]: crate::ln::wire::Type
/// [`PeerManager`]: crate::ln::peer_handler::PeerManager
#[macro_export]
macro_rules! composite_custom_message_handler {
(
Expand All @@ -273,26 +272,26 @@ macro_rules! composite_custom_message_handler {
#[derive(Debug)]
$message_visibility enum $message {
$(
$variant(<$type as $crate::lightning::ln::wire::CustomMessageReader>::CustomMessage),
$variant(<$type as $crate::ln::wire::CustomMessageReader>::CustomMessage),
)*
}

impl $crate::lightning::ln::peer_handler::CustomMessageHandler for $handler {
impl $crate::ln::peer_handler::CustomMessageHandler for $handler {
fn handle_custom_message(
&self, msg: Self::CustomMessage, sender_node_id: $crate::bitcoin::secp256k1::PublicKey
) -> Result<(), $crate::lightning::ln::msgs::LightningError> {
&self, msg: Self::CustomMessage, sender_node_id: bitcoin::secp256k1::PublicKey
) -> Result<(), $crate::ln::msgs::LightningError> {
match msg {
$(
$message::$variant(message) => {
$crate::lightning::ln::peer_handler::CustomMessageHandler::handle_custom_message(
$crate::ln::peer_handler::CustomMessageHandler::handle_custom_message(
&self.$field, message, sender_node_id
)
},
)*
}
}

fn get_and_clear_pending_msg(&self) -> Vec<($crate::bitcoin::secp256k1::PublicKey, Self::CustomMessage)> {
fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, Self::CustomMessage)> {
vec![].into_iter()
$(
.chain(
Expand All @@ -305,13 +304,13 @@ macro_rules! composite_custom_message_handler {
.collect()
}

fn peer_disconnected(&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey) {
fn peer_disconnected(&self, their_node_id: 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<(), ()> {
fn peer_connected(&self, their_node_id: bitcoin::secp256k1::PublicKey, msg: &$crate::ln::msgs::Init, inbound: bool) -> Result<(), ()> {
let mut result = Ok(());
$(
if let Err(e) = self.$field.peer_connected(their_node_id, msg, inbound) {
Expand All @@ -321,28 +320,28 @@ macro_rules! composite_custom_message_handler {
result
}

fn provided_node_features(&self) -> $crate::lightning::types::features::NodeFeatures {
$crate::lightning::types::features::NodeFeatures::empty()
fn provided_node_features(&self) -> $crate::types::features::NodeFeatures {
$crate::types::features::NodeFeatures::empty()
$(
| self.$field.provided_node_features()
)*
}

fn provided_init_features(
&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey
) -> $crate::lightning::types::features::InitFeatures {
$crate::lightning::types::features::InitFeatures::empty()
&self, their_node_id: bitcoin::secp256k1::PublicKey
) -> $crate::types::features::InitFeatures {
$crate::types::features::InitFeatures::empty()
$(
| self.$field.provided_init_features(their_node_id)
)*
}
}

impl $crate::lightning::ln::wire::CustomMessageReader for $handler {
impl $crate::ln::wire::CustomMessageReader for $handler {
type CustomMessage = $message;
fn read<R: $crate::lightning::util::ser::LengthLimitedRead>(
fn read<R: $crate::util::ser::LengthLimitedRead>(
&self, message_type: u16, buffer: &mut R
) -> Result<Option<Self::CustomMessage>, $crate::lightning::ln::msgs::DecodeError> {
) -> Result<Option<Self::CustomMessage>, $crate::ln::msgs::DecodeError> {
match message_type {
$(
$pattern => match <$type>::read(&self.$field, message_type, buffer)? {
Expand All @@ -355,7 +354,7 @@ macro_rules! composite_custom_message_handler {
}
}

impl $crate::lightning::ln::wire::Type for $message {
impl $crate::ln::wire::Type for $message {
fn type_id(&self) -> u16 {
match self {
$(
Expand All @@ -365,8 +364,8 @@ macro_rules! composite_custom_message_handler {
}
}

impl $crate::lightning::util::ser::Writeable for $message {
fn write<W: $crate::lightning::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::lightning::io::Error> {
impl $crate::util::ser::Writeable for $message {
fn write<W: $crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::io::Error> {
match self {
$(
Self::$variant(message) => message.write(writer),
Expand Down
1 change: 1 addition & 0 deletions lightning/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod async_poll;
pub mod base32;
#[cfg(not(fuzzing))]
pub(crate) mod base32;
pub mod custom_message;
pub mod errors;
pub mod message_signing;
pub mod native_async;
Expand Down
1 change: 0 additions & 1 deletion msrv-no-dev-deps-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ lightning-net-tokio = { path = "../lightning-net-tokio" }
lightning-persister = { path = "../lightning-persister" }
lightning-background-processor = { path = "../lightning-background-processor" }
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
lightning-custom-message = { path = "../lightning-custom-message" }
Loading