From b86f02afad22f0d2b8fe30e3427bfc63bd0b086d Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 14 Nov 2023 17:08:26 -0600 Subject: [PATCH] Return socket addresses from DefaultMessageRouter When there isn't a direct connection with the Destination of an OnionMessage, look up socket addresses from the NetworkGraph. This is used to signal to OnionMessenger that a direct connection is needed to send the message. --- lightning/src/onion_message/messenger.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index eb309b622..9135157b8 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -25,7 +25,7 @@ use crate::ln::features::{InitFeatures, NodeFeatures}; use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress}; use crate::ln::onion_utils; use crate::ln::peer_handler::IgnoringMessageHandler; -use crate::routing::gossip::NetworkGraph; +use crate::routing::gossip::{NetworkGraph, NodeId}; pub use super::packet::OnionMessageContents; use super::packet::ParsedOnionMessageContents; use super::offers::OffersMessageHandler; @@ -282,10 +282,24 @@ where fn find_path( &self, _sender: PublicKey, peers: Vec, destination: Destination ) -> Result { - if peers.contains(&destination.first_node()) { + let first_node = destination.first_node(); + if peers.contains(&first_node) { Ok(OnionMessagePath { intermediate_nodes: vec![], destination, addresses: None }) } else { - Err(()) + let network_graph = self.network_graph.deref().read_only(); + let node_announcement = network_graph + .node(&NodeId::from_pubkey(&first_node)) + .and_then(|node_info| node_info.announcement_info.as_ref()) + .and_then(|announcement_info| announcement_info.announcement_message.as_ref()) + .map(|node_announcement| &node_announcement.contents); + + match node_announcement { + Some(node_announcement) if node_announcement.features.supports_onion_messages() => { + let addresses = Some(node_announcement.addresses.clone()); + Ok(OnionMessagePath { intermediate_nodes: vec![], destination, addresses }) + }, + _ => Err(()), + } } } } -- 2.39.5