mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-07-06 21:11:35 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
6203109751 | |||
25eeedd20e | |||
5c88d77aaa | |||
f6871afd76 | |||
734c491bb0 | |||
c43a52d176 | |||
af1ba5a409 | |||
c5b724ab93 | |||
6fb45b775b | |||
85c68b5df4 | |||
27ac0a5670 | |||
2de533e15b | |||
aacb0e27d0 | |||
c00f94dfaf | |||
5967834a2f |
40
CHANGELOG.md
40
CHANGELOG.md
@ -1,3 +1,43 @@
|
||||
<a name="0.2.5"></a>
|
||||
## [0.2.5](https://github.com/libp2p/js-interfaces/compare/v0.2.4...v0.2.5) (2020-02-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **connection:** tracks streams properly ([#25](https://github.com/libp2p/js-interfaces/issues/25)) ([5c88d77](https://github.com/libp2p/js-interfaces/commit/5c88d77))
|
||||
|
||||
|
||||
|
||||
<a name="0.2.4"></a>
|
||||
## [0.2.4](https://github.com/libp2p/js-interfaces/compare/v0.2.3...v0.2.4) (2020-02-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dependencies for tests should not be needed by who requires the tests ([#18](https://github.com/libp2p/js-interfaces/issues/18)) ([c5b724a](https://github.com/libp2p/js-interfaces/commit/c5b724a))
|
||||
|
||||
|
||||
|
||||
<a name="0.2.3"></a>
|
||||
## [0.2.3](https://github.com/libp2p/js-interfaces/compare/v0.2.2...v0.2.3) (2020-01-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **transport:** make close listener test more resilient ([#21](https://github.com/libp2p/js-interfaces/issues/21)) ([2de533e](https://github.com/libp2p/js-interfaces/commit/2de533e))
|
||||
|
||||
|
||||
|
||||
<a name="0.2.2"></a>
|
||||
## [0.2.2](https://github.com/libp2p/js-interfaces/compare/v0.2.1...v0.2.2) (2020-01-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **connection:** dont require remoteAddr on creation ([#20](https://github.com/libp2p/js-interfaces/issues/20)) ([5967834](https://github.com/libp2p/js-interfaces/commit/5967834))
|
||||
|
||||
|
||||
|
||||
<a name="0.2.1"></a>
|
||||
## [0.2.1](https://github.com/libp2p/js-interfaces/compare/v0.2.0...v0.2.1) (2019-12-28)
|
||||
|
||||
|
21
package.json
21
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-interfaces",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.5",
|
||||
"description": "Interfaces for JS Libp2p",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@ -34,8 +34,7 @@
|
||||
"homepage": "https://github.com/libp2p/js-interfaces#readme",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"abortable-iterator": "^2.1.0",
|
||||
"async-iterator-to-pull-stream": "^1.3.0",
|
||||
"abortable-iterator": "^3.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai-checkmark": "^1.0.1",
|
||||
"class-is": "^1.1.0",
|
||||
@ -43,20 +42,20 @@
|
||||
"dirty-chai": "^2.0.1",
|
||||
"err-code": "^2.0.0",
|
||||
"it-goodbye": "^2.0.1",
|
||||
"it-pair": "^1.0.0",
|
||||
"it-pipe": "^1.0.1",
|
||||
"libp2p-tcp": "^0.14.1",
|
||||
"multiaddr": "^7.1.0",
|
||||
"p-limit": "^2.2.1",
|
||||
"p-limit": "^2.2.2",
|
||||
"p-wait-for": "^3.1.0",
|
||||
"peer-id": "^0.13.3",
|
||||
"sinon": "^7.5.0",
|
||||
"peer-info": "^0.17.0",
|
||||
"sinon": "^8.1.1",
|
||||
"streaming-iterables": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^20.4.1",
|
||||
"it-handshake": "^1.0.0",
|
||||
"it-pair": "^1.0.0",
|
||||
"it-pipe": "^1.0.1",
|
||||
"peer-info": "^0.17.0"
|
||||
"aegir": "^20.5.0",
|
||||
"it-handshake": "^1.0.1"
|
||||
},
|
||||
"contributors": [
|
||||
"Alan Shaw <alan.shaw@protocol.ai>",
|
||||
@ -66,6 +65,7 @@
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Greg Zuro <gregzuro@users.noreply.github.com>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
"Jacob Heun <jacobheun@Jacobs-MacBook-Pro.local>",
|
||||
"James Ray <16969914+jamesray1@users.noreply.github.com>",
|
||||
"Jeffrey Hulten <jhulten@gmail.com>",
|
||||
"João Santos <joaosantos15@users.noreply.github.com>",
|
||||
@ -78,6 +78,7 @@
|
||||
"Sathya Narrayanan <plasmashadowx@gmail.com>",
|
||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||
"Vasco Santos <vasco.santos@ua.pt>",
|
||||
"dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>",
|
||||
"dirkmc <dirkmdev@gmail.com>",
|
||||
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>",
|
||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||
|
@ -110,7 +110,7 @@ const conn = new Connection({
|
||||
Creates a new Connection instance.
|
||||
|
||||
`localAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used by the local peer to reach the remote.
|
||||
`remoteAddr` is the [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer.
|
||||
`remoteAddr` is the optional [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer.
|
||||
`localPeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the local peer.
|
||||
`remotePeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the remote peer.
|
||||
`newStream` is the `function` responsible for getting a new muxed+multistream-selected stream.
|
||||
|
@ -18,7 +18,7 @@ class Connection {
|
||||
* Creates an instance of Connection.
|
||||
* @param {object} properties properties of the connection.
|
||||
* @param {multiaddr} [properties.localAddr] local multiaddr of the connection if known.
|
||||
* @param {multiaddr} properties.remoteAddr remote multiaddr of the connection.
|
||||
* @param {multiaddr} [properties.remoteAddr] remote multiaddr of the connection.
|
||||
* @param {PeerId} properties.localPeer local peer-id.
|
||||
* @param {PeerId} properties.remotePeer remote peer-id.
|
||||
* @param {function} properties.newStream new stream muxer function.
|
||||
@ -34,7 +34,6 @@ class Connection {
|
||||
*/
|
||||
constructor ({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }) {
|
||||
localAddr && assert(multiaddr.isMultiaddr(localAddr), 'localAddr must be an instance of multiaddr')
|
||||
assert(multiaddr.isMultiaddr(remoteAddr), 'remoteAddr must be an instance of multiaddr')
|
||||
assert(PeerId.isPeerId(localPeer), 'localPeer must be an instance of peer-id')
|
||||
assert(PeerId.isPeerId(remotePeer), 'remotePeer must be an instance of peer-id')
|
||||
assert(typeof newStream === 'function', 'new stream must be a function')
|
||||
@ -139,7 +138,7 @@ class Connection {
|
||||
|
||||
const { stream, protocol } = await this._newStream(protocols)
|
||||
|
||||
this.addStream(stream, protocol)
|
||||
this.addStream(stream, { protocol })
|
||||
|
||||
return {
|
||||
stream,
|
||||
|
@ -120,6 +120,19 @@ module.exports = (test) => {
|
||||
expect(connection.stat.status).to.equal(Status.CLOSED)
|
||||
})
|
||||
|
||||
it('should properly track streams', async () => {
|
||||
// Open stream
|
||||
const protocol = '/echo/0.0.1'
|
||||
const { stream } = await connection.newStream(protocol)
|
||||
const trackedStream = connection.registry.get(stream.id)
|
||||
expect(trackedStream).to.have.property('protocol', protocol)
|
||||
|
||||
// Close stream
|
||||
await stream.close()
|
||||
|
||||
expect(connection.registry.get(stream.id)).to.not.exist()
|
||||
})
|
||||
|
||||
it('should support a proxy on the timeline', async () => {
|
||||
sinon.spy(proxyHandler, 'set')
|
||||
expect(connection.stat.timeline.close).to.not.exist()
|
||||
|
@ -70,7 +70,7 @@ module.exports = (common) => {
|
||||
])
|
||||
|
||||
// Give the listener a chance to finish its upgrade
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
await pWaitFor(() => listenerConns.length === 2)
|
||||
|
||||
// Wait for the data send and close to finish
|
||||
await Promise.all([
|
||||
|
@ -25,7 +25,7 @@ describe('compliance tests', () => {
|
||||
const openStreams = []
|
||||
let streamId = 0
|
||||
|
||||
return new Connection({
|
||||
const connection = new Connection({
|
||||
localPeer,
|
||||
remotePeer,
|
||||
localAddr,
|
||||
@ -43,7 +43,10 @@ describe('compliance tests', () => {
|
||||
const id = streamId++
|
||||
const stream = pair()
|
||||
|
||||
stream.close = () => stream.sink([])
|
||||
stream.close = async () => {
|
||||
await stream.sink([])
|
||||
connection.removeStream(stream.id)
|
||||
}
|
||||
stream.id = id
|
||||
|
||||
openStreams.push(stream)
|
||||
@ -57,6 +60,7 @@ describe('compliance tests', () => {
|
||||
getStreams: () => openStreams,
|
||||
...properties
|
||||
})
|
||||
return connection
|
||||
},
|
||||
async teardown () {
|
||||
// cleanup resources created by setup()
|
||||
|
48
test/connection/index.spec.js
Normal file
48
test/connection/index.spec.js
Normal file
@ -0,0 +1,48 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const { Connection } = require('../../src/connection')
|
||||
const peers = require('../../src/utils/peers')
|
||||
const PeerId = require('peer-id')
|
||||
const pair = require('it-pair')
|
||||
|
||||
describe('connection tests', () => {
|
||||
it('should not require local or remote addrs', async () => {
|
||||
const [localPeer, remotePeer] = await Promise.all([
|
||||
PeerId.createFromJSON(peers[0]),
|
||||
PeerId.createFromJSON(peers[1])
|
||||
])
|
||||
const openStreams = []
|
||||
let streamId = 0
|
||||
|
||||
return new Connection({
|
||||
localPeer,
|
||||
remotePeer,
|
||||
stat: {
|
||||
timeline: {
|
||||
open: Date.now() - 10,
|
||||
upgraded: Date.now()
|
||||
},
|
||||
direction: 'outbound',
|
||||
encryption: '/secio/1.0.0',
|
||||
multiplexer: '/mplex/6.7.0'
|
||||
},
|
||||
newStream: (protocols) => {
|
||||
const id = streamId++
|
||||
const stream = pair()
|
||||
|
||||
stream.close = () => stream.sink([])
|
||||
stream.id = id
|
||||
|
||||
openStreams.push(stream)
|
||||
|
||||
return {
|
||||
stream,
|
||||
protocol: protocols[0]
|
||||
}
|
||||
},
|
||||
close: () => {},
|
||||
getStreams: () => openStreams
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user