This project implements a Chord Distributed Hash Table (DHT) protocol along with a Graphical User Interface (GUI) for simulation and visualization. It enables users to interact with the DHT by adding/removing nodes, storing and retrieving key-value pairs, and visualizing the dynamic structure of the DHT ring.
The Chord DHT protocol provides a scalable and efficient peer-to-peer network structure using consistent hashing and finger tables for quick lookups. The GUI further enhances usability by presenting the DHT ring structure and operations in a visual and interactive manner.
-
Chord Protocol Implementation:
- Consistent hashing for distributed key management.
- Efficient lookup with (O(\log N)) complexity using finger tables.
- Dynamic node addition and removal.
- Replication for fault tolerance.
-
Interactive GUI:
- Add or remove nodes in the ring.
- Store and retrieve key-value pairs.
- Query nodes for successor and predecessor.
- Real-time visualization of the DHT structure.
-
Visualization:
- Circular DHT ring with nodes and edges.
- Blue edges: Successor links.
- Red dashed edges: Finger table connections.
- Logging:
- Detailed logs for node operations, key storage, replication, and retrieval.
- Logs are displayed in the terminal for debugging.
- Python 3.8+
- Libraries:
matplotlib
networkx
tkinter
numpy
-
Clone the repository:
git clone git@github.com:ss-369/Chord_DHT-Replication.git cd Chord_DHT-Replication
-
Install dependencies:
pip install -r requirements.txt
(If
requirements.txt
is unavailable, manually install required libraries):pip install matplotlib networkx numpy
-
Run the application:
python chord_dht_gui_fixed.py
- Add Node:
- Enter an optional node ID or let the system assign one automatically.
- Remove Node:
- Remove a node by entering its ID.
- Store Key-Value:
- Store a key-value pair in the DHT.
- Retrieve Key:
- Retrieve a value associated with a key from the DHT.
- Query Node:
- Find the successor and predecessor of a specific node.
- Nodes are displayed in a circular layout.
- Blue Edges: Represent successor relationships.
- Red Dashed Edges: Represent finger table connections.
Chord_DHT-Replication/
├── chord_dht_gui_fixed.py # Main application with GUI
├── README.md # Documentation
├── requirements.txt # Dependencies
├── screenshots/ # Images for README
│ ├── chord.png
│ ├── GUI.png
│ └── logging.png
└── assets/ # Additional resources
The Chord protocol enables scalable and efficient peer-to-peer communication:
- Consistent Hashing:
- Nodes and keys are hashed to a fixed-size identifier space (e.g., (0) to (2^M - 1)).
- Finger Tables:
- Each node maintains a routing table for efficient key lookups.
- Successors and Predecessors:
- Ensure the ring structure remains intact during node joins and leaves.
- Replication:
- Increases fault tolerance by duplicating data across multiple nodes.
The replication factor R
determines how many nodes store a copy of a key-value pair. It is configurable for increased fault tolerance.
Change the identifier space size by updating the M
constant in the code:
M = 5 # Number of bits (identifier range: 0 to 31)
Adjust the replication factor by modifying the R
constant:
R = 3 # Replication factor
Enable file logging and customize log levels by modifying the logging setup:
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s:%(message)s',
handlers=[
logging.FileHandler("chord_dht.log"), # Save logs to a file
logging.StreamHandler(sys.stdout) # Print logs to console
]
)
- Implement a web-based interface for remote access.
- Extend visualization to show data replication and storage distribution.
- Introduce failure recovery mechanisms for nodes.
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Description of changes"
- Push your changes:
git push origin feature-name
- Open a pull request.
This implementation is inspired by the Chord DHT protocol paper and aims to provide an educational tool for understanding its principles.
-
Add all files and updated README to Git:
git add .
-
Commit changes with a descriptive message:
git commit -m "Updated README with screenshots and features"
-
Push to the
main
branch:git push origin main