DEV Community
Follow
Building a P2P Chat over Tor with Rust's arti-client
This post details the complexities of peer discovery and session setup in Anyhide, focusing on Tor hidden services. It explains why hidden services are crucial for mutual anonymity between users, unlike regular servers. The process of converting a Tor hidden service ID into a human-readable .onion address is described with code and specific implementation details. Bootstrapping the `arti` Tor client library is shown, highlighting its embedded nature compared to a separate daemon. Hosting a hidden service involves configuration and obtaining a request stream for incoming connections. Connecting to a hidden service is similarly straightforward. The article discusses a bidirectional connection racing approach where both peers attempt to initiate a connection simultaneously, promoting equality and ease of use, despite added complexity. A three-message handshake mechanism is outlined for establishing secure session keys once a connection is made. It clarifies what the `arti` library provides, such as circuit management and hidden service integration, and what it currently lacks, noting its experimental status for security-critical applications. The author emphasizes keeping cryptographic primitives synchronous to avoid cancellation safety issues. The next post will cover the user interface, including contact management and connection request handling.