node中的一个DHT实现:Kademlia

jopen 10年前

node中的一个Kademlia  DHT实现, 可被用作分布式数据存储。

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 });

项目主页:http://www.open-open.com/lib/view/home/1417747844933