How dung-h/liketorrent_242 works
Project type and purpose
• This is a peer‑to‑peer file‑sharing application (“LikeTorrent”) with two main subsystems: a Flask‑based HTTP tracker and a Python/Tkinter‑based client.
• It implements the BitTorrent protocol (announce/scrape endpoints, piece exchange, seeding, leeching) and provides GUIs for both tracker and client.
File structure
• Top‑level:
• requirements.txt, LICENSE, README.md, torrent.db (SQLite)
• src/ui.py (Client GUI)
• src/tracker_ui.py (Tracker GUI)
• src/peer/… (Peer modules)
• src/tracker/tracker.py (Tracker service)
• Patterns:
• Separation between UI and core logic
• MVC‑style: UI modules call into core (“client.py”, “peer.py”, “tracker.py”)
• Persistence: SQLite database (“torrent.db”) handled by tracker
Key insights from README
• Tracker exposes /announce and /scrape endpoints via Flask
• Client implements multi‑threaded piece downloads/uploads, SHA‑1 hashing, rarest‑first selection, optimistic unchoking
• GUIs built with Tkinter, use matplotlib for graphs
Main components and interactions
a. Components
1. Tracker subsystem
• Tracker UI (tracker_ui.py)
• HTTP Tracker service (tracker.py)
• SQLite database (torrent.db)
2. Peer (Client) subsystem
• Client UI (ui.py)
• Core modules in src/peer:
• client.py (orchestrator)
• config.py (settings)
• metainfo.py (parse/.torrent)
• torrent_maker.py (create .torrent)
• piece_manager.py (file I/O, piece hashing)
• peer.py (socket handling, message framing)
3. External interactions
• HTTP calls (requests) between client and tracker
• TCP connections (peer‑to‑peer) between clients
4. Third‑party libraries
• Flask, flask‑cors, requests, bencodepy, tkinter, matplotlib, Pillow
b. Relationships & data flows
• Client UI → invokes client.py to:
• Load/create torrents via metainfo and torrent_maker
• Start/stop downloads (spawns worker threads)
• client.py ↔ tracker.py (HTTP announce/scrape)
• client.py ↔ peer.py + piece_manager.py (TCP piece exchange)
• tracker.py ↔ SQLite DB (peer/torrent registration)
• Tracker UI polls tracker.py for real‑time stats (internal API calls)
c. Architectural patterns & principles
• Modular separation: UI vs. core logic vs. data persistence
• Multi‑threaded concurrency in client for parallel piece downloads
• MVC‑inspired layering: GUI (View) ↔ client logic (Controller) ↔ file system/DB (Model)
• Strategy pattern: rarest‑first piece selection, optimistic unchoking