@@ -21,7 +21,7 @@ use ln::msgs::{self, OnionMessageHandler};
21
21
use ln:: onion_utils;
22
22
use ln:: peer_handler:: IgnoringMessageHandler ;
23
23
use super :: blinded_route:: { BlindedRoute , ForwardTlvs , ReceiveTlvs } ;
24
- pub use super :: packet:: { CustomMessageReadable , Message , OnionMessageContents } ;
24
+ pub use super :: packet:: { Message , OnionMessageContents } ;
25
25
use super :: packet:: { BIG_PACKET_HOP_DATA_LEN , ForwardControlTlvs , Packet , Payload , ReceiveControlTlvs , SMALL_PACKET_HOP_DATA_LEN } ;
26
26
use super :: utils;
27
27
use util:: events:: OnionMessageProvider ;
@@ -43,9 +43,12 @@ use prelude::*;
43
43
/// # use bitcoin::hashes::_export::_core::time::Duration;
44
44
/// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
45
45
/// # use lightning::chain::keysinterface::{InMemorySigner, KeysManager, KeysInterface};
46
+ /// # use lightning::ln::msgs::DecodeError;
46
47
/// # use lightning::ln::peer_handler::IgnoringMessageHandler;
47
- /// # use lightning::onion_message::{BlindedRoute, Destination, Message, OnionMessenger};
48
+ /// # use lightning::onion_message::{BlindedRoute, Destination, Message, OnionMessageContents, OnionMessenger};
48
49
/// # use lightning::util::logger::{Logger, Record};
50
+ /// # use lightning::util::ser::{MaybeReadableArgs, Writeable, Writer};
51
+ /// # use std::io;
49
52
/// # use std::sync::Arc;
50
53
/// # struct FakeLogger {};
51
54
/// # impl Logger for FakeLogger {
@@ -58,18 +61,36 @@ use prelude::*;
58
61
/// # let node_secret = SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
59
62
/// # let secp_ctx = Secp256k1::new();
60
63
/// # let hop_node_id1 = PublicKey::from_secret_key(&secp_ctx, &node_secret);
61
- /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1,
62
- /// hop_node_id1);
64
+ /// # let (hop_node_id2, hop_node_id3, hop_node_id4) = (hop_node_id1, hop_node_id1, hop_node_id1);
63
65
/// # let destination_node_id = hop_node_id1;
64
66
/// # let your_custom_message_handler = IgnoringMessageHandler {};
65
67
/// // Create the onion messenger. This must use the same `keys_manager` as is passed to your
66
68
/// // ChannelManager.
67
69
/// let onion_messenger = OnionMessenger::new(&keys_manager, logger, your_custom_message_handler);
68
70
///
69
- /// // Send an custom onion message to a node id.
71
+ /// # struct YourCustomMessage {}
72
+ /// impl Writeable for YourCustomMessage {
73
+ /// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
74
+ /// # Ok(())
75
+ /// // Write your custom onion message to `w`
76
+ /// }
77
+ /// }
78
+ /// impl OnionMessageContents for YourCustomMessage {
79
+ /// fn tlv_type(&self) -> u64 {
80
+ /// # let your_custom_message_type = 42;
81
+ /// your_custom_message_type
82
+ /// }
83
+ /// }
84
+ /// impl MaybeReadableArgs<u64> for YourCustomMessage {
85
+ /// fn read<R: io::Read>(r: &mut R, message_type: u64) -> Result<Option<Self>, DecodeError> {
86
+ /// # unreachable!()
87
+ /// // Read your custom onion message from `r`
88
+ /// }
89
+ /// }
90
+ /// // Send a custom onion message to a node id.
70
91
/// let intermediate_hops = [hop_node_id1, hop_node_id2];
71
92
/// let reply_path = None;
72
- /// # let your_custom_message = () ;
93
+ /// # let your_custom_message = YourCustomMessage {} ;
73
94
/// let message = Message::Custom(your_custom_message);
74
95
/// onion_messenger.send_onion_message(&intermediate_hops, Destination::Node(destination_node_id), message, reply_path);
75
96
///
@@ -81,6 +102,7 @@ use prelude::*;
81
102
/// // Send a custom onion message to a blinded route.
82
103
/// # let intermediate_hops = [hop_node_id1, hop_node_id2];
83
104
/// let reply_path = None;
105
+ /// # let your_custom_message = YourCustomMessage {};
84
106
/// let message = Message::Custom(your_custom_message);
85
107
/// onion_messenger.send_onion_message(&intermediate_hops, Destination::BlindedRoute(blinded_route), message, reply_path);
86
108
/// ```
@@ -419,8 +441,8 @@ pub type SimpleRefOnionMessenger<'a, 'b, L> = OnionMessenger<InMemorySigner, &'a
419
441
/// Construct onion packet payloads and keys for sending an onion message along the given
420
442
/// `unblinded_path` to the given `destination`.
421
443
fn packet_payloads_and_keys < T : OnionMessageContents , S : secp256k1:: Signing + secp256k1:: Verification > (
422
- secp_ctx : & Secp256k1 < S > , unblinded_path : & [ PublicKey ] , destination : Destination , message :
423
- Message < T > , mut reply_path : Option < BlindedRoute > , session_priv : & SecretKey
444
+ secp_ctx : & Secp256k1 < S > , unblinded_path : & [ PublicKey ] , destination : Destination ,
445
+ message : Message < T > , mut reply_path : Option < BlindedRoute > , session_priv : & SecretKey
424
446
) -> Result < ( Vec < ( Payload < T > , [ u8 ; 32 ] ) > , Vec < onion_utils:: OnionKeys > ) , secp256k1:: Error > {
425
447
let num_hops = unblinded_path. len ( ) + destination. num_hops ( ) ;
426
448
let mut payloads = Vec :: with_capacity ( num_hops) ;
0 commit comments