Overview
Built a full BitTorrent-inspired peer-to-peer file sharing system from scratch in Python for CNT5106C (Computer Networks). The system implements the complete P2P protocol including TCP handshaking, bitfield-based piece tracking, choke/unchoke scheduling, and optimistic unchoking — supporting concurrent multi-peer file distribution across a simulated 6-node network.
Highlights
- Implemented the full P2P message protocol (CHOKE, UNCHOKE, INTERESTED, HAVE, BITFIELD, REQUEST, PIECE) over raw TCP sockets with framed length-prefixed messages
- Built a bitfield module tracking per-peer piece ownership; broadcasts HAVE to all active connections on piece completion
- Designed a preferred-neighbor scheduler that ranks peers by download rate and unchokes the top-k neighbors on a configurable interval
- Implemented optimistic unchoking to give randomly selected choked-but-interested peers a chance to receive data, preventing starvation
- Validated correctness via MD5 hash verification across all 5 downloading peers against a 20 MB reference file
Tech Stack
PythonTCP SocketsThreadingBitfield ProtocolP2P Networking