npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

p2pdht

v0.2.2

Published

An implementation of the Kademlia DHT in node.js, with UDP streaming for large data

Downloads

6

Readme

Kademlia

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

Install using npm install p2pdht

Use:

var dht = require('p2pdht')
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.

License

See LICENSE.