@libp2p/interface-compliance-tests 6.4.16 → 6.5.0-8484de8a2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection-encryption/index.d.ts.map +1 -1
- package/dist/src/connection-encryption/index.js +24 -15
- package/dist/src/connection-encryption/index.js.map +1 -1
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/base-test.js +62 -341
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +254 -305
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/index.js +2 -2
- package/dist/src/stream-muxer/index.js.map +1 -1
- package/dist/src/stream-muxer/{mega-stress-test.d.ts → stream-test.d.ts} +2 -2
- package/dist/src/stream-muxer/stream-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/stream-test.js +289 -0
- package/dist/src/stream-muxer/stream-test.js.map +1 -0
- package/dist/src/stream-muxer/stress-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/stress-test.js +70 -16
- package/dist/src/stream-muxer/stress-test.js.map +1 -1
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +232 -203
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/utils.js +2 -2
- package/dist/src/transport/utils.js.map +1 -1
- package/package.json +23 -51
- package/src/connection-encryption/index.ts +27 -20
- package/src/stream-muxer/base-test.ts +75 -409
- package/src/stream-muxer/close-test.ts +304 -327
- package/src/stream-muxer/index.ts +2 -2
- package/src/stream-muxer/stream-test.ts +380 -0
- package/src/stream-muxer/stress-test.ts +92 -18
- package/src/transport/index.ts +280 -241
- package/src/transport/utils.ts +2 -2
- package/dist/src/connection-encryption/utils/index.d.ts +0 -3
- package/dist/src/connection-encryption/utils/index.d.ts.map +0 -1
- package/dist/src/connection-encryption/utils/index.js +0 -21
- package/dist/src/connection-encryption/utils/index.js.map +0 -1
- package/dist/src/matchers.d.ts +0 -12
- package/dist/src/matchers.d.ts.map +0 -1
- package/dist/src/matchers.js +0 -14
- package/dist/src/matchers.js.map +0 -1
- package/dist/src/mocks/connection-manager.d.ts +0 -27
- package/dist/src/mocks/connection-manager.d.ts.map +0 -1
- package/dist/src/mocks/connection-manager.js +0 -147
- package/dist/src/mocks/connection-manager.js.map +0 -1
- package/dist/src/mocks/connection.d.ts +0 -41
- package/dist/src/mocks/connection.d.ts.map +0 -1
- package/dist/src/mocks/connection.js +0 -234
- package/dist/src/mocks/connection.js.map +0 -1
- package/dist/src/mocks/duplex.d.ts +0 -4
- package/dist/src/mocks/duplex.d.ts.map +0 -1
- package/dist/src/mocks/duplex.js +0 -9
- package/dist/src/mocks/duplex.js.map +0 -1
- package/dist/src/mocks/index.d.ts +0 -12
- package/dist/src/mocks/index.d.ts.map +0 -1
- package/dist/src/mocks/index.js +0 -8
- package/dist/src/mocks/index.js.map +0 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +0 -17
- package/dist/src/mocks/multiaddr-connection.d.ts.map +0 -1
- package/dist/src/mocks/multiaddr-connection.js +0 -64
- package/dist/src/mocks/multiaddr-connection.js.map +0 -1
- package/dist/src/mocks/muxer.d.ts +0 -36
- package/dist/src/mocks/muxer.d.ts.map +0 -1
- package/dist/src/mocks/muxer.js +0 -234
- package/dist/src/mocks/muxer.js.map +0 -1
- package/dist/src/mocks/registrar.d.ts +0 -16
- package/dist/src/mocks/registrar.d.ts.map +0 -1
- package/dist/src/mocks/registrar.js +0 -66
- package/dist/src/mocks/registrar.js.map +0 -1
- package/dist/src/mocks/upgrader.d.ts +0 -9
- package/dist/src/mocks/upgrader.d.ts.map +0 -1
- package/dist/src/mocks/upgrader.js +0 -46
- package/dist/src/mocks/upgrader.js.map +0 -1
- package/dist/src/pubsub/api.d.ts +0 -6
- package/dist/src/pubsub/api.d.ts.map +0 -1
- package/dist/src/pubsub/api.js +0 -88
- package/dist/src/pubsub/api.js.map +0 -1
- package/dist/src/pubsub/connection-handlers.d.ts +0 -6
- package/dist/src/pubsub/connection-handlers.d.ts.map +0 -1
- package/dist/src/pubsub/connection-handlers.js +0 -329
- package/dist/src/pubsub/connection-handlers.js.map +0 -1
- package/dist/src/pubsub/emit-self.d.ts +0 -6
- package/dist/src/pubsub/emit-self.d.ts.map +0 -1
- package/dist/src/pubsub/emit-self.js +0 -80
- package/dist/src/pubsub/emit-self.js.map +0 -1
- package/dist/src/pubsub/index.d.ts +0 -18
- package/dist/src/pubsub/index.d.ts.map +0 -1
- package/dist/src/pubsub/index.js +0 -17
- package/dist/src/pubsub/index.js.map +0 -1
- package/dist/src/pubsub/messages.d.ts +0 -6
- package/dist/src/pubsub/messages.d.ts.map +0 -1
- package/dist/src/pubsub/messages.js +0 -48
- package/dist/src/pubsub/messages.js.map +0 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +0 -6
- package/dist/src/pubsub/multiple-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/multiple-nodes.js +0 -350
- package/dist/src/pubsub/multiple-nodes.js.map +0 -1
- package/dist/src/pubsub/two-nodes.d.ts +0 -6
- package/dist/src/pubsub/two-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/two-nodes.js +0 -216
- package/dist/src/pubsub/two-nodes.js.map +0 -1
- package/dist/src/pubsub/utils.d.ts +0 -5
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -27
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.js +0 -11
- package/dist/src/stream-muxer/mega-stress-test.js.map +0 -1
- package/dist/src/stream-muxer/spawner.d.ts +0 -4
- package/dist/src/stream-muxer/spawner.d.ts.map +0 -1
- package/dist/src/stream-muxer/spawner.js +0 -37
- package/dist/src/stream-muxer/spawner.js.map +0 -1
- package/dist/typedoc-urls.json +0 -44
- package/src/connection-encryption/utils/index.ts +0 -27
- package/src/matchers.ts +0 -18
- package/src/mocks/connection-manager.ts +0 -216
- package/src/mocks/connection.ts +0 -307
- package/src/mocks/duplex.ts +0 -11
- package/src/mocks/index.ts +0 -11
- package/src/mocks/multiaddr-connection.ts +0 -80
- package/src/mocks/muxer.ts +0 -331
- package/src/mocks/registrar.ts +0 -86
- package/src/mocks/upgrader.ts +0 -65
- package/src/pubsub/api.ts +0 -116
- package/src/pubsub/connection-handlers.ts +0 -413
- package/src/pubsub/emit-self.ts +0 -99
- package/src/pubsub/index.ts +0 -34
- package/src/pubsub/messages.ts +0 -59
- package/src/pubsub/multiple-nodes.ts +0 -440
- package/src/pubsub/two-nodes.ts +0 -272
- package/src/pubsub/utils.ts +0 -34
- package/src/stream-muxer/mega-stress-test.ts +0 -14
- package/src/stream-muxer/spawner.ts +0 -55
|
@@ -1,454 +1,120 @@
|
|
|
1
|
+
import { multiaddrConnectionPair, byteStream } from '@libp2p/utils'
|
|
1
2
|
import { expect } from 'aegir/chai'
|
|
2
|
-
import
|
|
3
|
-
import { byteStream } from 'it-byte-stream'
|
|
4
|
-
import map from 'it-map'
|
|
5
|
-
import { duplexPair } from 'it-pair/duplex'
|
|
6
|
-
import { pipe } from 'it-pipe'
|
|
7
|
-
import defer from 'p-defer'
|
|
8
|
-
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
+
import { pEvent } from 'p-event'
|
|
9
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
11
|
-
import { isValidTick } from '../is-valid-tick.js'
|
|
12
5
|
import type { TestSetup } from '../index.js'
|
|
13
|
-
import type { Stream, StreamMuxerFactory } from '@libp2p/interface'
|
|
14
|
-
import type { Source } from 'it-stream-types'
|
|
15
|
-
import type { DeferredPromise } from 'p-defer'
|
|
6
|
+
import type { Stream, StreamMuxer, StreamMuxerFactory } from '@libp2p/interface'
|
|
16
7
|
|
|
17
8
|
export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
18
9
|
describe('base', () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
let dialer: StreamMuxer
|
|
11
|
+
let listener: StreamMuxer
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
const [outboundConnection, inboundConnection] = multiaddrConnectionPair()
|
|
23
15
|
|
|
24
16
|
const dialerFactory = await common.setup()
|
|
25
|
-
|
|
17
|
+
dialer = dialerFactory.createStreamMuxer(outboundConnection)
|
|
26
18
|
|
|
27
19
|
const listenerFactory = await common.setup()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
onIncomingStream: (stream) => {
|
|
31
|
-
onStreamPromise.resolve(stream)
|
|
32
|
-
},
|
|
33
|
-
onStreamEnd: (stream) => {
|
|
34
|
-
onStreamEndPromise.resolve(stream)
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
void pipe(p[0], dialer, p[0])
|
|
39
|
-
void pipe(p[1], listener, p[1])
|
|
40
|
-
|
|
41
|
-
const dialerStream = await dialer.newStream()
|
|
42
|
-
expect(dialer.streams).to.include(dialerStream)
|
|
43
|
-
expect(isValidTick(dialerStream.timeline.open)).to.equal(true)
|
|
44
|
-
|
|
45
|
-
const dialerBytes = byteStream(dialerStream)
|
|
46
|
-
void dialerBytes.write(uint8ArrayFromString('hello'))
|
|
20
|
+
listener = listenerFactory.createStreamMuxer(inboundConnection)
|
|
21
|
+
})
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
await dialer?.close()
|
|
25
|
+
await listener?.close()
|
|
26
|
+
})
|
|
52
27
|
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
it('should have a protocol', async () => {
|
|
29
|
+
expect(dialer.protocol).to.be.a('string')
|
|
30
|
+
})
|
|
55
31
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
it('should be open', async () => {
|
|
33
|
+
expect(dialer.status).to.equal('open')
|
|
34
|
+
})
|
|
59
35
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
it('should be closing during closing', async () => {
|
|
37
|
+
const closePromise = dialer.close()
|
|
38
|
+
expect(dialer.status).to.equal('closing')
|
|
63
39
|
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
await closePromise
|
|
41
|
+
})
|
|
66
42
|
|
|
43
|
+
it('should be closed after closing', async () => {
|
|
67
44
|
await dialer.close()
|
|
68
|
-
await listener.close()
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
expect(dialer.streams).to.have.length(0)
|
|
72
|
-
expect(listener.streams).to.have.length(0)
|
|
46
|
+
expect(dialer.status).to.equal('closed')
|
|
73
47
|
})
|
|
74
48
|
|
|
75
|
-
it('should open a stream
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
onStreamPromise.resolve(stream)
|
|
84
|
-
},
|
|
85
|
-
onStreamEnd: (stream) => {
|
|
86
|
-
onStreamEndPromise.resolve(stream)
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const listenerFactory = await common.setup()
|
|
91
|
-
const listener = listenerFactory.createStreamMuxer({ direction: 'inbound' })
|
|
92
|
-
|
|
93
|
-
void pipe(p[0], dialer, p[0])
|
|
94
|
-
void pipe(p[1], listener, p[1])
|
|
49
|
+
it('should open a stream', async () => {
|
|
50
|
+
const [
|
|
51
|
+
listenerStream,
|
|
52
|
+
dialerStream
|
|
53
|
+
] = await Promise.all([
|
|
54
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
55
|
+
dialer.createStream()
|
|
56
|
+
])
|
|
95
57
|
|
|
96
|
-
const
|
|
58
|
+
const dialerBytes = byteStream(dialerStream)
|
|
97
59
|
const listenerBytes = byteStream(listenerStream)
|
|
98
|
-
void listenerBytes.write(uint8ArrayFromString('hello'))
|
|
99
|
-
|
|
100
|
-
const dialerStream = await onStreamPromise.promise
|
|
101
60
|
|
|
102
|
-
|
|
103
|
-
expect(listener.streams).to.include(listenerStream)
|
|
104
|
-
expect(isValidTick(listenerStream.timeline.open)).to.equal(true)
|
|
61
|
+
const input = uint8ArrayFromString('hello')
|
|
105
62
|
|
|
106
|
-
await
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const endedStream = await onStreamEndPromise.promise
|
|
111
|
-
expect(dialer.streams).to.not.include(endedStream)
|
|
112
|
-
|
|
113
|
-
if (endedStream.timeline.close == null) {
|
|
114
|
-
throw new Error('timeline had no close time')
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Make sure the stream is removed from tracking
|
|
118
|
-
expect(isValidTick(endedStream.timeline.close)).to.equal(true)
|
|
63
|
+
const [, output] = await Promise.all([
|
|
64
|
+
dialerBytes.write(input),
|
|
65
|
+
listenerBytes.read()
|
|
66
|
+
])
|
|
119
67
|
|
|
120
|
-
|
|
121
|
-
await listener.close()
|
|
68
|
+
expect(output?.subarray()).to.equalBytes(input.subarray())
|
|
122
69
|
})
|
|
123
70
|
|
|
124
71
|
it('should open a stream on both sides', async () => {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const dialerFactory = await common.setup()
|
|
129
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
130
|
-
direction: 'outbound',
|
|
131
|
-
onIncomingStream: (stream) => {
|
|
132
|
-
onDialerStreamPromise.resolve(stream)
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
const listenerFactory = await common.setup()
|
|
137
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
138
|
-
direction: 'inbound',
|
|
139
|
-
onIncomingStream: (stream) => {
|
|
140
|
-
onListenerStreamPromise.resolve(stream)
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
void pipe(p[0], dialer, p[0])
|
|
145
|
-
void pipe(p[1], listener, p[1])
|
|
72
|
+
const [
|
|
73
|
+
listenerInboundStream,
|
|
74
|
+
dialerOutboundStream,
|
|
146
75
|
|
|
147
|
-
|
|
148
|
-
|
|
76
|
+
dialerInboundStream,
|
|
77
|
+
listenerOutboundStream
|
|
78
|
+
] = await Promise.all([
|
|
79
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
80
|
+
dialer.createStream(),
|
|
149
81
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
listenerInitiatorStream.close(),
|
|
153
|
-
onDialerStreamPromise.promise.then(async stream => { await stream.close() }),
|
|
154
|
-
onListenerStreamPromise.promise.then(async stream => { await stream.close() })
|
|
82
|
+
pEvent<'stream', CustomEvent<Stream>>(dialer, 'stream').then(evt => evt.detail),
|
|
83
|
+
listener.createStream()
|
|
155
84
|
])
|
|
156
85
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
listener.close()
|
|
160
|
-
])
|
|
161
|
-
})
|
|
86
|
+
const dialerOutboundBytes = byteStream(dialerOutboundStream)
|
|
87
|
+
const listenerInboundBytes = byteStream(listenerInboundStream)
|
|
162
88
|
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
166
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
167
|
-
const onListenerStreamPromise: DeferredPromise<Stream> = defer()
|
|
168
|
-
const dialerFactory = await common.setup()
|
|
169
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
170
|
-
direction: 'outbound',
|
|
171
|
-
onIncomingStream: (stream) => {
|
|
172
|
-
onDialerStreamPromise.resolve(stream)
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
const listenerFactory = await common.setup()
|
|
176
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
177
|
-
direction: 'inbound',
|
|
178
|
-
onIncomingStream: (stream) => {
|
|
179
|
-
onListenerStreamPromise.resolve(stream)
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
void pipe(p[0], dialer, p[0])
|
|
184
|
-
void pipe(p[1], listener, p[1])
|
|
89
|
+
const listenerOutboundBytes = byteStream(listenerOutboundStream)
|
|
90
|
+
const dialerInboundBytes = byteStream(dialerInboundStream)
|
|
185
91
|
|
|
186
|
-
const
|
|
187
|
-
const
|
|
92
|
+
const inputA = uint8ArrayFromString('hello')
|
|
93
|
+
const inputB = uint8ArrayFromString('world')
|
|
188
94
|
|
|
189
|
-
|
|
190
|
-
|
|
95
|
+
const [, outputA] = await Promise.all([
|
|
96
|
+
dialerOutboundBytes.write(inputA),
|
|
97
|
+
listenerInboundBytes.read(),
|
|
191
98
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
listenerStream
|
|
195
|
-
] = await Promise.all([
|
|
196
|
-
onDialerStreamPromise.promise,
|
|
197
|
-
onListenerStreamPromise.promise
|
|
99
|
+
listenerOutboundBytes.write(inputB),
|
|
100
|
+
dialerInboundBytes.read()
|
|
198
101
|
])
|
|
199
102
|
|
|
103
|
+
expect(outputA?.subarray()).to.equalBytes(inputA.subarray())
|
|
104
|
+
expect(inputB?.subarray()).to.equalBytes(inputB.subarray())
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('should store a stream in the streams list', async () => {
|
|
200
108
|
const [
|
|
201
|
-
|
|
202
|
-
|
|
109
|
+
listenerStream,
|
|
110
|
+
dialerStream
|
|
203
111
|
] = await Promise.all([
|
|
204
|
-
|
|
205
|
-
|
|
112
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
113
|
+
dialer.createStream()
|
|
206
114
|
])
|
|
207
115
|
|
|
208
|
-
expect(
|
|
209
|
-
expect(
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
it('should echo a small value via a pipe', async () => {
|
|
213
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
214
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
215
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
216
|
-
const dialerFactory = await common.setup()
|
|
217
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
218
|
-
direction: 'outbound',
|
|
219
|
-
onIncomingStream: (stream) => {
|
|
220
|
-
onDialerStreamPromise.resolve(stream)
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
const listenerFactory = await common.setup()
|
|
224
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
225
|
-
direction: 'inbound',
|
|
226
|
-
onIncomingStream: (stream) => {
|
|
227
|
-
void Promise.resolve().then(async () => {
|
|
228
|
-
const output = new Uint8ArrayList()
|
|
229
|
-
|
|
230
|
-
for await (const buf of stream.source) {
|
|
231
|
-
output.append(buf)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
235
|
-
})
|
|
236
|
-
}
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
void pipe(p[0], dialer, p[0])
|
|
240
|
-
void pipe(p[1], listener, p[1])
|
|
241
|
-
|
|
242
|
-
const stream = await dialer.newStream()
|
|
243
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
244
|
-
|
|
245
|
-
await pipe(
|
|
246
|
-
[input],
|
|
247
|
-
stream
|
|
248
|
-
)
|
|
249
|
-
await stream.close()
|
|
250
|
-
|
|
251
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
it('should echo a large value via a pipe', async () => {
|
|
255
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
256
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
257
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
258
|
-
const dialerFactory = await common.setup()
|
|
259
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
260
|
-
direction: 'outbound',
|
|
261
|
-
onIncomingStream: (stream) => {
|
|
262
|
-
onDialerStreamPromise.resolve(stream)
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
const listenerFactory = await common.setup()
|
|
266
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
267
|
-
direction: 'inbound',
|
|
268
|
-
onIncomingStream: (stream) => {
|
|
269
|
-
void Promise.resolve().then(async () => {
|
|
270
|
-
const output = new Uint8ArrayList()
|
|
271
|
-
|
|
272
|
-
for await (const buf of stream.source) {
|
|
273
|
-
output.append(buf)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
277
|
-
})
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
void pipe(p[0], dialer, p[0])
|
|
282
|
-
void pipe(p[1], listener, p[1])
|
|
283
|
-
|
|
284
|
-
const stream = await dialer.newStream()
|
|
285
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
286
|
-
|
|
287
|
-
await pipe(
|
|
288
|
-
[input],
|
|
289
|
-
stream
|
|
290
|
-
)
|
|
291
|
-
await stream.close()
|
|
292
|
-
|
|
293
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
it('should echo a small value via sink', async () => {
|
|
297
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
298
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
299
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
300
|
-
const dialerFactory = await common.setup()
|
|
301
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
302
|
-
direction: 'outbound',
|
|
303
|
-
onIncomingStream: (stream) => {
|
|
304
|
-
onDialerStreamPromise.resolve(stream)
|
|
305
|
-
}
|
|
306
|
-
})
|
|
307
|
-
const listenerFactory = await common.setup()
|
|
308
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
309
|
-
direction: 'inbound',
|
|
310
|
-
onIncomingStream: (stream) => {
|
|
311
|
-
void Promise.resolve().then(async () => {
|
|
312
|
-
const output = new Uint8ArrayList()
|
|
313
|
-
|
|
314
|
-
for await (const buf of stream.source) {
|
|
315
|
-
output.append(buf)
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
319
|
-
})
|
|
320
|
-
}
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
void pipe(p[0], dialer, p[0])
|
|
324
|
-
void pipe(p[1], listener, p[1])
|
|
325
|
-
|
|
326
|
-
const stream = await dialer.newStream()
|
|
327
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
328
|
-
|
|
329
|
-
await stream.sink([input])
|
|
330
|
-
await stream.close()
|
|
331
|
-
|
|
332
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
it('should echo a large value via sink', async () => {
|
|
336
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
337
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
338
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
339
|
-
const dialerFactory = await common.setup()
|
|
340
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
341
|
-
direction: 'outbound',
|
|
342
|
-
onIncomingStream: (stream) => {
|
|
343
|
-
onDialerStreamPromise.resolve(stream)
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
const listenerFactory = await common.setup()
|
|
347
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
348
|
-
direction: 'inbound',
|
|
349
|
-
onIncomingStream: (stream) => {
|
|
350
|
-
void Promise.resolve().then(async () => {
|
|
351
|
-
const output = new Uint8ArrayList()
|
|
352
|
-
|
|
353
|
-
for await (const buf of stream.source) {
|
|
354
|
-
output.append(buf)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
358
|
-
})
|
|
359
|
-
}
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
void pipe(p[0], dialer, p[0])
|
|
363
|
-
void pipe(p[1], listener, p[1])
|
|
364
|
-
|
|
365
|
-
const stream = await dialer.newStream()
|
|
366
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
367
|
-
|
|
368
|
-
await stream.sink([input])
|
|
369
|
-
await stream.close()
|
|
370
|
-
|
|
371
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
it('should echo a small value via a pushable', async () => {
|
|
375
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
376
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
377
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
378
|
-
const dialerFactory = await common.setup()
|
|
379
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
380
|
-
direction: 'outbound',
|
|
381
|
-
onIncomingStream: (stream) => {
|
|
382
|
-
onDialerStreamPromise.resolve(stream)
|
|
383
|
-
}
|
|
384
|
-
})
|
|
385
|
-
const listenerFactory = await common.setup()
|
|
386
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
387
|
-
direction: 'inbound',
|
|
388
|
-
onIncomingStream: (stream) => {
|
|
389
|
-
void Promise.resolve().then(async () => {
|
|
390
|
-
const output = new Uint8ArrayList()
|
|
391
|
-
|
|
392
|
-
for await (const buf of stream.source) {
|
|
393
|
-
output.append(buf)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
397
|
-
})
|
|
398
|
-
}
|
|
399
|
-
})
|
|
400
|
-
|
|
401
|
-
void pipe(p[0], dialer, p[0])
|
|
402
|
-
void pipe(p[1], listener, p[1])
|
|
403
|
-
|
|
404
|
-
const stream = await dialer.newStream()
|
|
405
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
406
|
-
|
|
407
|
-
const pushable = byteStream(stream)
|
|
408
|
-
await pushable.write(input)
|
|
409
|
-
await pushable.unwrap().close()
|
|
410
|
-
|
|
411
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
412
|
-
})
|
|
413
|
-
|
|
414
|
-
it('should echo a large value via a pushable', async () => {
|
|
415
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
416
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
417
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
418
|
-
const dialerFactory = await common.setup()
|
|
419
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
420
|
-
direction: 'outbound',
|
|
421
|
-
onIncomingStream: (stream) => {
|
|
422
|
-
onDialerStreamPromise.resolve(stream)
|
|
423
|
-
}
|
|
424
|
-
})
|
|
425
|
-
const listenerFactory = await common.setup()
|
|
426
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
427
|
-
direction: 'inbound',
|
|
428
|
-
onIncomingStream: (stream) => {
|
|
429
|
-
void Promise.resolve().then(async () => {
|
|
430
|
-
const output = new Uint8ArrayList()
|
|
431
|
-
|
|
432
|
-
for await (const buf of stream.source) {
|
|
433
|
-
output.append(buf)
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
void pipe(p[0], dialer, p[0])
|
|
442
|
-
void pipe(p[1], listener, p[1])
|
|
443
|
-
|
|
444
|
-
const stream = await dialer.newStream()
|
|
445
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
446
|
-
|
|
447
|
-
const pushable = byteStream(stream)
|
|
448
|
-
await pushable.write(input)
|
|
449
|
-
await pushable.unwrap().close()
|
|
450
|
-
|
|
451
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
116
|
+
expect(dialer.streams).to.include(dialerStream, 'dialer did not store outbound stream')
|
|
117
|
+
expect(listener.streams).to.include(listenerStream, 'listener did not store inbound stream')
|
|
452
118
|
})
|
|
453
119
|
})
|
|
454
120
|
}
|