From: Valentine Wallace Date: Mon, 22 Aug 2022 16:22:22 +0000 (-0400) Subject: Implement OnionMessageProvider for OnionMessenger X-Git-Tag: v0.0.111~23^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b28783a0b5b537acb4891438adcf5f83c239256a;p=rust-lightning Implement OnionMessageProvider for OnionMessenger --- diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 2684ab8b3..75eb4619b 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -86,7 +86,7 @@ pub struct OnionMessenger { keys_manager: K, logger: L, - pending_messages: Mutex>>, + pending_messages: Mutex>>, secp_ctx: Secp256k1, // Coming soon: // invoice_handler: InvoiceHandler, @@ -170,8 +170,8 @@ impl OnionMessenger packet_payloads, packet_keys, prng_seed).map_err(|()| SendError::TooBigPacket)?; let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap(); - let pending_msgs = pending_per_peer_msgs.entry(introduction_node_id).or_insert(Vec::new()); - pending_msgs.push( + let pending_msgs = pending_per_peer_msgs.entry(introduction_node_id).or_insert_with(VecDeque::new); + pending_msgs.push_back( msgs::OnionMessage { blinding_point, onion_routing_packet: onion_packet, @@ -181,7 +181,7 @@ impl OnionMessenger } #[cfg(test)] - pub(super) fn release_pending_msgs(&self) -> HashMap> { + pub(super) fn release_pending_msgs(&self) -> HashMap> { let mut pending_msgs = self.pending_messages.lock().unwrap(); let mut msgs = HashMap::new(); core::mem::swap(&mut *pending_msgs, &mut msgs); @@ -253,8 +253,8 @@ impl OnionMessageHandler for OnionMessenger blinding_point, @@ -295,6 +295,10 @@ impl OnionMessageProvider for OnionMessenger Option { + let mut pending_msgs = self.pending_messages.lock().unwrap(); + if let Some(msgs) = pending_msgs.get_mut(&peer_node_id) { + return msgs.pop_front() + } None } }