+ &self, contents: T, destination: Destination, reply_path: Option<BlindedPath>
+ ) -> Result<SendSuccess, SendError> {
+ self.find_path_and_enqueue_onion_message(
+ contents, destination, reply_path, format_args!("")
+ )
+ }
+
+ fn find_path_and_enqueue_onion_message<T: OnionMessageContents>(
+ &self, contents: T, destination: Destination, reply_path: Option<BlindedPath>,
+ log_suffix: fmt::Arguments
+ ) -> Result<SendSuccess, SendError> {
+ let result = self.find_path(destination)
+ .and_then(|path| self.enqueue_onion_message(path, contents, reply_path, log_suffix));
+
+ match result.as_ref() {
+ Err(SendError::GetNodeIdFailed) => {
+ log_warn!(self.logger, "Unable to retrieve node id {}", log_suffix);
+ },
+ Err(SendError::PathNotFound) => {
+ log_trace!(self.logger, "Failed to find path {}", log_suffix);
+ },
+ Err(e) => {
+ log_trace!(self.logger, "Failed sending onion message {}: {:?}", log_suffix, e);
+ },
+ Ok(SendSuccess::Buffered) => {
+ log_trace!(self.logger, "Buffered onion message {}", log_suffix);
+ },
+ Ok(SendSuccess::BufferedAwaitingConnection(node_id)) => {
+ log_trace!(
+ self.logger, "Buffered onion message waiting on peer connection {}: {:?}",
+ log_suffix, node_id
+ );
+ },
+ }
+
+ result
+ }
+
+ fn find_path(&self, destination: Destination) -> Result<OnionMessagePath, SendError> {
+ let sender = self.node_signer
+ .get_node_id(Recipient::Node)
+ .map_err(|_| SendError::GetNodeIdFailed)?;
+
+ let peers = self.message_recipients.lock().unwrap()
+ .iter()
+ .filter(|(_, recipient)| matches!(recipient, OnionMessageRecipient::ConnectedPeer(_)))
+ .map(|(node_id, _)| *node_id)
+ .collect();
+
+ self.message_router
+ .find_path(sender, peers, destination)
+ .map_err(|_| SendError::PathNotFound)
+ }
+
+ fn enqueue_onion_message<T: OnionMessageContents>(
+ &self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>,
+ log_suffix: fmt::Arguments
+ ) -> Result<SendSuccess, SendError> {
+ log_trace!(self.logger, "Constructing onion message {}: {:?}", log_suffix, contents);
+
+ let (first_node_id, onion_message, addresses) = create_onion_message(