From 28cf5f5ac2af058fad3819d6b3b8a084dc92e934 Mon Sep 17 00:00:00 2001 From: Leo Nash Date: Mon, 2 Feb 2026 18:04:48 +0000 Subject: [PATCH] Pass the `addr` field of `tor_connect_outbound` to connection setup When `setup_outbound` was used to setup a connection proxied over Tor, it previously set the remote address of the peer to the address of the Tor proxy. This address of the Tor proxy was assigned to the `PeerDetails::socket_address` for that peer in `PeerManager::list_peers`, and if it was not a private IPV4 or IPV6 address, it was also reported to the peer in our init message. This commit refactors `tor_connect_outbound` to pass its own peer address parameter directly to the connection setup code. This peer address will now appear in `PeerManager::list_peers` for outbound Tor connections made using `tor_connect_outbound`, and will be reported to the peer in our init message if it is not a private IPV4 or IPV6 address. --- lightning-net-tokio/src/lib.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index eec0e424eaa..31b58c2982f 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -384,6 +384,16 @@ where PM::Target: APeerManager, { let remote_addr = get_addr_from_stream(&stream); + setup_outbound_internal(peer_manager, their_node_id, stream, remote_addr) +} + +fn setup_outbound_internal( + peer_manager: PM, their_node_id: PublicKey, stream: StdTcpStream, + remote_addr: Option, +) -> impl std::future::Future +where + PM::Target: APeerManager, +{ let (reader, mut write_receiver, read_receiver, us) = Connection::new(stream); #[cfg(test)] let last_us = Arc::clone(&us); @@ -478,8 +488,15 @@ where /// Routes [`connect_outbound`] through Tor. Implements stream isolation for each connection /// using a stream isolation parameter sourced from [`EntropySource::get_secure_random_bytes`]. /// +/// The `addr` parameter will be set to the [`PeerDetails::socket_address`] for that peer in +/// [`PeerManager::list_peers`], and if it is not a private IPV4 or IPV6 address, it will also +/// reported to the peer in our init message. +/// /// Returns a future (as the fn is async) that yields another future, see [`connect_outbound`] for /// details on this return value. +/// +/// [`PeerDetails::socket_address`]: lightning::ln::peer_handler::PeerDetails::socket_address +/// [`PeerManager::list_peers`]: lightning::ln::peer_handler::PeerManager::list_peers pub async fn tor_connect_outbound( peer_manager: PM, their_node_id: PublicKey, addr: SocketAddress, tor_proxy_addr: SocketAddr, entropy_source: ES, @@ -488,12 +505,14 @@ where PM::Target: APeerManager, { let connect_fut = async { - tor_connect(addr, tor_proxy_addr, entropy_source).await.map(|s| s.into_std().unwrap()) + tor_connect(addr.clone(), tor_proxy_addr, entropy_source) + .await + .map(|s| s.into_std().unwrap()) }; if let Ok(Ok(stream)) = time::timeout(Duration::from_secs(TOR_CONNECT_OUTBOUND_TIMEOUT), connect_fut).await { - Some(setup_outbound(peer_manager, their_node_id, stream)) + Some(setup_outbound_internal(peer_manager, their_node_id, stream, Some(addr))) } else { None }