mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 17:52:21 +00:00
Update the spec to follow #1 idea, write tests to check for that
This commit is contained in:
parent
10e6728d64
commit
2e90edebea
@ -45,7 +45,9 @@ var common = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tests(tape, common)
|
var megaTest = false // a really really intensive test case
|
||||||
|
|
||||||
|
tests(tape, common, megaTest)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Go
|
## Go
|
||||||
@ -71,7 +73,8 @@ If `err` is passed, no operation should be made in `conn`.
|
|||||||
|
|
||||||
### Dial(open/create) a new stream
|
### Dial(open/create) a new stream
|
||||||
|
|
||||||
- `Node.js` conn.dialStream(function (err, stream))
|
|
||||||
|
- `Node.js` stream = conn.dialStream([function (err, stream)])
|
||||||
- `Go` stream, err := conn.DialStream()
|
- `Go` stream, err := conn.DialStream()
|
||||||
|
|
||||||
This method negotiates and opens a new stream with the other endpoint.
|
This method negotiates and opens a new stream with the other endpoint.
|
||||||
@ -80,6 +83,8 @@ If `err` is passed, no operation should be made in `stream`.
|
|||||||
|
|
||||||
`stream` abstract our established Stream with the other endpoint, it must implement the [Duplex Stream interface](https://nodejs.org/api/stream.html#stream_class_stream_duplex) in Node.js or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
`stream` abstract our established Stream with the other endpoint, it must implement the [Duplex Stream interface](https://nodejs.org/api/stream.html#stream_class_stream_duplex) in Node.js or the [ReadWriteCloser](http://golang.org/pkg/io/#ReadWriteCloser) in Go.
|
||||||
|
|
||||||
|
In the Node.js 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
|
||||||
|
|
||||||
- `Node.js` conn.on('stream', function (stream))
|
- `Node.js` conn.on('stream', function (stream))
|
||||||
|
@ -48,4 +48,66 @@ module.exports.all = function (test, common) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Open a stream using the net.connect pattern', function (t) {
|
||||||
|
common.setup(test, function (err, Muxer) {
|
||||||
|
t.plan(3)
|
||||||
|
t.ifError(err, 'Should not throw')
|
||||||
|
|
||||||
|
var pair = streamPair.create()
|
||||||
|
var dialer = new Muxer()
|
||||||
|
var listener = new Muxer()
|
||||||
|
|
||||||
|
var connDialer = dialer.attach(pair)
|
||||||
|
var connListener = listener.attach(pair.other)
|
||||||
|
|
||||||
|
var stream = connListener.dialStream()
|
||||||
|
|
||||||
|
stream.on('ready', function () {
|
||||||
|
t.pass('dialed stream')
|
||||||
|
})
|
||||||
|
|
||||||
|
stream.on('error', function (err) {
|
||||||
|
t.ifError(err, 'Should not throw')
|
||||||
|
})
|
||||||
|
|
||||||
|
connDialer.on('stream', function (stream) {
|
||||||
|
t.pass('got stream')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Buffer writes Open a stream using the net.connect pattern', function (t) {
|
||||||
|
common.setup(test, function (err, Muxer) {
|
||||||
|
t.plan(4)
|
||||||
|
t.ifError(err, 'Should not throw')
|
||||||
|
|
||||||
|
var pair = streamPair.create()
|
||||||
|
var dialer = new Muxer()
|
||||||
|
var listener = new Muxer()
|
||||||
|
|
||||||
|
var connDialer = dialer.attach(pair)
|
||||||
|
var connListener = listener.attach(pair.other)
|
||||||
|
|
||||||
|
var stream = connListener.dialStream()
|
||||||
|
|
||||||
|
stream.write('buffer this')
|
||||||
|
|
||||||
|
stream.on('ready', function () {
|
||||||
|
t.pass('dialed stream')
|
||||||
|
})
|
||||||
|
|
||||||
|
stream.on('error', function (err) {
|
||||||
|
t.ifError(err, 'Should not throw')
|
||||||
|
})
|
||||||
|
|
||||||
|
connDialer.on('stream', function (stream) {
|
||||||
|
t.pass('got stream')
|
||||||
|
|
||||||
|
stream.on('data', function (chunk) {
|
||||||
|
t.equal(chunk.toString(), 'buffer this')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user