Skip to content

Commit 0aff329

Browse files
committed
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.
1 parent ab585fc commit 0aff329

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::ln::features::{InitFeatures, NodeFeatures};
2525
use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
2626
use crate::ln::onion_utils;
2727
use crate::ln::peer_handler::IgnoringMessageHandler;
28-
use crate::routing::gossip::NetworkGraph;
28+
use crate::routing::gossip::{NetworkGraph, NodeId};
2929
pub use super::packet::OnionMessageContents;
3030
use super::packet::ParsedOnionMessageContents;
3131
use super::offers::OffersMessageHandler;
@@ -280,10 +280,24 @@ where
280280
fn find_path(
281281
&self, _sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
282282
) -> Result<OnionMessagePath, ()> {
283-
if peers.contains(&destination.first_node()) {
283+
let first_node = destination.first_node();
284+
if peers.contains(&first_node) {
284285
Ok(OnionMessagePath { intermediate_nodes: vec![], destination, addresses: None })
285286
} else {
286-
Err(())
287+
let network_graph = self.network_graph.deref().read_only();
288+
let node_announcement = network_graph
289+
.node(&NodeId::from_pubkey(&first_node))
290+
.and_then(|node_info| node_info.announcement_info.as_ref())
291+
.and_then(|announcement_info| announcement_info.announcement_message.as_ref())
292+
.map(|node_announcement| &node_announcement.contents);
293+
294+
match node_announcement {
295+
Some(node_announcement) if node_announcement.features.supports_onion_messages() => {
296+
let addresses = Some(node_announcement.addresses.clone());
297+
Ok(OnionMessagePath { intermediate_nodes: vec![], destination, addresses })
298+
},
299+
_ => Err(()),
300+
}
287301
}
288302
}
289303
}

0 commit comments

Comments
 (0)