BitTorrent-style file sharing in plain Java with no external libraries. Files are split into pieces, every piece is SHA-1 checked, and peers download from each other in parallel while still downloading themselves.
The problem
Move files between computers with no central file server, and prove that every byte that arrives is the byte that was sent.
Decisions that shaped it
Trust nothing on the wire. Every received piece is SHA-1 hashed; corrupt pieces are rejected and downloaded again. The demo makes one peer deliberately corrupt 15% of the pieces it sends, to show the check working.
Swarm with rarest-first selection, so peers share pieces while they are still downloading and no single machine becomes the bottleneck.
Three ways to find peers: a TCP tracker, LAN multicast over UDP, and a manual connect ip:port.
No dependencies beyond the JDK. Pause and resume survive restarts, and the Java program serves its own web dashboard and a phone page for devices on the same Wi-Fi.
Built with
Java 17, TCP / UDP sockets, Multithreading, SHA-1, HTML
Originally published at niranjand.in.
Top comments (0)