- pub fn send_onion_message(&self, intermediate_nodes: &[PublicKey], destination: Destination, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
- if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
+ pub fn send_onion_message<T: CustomOnionMessageContents>(
+ &self, path: OnionMessagePath, message: OnionMessageContents<T>,
+ reply_path: Option<BlindedPath>
+ ) -> Result<(), SendError> {
+ let (introduction_node_id, onion_msg) = Self::create_onion_message(
+ &self.entropy_source,
+ &self.node_signer,
+ &self.secp_ctx,
+ path,
+ message,
+ reply_path
+ )?;
+
+ let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap();
+ if outbound_buffer_full(&introduction_node_id, &pending_per_peer_msgs) { return Err(SendError::BufferFull) }
+ match pending_per_peer_msgs.entry(introduction_node_id) {
+ hash_map::Entry::Vacant(_) => Err(SendError::InvalidFirstHop),
+ hash_map::Entry::Occupied(mut e) => {
+ e.get_mut().push_back(onion_msg);
+ Ok(())
+ }
+ }
+ }
+
+ /// Create an onion message with contents `message` to the destination of `path`.
+ /// Returns (introduction_node_id, onion_msg)
+ pub fn create_onion_message<T: CustomOnionMessageContents>(
+ entropy_source: &ES,
+ node_signer: &NS,
+ secp_ctx: &Secp256k1<secp256k1::All>,
+ path: OnionMessagePath,
+ message: OnionMessageContents<T>,
+ reply_path: Option<BlindedPath>,
+ ) -> Result<(PublicKey, msgs::OnionMessage), SendError> {
+ let OnionMessagePath { intermediate_nodes, mut destination } = path;
+ if let Destination::BlindedPath(BlindedPath { ref blinded_hops, .. }) = destination {