• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DHT implementation

Kademlia

A Kademlia DHT implementation in node, ready to be used as a distributed data store.

Install using npm install kademlia

Use:

var dht = require('kademlia')
var node = new dht.KNode({ address: 'IP address', port: portNumber });
node.connect('existing peer ip', port);
node.set('foo', 'bar');

node.get('foo', function(err, data) {
    console.log("Retrieved", data, "from DHT");
    console.log(data == 'bar');
});

API

KNode

The KNode represents a Kademlia node and handles all communication and storage. This should be the only thing you need to interact with the Kademlia overlay network.

KNode(configuration)

A KNode is created by passing it an object having address and port properties. The node will bind to port and start running.

var node = new dht.KNode({ address: '10.100.98.60', port: 12345 });

connect(address, port[, callback])

Used to introduce this Kademlia node to the overlay network. If you know the address and port of an existing Kademlia peer, you may connect to it so that this node can become part of the network. If callback is passed it is called with the result of the join. connect succeeds (err is null) when the entire Kademlia join sequence is finished.

node.connect('10.100.98.12', 42922, function(err) {
    if (err)
        process.exit();
    startHeavyLifting();
});

get(key, callback)

Gets the value associated with key from the Kademlia network. callback is a function with arguments (err, value). If the value is found, err is null, otherwise err will be an object containing information about what went wrong and value will be null.

node.get('foo', function(err, value) {
    if (err) {
        // something went wrong
        return;
    }

    // use value
});

set(key, value[, callback])

Store the key, value pair in the Kademlia network. set() is not guaranteed to succeed. callback can be used to check the result of the store. It is function (err). If the store succeeded, err is null, otherwise err describes what went wrong.

node.set('foo', 'bar', function(err) {
    if (err) {
        // might want to try again
    }
});

self

An object describing this node. self is frozen, attempts to modify it will fail (and raise an exception in strict mode).

node.self is {
    nodeID: 'f386f180b2722ab92060661152e680b88976126f',
    address: '10.100.98.60',
    port: 12345
}

Hacking

To use the test scripts, assign the IP address to bind to, to the environment variable KADEMLIA_BIND_ADDRESS.

Contributors

Maintainer: Nikhil Marathe [email protected] Contributors: https://github.com/nikhilm/kademlia/contributors

License

Kademlia is distributed under the MIT License.

More Repositories

1

uvbook

An Introduction to libuv
C
1,588
star
2

qhttpserver

HTTP server implementation for Qt based on node.js' http parser
C
343
star
3

node-taglib

Simple taglib bindings to Javascript using node.js
C++
147
star
4

gocco

Go port of Jash Kenas' docco
Go
67
star
5

ninja-rs

An educational implementation of the ninja build system, based on ideas from the Build Systems a la Carte paper.
Rust
56
star
6

jsfoo-pune-2012

Native Bindings to node.js - Slides and code for the talk at jsfoo
C++
33
star
7

flickr-hugo-embed

Print shortcodes to embed a set of images from an album on Flickr into Hugo
JavaScript
23
star
8

vignette

A sampling profiler as a library
Rust
13
star
9

tictactoe

zero server-side logic 2-player realtime tic-tac-toe.
JavaScript
12
star
10

sasljs

Server side SASL support for node.js
C++
12
star
11

rustc-worker

A Bazel persistent worker for Rust
Rust
8
star
12

qommunicate

[old-project] A Qt-based cross-platform implementation of the IPmsg (http://ipmsg.org) protocol
C++
8
star
13

mugshot

Simple face detection web service
JavaScript
7
star
14

simplechat

SimplePush based chat.
JavaScript
5
star
15

kio-upnp-ms

Mirror of http://gitorious.org/kio-upnp-ms
C++
4
star
16

socket-ipc

Benchmarking unix domain sockets vs UDP multicast performance
C++
2
star
17

container-experiments

Playing with Linux containerization primitives
Rust
2
star
18

upnpls

Browse UPnP MediaServers using Qt and HUPnP
C++
2
star
19

minestrone

Meant to be a music streaming server based on node.js
JavaScript
2
star
20

solarwolf-qml

A port of Solarwolf (http://www.pygame.org/shredwheat/solarwolf/) to QML
JavaScript
2
star
21

logos

[DEAD] A XMPP server powered by node.js, currently in embryonic stage
JavaScript
2
star
22

Tetrablocks

[old-project] Because everyone has to implement tetris atleast once in their lives. C++ and SDL
C++
2
star
23

confkdein11

Code for KDE India Conference talks (March 9th-11th)
JavaScript
2
star
24

python-struct-unpacking

some experiments with struct.unpack performance
Python
2
star
25

save-my-tabs

Save Chrome tabs (to Dropbox for now)
JavaScript
1
star
26

unwind-arguments

Example code for a blog post.
C
1
star
27

substrate.js

Submission for the js1k contest
JavaScript
1
star
28

api-test

test repository for github API experiments
1
star
29

compilers-assignment

C
1
star
30

brainstorm

Something like a whiteboard Development is now at BitBucket http://bitbucket.org/nikhilm/brainstorm/
Java
1
star
31

login

[old-project] Conway's game of life in SDL
C++
1
star
32

valdo

Todo system based on backbone.js and OpenKeyVal.org
JavaScript
1
star
33

rational

Rational human-readable argument parser for node.js
JavaScript
1
star
34

AdventOfCode2020

Solutions in Pharo Smalltalk
Smalltalk
1
star
35

cleanup

A Javascript (Canvas) clone of Solarwolf for the CodeChef May 2009 game contest
JavaScript
1
star
36

pypes

[old-project] Pygame based clone of mobile game. Connect all the pipes together into a coherent whole.
Python
1
star
37

muzicast

web based music streaming server [software engineering project]
Python
1
star
38

threadtimes

benchmarking time to retrieve thread usage times on various operating systems
Rust
1
star
39

lunchbot

A easy way to coordinate lunch on IRC
JavaScript
1
star
40

squeeze

node.js library to interact with UploadJuicer.com's cloud image manipulation service
JavaScript
1
star
41

foss.in

Twitter client from the KDE PotD
C++
1
star
42

push-app-to-phone

SimplePush uber-demo
JavaScript
1
star
43

preserve

Python implementation of the esoteric Chef programming language. A spontaneous top-of-my-head effort.
Python
1
star
44

unbound

A prototype collaborative textbook web application created at a MIT Media Lab workshop in 2 days.
JavaScript
1
star
45

pixelframe

[old-project] Pixelframe. Ajaxified, awesome (for that time) image gallery powered by PHP and custom JS library.
JavaScript
1
star
46

ricochet

[old-project] Use mirrors to guide the light to the switch and go to the next level. Python + Pygame
C++
1
star
47

muc

demo multi user chat with support for multiple rooms using node + NowJS
JavaScript
1
star