Skip to content

Commit 28cf5f5

Browse files
committed
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.
1 parent 8679d8d commit 28cf5f5

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ where
384384
PM::Target: APeerManager<Descriptor = SocketDescriptor>,
385385
{
386386
let remote_addr = get_addr_from_stream(&stream);
387+
setup_outbound_internal(peer_manager, their_node_id, stream, remote_addr)
388+
}
389+
390+
fn setup_outbound_internal<PM: Deref + 'static + Send + Sync + Clone>(
391+
peer_manager: PM, their_node_id: PublicKey, stream: StdTcpStream,
392+
remote_addr: Option<SocketAddress>,
393+
) -> impl std::future::Future<Output = ()>
394+
where
395+
PM::Target: APeerManager<Descriptor = SocketDescriptor>,
396+
{
387397
let (reader, mut write_receiver, read_receiver, us) = Connection::new(stream);
388398
#[cfg(test)]
389399
let last_us = Arc::clone(&us);
@@ -478,8 +488,15 @@ where
478488
/// Routes [`connect_outbound`] through Tor. Implements stream isolation for each connection
479489
/// using a stream isolation parameter sourced from [`EntropySource::get_secure_random_bytes`].
480490
///
491+
/// The `addr` parameter will be set to the [`PeerDetails::socket_address`] for that peer in
492+
/// [`PeerManager::list_peers`], and if it is not a private IPV4 or IPV6 address, it will also
493+
/// reported to the peer in our init message.
494+
///
481495
/// Returns a future (as the fn is async) that yields another future, see [`connect_outbound`] for
482496
/// details on this return value.
497+
///
498+
/// [`PeerDetails::socket_address`]: lightning::ln::peer_handler::PeerDetails::socket_address
499+
/// [`PeerManager::list_peers`]: lightning::ln::peer_handler::PeerManager::list_peers
483500
pub async fn tor_connect_outbound<PM: Deref + 'static + Send + Sync + Clone, ES: EntropySource>(
484501
peer_manager: PM, their_node_id: PublicKey, addr: SocketAddress, tor_proxy_addr: SocketAddr,
485502
entropy_source: ES,
@@ -488,12 +505,14 @@ where
488505
PM::Target: APeerManager<Descriptor = SocketDescriptor>,
489506
{
490507
let connect_fut = async {
491-
tor_connect(addr, tor_proxy_addr, entropy_source).await.map(|s| s.into_std().unwrap())
508+
tor_connect(addr.clone(), tor_proxy_addr, entropy_source)
509+
.await
510+
.map(|s| s.into_std().unwrap())
492511
};
493512
if let Ok(Ok(stream)) =
494513
time::timeout(Duration::from_secs(TOR_CONNECT_OUTBOUND_TIMEOUT), connect_fut).await
495514
{
496-
Some(setup_outbound(peer_manager, their_node_id, stream))
515+
Some(setup_outbound_internal(peer_manager, their_node_id, stream, Some(addr)))
497516
} else {
498517
None
499518
}

0 commit comments

Comments
 (0)