KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
BitTorrentClient
★ 10
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
eye_control_example
:
3D eye control example
voice-assistant-example
:
Example setup for a local Voice Assistant.
kali-linux-gpu-switcher
:
A beautiful Apple-style dark UI for managing NVIDIA Optimus GPUs on Kali Linux. Made with ❤️ by Navneet Singh
tecnofast
:
No description available.
ConsoleHBuss
:
ConsoleH Buss plugin
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
BitTorrentClient
?
Download (.md)
# BitTorrent Client A production-ready BitTorrent v1 client implementation in Python following the [official protocol specification](http://www.bittorrent.org/beps/bep_0003.html). Supports complete torrent downloads with request pipelining and parallel peer connections. ## Quick Start ```bash # Install pip install -e ".[dev]" # Download a torrent python download_torrent.py big-buck-bunny.torrent # Inspect torrent metadata python inspect_torrent.py ubuntu.torrent ``` ## Features **Protocol Implementation** - Bencode encoding/decoding with strict validation - .torrent file parsing (single-file and multi-file) - SHA-1 infohash computation - HTTP/HTTPS tracker protocol (bencoded) - UDP tracker protocol (BEP 15) - Complete peer wire protocol with all standard messages - Automatic tracker fallback **Storage & Download** - Multi-file storage with global address space mapping - Piece spanning across file boundaries - Path traversal attack prevention - Piece and block management with SHA-1 verification - Request pipelining (50 requests per peer) - Parallel peer connections (up to 10 concurrent) - Thread-safe operations with proper locking - Real-time progress tracking and statistics **Performance Optimizations** - Request pipelining reduces round-trip latency - Concurrent peer connections via ThreadPoolExecutor - Fast connection timeout (5s) for unresponsive peers - Direct file I/O with efficient offset calculations ## Installation ```bash git clone https://github.com/HickoDev/BitTorrentClient cd BittorentClient pip install -e ".[dev]" pytest # Verify installation ``` **Requirements:** Python 3.10+, pytest (dev only) ## Usage ### Parse Torrent Files ```python from bt.metainfo import parse_torrent, format_infohash meta = parse_torrent('ubuntu-22.04.torrent') print(f"Infohash: {format_infohash(meta.infohash)}") print(f"Size: {meta.total_length} bytes") print(f"Pieces: {len(meta.piece_hashes)}") ``` ### Connect to Trackers ```python from bt.tracker import announce_simple_with_fallback response, url = announce_simple_with_fallback( tracker_urls=trackers, infohash=meta.infohash, total_length=meta.total_length, port=6881 ) print(f"Peers: {len(response.peers)}") ``` ### Download Torrents ```python from bt.storage import TorrentStorage from bt.pieces import PieceManager from bt.wire import PeerConnection storage = TorrentStorage(meta.files, './downloads', meta.piece_length) storage.preallocate() piece_manager = PieceManager(meta, storage) # See download_torrent.py for complete implementation ``` ### Command-Line Tools ```bash python download_torrent.py file.torrent [output_dir] python inspect_torrent.py file.torrent python test_real_tracker.py file.torrent python test_download_piece.py file.torrent ``` ## Testing ```bash pytest # Run all tests pytest --cov=bt --cov-report=html # With coverage # Individual modules pytest tests/test_bencode.py pytest tests/test_metainfo.py pytest tests/test_storage.py pytest tests/test_tracker.py pytest tests/test_wire.py pytest tests/test_pieces.py ``` ## Architecture ``` bt/ ├── bencode.py # Bencode encoding/decoding ├── metainfo.py # .torrent parser + infohash ├── storage.py # Multi-file storage manager ├── tracker_http.py # HTTP/HTTPS tracker protocol ├── tracker_udp.py # UDP tracker protocol (BEP 15) ├── tracker.py # Unified tracker interface ├── wire.py # Peer wire protocol ├── pieces.py # Piece and block management └── utils.py # Utilities tests/ # Comprehensive test suite download_torrent.py # CLI download client inspect_torrent.py # Torrent metadata inspector ``` ## Development Status **Completed** - Bencode encoding/decoding - Torrent file parsing - HTTP/HTTPS and UDP tracker protocols - Peer wire protocol - Download pipeline with pipelining and parallelization - Multi-file storage management - Comprehensive test coverage **Future Enhancements** - DHT support for trackerless torrents - Magnet link support - Upload/seeding capability - Resume partial downloads - Rate limiting and bandwidth control ## License MIT ## References - [BitTorrent Protocol Specification (BEP 3)](http://www.bittorrent.org/beps/bep_0003.html) - [UDP Tracker Protocol (BEP 15)](http://www.bittorrent.org/beps/bep_0015.html)