Feat/4299 tor networking crate #4330
Open
+1,146
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new lightning-net-tor crate that provides native Tor networking support for Lightning Network nodes, enabling enhanced privacy through .onion connections.
Motivation
Lightning nodes often need to connect over Tor for privacy reasons. Currently, users must implement their own Tor integration or use external tools. This crate provides a first-class Tor networking stack similar to lightning-net-tokio, making it easy to connect Lightning nodes over Tor with minimal setup.
Implementation Details
New Crate: lightning-net-tor
• Location: lightning-net-tor/
• Architecture: Built on top of Arti, the Rust implementation of Tor
• Runtime: Uses Tokio for async operations
• API: Mirrors lightning-net-tokio for consistency
Core Components
◦ connect_outbound_tor() - Connect to a Lightning node over Tor
◦ setup_outbound_tor() - Initialize outbound Tor connection
◦ setup_inbound_tor() - Initialize inbound Tor connection (for hidden services)
USAGE EXAMPLE
Testing
Integration Tests
Added comprehensive integration tests in tests/integration_test.rs:
• Tor client initialization - Verifies Tor client creation and bootstrap
• Real connectivity test - Connects to DuckDuckGo's .onion service to verify Tor connectivity
• PeerManager integration - Ensures TorSocketDescriptor works with Lightning's PeerManager
• Daemon status checks - Helper to verify Tor daemon is running
Testing Documentation
Added TESTING.md with:
• Installation instructions for Tor daemon (Ubuntu, macOS, Arch)
• Step-by-step test execution guide
• Manual end-to-end testing with real Lightning nodes
• Troubleshooting for common issues
• Performance benchmarks and security considerations
• CI/CD integration examples