Implementation of the Chord DHT Peer-to-Peer algorithm using Flask.
Visualization of the network and key retrieval using D3
If you don't have node.js download here
cd visualize
npm install
webpack
If you have yarn, you can use the yarn
command instead.
You can edit the parameters in visualize.html to preview how the front end works.
Ensure you have python installed.
If you do not have virtualenv installed you can do so by pip install virtalenv
Now you can make a virtual environment and install the requirements:
virtualenv .venv
pip install -r requirements.txt
source .venv/bin/activate
Install redis
sudo apt-get install redis-server
Run a redis server for each chord node
redis-server --port 6000
redis-server --port 6001
redis-server --port 6002
redis-server --port 6003
Now you can initalize each dht server
python runserver.py -p=5000 -r=6000
python runserver.py -p=5001 -r=6001
python runserver.py -p=5002 -r=6002
python runserver.py -p=5003 -r=6003
I used postman to send requests. You can also use curl
curl --location --request PUT "localhost.localdomain:5000/dht/join" \
--data "localhost.localdomain:5001
localhost.localdomain:5002
localhost.localdomain:5003"
curl --location --request PUT "localhost.localdomain:5000/db/keyval" \
--data "this is the data"
curl --location --request GET "localhost.localdomain:5002/db/keyval"
Open in browser:
localhost.localdomain:5000/dht/peers/view
This is an example of what a visualization of the peer to peer network would look like:
localhost.localdomain:5000/db/view/somekey
This is an example of what a path would look like when trying to find the key
Postman tests can be run by calling this script, which starts all the chord nodes, and redis servers.
Or if you have postman installed:
Just make sure there are 5 servers running on port 5000, 5001, 5002, 5003, 5007, each with a redis server
Unit tests can be run using:
cd dht
python -m test.dht_node_test