Skip to content

Commit 427b76a

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 427b76a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 23 additions & 3 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);
@@ -469,7 +479,8 @@ where
469479
if let Ok(Ok(stream)) =
470480
time::timeout(Duration::from_secs(CONNECT_OUTBOUND_TIMEOUT), connect_fut).await
471481
{
472-
Some(setup_outbound(peer_manager, their_node_id, stream))
482+
let remote_addr = get_addr_from_stream(&stream);
483+
Some(setup_outbound_internal(peer_manager, their_node_id, stream, remote_addr))
473484
} else {
474485
None
475486
}
@@ -478,8 +489,15 @@ where
478489
/// Routes [`connect_outbound`] through Tor. Implements stream isolation for each connection
479490
/// using a stream isolation parameter sourced from [`EntropySource::get_secure_random_bytes`].
480491
///
492+
/// The `addr` parameter will be set to the [`PeerDetails::socket_address`] for that peer in
493+
/// [`PeerManager::list_peers`], and if it is not a private IPV4 or IPV6 address, it will also
494+
/// reported to the peer in our init message.
495+
///
481496
/// Returns a future (as the fn is async) that yields another future, see [`connect_outbound`] for
482497
/// details on this return value.
498+
///
499+
/// [`PeerDetails::socket_address`]: lightning::ln::peer_handler::PeerDetails::socket_address
500+
/// [`PeerManager::list_peers`]: lightning::ln::peer_handler::PeerManager::list_peers
483501
pub async fn tor_connect_outbound<PM: Deref + 'static + Send + Sync + Clone, ES: EntropySource>(
484502
peer_manager: PM, their_node_id: PublicKey, addr: SocketAddress, tor_proxy_addr: SocketAddr,
485503
entropy_source: ES,
@@ -488,12 +506,14 @@ where
488506
PM::Target: APeerManager<Descriptor = SocketDescriptor>,
489507
{
490508
let connect_fut = async {
491-
tor_connect(addr, tor_proxy_addr, entropy_source).await.map(|s| s.into_std().unwrap())
509+
tor_connect(addr.clone(), tor_proxy_addr, entropy_source)
510+
.await
511+
.map(|s| s.into_std().unwrap())
492512
};
493513
if let Ok(Ok(stream)) =
494514
time::timeout(Duration::from_secs(TOR_CONNECT_OUTBOUND_TIMEOUT), connect_fut).await
495515
{
496-
Some(setup_outbound(peer_manager, their_node_id, stream))
516+
Some(setup_outbound_internal(peer_manager, their_node_id, stream, Some(addr)))
497517
} else {
498518
None
499519
}

0 commit comments

Comments
 (0)