Compare commits

...

8 Commits

6 changed files with 40 additions and 10 deletions

View File

@ -1,3 +1,28 @@
<a name="0.1.6"></a>
## [0.1.6](https://github.com/libp2p/js-interfaces/compare/v0.1.5...v0.1.6) (2019-12-02)
### Bug Fixes
* multicodec topology disconnect with peer param ([#12](https://github.com/libp2p/js-interfaces/issues/12)) ([d5dd256](https://github.com/libp2p/js-interfaces/commit/d5dd256))
<a name="0.1.5"></a>
## [0.1.5](https://github.com/libp2p/js-interfaces/compare/v0.1.4...v0.1.5) (2019-11-15)
### Bug Fixes
* multicodec topology update peers with multicodec ([#10](https://github.com/libp2p/js-interfaces/issues/10)) ([21d8ae6](https://github.com/libp2p/js-interfaces/commit/21d8ae6))
### Features
* add class-is to topology ([#11](https://github.com/libp2p/js-interfaces/issues/11)) ([a67abcc](https://github.com/libp2p/js-interfaces/commit/a67abcc))
<a name="0.1.4"></a>
## [0.1.4](https://github.com/libp2p/js-interfaces/compare/v0.1.3...v0.1.4) (2019-11-14)

View File

@ -1,4 +1,4 @@
# JS Libp2p Interfaces
# JS libp2p Interfaces
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-interfaces",
"version": "0.1.4",
"version": "0.1.6",
"description": "Interfaces for JS Libp2p",
"main": "src/index.js",
"files": [

View File

@ -1,5 +1,7 @@
'use strict'
const withIs = require('class-is')
const noop = () => {}
class Topology {
@ -41,4 +43,4 @@ class Topology {
}
}
module.exports = Topology
module.exports = withIs(Topology, { className: 'Topology', symbolName: '@libp2p/js-interfaces/topology' })

View File

@ -1,6 +1,8 @@
'use strict'
const assert = require('assert')
const withIs = require('class-is')
const Topology = require('./index')
class MulticodecTopology extends Topology {
@ -50,7 +52,7 @@ class MulticodecTopology extends Topology {
*/
_updatePeers (peerInfoIterable) {
for (const peerInfo of peerInfoIterable) {
if (this.multicodecs.filter(multicodec => peerInfo.protocols.has(multicodec))) {
if (this.multicodecs.filter(multicodec => peerInfo.protocols.has(multicodec)).length) {
// Add the peer regardless of whether or not there is currently a connection
this.peers.set(peerInfo.id.toB58String(), peerInfo)
// If there is a connection, call _onConnect
@ -75,9 +77,7 @@ class MulticodecTopology extends Topology {
// Not supporting the protocol anymore?
if (existingPeer && hasProtocol.length === 0) {
this._onDisconnect({
peerInfo
})
this._onDisconnect(peerInfo)
}
// New to protocol support
@ -90,4 +90,4 @@ class MulticodecTopology extends Topology {
}
}
module.exports = MulticodecTopology
module.exports = withIs(MulticodecTopology, { className: 'MulticodecTopology', symbolName: '@libp2p/js-interfaces/topology/multicodec-topology' })

View File

@ -49,6 +49,7 @@ module.exports = (test) => {
const id2 = await PeerId.createFromJSON(peers[1])
const peer2 = await PeerInfo.create(id2)
topology.multicodecs.forEach((m) => peer2.protocols.add(m))
const peerStore = topology._registrar.peerStore
peerStore.emit('change:protocols', {
@ -66,9 +67,9 @@ module.exports = (test) => {
const id2 = await PeerId.createFromJSON(peers[1])
const peer2 = await PeerInfo.create(id2)
const peerStore = topology._registrar.peerStore
topology.multicodecs.forEach((m) => peer2.protocols.add(m))
// Peer with the protocol
const peerStore = topology._registrar.peerStore
peerStore.emit('change:protocols', {
peerInfo: peer2,
protocols: Array.from(topology.multicodecs)
@ -76,6 +77,7 @@ module.exports = (test) => {
expect(topology.peers.size).to.eql(1)
topology.multicodecs.forEach((m) => peer2.protocols.delete(m))
// Peer does not support the protocol anymore
peerStore.emit('change:protocols', {
peerInfo: peer2,
@ -84,6 +86,7 @@ module.exports = (test) => {
expect(topology.peers.size).to.eql(1)
expect(topology._onDisconnect.callCount).to.equal(1)
expect(topology._onDisconnect.calledWith(peer2)).to.equal(true)
})
})
}