Skip to content

Conversation

@tankyleo
Copy link
Contributor

@tankyleo tankyleo commented Feb 2, 2026


    Add `remote_addr` field to `lightning_net_tokio::setup_outbound`

    When `setup_outbound` was used to setup a connection proxied over Tor,
    it previously set `remote_addr` to the address of the Tor proxy, and not
    the address of the peer on the other side of the stream.

    The 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.

    Here we ask callers of `setup_outbound` to pass a `remote_addr`
    separately from the `StdTcpStream`. `connect_outbound` sets this new
    `remote_addr` parameter to `get_addr_from_stream`, and
    `tor_connect_outbound` passes its own `addr` parameter directly to
    `remote_addr`.

    Notably, Onion V3 addresses will now appear in `PeerManager::list_peers`
    for outbound Tor connections to Onion V3 services made using
    `tor_connect_outbound`, and will be reported to the peer in our init
    message.

    While this adds a new parameter to the public `fn setup_outbound`
    function, this closely mirrors the existing public method
    `PeerManager::new_outbound_connection`.

When `setup_outbound` was used to setup a connection proxied over Tor,
it previously set `remote_addr` to the address of the Tor proxy, and not
the address of the peer on the other side of the stream.

The 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.

Here we ask callers of `setup_outbound` to pass a `remote_addr`
separately from the `StdTcpStream`. `connect_outbound` sets this new
`remote_addr` parameter to `get_addr_from_stream`, and
`tor_connect_outbound` passes its own `addr` parameter directly to
`remote_addr`.

Notably, Onion V3 addresses will now appear in `PeerManager::list_peers`
for outbound Tor connections to Onion V3 services made using
`tor_connect_outbound`, and will be reported to the peer in our init
message.

While this adds a new parameter to the public `fn setup_outbound`
function, this closely mirrors the existing public method
`PeerManager::new_outbound_connection`.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 2, 2026

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tankyleo
Copy link
Contributor Author

tankyleo commented Feb 2, 2026

Fixes the issues @jharveyb reported in lightningdevkit/ldk-node#778

@tankyleo tankyleo requested review from TheBlueMatt and tnull February 2, 2026 19:27
@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

❌ Patch coverage is 41.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.00%. Comparing base (8679d8d) to head (f8906d7).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
lightning-net-tokio/src/lib.rs 41.66% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4372      +/-   ##
==========================================
+ Coverage   85.98%   86.00%   +0.01%     
==========================================
  Files         156      156              
  Lines      102641   102694      +53     
  Branches   102641   102694      +53     
==========================================
+ Hits        88258    88317      +59     
+ Misses      11873    11869       -4     
+ Partials     2510     2508       -2     
Flag Coverage Δ
tests 86.00% <41.66%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally makes sense. One question, otherwise CI seems unhappy right now.

/// [`PeerManager::list_peers`]: lightning::ln::peer_handler::PeerManager::list_peers
pub fn setup_outbound<PM: Deref + 'static + Send + Sync + Clone>(
peer_manager: PM, their_node_id: PublicKey, stream: StdTcpStream,
remote_addr: Option<SocketAddress>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, rather than adding this on the generic setup_outbound, would it make sense to refactor this to be an setup_outbound_internal and offer two setup_outbound and setup_outbound_tor variants that do the right (tm) thing for the user? Or, put differently, for non-Tor users this remote_addr argument might be confusing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants