mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-07-12 15:41:50 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
a5d7b14914 | |||
b40195c197 | |||
79a7843767 | |||
d2032e606c | |||
b258db2a75 | |||
059e563327 | |||
eda5019248 | |||
5792b13d76 |
30
CHANGELOG.md
30
CHANGELOG.md
@ -1,33 +1,3 @@
|
|||||||
<a name="0.3.1"></a>
|
|
||||||
## [0.3.1](https://github.com/libp2p/js-interfaces/compare/v0.2.8...v0.3.1) (2020-07-03)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* content and peer routing multiaddrs property ([#49](https://github.com/libp2p/js-interfaces/issues/49)) ([9fbf9d0](https://github.com/libp2p/js-interfaces/commit/9fbf9d0))
|
|
||||||
* peer-routing typo ([#47](https://github.com/libp2p/js-interfaces/issues/47)) ([9a8f375](https://github.com/libp2p/js-interfaces/commit/9a8f375))
|
|
||||||
* reconnect should trigger topology on connect if protocol stored ([#54](https://github.com/libp2p/js-interfaces/issues/54)) ([e10a154](https://github.com/libp2p/js-interfaces/commit/e10a154))
|
|
||||||
|
|
||||||
|
|
||||||
### Chores
|
|
||||||
|
|
||||||
* remove peer-info usage on topology ([#42](https://github.com/libp2p/js-interfaces/issues/42)) ([a55c7c4](https://github.com/libp2p/js-interfaces/commit/a55c7c4))
|
|
||||||
* update content and peer routing interfaces removing peer-info ([#43](https://github.com/libp2p/js-interfaces/issues/43)) ([87e2e89](https://github.com/libp2p/js-interfaces/commit/87e2e89))
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* peer-discovery not using peer-info ([bdd2502](https://github.com/libp2p/js-interfaces/commit/bdd2502))
|
|
||||||
|
|
||||||
|
|
||||||
### BREAKING CHANGES
|
|
||||||
|
|
||||||
* topology api now uses peer-id instead of peer-info
|
|
||||||
* content-routing and peer-routing APIs return an object with relevant properties instead of peer-info
|
|
||||||
* peer-discovery emits object with id and multiaddrs properties
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.3.0"></a>
|
<a name="0.3.0"></a>
|
||||||
# [0.3.0](https://github.com/libp2p/js-interfaces/compare/v0.2.8...v0.3.0) (2020-04-21)
|
# [0.3.0](https://github.com/libp2p/js-interfaces/compare/v0.2.8...v0.3.0) (2020-04-21)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-interfaces",
|
"name": "libp2p-interfaces",
|
||||||
"version": "0.3.1",
|
"version": "0.3.0",
|
||||||
"description": "Interfaces for JS Libp2p",
|
"description": "Interfaces for JS Libp2p",
|
||||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
@ -57,7 +57,7 @@
|
|||||||
"streaming-iterables": "^4.1.0"
|
"streaming-iterables": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^22.0.0",
|
"aegir": "^21.9.0",
|
||||||
"it-handshake": "^1.0.1"
|
"it-handshake": "^1.0.1"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
@ -43,7 +43,7 @@ Find peers in the network that can provide a specific value, given a key.
|
|||||||
|
|
||||||
It returns an `AsyncIterable` containing the identification and addresses of the peers providing the given key, as follows:
|
It returns an `AsyncIterable` containing the identification and addresses of the peers providing the given key, as follows:
|
||||||
|
|
||||||
`AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>`
|
`AsyncIterable<{ id: PeerId, addrs: Multiaddr[] }>`
|
||||||
|
|
||||||
### provide
|
### provide
|
||||||
|
|
||||||
|
@ -43,4 +43,4 @@ Query the network for all multiaddresses associated with a `PeerId`.
|
|||||||
|
|
||||||
It returns the [peerId](https://github.com/libp2p/js-peer-id) together with the known peers [multiaddrs](https://github.com/multiformats/js-multiaddr), as follows:
|
It returns the [peerId](https://github.com/libp2p/js-peer-id) together with the known peers [multiaddrs](https://github.com/multiformats/js-multiaddr), as follows:
|
||||||
|
|
||||||
`Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>`
|
`Promise<{ id: PeerId, addrs: Multiaddr[] }>`
|
||||||
|
@ -43,13 +43,11 @@ class MulticodecTopology extends Topology {
|
|||||||
this._registrar = undefined
|
this._registrar = undefined
|
||||||
|
|
||||||
this._onProtocolChange = this._onProtocolChange.bind(this)
|
this._onProtocolChange = this._onProtocolChange.bind(this)
|
||||||
this._onPeerConnect = this._onPeerConnect.bind(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set registrar (registrar) {
|
set registrar (registrar) {
|
||||||
this._registrar = registrar
|
this._registrar = registrar
|
||||||
this._registrar.peerStore.on('change:protocols', this._onProtocolChange)
|
this._registrar.peerStore.on('change:protocols', this._onProtocolChange)
|
||||||
this._registrar.connectionManager.on('peer:connect', this._onPeerConnect)
|
|
||||||
|
|
||||||
// Update topology peers
|
// Update topology peers
|
||||||
this._updatePeers(this._registrar.peerStore.peers.values())
|
this._updatePeers(this._registrar.peerStore.peers.values())
|
||||||
@ -99,25 +97,6 @@ class MulticodecTopology extends Topology {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify if a new connected peer has a topology multicodec and call _onConnect.
|
|
||||||
* @param {Connection} connection
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
_onPeerConnect (connection) {
|
|
||||||
const peerId = connection.remotePeer
|
|
||||||
const protocols = this._registrar.peerStore.protoBook.get(peerId)
|
|
||||||
|
|
||||||
if (!protocols) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.multicodecs.find(multicodec => protocols.includes(multicodec))) {
|
|
||||||
this.peers.add(peerId.toB58String())
|
|
||||||
this._onConnect(peerId, connection)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = withIs(MulticodecTopology, { className: 'MulticodecTopology', symbolName: '@libp2p/js-interfaces/topology/multicodec-topology' })
|
module.exports = withIs(MulticodecTopology, { className: 'MulticodecTopology', symbolName: '@libp2p/js-interfaces/topology/multicodec-topology' })
|
||||||
|
@ -96,38 +96,5 @@ module.exports = (test) => {
|
|||||||
expect(topology._onDisconnect.callCount).to.equal(1)
|
expect(topology._onDisconnect.callCount).to.equal(1)
|
||||||
expect(topology._onDisconnect.calledWith(id2)).to.equal(true)
|
expect(topology._onDisconnect.calledWith(id2)).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should trigger "onConnect" when a peer connects and has one of the topology multicodecs in its known protocols', () => {
|
|
||||||
sinon.spy(topology, '_onConnect')
|
|
||||||
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns(topology.multicodecs)
|
|
||||||
|
|
||||||
topology._registrar.connectionManager.emit('peer:connect', {
|
|
||||||
remotePeer: id
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(topology._onConnect.callCount).to.equal(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not trigger "onConnect" when a peer connects and has none of the topology multicodecs in its known protocols', () => {
|
|
||||||
sinon.spy(topology, '_onConnect')
|
|
||||||
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns([])
|
|
||||||
|
|
||||||
topology._registrar.connectionManager.emit('peer:connect', {
|
|
||||||
remotePeer: id
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(topology._onConnect.callCount).to.equal(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not trigger "onConnect" when a peer connects and its protocols are not known', () => {
|
|
||||||
sinon.spy(topology, '_onConnect')
|
|
||||||
sinon.stub(topology._registrar.peerStore.protoBook, 'get').returns(undefined)
|
|
||||||
|
|
||||||
topology._registrar.connectionManager.emit('peer:connect', {
|
|
||||||
remotePeer: id
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(topology._onConnect.callCount).to.equal(0)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,6 @@ class MockPeerStore extends EventEmitter {
|
|||||||
constructor (peers) {
|
constructor (peers) {
|
||||||
super()
|
super()
|
||||||
this.peers = peers
|
this.peers = peers
|
||||||
this.protoBook = {
|
|
||||||
get: () => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get (peerId) {
|
get (peerId) {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { EventEmitter } = require('events')
|
|
||||||
|
|
||||||
const tests = require('../../src/topology/tests/multicodec-topology')
|
const tests = require('../../src/topology/tests/multicodec-topology')
|
||||||
const MulticodecTopology = require('../../src/topology/multicodec-topology')
|
const MulticodecTopology = require('../../src/topology/multicodec-topology')
|
||||||
const MockPeerStore = require('./mock-peer-store')
|
const MockPeerStore = require('./mock-peer-store')
|
||||||
@ -25,11 +23,9 @@ describe('multicodec topology compliance tests', () => {
|
|||||||
if (!registrar) {
|
if (!registrar) {
|
||||||
const peers = new Map()
|
const peers = new Map()
|
||||||
const peerStore = new MockPeerStore(peers)
|
const peerStore = new MockPeerStore(peers)
|
||||||
const connectionManager = new EventEmitter()
|
|
||||||
|
|
||||||
registrar = {
|
registrar = {
|
||||||
peerStore,
|
peerStore,
|
||||||
connectionManager,
|
|
||||||
getConnection: () => { }
|
getConnection: () => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user