libp2p-kad-dht
Advanced tools
Comparing version 0.14.4 to 0.14.5
@@ -0,1 +1,11 @@ | ||
<a name="0.14.5"></a> | ||
## [0.14.5](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.14.4...v0.14.5) (2019-02-05) | ||
### Features | ||
* emit event on peer connected ([#66](https://github.com/libp2p/js-libp2p-kad-dht/issues/66)) ([ba0a537](https://github.com/libp2p/js-libp2p-kad-dht/commit/ba0a537)) | ||
<a name="0.14.4"></a> | ||
@@ -2,0 +12,0 @@ ## [0.14.4](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.14.3...v0.14.4) (2019-01-14) |
{ | ||
"name": "libp2p-kad-dht", | ||
"version": "0.14.4", | ||
"version": "0.14.5", | ||
"description": "JavaScript implementation of the Kad-DHT for libp2p", | ||
@@ -42,2 +42,3 @@ "leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"base32.js": "~0.1.0", | ||
"chai-checkmark": "^1.0.1", | ||
"cids": "~0.5.7", | ||
@@ -88,6 +89,6 @@ "debug": "^4.1.1", | ||
"Richard Schneider <makaretu@gmail.com>", | ||
"Vasco Santos <vasco.santos@ua.pt>", | ||
"Vasco Santos <vasco.santos@moxy.studio>", | ||
"Vasco Santos <vasco.santos@ua.pt>", | ||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>" | ||
] | ||
} |
'use strict' | ||
const { EventEmitter } = require('events') | ||
const libp2pRecord = require('libp2p-record') | ||
@@ -30,3 +31,3 @@ const MemoryStore = require('interface-datastore').MemoryDatastore | ||
*/ | ||
class KadDHT { | ||
class KadDHT extends EventEmitter { | ||
/** | ||
@@ -44,2 +45,3 @@ * Create a new KadDHT. | ||
constructor (sw, options) { | ||
super() | ||
assert(sw, 'libp2p-kad-dht requires a instance of Switch') | ||
@@ -613,4 +615,8 @@ options = options || {} | ||
} | ||
_peerDiscovered (peerInfo) { | ||
this.emit('peer', peerInfo) | ||
} | ||
} | ||
module.exports = KadDHT |
@@ -125,2 +125,4 @@ 'use strict' | ||
this.dht._peerDiscovered(peer) | ||
this._log('added to the routing table: %s', peer.id.toB58String()) | ||
@@ -127,0 +129,0 @@ }) |
@@ -209,2 +209,3 @@ 'use strict' | ||
closer = query.dht.peerBook.put(closer) | ||
query.dht._peerDiscovered(closer) | ||
addPeerToQuery(closer.id, query.dht, path, cb) | ||
@@ -211,0 +212,0 @@ }, callback) |
@@ -6,2 +6,3 @@ /* eslint-env mocha */ | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-checkmark')) | ||
const expect = chai.expect | ||
@@ -260,2 +261,27 @@ const sinon = require('sinon') | ||
it('should emit a peer event when a peer is connected', function (done) { | ||
this.timeout(10 * 1000) | ||
const tdht = new TestDHT() | ||
tdht.spawn(2, (err, dhts) => { | ||
expect(err).to.not.exist() | ||
const dhtA = dhts[0] | ||
const dhtB = dhts[1] | ||
dhtA.on('peer', (peerInfo) => { | ||
expect(peerInfo).to.exist().mark() | ||
}) | ||
dhtB.on('peer', (peerInfo) => { | ||
expect(peerInfo).to.exist().mark() | ||
}) | ||
connect(dhtA, dhtB, (err) => { | ||
expect(err).to.not.exist() | ||
}) | ||
}) | ||
expect(2).checks(done) | ||
}) | ||
it('put - get', function (done) { | ||
@@ -262,0 +288,0 @@ this.timeout(10 * 1000) |
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
174772
5317
22
+ Addedchai-checkmark@^1.0.1
+ Addedchai-checkmark@1.0.1(transitive)