Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dcsunset/chord-dht
A DHT (distributed hash table) implementation in Rust based on Chord with high performance and data replication.
https://github.com/dcsunset/chord-dht
Last synced: 2 months ago
JSON representation
A DHT (distributed hash table) implementation in Rust based on Chord with high performance and data replication.
- Host: GitHub
- URL: https://github.com/dcsunset/chord-dht
- Owner: DCsunset
- License: agpl-3.0
- Created: 2022-03-03T15:05:11.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-27T22:05:07.000Z (over 2 years ago)
- Last Synced: 2024-10-12T02:55:59.689Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 109 KB
- Stars: 11
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chord-dht
[![crates.io](https://badgen.net/crates/v/chord-dht)](https://crates.io/crates/chord-dht)
[![docker](https://badgen.net/docker/size/dcsunset/chord-dht)](https://hub.docker.com/repository/docker/dcsunset/chord-dht)A DHT (distributed hash table) implementation in Rust based on Chord with high performance and data replication.
It can be used either as a library or as a standalone application.
## Installation
For library, add `chord-dht` to the dependencies in your `Cargo.toml`.
For standalone binaries, use `cargo install chord-dht`.
You can also use the docker image:```sh
# For server (suppose the port to use is )
docker run -d -p : chord-dht chord-dht-server# For client
docker run -it chord-dht chord-dht-client
```## Usage
### Library
As a client:
```rust
use chord_dht::client::setup_client;
use tarpc::context;#[tokio::main]
async fn main() -> anyhow::Result<()> {
// server address
let addr = "127.0.0.1:9800"
let client = setup_client(&addr).await?;let ctx = context::current();
let key = "key".as_bytes();
let value = "value".as_bytes();
client.set_rpc(ctx, key.clone(), Some(value.clone())).await?;
let ret = client.get_rpc(ctx, key.clone()).await?;
assert_eq!(ret.unwrap(), value);
Ok(())
}
```As a server:
```rust
use chord_dht::core::{
Node,
NodeServer,
config::Config
};#[tokio::main]
async fn main() -> anyhow::Result<()> {
let node = Node {
addr: "127.0.0.1:9800".to_string(),
id: 0
};
let mut server = NodeServer::new(node, Config::default());
let manager = server.start(None).await?;
// Wait for the server
manager.wait().await?;Ok(())
}
```### Standalone Application
To start a server:
```sh
cargo run -- chord-dht-server [--join ]
```To start a client:
```sh
cargo run -- chord-dht-client
> set key value
> get key
value
```## Features built upon Chord
* In-memory key-value storage
* Data replication
* Fault toleranceThe in-memory key-value DHT is aimed to be efficient when storing ephemeral data (e.g. user tokens).
## TODO
- [ ] Transfer existing keys when node is down or joins the ring
- [ ] Allow node to leave## License
Licensed under the [AGPLv3](LICENSE) license.