Coder Social home page Coder Social logo

chord-dht's Introduction

Chord-DHT

Distributed Systems Course, implementation of Chord DHT in node.js

Node DHT

A simple Distributed Hash Table made in NodeJS

Introduction

This is just an experiment as a coursework for Distributed Systems class on National Technical University of Athens. The goal is to implement a simple DHT using some defined rules:

  • There must always be a ring of nodes, which every node has a pointer to the next one and another pointer to the previous one
  • If a node is alone then it points to no one
  • If there are only two nodes, then them both point to each other
  • File retrieval must be routed through the ring until it finds the specified file and returns it to the sender, this differs from the original DHT implementation since it does not guarantee a O(nlogn) search time
  • To join the network, the node must know at least one other node which has already joined the network, otherwise it will create a new DHT.
  • We are not assuming failures, all nodes work to perfection and grecefuly exits the network at all times.

Installation

You need to have Node.js installed (newest edition, version 14 and after), see Node's official website.

After that, run npm install inside the folder

Running

The main entrypoint is the index.js file. It accepts a single argument from the command line, the known hostlist, this will tell the node to connect to an existing network of other nodes. This list can be comma separated and the program will try to connect to each one of them, the first one to answer will be the entrypoint to the network.

If no nodes respond, a new network will be created.

  • Running as first node: node index.js replication X type Y X can take any number from 1 to n and Y can take two values: either "chain-replication" or "eventual consistency"
  • Try to connect to an existing node: node index.js localhost:<port> or node index.js <ip_address>:<port>

Protocol

Every node must contain 3 base informations:

  • The next node
  • The previous node
  • The node ID

Previous and next nodes are objects with 3 properties: ip, port and id. The IP and port are String and Int respectively, the ID is a sha1 hash computed on hashFactory using a fixed password and ip:port as base data.

{
  port: Number,
  ip: String,
  id: String
}

Files

The folder structure looks like the following:

  • src: Contains all the source files
    • config: Contains the message strings to all commands
    • consoleCommands: That is the client side implementation of all the interactive commands the user can issue at the terminal, in short, the files here are what should happen if you issue a valid command
    • messages: Contains the implementation of all messages from the receiver perspective (aKa, what should happen if I receive such message)
    • utils: Utility wrappers
    • node.js: Main node file, contains all definitions of a node

Commands

When the node connects you can type help into the terminal to get a list of all available commands along with their params.

insert key, value

Inserts key value pair inside Chord

query key

Queries key inside Chord

depart

Gracefully departs node

delete key

Deletes key value pair from the Chord

overlay

Gives an overview of the Chord network

help

Explains all these commands

chord-dht's People

Contributors

evangelosmeklis avatar

Watchers

 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.