https://github.com/ep2p/dht-sample
Distributed Hash Table sample using Kademlia API, Spring Boot and ROW
https://github.com/ep2p/dht-sample
Last synced: about 2 months ago
JSON representation
Distributed Hash Table sample using Kademlia API, Spring Boot and ROW
- Host: GitHub
- URL: https://github.com/ep2p/dht-sample
- Owner: ep2p
- Created: 2020-10-24T06:59:43.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-01T09:06:30.000Z (over 5 years ago)
- Last Synced: 2025-01-08T13:27:21.522Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 25.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dht-sample
Distributed Hash Table sample using Spring Boot and ROW
This repository contains a sample DHT using [Eleuth Kademlia Api](https://github.com/ep2p/kademlia-api), and [Rest Over Websocket](https://github.com/idioglossia/spring-rest-over-ws)
## RUN
First run 2 nodes:
**Node 1**
`mvn spring-boot:run -Dspring-boot.run.arguments="--nodeId=1 --server.port=8001 --server.address=127.0.0.1"`
**Node 2**
`mvn spring-boot:run -Dspring-boot.run.arguments="--nodeId=2 --server.port=8002 --server.address=127.0.0.1"`
---
Start node 1:
```
curl --request GET \
--url http://localhost:8001/manager/start
```
Bootstrap node 2 using node 1 address:
```
curl --request POST \
--url http://localhost:8002/manager/bootstrap \
--header 'content-type: application/json' \
--data '{
"id": 1,
"connectionInfo": {
"address": "127.0.0.1",
"port": 8001
}
}'
```
Store data on nodes.
```
curl --request POST \
--url http://localhost:8002/manager/store \
--header 'content-type: application/json' \
--data '{
"key": 1,
"value": "Value for key 1"
}'
```
response: `Node #1 STORED DATA`
Store another data:
```
curl --request POST \
--url http://localhost:8002/manager/store \
--header 'content-type: application/json' \
--data '{
"key": 2,
"value": "Value for key 2"
}'
```
response: `Node #2 STORED DATA`
Both store calls were sent to second node, but as you can see, node#1 stored data for key 1.
Get data of key 1:
```
curl --request GET \
--url http://localhost:8002/manager/get/1
```
Response: `Node #1 GOT DATA: Value for key 1`
Get data of key 2:
```
curl --request GET \
--url http://localhost:8002/manager/get/2
```
Response: `Node #2 GOT DATA: Value for key 2`
So data is distributed. Now shutdown node 1 by pressing `cntl+c`.
After shutdown, try to get data of key 1, which previously was stored in node 1.
```
curl --request GET \
--url http://localhost:8002/manager/get/1
```
Response: `Node #2 GOT DATA: Value for key 1`
Which means data was moved to closest node (from 1 to 2) before shutdown.
You can run this on more nodes, and results would have same logic :)