Decentralized, LAN‑first peer‑to‑peer file sharing with a modern JavaFX UI. Files are chunked, content‑addressed (SHA‑256 CIDs), announced over the LAN, and fetched from multiple peers with fault tolerance. Includes a simple peer‑to‑peer chat.
- Content‑addressed storage: 256KB chunks hashed with SHA‑256. A serialized
Manifestrecords the original filename, size, and ordered chunk CIDs. The root CID is the SHA‑256 of the manifest bytes. - LAN peer discovery: periodic UDP broadcast on port 8888 with payload
TOY_IPFS_HELLO:<tcpPort>every 5s. - P2P server: binds the first free TCP port starting at 5000 and serves blocks and chat messages.
- Swarming downloads: attempts chunks in parallel from multiple peers, redistributing work if peers disappear.
- JavaFX desktop app: dark/light themes, activity log, Merkle‑style DAG view for manifests, peer topology mini‑graph, progress cards, and built‑in chat.
Requirements
- Java 11 (JDK) or later
- Maven 3.8+
Run (dev):
mvn clean javafx:runTip: Run on two machines on the same LAN (or twice on one machine) to see discovery and downloads. Allow the app through your OS firewall for UDP 8888 and the chosen TCP port (>=5000).
- Start the app: the UI loads and LAN discovery starts. The status cards show server state and peer count.
- Start server: toggle “Start Server”. The node binds a TCP port (≥5000) and begins announcing
TOY_IPFS_HELLO:<port>. - Upload a file: pick any file. The app chunks it, stores blocks in
./storage/, creates aManifest, computes a root CID, and copies it to your clipboard. - Share/download:
- Share the root CID with another node on the LAN.
- On the downloader, paste the root CID and click Download.
- The client fetches the manifest, then all chunks in parallel from available peers.
- Output: the file is reassembled to
~/Downloads/IPFS-P2P/<filename>.
Chat
- Select a peer from the list and send a message. Messages use the same TCP channel with a
CHAT:prefix. If the message looks like a CID, right‑click to “Download from CID”.
Relevant sources only; see tree for full listing.
-
App and UI
src/main/java/com/example/App.java– JavaFX entrypoint and DI wiring.src/main/java/com/example/ui/MainController.java– UI logic (upload/download, server control, DAG, graph, chat).src/main/resources/com/example/main-view.fxml– UI layout.src/main/resources/com/example/styles.cssandstyles-light.css– themes.
-
Core
src/main/java/com/example/core/Block.java– immutable data block (byte[] + CID).src/main/java/com/example/core/Manifest.java– filename, size, ordered chunk CIDs; Java serialization for bytes.src/main/java/com/example/core/io/FileChunker.java– splits files into 256KB blocks (SHA‑256 CIDs).src/main/java/com/example/core/io/FileAssembler.java– reassembles blocks into a file.src/main/java/com/example/core/storage/Storage.java– storage interface.src/main/java/com/example/core/storage/DiskStorage.java– file‑per‑CID under./storage/.
-
Networking
src/main/java/com/example/net/PeerDiscovery.java– UDP discovery on 8888; broadcastsTOY_IPFS_HELLO:<port>and maintains an active peer list.src/main/java/com/example/net/PeerServer.java– serves blocks and receives chat over TCP; picks first free port ≥5000.src/main/java/com/example/net/P2PClient.java– downloads single blocks or swarms all chunks for a Manifest; also sends chat.src/main/java/com/example/net/chat/ChatService.java– chat protocol wrapper over the existing TCP channel.
-
Utils
src/main/java/com/example/util/ActivityLog.java– pluggable UI log sink.src/main/java/com/example/util/HashingUtil.java,src/main/java/com/example/util/FormatUtil.java– helpers.
Build
pom.xml– Java 11, JavaFX 17.0.2, andjavafx-maven-pluginformvn javafx:run.
- Chunking & CIDs:
FileChunkerreads 256KB chunks and computes CID = SHA‑256(chunk). TheManifestis serialized and its root CID = SHA‑256(manifestBytes). - Storage layout: each CID is a file under
./storage/<cid>. Manifests are stored the same way. - Discovery: every 5s the node broadcasts
TOY_IPFS_HELLO:<port>to255.255.255.255:8888and listens on UDP 8888, pruning peers not heard from in ~10s. - Serving:
PeerServerreplies to a CID request with a presence flag and raw bytes (or a miss). It also acceptsCHAT:<payload>. - Swarming download:
P2PClientassigns chunks to peers, tries up to three peers per chunk, redistributes if peers vanish, and reports progress. - UI extras: Merkle‑style DAG tree for a manifest’s chunks; animated peer graph; light/dark theme toggle; toast notifications; progress cards.
Run in dev (JavaFX via Maven):
mvn clean javafx:runPackage a jar (UI apps are usually run via the plugin; a runnable fat‑jar would require additional JavaFX packaging which is not configured here).
Configuration knobs:
- Discovery port: fixed at UDP 8888 in
PeerDiscovery. - Broadcast interval: 5s in
PeerDiscovery. - Server base port: 5000 in
PeerServer(auto‑increments to the next free port). - Chunk size: 256KB in
FileChunker.
- No peers found:
- Ensure the other node pressed “Start Server”.
- Machines must be on the same LAN and subnet; allow UDP 8888 and TCP ≥5000 through your firewall.
- Some networks block broadcast
255.255.255.255; try on a home/office LAN.
- Download stalls:
- Keep at least one server online that has the requested CIDs.
- The client will pause and retry when no peers are available.
- Windows specifics:
- On first run, allow Java through Windows Defender Firewall for private networks.
MIT Lisence