This project implements a Chord Distributed Hash Table (DHT) with additional features such as leader election and networking with broadcast/gossip mechanism.
.
├── .gitignore
├── Dockerfile
├── Makefile
├── README.md
├── cleanup_port.py
├── main.py
├── requirements.txt
├── setup.py
├── chord.egg-info/
├── src/
│ ├── chord.py
│ ├── connector.py
├── test/
│ ├── playground.py
│ ├── test_failure_detector.py
│ ├── test_bully_leader_election.py
│ ├── test_chord.py
│ ├── test_network_broadcast.py
│ ├── test_gossiping.py
└── __pycache__/
- Python 3.12 or higher
pip(Python package installer)
git clone https://github.com/onggiahuy97/chord.git
cd chordpython -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`pip install -r requirements.txtpip install -e .python main.pyThe server will start on http://localhost:5000 by default.
git clone https://github.com/onggiahuy97/chord_ui_swiftYou will need macOS (macbook) to run the application.
GET /nodesResponse Example:
{
"nodes": [
{
"id": 8,
"successor": 15,
"messagesCount": 1
}
]
}POST /joinResponse Example:
{
"message": "Node joined",
"node_id": 8
}Error Response (400):
{
"error": "The Chord ring is full"
}GET /hash?key=<key>Response Example:
{
"hash": 23,
"successor": 8
}POST /insert
Content-Type: application/jsonRequest Body:
{
"key": "test",
"value": "success"
}Response Example:
{
"message": "Key 'test' with value 'success' has been inserted",
"key": "test",
"value": "success",
"hash_id": 27,
"stored_at_node": 8
}GET /get/<key>Response Example:
{
"key": "test",
"value": "success",
"hash_id": 27,
"stored_at_node": 8
}Error Response (404):
{
"message": "Key not found"
}POST /leave/<id>Response Example:
{
"message": "Node '25' successfully left the ring."
}GET /info/<id>Response Example:
{
"id": 8,
"successor": 15,
"messages": [
{
"hash_id": 7,
"key": "genre1",
"value": "Rock"
}
]
}Run all tests:
make test-allRun individual tests:
make test-chord
make test-broadcast
make test-leader-election
make test-failure-detector
make test-gossipingClean up processes on ports 5000-5010:
python cleanup_port.pydocker build -t chord .
docker run -p 5000:5000 chord- Chord DHT:
src/chord.py - Network Connector:
src/connector.py - Leader Election:
test/test_bully_leader_election.py - Broadcast peer-to-peer:
test/test_network_broadcast.py - Gossip:
test/test_gossiping - Failure Detector:
test/test_failure_detector
Contributions are welcome! Please open an issue or submit a pull request.