GithubHelp home page GithubHelp logo

dcsunset / chord-dht Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 4.0 112 KB

A DHT (distributed hash table) implementation in Rust based on Chord with high performance and data replication.

License: GNU Affero General Public License v3.0

Rust 99.50% Dockerfile 0.50%

chord-dht's Introduction

chord-dht

crates.io docker

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:

# For server (suppose the port to use is <port>)
docker run -d -p <port>:<port> chord-dht chord-dht-server <server_args>

# For client
docker run -it chord-dht chord-dht-client <client_args>

Usage

Library

As a client:

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:

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:

cargo run -- chord-dht-server <bind_addr> [--join <addr>]

To start a client:

cargo run -- chord-dht-client <server_addr>
> set key value
> get key
value

Features built upon Chord

  • In-memory key-value storage
  • Data replication
  • Fault tolerance

The 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.

chord-dht's People

Contributors

dcsunset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chord-dht's Issues

Transfer existing keys and leaving features

Hello,

I am researching Chord DHT for distributed key-values in Rust and came across your chord-dht project.

I want to learn from it as well as was wondering if you had thoughts about completing the TODO list:

  1. Transfer existing keys when node is down or joins the ring
  2. Allow node to leave

Also do you have any plans or options on changing the license from AGPL to MIT/BSD or some other so that it can be easier to include as part of larger projects since I could possible see some really good use for it and would not like to rewrite a whole new system from scratch if yours would work well as a library part of the project instead.

Thanks and have a great day

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.