Skip to content

irinatomic/P2P_Chord_file_system

Repository files navigation

P2P Chord File System

A fault-tolerant, decentralized peer-to-peer (P2P) file sharing system in Java. It uses a Chord Distributed Hash Table (DHT) to organize nodes, ensuring efficient file lookups and network stability.

Key Features

  • Decentralized & Fault-Tolerant: No central server. A heartbeat protocol detects node failures, updates the network, and re-replicates lost data.
  • Distributed Concurrency Control: Uses the Suzuki-Kasami algorithm for distributed mutual exclusion during critical network operations (node join/failure).
  • Data Replication: Files are stored on a primary node and backed up on its immediate successor and predecessor for redundancy.
  • Access Control: A social-style privacy model where files can be public or private (visible only to approved "followers").
  • CLI Control: Each node is managed via a command-line interface.

System Architecture

  • Chord DHT: The core of the system. Each node and file path is hashed to an ID in a circular address space. This allows for efficient file location by asking "who is responsible for this ID?". Each node only needs to know about a few other nodes (its successor, predecessor, and a "finger table") to route requests efficiently.

  • Heartbeat & Fault Detection: The HeartbeatManager runs on each node, periodically sending PING messages to its neighbors. If a PONG response is not received within a "weak" time limit, the node is marked as SUSPICIOUS, and another node is asked to verify its status. If the node remains unresponsive past a "strong" time limit, it is declared DEAD, and the distributed mutex is acquired to safely remove it from the ring and re-distribute its responsibilities.

  • Suzuki-Kasami Mutex: To prevent the network from entering an inconsistent state when multiple nodes try to modify the ring structure simultaneously (e.g., a node joining while another fails), this algorithm is used. A single logical "token" is passed around the network, and only the node holding the token is permitted to perform critical section operations like welcoming a new node or removing a dead one.

Commands

Command Arguments Description
info - Displays the node's IP, port, and Chord ID.
successor_info - Prints the node's finger table (list of successors).
upload [file_path] Uploads a file to the DHT, where it is replicated.
remove [file_path] Removes a file from the DHT (only the original uploader can do this).
list_files [port] Lists files owned by the node at the specified port, obeying visibility rules.
visibility [true, false] Sets file visibility. true for public, false for private.
follow [port] Sends a request to follow the node at the specified port.
accept [port] Accepts a pending follow request from the specified node.
pause [milliseconds] Pauses the CLI thread. Useful for scripting.
stop - Gracefully shuts down the node and notifies the network.

Build & Run

Requirements

  • Java JDK 17+
  • Lombok (ensure your IDE has the plugin installed).

Building

The project can be built using an IDE like IntelliJ or Eclipse. For manual compilation with javac:

# Create a build directory
mkdir -p build/classes/java/main

# Compile source files (ensure lombok.jar is in your classpath)
javac -d build/classes/java/main -cp "path/to/lombok.jar" src/main/java/com/kids/**/*.java

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages