How ikatson/rqbit works
Main Components
• Core Application Binary & Libraries:
• The main binary is located in crates/rqbit, while the primary library code lives in crates/librqbit.
• Complementary libraries provide various core functionalities. For instance, crates/librqbit-core contains torrent utilities (magnet, file info, hash/peer ID generation) and crates/bencode handles Bencode serialization/deserialization.
• Network and Protocol Modules:
• Distributed Hash Table (DHT): Implemented in crates/dht to provide peer discovery and enhance magnet link usage.
• Peer-to-Peer Communication: The peer_binary_protocol crate implements the protocol for interacting with other peers.
• Tracker Communications: The tracker_comms crate deals with both HTTP and UDP tracker interactions.
• UPnP: There are two related crates – crates/upnp for UPnP port forwarding and crates/upnp-serve for the integrated UPnP media server that advertises torrents to LAN devices.
• Cryptographic and Buffer Utilities: Modules such as crates/sha1w (for SHA1 checksumming) and crates/buffers support low-level operations.
• Web and HTTP API Components:
• HTTP API: The API exposes endpoints for torrent control (uploading, starting, pausing, stats, etc.) and in the README you see examples such as /torrents, /dht/stats, and /web/.
• Web UI: Implemented under crates/librqbit/webui; this serves as the frontend for managing torrents.
• Desktop Application:
• A separate desktop directory (with Tauri configuration and Rust backend in desktop/src-tauri) wraps the Web UI for a native desktop experience on platforms like Windows, OSX, and Linux.
Relationships and Interactions
• The CLI and API Server (crates/rqbit) is the entry point and orchestrates torrent-related activities by calling functions from the core libraries (librqbit, librqbit-core, bencode, etc.).
• Torrent files, magnet links, and command line arguments flow into the core engine, triggering network communication with peers, trackers, and DHT operations.
• The HTTP API and Web UI interface together: the HTTP server is the backend for both the web interface (served on http://localhost:3030/web/) and the desktop app, which essentially wraps this web layer.
• Specialized network protocols (peer, tracker, UPnP) are loosely coupled to the core downloading logic, with clearly defined responsibilities (e.g., requesting pieces, managing connections, verifying pieces via the SHA1 wrapper).
Architectural Patterns and Design Principles
• Modular Design: The project is divided into multiple crates—each handling a specific functionality (bencode, DHT, peer protocol, storage, etc.)—which promotes separation of concerns and maintainability.
• Layered Architecture: At the lowest layer, you have protocol handling and low-level data structures; above that is the core torrent management library; and at the top, you have the CLI/API and UI layers.
• Integration of External Services: UPnP for port forwarding and the media server for streaming to external devices are cleanly integrated as separate services.
• Reuse and Extensibility: The design allows both using rqbit as an application and as a library for further extension.