libp2p-kad-dht
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "libp2p-kad-dht", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "JavaScript implementation of the Kad-DHT for libp2p", | ||
@@ -8,3 +8,3 @@ "main": "src/index.js", | ||
"lint": "aegir-lint", | ||
"test": "aegir-test", | ||
"test": "aegir-test --env node", | ||
"test:node": "aegir-test node", | ||
@@ -14,5 +14,5 @@ "test:browser": "aegir-test browser", | ||
"docs": "aegir-docs", | ||
"release": "aegir-release --docs", | ||
"release-minor": "aegir-release --type minor --docs", | ||
"release-major": "aegir-release --type major --docs", | ||
"release": "aegir-release --docs --env node", | ||
"release-minor": "aegir-release --type minor --docs --env node", | ||
"release-major": "aegir-release --type major --docs --env node", | ||
"coverage": "aegir-coverage", | ||
@@ -54,6 +54,6 @@ "coverage-publish": "aegir-coverage publish" | ||
"k-bucket": "^3.2.1", | ||
"libp2p-crypto": "^0.8.7", | ||
"libp2p-record": "^0.3.1", | ||
"libp2p-crypto": "~0.8.7", | ||
"libp2p-record": "~0.3.1", | ||
"multihashing-async": "~0.4.5", | ||
"peer-id": "^0.8.7", | ||
"peer-id": "~0.8.7", | ||
"peer-info": "~0.9.2", | ||
@@ -70,7 +70,8 @@ "priorityqueue": "^0.2.0", | ||
"chai": "^3.5.0", | ||
"datastore-level": "^0.3.0", | ||
"dirty-chai": "^1.2.2", | ||
"interface-connection": "^0.3.2", | ||
"left-pad": "^1.1.3", | ||
"libp2p-ipfs-browser": "^0.23.0", | ||
"libp2p-ipfs-nodejs": "^0.23.0", | ||
"libp2p-ipfs-browser": "~0.23.0", | ||
"libp2p-ipfs-nodejs": "~0.23.0", | ||
"lodash": "^4.17.4", | ||
@@ -81,3 +82,6 @@ "lodash.random": "^3.2.0", | ||
"pre-commit": "^1.2.2" | ||
} | ||
} | ||
}, | ||
"contributors": [ | ||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>" | ||
] | ||
} |
@@ -1,2 +0,2 @@ | ||
# js-libp2p-dht | ||
# js-libp2p-kad-dht | ||
@@ -6,5 +6,5 @@ [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) | ||
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) | ||
[![Build Status](https://travis-ci.org/ipfs/js-libp2p-dht.svg?style=flat-square)](https://travis-ci.org/ipfs/js-libp2p-dht) | ||
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-libp2p-dht/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-libp2p-dht?branch=master) | ||
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-dht.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-dht) | ||
[![Build Status](https://travis-ci.org/ipfs/js-libp2p-kad-dht.svg?style=flat-square)](https://travis-ci.org/ipfs/js-libp2p-kad-dht) | ||
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-libp2p-kad-dht/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-libp2p-kad-dht?branch=master) | ||
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-kad-dht.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-kad-dht) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) | ||
@@ -15,3 +15,3 @@ [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) | ||
> JavaScript implementation of the Kademlia DHT for libp2p, based on [go-kad-dht](https://github.com/libp2p/go-libp2p-kad-dht). | ||
> JavaScript implementation of the Kademlia DHT for libp2p, based on [go-libp2p-kad-dht](https://github.com/libp2p/go-libp2p-kad-dht). | ||
@@ -38,3 +38,3 @@ ## Table of Contents | ||
```js | ||
const KadDHT = require('libp2p-dht') | ||
const KadDHT = require('libp2p-kad-dht') | ||
``` | ||
@@ -44,3 +44,3 @@ | ||
See https://libp2p.github.io/js-libp2p-dht | ||
See https://libp2p.github.io/js-libp2p-kad-dht | ||
@@ -47,0 +47,0 @@ ## Contribute |
@@ -443,2 +443,3 @@ 'use strict' | ||
} | ||
// already got it | ||
@@ -454,2 +455,3 @@ if (pi != null) { | ||
const peers = this.routingTable.closestPeers(key, c.ALPHA) | ||
if (peers.length === 0) { | ||
@@ -456,0 +458,0 @@ return cb(new errors.LookupFailureError()) |
@@ -52,8 +52,8 @@ 'use strict' | ||
// handle incoming connections | ||
this.libp2p.swarm.handle(c.PROTOCOL_DHT, this._rpc) | ||
// handle new connections | ||
this.libp2p.on('peer:connect', this._onPeerConnected) | ||
// handle incoming connections | ||
this.libp2p.swarm.handle(c.PROTOCOL_DHT, this._rpc) | ||
cb() | ||
@@ -76,2 +76,3 @@ } | ||
this.libp2p.removeListener('peer:connect', this._onPeerConnected) | ||
this.libp2p.swarm.unhandle(c.PROTOCOL_DHT) | ||
@@ -113,5 +114,5 @@ cb() | ||
if (err) { | ||
this._log('%s does not support protocol: %s', peer.id.toB58String(), c.PROTOCOL_DHT) | ||
return | ||
return this._log('%s does not support protocol: %s', peer.id.toB58String(), c.PROTOCOL_DHT) | ||
} | ||
// TODO: conn.close() | ||
@@ -122,4 +123,3 @@ pull(pull.empty(), conn) | ||
if (err) { | ||
this._log.error('Failed to add to the routing table', err) | ||
return | ||
return this._log.error('Failed to add to the routing table', err) | ||
} | ||
@@ -126,0 +126,0 @@ |
@@ -130,6 +130,3 @@ 'use strict' | ||
} | ||
this.kb.add({ | ||
id: id, | ||
peer: peer | ||
}) | ||
this.kb.add({ id: id, peer: peer }) | ||
callback() | ||
@@ -136,0 +133,0 @@ }) |
@@ -46,5 +46,3 @@ /* eslint-env mocha */ | ||
// Give the nodes some time to finish request | ||
setTimeout(() => { | ||
util.teardown(done) | ||
}, 100) | ||
setTimeout(() => util.teardown(done), 100) | ||
}) | ||
@@ -90,3 +88,3 @@ | ||
(cb) => connect(dhts[1], dhts[2], cb), | ||
(cb) => connect(dhts[1], dhts[3], cb), | ||
(cb) => connect(dhts[2], dhts[3], cb), | ||
(cb) => each(values, (v, cb) => { | ||
@@ -410,27 +408,26 @@ dhts[3].provide(v.cid, cb) | ||
const find = (a, b, cb) => retry({ | ||
times: 50, | ||
interval: 100 | ||
}, (cb) => { | ||
a.routingTable.find(b.self.id, (err, match) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
if (!match) { | ||
return cb(new Error('not found')) | ||
} | ||
function find (a, b, cb) { | ||
retry({ times: 50, interval: 100 }, (cb) => { | ||
a.routingTable.find(b.self.id, (err, match) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
if (!match) { | ||
return cb(new Error('not found')) | ||
} | ||
try { | ||
expect( | ||
a.peerBook.get(b.self).multiaddrs.toArray()[0].toString() | ||
).to.eql( | ||
b.self.multiaddrs.toArray()[0].toString() | ||
) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
try { | ||
expect( | ||
a.peerBook.get(b.self).multiaddrs.toArray()[0].toString() | ||
).to.eql( | ||
b.self.multiaddrs.toArray()[0].toString() | ||
) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
cb() | ||
}) | ||
}, cb) | ||
cb() | ||
}) | ||
}, cb) | ||
} | ||
@@ -437,0 +434,0 @@ // connect two dhts and wait for them to have each other |
@@ -32,2 +32,3 @@ 'use strict' | ||
let i = 0 | ||
exports.setupDHT = (callback) => { | ||
@@ -42,4 +43,5 @@ exports.makePeers(1, (err, peers) => { | ||
const libp2p = new Libp2p(p) | ||
const libp2p = new Libp2p(p, undefined, { mdns: false }) | ||
const dht = new KadDHT(libp2p, 20, new MemoryDatastore()) | ||
dht.validators.v = { | ||
@@ -46,0 +48,0 @@ func (key, publicKey, callback) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55
135837
13
4576
Updatedlibp2p-crypto@~0.8.7
Updatedlibp2p-record@~0.3.1
Updatedpeer-id@~0.8.7