BitTorrent Client (fast-peer) - LLM Project Summary
Structured technical summary optimized for Large Language Model consumption
- Project Name: Simple BitTorrent Client (fast-peer)
- Language: Python 3.10+
- Type: P2P File Sharing Client
- Purpose: Educational/Research BitTorrent implementation
- GitHub: https://github.com/patelchaitany/bit_torrent_v1
- License: Open Source
- Dependencies: requests (required), libtorrent (optional)
- PeerManager: Manages peer connections, DHT integration, peer lifecycle
- PieceManager: Handles piece downloading, verification, distribution
- DHT: Distributed Hash Table for trackerless peer discovery (BEP 5)
- MetadataManager: Manages torrent metadata exchange for magnet links
- Peer: Individual peer connection handler with async I/O
- BitTorrent Protocol: Standard peer-to-peer communication
- DHT (BEP 5): ping, find_node, get_peers, announce_peer
- PEX (ut_pex): Peer exchange extension
- Magnet Links: Metadata exchange protocol (ut_metadata)
- HTTP/UDP Trackers: Standard announce requests
BASIC_COMMANDS = {
"decode": "Decode bencoded data to JSON",
"info": "Display torrent file information",
"peers": "Discover available peers",
"handshake": "Perform BitTorrent handshake",
"download_piece": "Download specific piece",
"download": "Download complete file"
}
MAGNET_COMMANDS = {
"magnet_parse": "Parse magnet link information",
"magnet_handshake": "Handshake using magnet link",
"magnet_info": "Retrieve metadata from magnet",
"magnet_download_piece": "Download piece via magnet",
"magnet_download": "Download file via magnet"
}
DHT_COMMANDS = {
"dht": "DHT-based peer discovery and download",
"nhandshake": "Negotiated handshake with extensions"
}
- Fast Peer Acquisition: Immediate piece requests after handshake
- Auto-Replenish Peers: DHT lookups when connections drop
- Parallel Downloads: Configurable concurrency per piece
- Trackerless Support: Full DHT implementation
- Magnet Link Support: Metadata downloader included
- Async I/O: Non-blocking network operations
PROJECT_STRUCTURE = {
"app/main.py": "Main client implementation (~2130 lines)",
"app/seeder.py": "Seeding functionality using libtorrent",
"app/test.py": "Testing utilities for localhost peers",
"app/p.py": "Additional utilities",
"app/temp.py": "Temporary/experimental code",
"README.md": "Project documentation",
"your_program.sh": "Execution script",
"*.torrent": "Sample torrent files for testing"
}
CORE_FUNCTIONS = {
"decode_bencode()": "Decode bencoded data structures",
"read_torrent()": "Parse .torrent files",
"discover_peer()": "Find peers via trackers/DHT",
"perform_handshake()": "BitTorrent protocol handshake",
"download_whole_file_async()": "Async file download orchestration",
"parse_magnet_link()": "Extract info from magnet URLs",
"meta_info_downloader()": "Download metadata for magnets",
"get_info_hash()": "Calculate SHA1 hash of info dict",
"payload_create()": "Create BitTorrent protocol messages"
}
DHT_DETAILS = {
"bootstrap_nodes": [
"router.bittorrent.com:6881",
"dht.transmissionbt.com:6881",
"router.utorrent.com:6881",
"dht.aelitis.com:6881",
"dht.libtorrent.org:25401"
],
"supported_queries": ["ping", "find_node", "get_peers", "announce_peer"],
"routing_table": "Maintains known DHT nodes",
"peer_discovery": "Automatic peer replenishment",
"port": 6881
}
# Basic file download
python app/main.py download -o output.file sample.torrent
# Magnet link download
python app/main.py magnet_download -o file.zip "magnet:?xt=urn:btih:..."
# DHT-based download (trackerless)
python app/main.py dht -o file.zip "magnet:?xt=urn:btih:..."
# Peer discovery
python app/main.py peers sample.torrent
# Download specific piece
python app/main.py download_piece -o piece0.dat sample.torrent 0
# Parse magnet link
python app/main.py magnet_parse "magnet:?xt=urn:btih:..."
- Async Framework: asyncio for concurrent operations
- Network Protocol: TCP for peer connections, UDP for DHT
- Encoding: Bencode for data serialization
- Hash Algorithm: SHA1 for piece verification
- Block Size: 16KB default for piece subdivision
- Peer ID: 20-byte random identifier
- Threading: Separate thread for DHT operations
- Immediate Requests: No startup delay after handshake
- Parallel Blocks: Multiple block requests per piece
- Peer Sorting: Prioritize by throughput and interest
- Connection Pooling: Reuse connections when possible
- DHT Caching: Cache discovered peers
- Async I/O: Non-blocking network operations
- Connection Failures: Automatic retry with exponential backoff
- Piece Verification: SHA1 hash validation, re-download on failure
- Peer Timeouts: Keepalive messages and connection cleanup
- DHT Errors: Graceful handling of malformed messages
- Tracker Failures: Fallback to DHT for peer discovery
- Status: Functional prototype for research/education
- Testing: Includes localhost seeder for testing
- Production Ready: No - designed for experimentation
- Code Quality: Research-grade, extensive logging
- Documentation: README + inline comments