Giter Site home page Giter Site logo

kademlia's Introduction

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.

kademlia's People

Contributors

aredridel avatar nairboon avatar nikhilm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

kademlia's Issues

Document error codes

README should have a list of any public error codes reported by the node.
For example in get/set.

Implement send/receive similar to set/get

Nodes which receive a send, treat it as a message and deliver it to the upstream application. Receive triggers a callback defined by
the application. No data is stored.

no support for ipv6 addresses

Throws

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: bind EINVAL fc27:520a:25a3:60c4:be42:3d86:aab5:4307:64512
    at Object.exports._errnoException (util.js:837:11)
    at exports._exceptionWithHostPort (util.js:860:20)
    at dgram.js:213:18
    at doNTCallback3 (node.js:440:9)
    at process._tickCallback (node.js:346:17)
    at Function.Module.runMain (module.js:477:11)
    at startup (node.js:117:18)
    at node.js:951:3

When supplying an ipv6 address to the connect method.

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.