Skip to content

Commit cfe6b95

Browse files
committed
Import msgs::OnionMessage
1 parent a4894bd commit cfe6b95

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs
2020
use crate::blinded_path::utils;
2121
use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient};
2222
use crate::ln::features::{InitFeatures, NodeFeatures};
23-
use crate::ln::msgs::{self, OnionMessageHandler};
23+
use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler};
2424
use crate::ln::onion_utils;
2525
use crate::ln::peer_handler::IgnoringMessageHandler;
2626
pub use super::packet::{CustomOnionMessageContents, OnionMessageContents};
@@ -132,7 +132,6 @@ use crate::prelude::*;
132132
/// onion_messenger.send_onion_message(path, message, reply_path);
133133
/// ```
134134
///
135-
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
136135
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
137136
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
138137
pub struct OnionMessenger<ES: Deref, NS: Deref, L: Deref, MR: Deref, OMH: Deref, CMH: Deref>
@@ -147,20 +146,16 @@ where
147146
entropy_source: ES,
148147
node_signer: NS,
149148
logger: L,
150-
pending_messages: Mutex<HashMap<PublicKey, VecDeque<msgs::OnionMessage>>>,
149+
pending_messages: Mutex<HashMap<PublicKey, VecDeque<OnionMessage>>>,
151150
secp_ctx: Secp256k1<secp256k1::All>,
152151
message_router: MR,
153152
offers_handler: OMH,
154153
custom_handler: CMH,
155154
}
156155

157156
/// A trait defining behavior for routing an [`OnionMessage`].
158-
///
159-
/// [`OnionMessage`]: msgs::OnionMessage
160157
pub trait MessageRouter {
161158
/// Returns a route for sending an [`OnionMessage`] to the given [`Destination`].
162-
///
163-
/// [`OnionMessage`]: msgs::OnionMessage
164159
fn find_path(
165160
&self, sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
166161
) -> Result<OnionMessagePath, ()>;
@@ -177,7 +172,7 @@ impl MessageRouter for DefaultMessageRouter {
177172
}
178173
}
179174

180-
/// A path for sending an [`msgs::OnionMessage`].
175+
/// A path for sending an [`OnionMessage`].
181176
#[derive(Clone)]
182177
pub struct OnionMessagePath {
183178
/// Nodes on the path between the sender and the destination.
@@ -262,7 +257,7 @@ pub trait CustomOnionMessageHandler {
262257
/// or a Receive payload with decrypted contents.
263258
pub enum PeeledOnion<CM: CustomOnionMessageContents> {
264259
/// Forwarded onion, with the next node id and a new onion
265-
Forward(PublicKey, msgs::OnionMessage),
260+
Forward(PublicKey, OnionMessage),
266261
/// Received onion message, with decrypted contents, path_id, and reply path
267262
Receive(OnionMessageContents<CM>, Option<[u8; 32]>, Option<BlindedPath>)
268263
}
@@ -271,12 +266,10 @@ pub enum PeeledOnion<CM: CustomOnionMessageContents> {
271266
/// `path`.
272267
///
273268
/// Returns both the node id of the peer to send the message to and the message itself.
274-
///
275-
/// [`OnionMessage`]: msgs::OnionMessage
276269
pub fn create_onion_message<ES: Deref, NS: Deref, T: CustomOnionMessageContents>(
277270
entropy_source: &ES, node_signer: &NS, secp_ctx: &Secp256k1<secp256k1::All>,
278271
path: OnionMessagePath, contents: OnionMessageContents<T>, reply_path: Option<BlindedPath>,
279-
) -> Result<(PublicKey, msgs::OnionMessage), SendError>
272+
) -> Result<(PublicKey, OnionMessage), SendError>
280273
where
281274
ES::Target: EntropySource,
282275
NS::Target: NodeSigner,
@@ -322,7 +315,7 @@ where
322315
let onion_routing_packet = construct_onion_message_packet(
323316
packet_payloads, packet_keys, prng_seed).map_err(|()| SendError::TooBigPacket)?;
324317

325-
Ok((first_node_id, msgs::OnionMessage {
318+
Ok((first_node_id, OnionMessage {
326319
blinding_point,
327320
onion_routing_packet
328321
}))
@@ -332,7 +325,7 @@ where
332325
/// Returns either a Forward (another onion message), or Receive (decrypted content)
333326
pub fn peel_onion<NS: Deref, L: Deref, CMH: Deref>(
334327
node_signer: NS, secp_ctx: &Secp256k1<secp256k1::All>, logger: L, custom_handler: CMH,
335-
msg: &msgs::OnionMessage,
328+
msg: &OnionMessage,
336329
) -> Result<PeeledOnion<<<CMH>::Target as CustomOnionMessageHandler>::CustomMessage>, ()>
337330
where
338331
NS::Target: NodeSigner,
@@ -392,7 +385,7 @@ where
392385
hop_data: new_packet_bytes,
393386
hmac: next_hop_hmac,
394387
};
395-
let onion_message = msgs::OnionMessage {
388+
let onion_message = OnionMessage {
396389
blinding_point: match next_blinding_override {
397390
Some(blinding_point) => blinding_point,
398391
None => {
@@ -453,7 +446,7 @@ where
453446
}
454447
}
455448

456-
/// Sends an [`msgs::OnionMessage`] with the given `contents` for sending to the destination of
449+
/// Sends an [`OnionMessage`] with the given `contents` for sending to the destination of
457450
/// `path`.
458451
///
459452
/// See [`OnionMessenger`] for example usage.
@@ -527,7 +520,7 @@ where
527520
}
528521

529522
#[cfg(test)]
530-
pub(super) fn release_pending_msgs(&self) -> HashMap<PublicKey, VecDeque<msgs::OnionMessage>> {
523+
pub(super) fn release_pending_msgs(&self) -> HashMap<PublicKey, VecDeque<OnionMessage>> {
531524
let mut pending_msgs = self.pending_messages.lock().unwrap();
532525
let mut msgs = HashMap::new();
533526
// We don't want to disconnect the peers by removing them entirely from the original map, so we
@@ -539,7 +532,7 @@ where
539532
}
540533
}
541534

542-
fn outbound_buffer_full(peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, VecDeque<msgs::OnionMessage>>) -> bool {
535+
fn outbound_buffer_full(peer_node_id: &PublicKey, buffer: &HashMap<PublicKey, VecDeque<OnionMessage>>) -> bool {
543536
const MAX_TOTAL_BUFFER_SIZE: usize = (1 << 20) * 128;
544537
const MAX_PER_PEER_BUFFER_SIZE: usize = (1 << 10) * 256;
545538
let mut total_buffered_bytes = 0;
@@ -575,7 +568,7 @@ where
575568
/// Handle an incoming onion message. Currently, if a message was destined for us we will log, but
576569
/// soon we'll delegate the onion message to a handler that can generate invoices or send
577570
/// payments.
578-
fn handle_onion_message(&self, _peer_node_id: &PublicKey, msg: &msgs::OnionMessage) {
571+
fn handle_onion_message(&self, _peer_node_id: &PublicKey, msg: &OnionMessage) {
579572
match peel_onion(
580573
&*self.node_signer, &self.secp_ctx, &*self.logger, &*self.custom_handler, msg
581574
) {
@@ -649,7 +642,7 @@ where
649642
features
650643
}
651644

652-
fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option<msgs::OnionMessage> {
645+
fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option<OnionMessage> {
653646
let mut pending_msgs = self.pending_messages.lock().unwrap();
654647
if let Some(msgs) = pending_msgs.get_mut(&peer_node_id) {
655648
return msgs.pop_front()

0 commit comments

Comments
 (0)