在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

node中的一个DHT实现:Kademlia

2016-12-20 13:17| 发布者: zhangjf| 查看: 614| 评论: 0

摘要: node中的一个Kademlia DHT实现, 可被用作分布式数据存储。 Install using npm install kademlia Use:var dht = require('kademlia')var node = new dht.KNode({ address: 'IP address', port: portNumber });node. ...

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

Install using npm install kademlia

Use:

  1. var dht = require('kademlia')
  2. var node = new dht.KNode({ address: 'IP address', port: portNumber });
  3. node.connect('existing peer ip', port);
  4. node.set('foo', 'bar');
  5. node.get('foo', function(err, data) {
  6. console.log("Retrieved", data, "from DHT");
  7. console.log(data == 'bar');
  8. });
复制代码
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.

  1. var node = new dht.KNode({ address: '10.100.98.60', port: 12345 });
复制代码

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

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-8-19 03:45

Copyright 2015-2025 djqfx

返回顶部