Skip to content

VicegerentPrince/inter-planetery-file-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inter‑Planetary File System (Toy P2P)

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.


Overview

  • Content‑addressed storage: 256KB chunks hashed with SHA‑256. A serialized Manifest records 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.

Quick Start

Requirements

  • Java 11 (JDK) or later
  • Maven 3.8+

Run (dev):

mvn clean javafx:run

Tip: 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).


Using the App

  1. Start the app: the UI loads and LAN discovery starts. The status cards show server state and peer count.
  2. Start server: toggle “Start Server”. The node binds a TCP port (≥5000) and begins announcing TOY_IPFS_HELLO:<port>.
  3. Upload a file: pick any file. The app chunks it, stores blocks in ./storage/, creates a Manifest, computes a root CID, and copies it to your clipboard.
  4. 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.
  5. 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”.

Project Structure

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.css and styles-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; broadcasts TOY_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, and javafx-maven-plugin for mvn javafx:run.

How It Works

  • Chunking & CIDs: FileChunker reads 256KB chunks and computes CID = SHA‑256(chunk). The Manifest is 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> to 255.255.255.255:8888 and listens on UDP 8888, pruning peers not heard from in ~10s.
  • Serving: PeerServer replies to a CID request with a presence flag and raw bytes (or a miss). It also accepts CHAT:<payload>.
  • Swarming download: P2PClient assigns 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, Package, and Settings

Run in dev (JavaFX via Maven):

mvn clean javafx:run

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

Troubleshooting

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

License

MIT Lisence

About

A decentralized, Peer-to-Peer (P2P) file sharing system inspired by the InterPlanetary File System (IPFS).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors