Code Monkey home page Code Monkey logo

chord-dht's Introduction

Chord-DHT

Implementation of Chord P2P Distributed Hash Table

More Information about Chord Protocol can be found here - https://en.wikipedia.org/wiki/Chord_(peer-to-peer)

Typing "help" will show all supported commands

Implementation

Each node will be assigned a unique ID (within 2^m (m is 48 in this case)) by hashing key which will be "ip:port" of that node by SHA-1 Algorithm

A node can create a DHT ring, other nodes can join the ring by contacting this node using it's ip and port number

When a node creates or joins a ring, it spawns multiple threads which are responsible for tasks like listening to other nodes to join the ring, sending acknowledgement and other operations , doing stabilization tasks to ensure correct finger table entries, successor and predecessor pointers and a Successor list.

Each node contains m(48) entries in it's finger table.

Each node also maintains a successor list having r(10) entries. This list finds it's use when a node's successor leaves the ring, the node immediately assigns the next entry in the successor list as it's successor.

Each node regularly asks for acknowledgement from it's successor and predecessor to know that they are still present in the ring. If no acknowledgement is received then they have left the ring and stabilization is done accordingly

Each node keeps a map for storing key value pairs in it. When a key is entered, it is also assigned a unique ID, then it is stored in a node whose ID is just greater than this key's ID

When a node newly joins the ring, it gets all those keys from it's successor which should now belong to it

When a node leaves the ring, it transfers all it's keys to it's successor

m has been set to 48 in this implementation that means a maximum of 2^48 nodes can join the ring

Files

main.cpp is the main file

All important functions are inside the file functions.cpp

A class named NodeInformation is made which contains all the information of a Node and all the functions which every node performs to maintain correct information about the ring.

Another class SocketAndPort is made which contains all the information about socket ,ip address and port number. Object of class SocketAndPort is inside NodeInformation class

Another class HelperClass is made which contains all helper functions which are required by a node to perform various tasks

Supported Commands

typing "help" in the terminal shows all supported commands

create - will create a DHT ring

join "ip" "port" - will connect to the main node running at IP address and Port Number

printstate - will print successor, predecessor, fingerTable and Successor list of that node

print - will print all keys and values present in that node

port - will display port number on which node is listening

port "number" - will change port number to mentioned number if that port is free (will only run before the node has joined the ring)

put "key" "value" - will put key and value to the node it belongs to

get "key" - will get value of mentioned key

Execution

A Makefile has also been included. Just type make to build the whole project

chord-dht's People

Contributors

mitul227 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.