A lightweight, Python-based BitTorrent client that implements the core functionality of the BitTorrent protocol. This client allows you to load and parse torrent files, connect to trackers, and interact with peers in the BitTorrent network.
- Parse and decode
.torrentfiles - Connect to trackers to obtain peer lists
- Establish connections with peers using the BitTorrent protocol
- User-friendly graphical interface for easy interaction
- Implementation of Bencode encoding/decoding
- bencode.py: Implementation of the Bencode encoding/decoding used in BitTorrent
- torrent.py: Class for parsing and handling torrent metadata
- tracker.py: Communication with BitTorrent trackers
- peer.py: Handles peer connections and protocol messaging
- client.py: Command line interface for the BitTorrent client
- gui.py: Graphical user interface for the BitTorrent client
- Python 3.6 or higher
- Tkinter (for GUI)
-
Clone the repository:
git clone https://github.com/husal90/bittorrent-client.git cd bittorrent-client -
Run the client:
- For command line interface:
python client.py - For graphical interface:
python gui.py
- For command line interface:
The command line interface is designed for simple testing and demonstration:
python client.pyThis will try to load a default torrent file named 'ubuntu.torrent' and connect to its first available peer.
The GUI provides a more user-friendly way to interact with the client:
- Run
python gui.py - Click "Load .torrent File" and select a torrent file
- Once loaded, information about the torrent will be displayed
- Click "Connect to Peer" to establish a connection with one of the available peers
This project is developed using:
- Python 3: The entire codebase is written in Python, leveraging its simplicity and extensive standard library
- Socket Programming: Used for low-level network communications with peers
- Tkinter: Python's standard GUI toolkit for creating the graphical user interface
- urllib: Python's URL handling module for HTTP requests to trackers
- hashlib: For cryptographic hash functions, particularly SHA-1 for info hash generation
- struct: For binary data packing and unpacking in the peer protocol
This client implements the core aspects of the BitTorrent protocol:
- Bencode: A serialization format used to encode and decode BitTorrent data
- Tracker Protocol: Communication with trackers using HTTP to obtain peer lists
- Peer Protocol: Establishing connections with peers including the BitTorrent handshake
Bencode is a simple encoding used in the BitTorrent protocol for encoding and decoding data. It supports:
- Strings:
<length>:<string> - Integers:
i<number>e - Lists:
l<bencoded values>e - Dictionaries:
d<bencoded key><bencoded value>...e
- Implement piece downloading and file assembly
- Add support for multiple simultaneous peer connections
- Implement seeding capabilities
- Add download progress tracking and visualization
- Support for magnet links
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The BitTorrent protocol specification
- The Python community for excellent networking libraries