Skip to content

Commit d062514

Browse files
author
okekefrancis112
committed
refactor: merge lightning-custom-message into lightning crate
1 parent e9fd567 commit d062514

7 files changed

Lines changed: 39 additions & 68 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ members = [
1212
"lightning-persister",
1313
"lightning-background-processor",
1414
"lightning-rapid-gossip-sync",
15-
"lightning-custom-message",
1615
"lightning-macros",
1716
"lightning-dns-resolver",
1817
"lightning-liquidity",

ci/ci-tests.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ cargo test -p lightning-persister --quiet --color always --features tokio
8181
cargo check -p lightning-persister --quiet --color always --features tokio
8282
cargo doc -p lightning-persister --quiet --document-private-items --features tokio
8383

84-
echo -e "\n\nTest Custom Message Macros"
85-
cargo test -p lightning-custom-message --quiet --color always
86-
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
87-
8884
echo -e "\n\nTest backtrace-debug builds"
8985
cargo test -p lightning --quiet --color always --features backtrace
9086

lightning-custom-message/Cargo.toml

Lines changed: 0 additions & 23 deletions
This file was deleted.

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ use bitcoin::hashes::{Hash, HashEngine};
7878
///
7979
/// [BOLT 1] specifies a custom message type range for use with experimental or application-specific
8080
/// messages. `CustomMessageHandler` allows for user-defined handling of such types. See the
81-
/// [`lightning_custom_message`] crate for tools useful in composing more than one custom handler.
81+
/// [`util::custom_message`] module for tools useful in composing more than one custom handler.
8282
///
8383
/// [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
84-
/// [`lightning_custom_message`]: https://docs.rs/lightning_custom_message/latest/lightning_custom_message
84+
/// [`util::custom_message`]: crate::util::custom_message
8585
pub trait CustomMessageHandler: wire::CustomMessageReader {
8686
/// Handles the given message sent from `sender_node_id`, possibly producing messages for
8787
/// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`]
Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
110
//! Utilities for supporting custom peer-to-peer messages in LDK.
211
//!
312
//! [BOLT 1] specifies a custom message type range for use with experimental or application-specific
413
//! messages. While a [`CustomMessageHandler`] can be defined to support more than one message type,
514
//! defining such a handler requires a significant amount of boilerplate and can be error prone.
615
//!
7-
//! This crate provides the [`composite_custom_message_handler`] macro for easily composing
16+
//! This module provides the [`composite_custom_message_handler!`](crate::composite_custom_message_handler!) macro for easily composing
817
//! pre-defined custom message handlers into one handler. The resulting handler can be further
918
//! composed with other custom message handlers using the same macro.
1019
//!
@@ -13,14 +22,10 @@
1322
//!
1423
//!```
1524
//! # fn main() {} // Avoid #[macro_export] generating an in-function warning
16-
//! # extern crate bitcoin;
17-
//! extern crate lightning;
18-
//! #[macro_use]
19-
//! extern crate lightning_custom_message;
20-
//!
2125
//! # use bitcoin::secp256k1::PublicKey;
2226
//! # use lightning::io;
2327
//! # use lightning::ln::msgs::{DecodeError, Init, LightningError};
28+
//! use lightning::composite_custom_message_handler;
2429
//! use lightning::ln::peer_handler::CustomMessageHandler;
2530
//! use lightning::ln::wire::{CustomMessageReader, self};
2631
//! # use lightning::types::features::{InitFeatures, NodeFeatures};
@@ -228,12 +233,7 @@
228233
//!```
229234
//!
230235
//! [BOLT 1]: https://github.com/lightning/bolts/blob/master/01-messaging.md
231-
//! [`CustomMessageHandler`]: crate::lightning::ln::peer_handler::CustomMessageHandler
232-
233-
#![doc(test(no_crate_inject, attr(deny(warnings))))]
234-
235-
pub extern crate bitcoin;
236-
pub extern crate lightning;
236+
//! [`CustomMessageHandler`]: crate::ln::peer_handler::CustomMessageHandler
237237
238238
/// Defines a composite type implementing [`CustomMessageHandler`] (and therefore also implementing
239239
/// [`CustomMessageReader`]), along with a corresponding enumerated custom message [`Type`], from
@@ -244,13 +244,12 @@ pub extern crate lightning;
244244
/// though using OR-ed literal patterns is preferred in order to catch unreachable code for
245245
/// conflicting handlers.
246246
///
247-
/// See [crate documentation] for example usage.
247+
/// See [module documentation](self) for example usage.
248248
///
249-
/// [`CustomMessageHandler`]: crate::lightning::ln::peer_handler::CustomMessageHandler
250-
/// [`CustomMessageReader`]: crate::lightning::ln::wire::CustomMessageReader
251-
/// [`Type`]: crate::lightning::ln::wire::Type
252-
/// [`PeerManager`]: crate::lightning::ln::peer_handler::PeerManager
253-
/// [crate documentation]: self
249+
/// [`CustomMessageHandler`]: crate::ln::peer_handler::CustomMessageHandler
250+
/// [`CustomMessageReader`]: crate::ln::wire::CustomMessageReader
251+
/// [`Type`]: crate::ln::wire::Type
252+
/// [`PeerManager`]: crate::ln::peer_handler::PeerManager
254253
#[macro_export]
255254
macro_rules! composite_custom_message_handler {
256255
(
@@ -273,26 +272,26 @@ macro_rules! composite_custom_message_handler {
273272
#[derive(Debug)]
274273
$message_visibility enum $message {
275274
$(
276-
$variant(<$type as $crate::lightning::ln::wire::CustomMessageReader>::CustomMessage),
275+
$variant(<$type as $crate::ln::wire::CustomMessageReader>::CustomMessage),
277276
)*
278277
}
279278

280-
impl $crate::lightning::ln::peer_handler::CustomMessageHandler for $handler {
279+
impl $crate::ln::peer_handler::CustomMessageHandler for $handler {
281280
fn handle_custom_message(
282-
&self, msg: Self::CustomMessage, sender_node_id: $crate::bitcoin::secp256k1::PublicKey
283-
) -> Result<(), $crate::lightning::ln::msgs::LightningError> {
281+
&self, msg: Self::CustomMessage, sender_node_id: bitcoin::secp256k1::PublicKey
282+
) -> Result<(), $crate::ln::msgs::LightningError> {
284283
match msg {
285284
$(
286285
$message::$variant(message) => {
287-
$crate::lightning::ln::peer_handler::CustomMessageHandler::handle_custom_message(
286+
$crate::ln::peer_handler::CustomMessageHandler::handle_custom_message(
288287
&self.$field, message, sender_node_id
289288
)
290289
},
291290
)*
292291
}
293292
}
294293

295-
fn get_and_clear_pending_msg(&self) -> Vec<($crate::bitcoin::secp256k1::PublicKey, Self::CustomMessage)> {
294+
fn get_and_clear_pending_msg(&self) -> Vec<(bitcoin::secp256k1::PublicKey, Self::CustomMessage)> {
296295
vec![].into_iter()
297296
$(
298297
.chain(
@@ -305,13 +304,13 @@ macro_rules! composite_custom_message_handler {
305304
.collect()
306305
}
307306

308-
fn peer_disconnected(&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey) {
307+
fn peer_disconnected(&self, their_node_id: bitcoin::secp256k1::PublicKey) {
309308
$(
310309
self.$field.peer_disconnected(their_node_id);
311310
)*
312311
}
313312

314-
fn peer_connected(&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey, msg: &$crate::lightning::ln::msgs::Init, inbound: bool) -> Result<(), ()> {
313+
fn peer_connected(&self, their_node_id: bitcoin::secp256k1::PublicKey, msg: &$crate::ln::msgs::Init, inbound: bool) -> Result<(), ()> {
315314
let mut result = Ok(());
316315
$(
317316
if let Err(e) = self.$field.peer_connected(their_node_id, msg, inbound) {
@@ -321,28 +320,28 @@ macro_rules! composite_custom_message_handler {
321320
result
322321
}
323322

324-
fn provided_node_features(&self) -> $crate::lightning::types::features::NodeFeatures {
325-
$crate::lightning::types::features::NodeFeatures::empty()
323+
fn provided_node_features(&self) -> $crate::types::features::NodeFeatures {
324+
$crate::types::features::NodeFeatures::empty()
326325
$(
327326
| self.$field.provided_node_features()
328327
)*
329328
}
330329

331330
fn provided_init_features(
332-
&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey
333-
) -> $crate::lightning::types::features::InitFeatures {
334-
$crate::lightning::types::features::InitFeatures::empty()
331+
&self, their_node_id: bitcoin::secp256k1::PublicKey
332+
) -> $crate::types::features::InitFeatures {
333+
$crate::types::features::InitFeatures::empty()
335334
$(
336335
| self.$field.provided_init_features(their_node_id)
337336
)*
338337
}
339338
}
340339

341-
impl $crate::lightning::ln::wire::CustomMessageReader for $handler {
340+
impl $crate::ln::wire::CustomMessageReader for $handler {
342341
type CustomMessage = $message;
343-
fn read<R: $crate::lightning::util::ser::LengthLimitedRead>(
342+
fn read<R: $crate::util::ser::LengthLimitedRead>(
344343
&self, message_type: u16, buffer: &mut R
345-
) -> Result<Option<Self::CustomMessage>, $crate::lightning::ln::msgs::DecodeError> {
344+
) -> Result<Option<Self::CustomMessage>, $crate::ln::msgs::DecodeError> {
346345
match message_type {
347346
$(
348347
$pattern => match <$type>::read(&self.$field, message_type, buffer)? {
@@ -355,7 +354,7 @@ macro_rules! composite_custom_message_handler {
355354
}
356355
}
357356

358-
impl $crate::lightning::ln::wire::Type for $message {
357+
impl $crate::ln::wire::Type for $message {
359358
fn type_id(&self) -> u16 {
360359
match self {
361360
$(
@@ -365,8 +364,8 @@ macro_rules! composite_custom_message_handler {
365364
}
366365
}
367366

368-
impl $crate::lightning::util::ser::Writeable for $message {
369-
fn write<W: $crate::lightning::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::lightning::io::Error> {
367+
impl $crate::util::ser::Writeable for $message {
368+
fn write<W: $crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::io::Error> {
370369
match self {
371370
$(
372371
Self::$variant(message) => message.write(writer),

lightning/src/util/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod async_poll;
2525
pub mod base32;
2626
#[cfg(not(fuzzing))]
2727
pub(crate) mod base32;
28+
pub mod custom_message;
2829
pub mod errors;
2930
pub mod message_signing;
3031
pub mod native_async;

msrv-no-dev-deps-check/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ lightning-net-tokio = { path = "../lightning-net-tokio" }
1111
lightning-persister = { path = "../lightning-persister" }
1212
lightning-background-processor = { path = "../lightning-background-processor" }
1313
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
14-
lightning-custom-message = { path = "../lightning-custom-message" }

0 commit comments

Comments
 (0)