Menu

How I built EasyShare: peer-to-peer file sharing in Java
📰

How I built EasyShare: peer-to-peer file sharing in Java

DEV Community: java·Niranjan·4 days ago
#PjBuec7M
#devtojava#devto#dev#pieces#java
Reading 0:00
15s threshold

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.

Try it live · Source code

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.