How kamui-fin/dream works
Main Components
• DHT Service (Dream DHT): This corresponds to the dream-dht binary and is implemented under the src/dht directory (modules like compact.rs, context.rs, kademlia.rs, etc.). Its main role is to serve as a decentralized tracker for peer discovery.
• BitTorrent Engine (Dream Torrent): Implemented largely within src/bittorrent.rs, src/tracker.rs, and supported through peer management modules (src/peer/manager.rs, session.rs, stats.rs). This component handles the downloading/uploading of video segments between peers.
• HTTP Streaming Server: A component within the dream-torrent service that provides HTTP streaming to video players, ensuring on-demand video playback.
• Command-Line Interface (dream-cli): Located in src/bin/cli.rs, this tool allows users to upload, search, and stream videos seamlessly.
• External Dependencies: An ElasticSearch server (per the README instructions) acts as a bootstrap or indexing service to aid in video discovery.
Out Relationships and Interactions
• The CLI (dream-cli) acts as the entry point for user commands (e.g., upload, stream). It triggers functions within the BitTorrent engine.
• The BitTorrent engine fetches metadata from and communicates with the DHT network to obtain peer information and manage downloads/uploads.
• There is a clear interaction line between the BitTorrent engine and the HTTP server, with the engine providing video data on-demand to the HTTP service.
• The DHT service operates as a separate always-on service that continuously maintains the distributed network information.
• External ElasticSearch is used for video indexing—it communicates with the BitTorrent engine (or bootstrap node) to support search capabilities.
Architectural Patterns and Design Principles
• Modularity: The project is broken down into logical modules (dht, bittorrent, peer, tracker, stream, etc.) for separation of concerns.
• Service Separation: The three main services (DHT, BitTorrent engine, HTTP server) are loosely coupled but work in concert.
• Command-Driven: The CLI component facilitates direct user interaction with the system’s backend.
• Decentralization: Emphasize the peer-to-peer and distributed nature of the architecture, particularly in the design of the DHT-based decentralized tracker.
Relevant Technologies and Frameworks
• Rust (core implementation language)
• BitTorrent Protocol and Kademlia DHT (for P2P sharing/tracking)
• HTTP (for on-demand video streaming)
• ElasticSearch (external dependency for search/indexing)