Skip to content

Conversation

@sat-engineer
Copy link

@sat-engineer sat-engineer commented Feb 7, 2026

Summary

  • Implement SOCKS5 protocol (RFC 1928/1929) in connection.rs for routing outbound peer connections through a Tor proxy
  • Add set_tor_proxy_address() on NodeBuilder (FFI-compatible via UDL) to configure the SOCKS5 proxy
  • Route .onion (OnionV3) addresses through SOCKS5 with Tor stream isolation (random password auth per connection), clearnet addresses through direct TCP
  • Self-contained implementation that doesn't depend on unreleased lightning_net_tokio::tor_connect_outbound() from upstream PR Add Tor support for outbound connections via SOCKS lightningdevkit/ldk-node#778

Relates to getAlby/hub#2035

Related PRs

This is part of a 3-PR series enabling Tor .onion-to-.onion Lightning peer connections in Alby Hub:

  1. Rust SOCKS5 implementation 👈 you are here — feat: add Tor SOCKS5 proxy support for outbound .onion connections #91
  2. Go/C bindings rebuildfeat: add SetTorProxyAddress binding for .onion connections ldk-node-go#34
  3. Alby Hub integration (tor package, env vars, frontend)feat: add Tor hidden service and outbound .onion peer connections hub#2038

Dependency chain: PR 1 → PR 2 → PR 3

Files changed

  • src/connection.rs — SOCKS5 handshake, base32 encoder for OnionV3 address derivation, routing logic + 15 unit tests
  • src/builder.rstor_proxy_address field and set_tor_proxy_address() method on NodeBuilder
  • bindings/ldk_node.udl — FFI interface definition for set_tor_proxy_address

Test plan

  • cargo test --lib connection::tests — 15 tests passing (base32 encoding, SOCKS5 protocol with mock proxy)
  • cargo check passes with zero warnings
  • Deployed on two Umbrel instances connecting over Tor (.onion-to-.onion)
  • Successfully opened channel and sent Lightning payments (1k sats, 2k sats)
  • Verified stream isolation produces separate Tor circuits per connection

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Implement SOCKS5 protocol in connection.rs to route outbound peer
connections through a Tor proxy. This enables LDK nodes to connect
to peers at .onion addresses.

Changes:
- Add tor_socks5_connect() with full SOCKS5 handshake (RFC 1928/1929)
- Support Tor stream isolation via random password auth per connection
- Add set_tor_proxy_address() on NodeBuilder (FFI-compatible via UDL)
- Route OnionV3 addresses through SOCKS5, clearnet through direct TCP
- Include base32 encoder for OnionV3 address derivation

Based on the approach in upstream ldk-node PR lightningdevkit#778, but with a
self-contained SOCKS5 implementation that doesn't depend on unreleased
lightning_net_tokio::tor_connect_outbound().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant