mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-25 12:52:35 +00:00
docs(readme): update spec and code accordingly
This commit is contained in:
parent
c06da3b925
commit
98b08fda06
@ -83,8 +83,6 @@ If `err` is passed, no operation should be made in `stream`.
|
|||||||
|
|
||||||
`stream` interface our established Stream with the other endpoint, it must implement the [Duplex pull-stream interface](https://pull-stream.github.io) in JavaScript or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
`stream` interface our established Stream with the other endpoint, it must implement the [Duplex pull-stream interface](https://pull-stream.github.io) in JavaScript or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
||||||
|
|
||||||
In the JavaScript case, if no callback is passed, stream will emit an 'ready' event when it is prepared or a 'error' event if it fails to establish the connection, until then, it will buffer the 'write' calls.
|
|
||||||
|
|
||||||
### Listen(wait/accept) a new incoming stream
|
### Listen(wait/accept) a new incoming stream
|
||||||
|
|
||||||
- `JavaScript` muxedConn.on('stream', function (stream) {})
|
- `JavaScript` muxedConn.on('stream', function (stream) {})
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "interface-stream-muxer",
|
"name": "interface-stream-muxer",
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
"description": "A test suite and interface you can use to implement a stream muxer.",
|
"description": "A test suite and interface you can use to implement a stream muxer.",
|
||||||
"main": "src/index.js",
|
"main": "lib/index.js",
|
||||||
"jsnext:main": "src/index.js",
|
"jsnext:main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "exit(0)",
|
"test": "exit(0)",
|
||||||
@ -21,7 +21,6 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"Streams",
|
"Streams",
|
||||||
"Muxer",
|
"Muxer",
|
||||||
"interface",
|
|
||||||
"Interface"
|
"Interface"
|
||||||
],
|
],
|
||||||
"author": "David Dias <daviddias@ipfs.io>",
|
"author": "David Dias <daviddias@ipfs.io>",
|
||||||
@ -34,6 +33,7 @@
|
|||||||
"async": "^2.0.1",
|
"async": "^2.0.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"chai-checkmark": "^1.0.1",
|
"chai-checkmark": "^1.0.1",
|
||||||
|
"detect-node": "^2.0.3",
|
||||||
"libp2p-tcp": "^0.8.1",
|
"libp2p-tcp": "^0.8.1",
|
||||||
"multiaddr": "^2.0.2",
|
"multiaddr": "^2.0.2",
|
||||||
"pull-generate": "^2.2.0",
|
"pull-generate": "^2.2.0",
|
||||||
@ -43,6 +43,6 @@
|
|||||||
"run-series": "^1.1.4"
|
"run-series": "^1.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^6.0.1"
|
"aegir": "^8.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
|
/* eslint max-nested-callbacks: ["error", 8] */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
@ -11,7 +12,7 @@ const series = require('run-series')
|
|||||||
const Tcp = require('libp2p-tcp')
|
const Tcp = require('libp2p-tcp')
|
||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
|
|
||||||
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/10000')
|
||||||
|
|
||||||
function closeAndWait (stream) {
|
function closeAndWait (stream) {
|
||||||
pull(
|
pull(
|
||||||
@ -24,7 +25,7 @@ function closeAndWait (stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = (common) => {
|
module.exports = (common) => {
|
||||||
describe.only('close', () => {
|
describe('close', () => {
|
||||||
let muxer
|
let muxer
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
@ -40,14 +41,14 @@ module.exports = (common) => {
|
|||||||
|
|
||||||
const tcp = new Tcp()
|
const tcp = new Tcp()
|
||||||
const tcpListener = tcp.createListener((socket) => {
|
const tcpListener = tcp.createListener((socket) => {
|
||||||
const listener = muxer.listen(socket)
|
const listener = muxer.listener(socket)
|
||||||
listener.on('stream', (stream) => {
|
listener.on('stream', (stream) => {
|
||||||
pull(stream, stream)
|
pull(stream, stream)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tcpListener.listen(mh, () => {
|
tcpListener.listen(mh, () => {
|
||||||
const dialer = muxer.dial(tcp.dial(mh, () => {
|
const dialer = muxer.dialer(tcp.dial(mh, () => {
|
||||||
tcpListener.close()
|
tcpListener.close()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -73,8 +74,8 @@ module.exports = (common) => {
|
|||||||
|
|
||||||
it('closing one of the muxed streams doesn\'t close others', (done) => {
|
it('closing one of the muxed streams doesn\'t close others', (done) => {
|
||||||
const p = pair()
|
const p = pair()
|
||||||
const dialer = muxer.dial(p[0])
|
const dialer = muxer.dialer(p[0])
|
||||||
const listener = muxer.listen(p[1])
|
const listener = muxer.listener(p[1])
|
||||||
|
|
||||||
expect(6).checks(done)
|
expect(6).checks(done)
|
||||||
|
|
||||||
|
@ -2,14 +2,17 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const baseTest = require('./base-test')
|
const baseTest = require('./base-test')
|
||||||
const closeTest = require('./close-test')
|
|
||||||
const stressTest = require('./stress-test')
|
const stressTest = require('./stress-test')
|
||||||
const megaStressTest = require('./mega-stress-test')
|
const megaStressTest = require('./mega-stress-test')
|
||||||
|
const isNode = require('detect-node')
|
||||||
|
|
||||||
module.exports = (common) => {
|
module.exports = (common) => {
|
||||||
describe('interface-stream-muxer', () => {
|
describe('interface-stream-muxer', () => {
|
||||||
baseTest(common)
|
baseTest(common)
|
||||||
closeTest(common)
|
if (isNode) {
|
||||||
|
const closeTest = require('./close-test')
|
||||||
|
closeTest(common)
|
||||||
|
}
|
||||||
stressTest(common)
|
stressTest(common)
|
||||||
megaStressTest(common)
|
megaStressTest(common)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user