@fails-components/webtransport 0.2.1 → 0.3.0
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/CMakeLists.txt +3 -0
- package/dist/lib/client.d.ts +7 -3
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/dom.d.ts +15 -4
- package/dist/lib/dom.d.ts.map +1 -1
- package/dist/lib/error.d.ts +8 -0
- package/dist/lib/error.d.ts.map +1 -0
- package/dist/lib/event-loop.d.ts +4 -2
- package/dist/lib/event-loop.d.ts.map +1 -1
- package/dist/lib/native.d.ts.map +1 -1
- package/dist/lib/server.d.ts +5 -2
- package/dist/lib/server.d.ts.map +1 -1
- package/dist/lib/session.d.ts +36 -23
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/stream.d.ts +15 -4
- package/dist/lib/stream.d.ts.map +1 -1
- package/dist/lib/transport.d.ts +12 -3
- package/dist/lib/transport.d.ts.map +1 -1
- package/dist/lib/types.d.ts +43 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/webtransport.d.ts +11 -21
- package/dist/lib/webtransport.d.ts.map +1 -1
- package/dist/test/datagrams.spec.d.ts.map +1 -1
- package/dist/test/event-loop.node.d.ts +2 -0
- package/dist/test/event-loop.node.d.ts.map +1 -0
- package/dist/test/fixtures/chai.d.ts.map +1 -1
- package/dist/test/fixtures/known-bytes.d.ts +6 -0
- package/dist/test/fixtures/known-bytes.d.ts.map +1 -0
- package/dist/test/fixtures/read-cert-hash.d.ts +6 -0
- package/dist/test/fixtures/read-cert-hash.d.ts.map +1 -0
- package/dist/test/fixtures/read-stream.d.ts +10 -1
- package/dist/test/fixtures/read-stream.d.ts.map +1 -1
- package/dist/test/fixtures/reader-value.d.ts +16 -1
- package/dist/test/fixtures/reader-value.d.ts.map +1 -1
- package/dist/test/fixtures/server.d.ts +0 -5
- package/dist/test/fixtures/server.d.ts.map +1 -1
- package/dist/test/fixtures/webtransport.browser.d.ts +3 -0
- package/dist/test/fixtures/webtransport.browser.d.ts.map +1 -0
- package/dist/test/fixtures/webtransport.d.ts +3 -0
- package/dist/test/fixtures/webtransport.d.ts.map +1 -0
- package/dist/test/fixtures/write-stream.d.ts.map +1 -1
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/session.spec.d.ts +5 -0
- package/dist/test/session.spec.d.ts.map +1 -0
- package/dist/test/unidirectional-streams.spec.d.ts +1 -4
- package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
- package/lib/client.js +57 -43
- package/lib/dom.ts +18 -4
- package/lib/error.js +10 -0
- package/lib/event-loop.js +8 -5
- package/lib/native.js +4 -1
- package/lib/server.js +18 -10
- package/lib/session.js +145 -32
- package/lib/stream.js +52 -24
- package/lib/transport.js +48 -10
- package/lib/types.ts +53 -5
- package/lib/utils.js +13 -0
- package/lib/webtransport.js +10 -18
- package/{test → old_test}/echoserver.js +1 -2
- package/{test → old_test}/test.js +5 -3
- package/package.json +16 -5
- package/readme.md +64 -0
- package/src/http3client.cc +2 -2
- package/src/http3dispatcher.cc +3 -2
- package/src/http3dispatcher.h +2 -1
- package/src/http3eventloop.cc +106 -2
- package/src/http3eventloop.h +13 -0
- package/src/http3wtsessionvisitor.cc +2 -0
- package/src/http3wtsessionvisitor.h +41 -1
- package/test/bidirectional-streams.spec.js +41 -97
- package/test/datagrams.spec.js +50 -99
- package/test/fixtures/chai.js +2 -0
- package/test/fixtures/known-bytes.js +15 -0
- package/test/fixtures/read-cert-hash.js +7 -0
- package/test/fixtures/read-stream.js +5 -0
- package/test/fixtures/reader-value.js +32 -0
- package/test/fixtures/server.js +237 -21
- package/test/fixtures/webtransport.browser.js +2 -0
- package/test/fixtures/webtransport.js +3 -0
- package/test/fixtures/write-stream.js +8 -1
- package/test/index.js +87 -0
- package/test/session.spec.js +159 -0
- package/test/unidirectional-streams.spec.js +67 -138
- package/tsconfig.json +0 -1
- package/dist/test/echoclient.d.ts +0 -2
- package/dist/test/echoclient.d.ts.map +0 -1
- package/dist/test/echoserver.d.ts +0 -2
- package/dist/test/echoserver.d.ts.map +0 -1
- package/dist/test/event-loop.spec.d.ts +0 -2
- package/dist/test/event-loop.spec.d.ts.map +0 -1
- package/dist/test/test.d.ts +0 -2
- package/dist/test/test.d.ts.map +0 -1
- package/dist/test/testsuite.d.ts +0 -25
- package/dist/test/testsuite.d.ts.map +0 -1
- package/platform/base/strings/utf_ostream_operators.h +0 -5
- /package/{test → old_test}/echoclient.js +0 -0
- /package/{test → old_test}/testsuite.js +0 -0
- /package/test/{event-loop.spec.js → event-loop.node.js} +0 -0
|
@@ -1,189 +1,118 @@
|
|
|
1
1
|
/* eslint-env mocha */
|
|
2
2
|
|
|
3
|
-
import { createServer } from './fixtures/server.js'
|
|
4
3
|
import { getReaderValue } from './fixtures/reader-value.js'
|
|
5
|
-
import
|
|
4
|
+
import WebTransport from './fixtures/webtransport.js'
|
|
6
5
|
import { expect } from 'chai'
|
|
7
6
|
import { readStream } from './fixtures/read-stream.js'
|
|
8
7
|
import { writeStream } from './fixtures/write-stream.js'
|
|
9
|
-
import {
|
|
8
|
+
import { readCertHash } from './fixtures/read-cert-hash.js'
|
|
10
9
|
import * as ui8 from 'uint8arrays'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @template T
|
|
14
|
-
* @typedef {import('../lib/types').Deferred<T>} Deferred<T>
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const SERVER_PATH = '/unidirectional-streams'
|
|
10
|
+
import { KNOWN_BYTES, KNOWN_BYTES_LENGTH } from './fixtures/known-bytes.js'
|
|
18
11
|
|
|
19
12
|
describe('unidirectional streams', function () {
|
|
20
|
-
/** @type {import('../lib/server').Http3Server} */
|
|
21
|
-
let server
|
|
22
|
-
/** @type {import('./fixtures/certificate.js').Certificate} */
|
|
23
|
-
let certificate
|
|
24
13
|
/** @type {import('../lib/dom').WebTransport | undefined} */
|
|
25
14
|
let client
|
|
26
|
-
/** @type {string} */
|
|
27
|
-
let url
|
|
28
|
-
|
|
29
|
-
beforeEach(async () => {
|
|
30
|
-
;({ server, certificate } = await createServer())
|
|
31
|
-
server.startServer()
|
|
32
|
-
await server.ready
|
|
33
|
-
|
|
34
|
-
const address = server.address()
|
|
35
|
-
|
|
36
|
-
if (address == null || address.port == null) {
|
|
37
|
-
throw new Error('No address')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
url = `https://${address.host}:${address.port}`
|
|
41
|
-
})
|
|
42
15
|
|
|
43
16
|
// @ts-ignore
|
|
44
17
|
afterEach(async () => {
|
|
45
18
|
if (client != null) {
|
|
46
19
|
client.close()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (server != null) {
|
|
50
|
-
server.stopServer()
|
|
51
|
-
await server.closed
|
|
20
|
+
client = undefined
|
|
52
21
|
}
|
|
53
22
|
})
|
|
54
23
|
|
|
55
24
|
it('sends data over an outgoing unidirectional stream', async () => {
|
|
56
|
-
this.timeout(200)
|
|
57
|
-
/** @type {Deferred<Uint8Array[]>} */
|
|
58
|
-
const serverData = defer()
|
|
59
|
-
|
|
60
|
-
const input = [
|
|
61
|
-
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
62
|
-
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
63
|
-
Uint8Array.from([10, 11, 12, 13, 14])
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
// server context - waits for the client to open a bidi stream and pipes it back to them
|
|
67
|
-
Promise.resolve().then(async () => {
|
|
68
|
-
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
69
|
-
if (!session) throw new Error('no session')
|
|
70
|
-
const stream = await getReaderValue(session.incomingUnidirectionalStreams)
|
|
71
|
-
|
|
72
|
-
const output = await readStream(stream, ui8.concat(input).length)
|
|
73
|
-
serverData.resolve(output)
|
|
74
|
-
await stream.cancel() // cancel so that the client can progress
|
|
75
|
-
})
|
|
76
|
-
|
|
77
25
|
// client context - connects to the server, opens a bidi stream, sends some data and reads the response
|
|
78
|
-
|
|
79
|
-
|
|
26
|
+
try {
|
|
27
|
+
client = new WebTransport(
|
|
28
|
+
`${process.env.SERVER_URL}/unidirectional_client_send`,
|
|
80
29
|
{
|
|
81
|
-
|
|
82
|
-
|
|
30
|
+
serverCertificateHashes: [
|
|
31
|
+
{
|
|
32
|
+
algorithm: 'sha-256',
|
|
33
|
+
value: readCertHash(process.env.CERT_HASH)
|
|
34
|
+
}
|
|
35
|
+
]
|
|
83
36
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
37
|
+
)
|
|
38
|
+
await client.ready
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log('Peak unidirectional error:', error)
|
|
41
|
+
throw error
|
|
42
|
+
}
|
|
87
43
|
|
|
88
44
|
const stream = await client.createUnidirectionalStream()
|
|
89
|
-
|
|
45
|
+
// correct test
|
|
46
|
+
await writeStream(stream, KNOWN_BYTES)
|
|
90
47
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
48
|
+
// the remote will close the session
|
|
49
|
+
const result = await client.closed
|
|
50
|
+
|
|
51
|
+
// should receive the default close info
|
|
52
|
+
expect(result).to.have.property('reason', '')
|
|
53
|
+
expect(result).to.have.property('closeCode', 0)
|
|
96
54
|
})
|
|
97
55
|
|
|
98
56
|
it('receives data over an incoming unidirectional stream', async () => {
|
|
99
|
-
this.timeout(200)
|
|
100
|
-
const input = [
|
|
101
|
-
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
102
|
-
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
103
|
-
Uint8Array.from([10, 11, 12, 13, 14])
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
// server context - waits for the client to connect, opens a bidi stream, sends some data and reads the response
|
|
107
|
-
Promise.resolve().then(async () => {
|
|
108
|
-
const session = await getReaderValue(server.sessionStream(SERVER_PATH))
|
|
109
|
-
if (!session) throw new Error('no session')
|
|
110
|
-
const stream = await session.createUnidirectionalStream()
|
|
111
|
-
|
|
112
|
-
await writeStream(stream, input)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
57
|
// client context - waits for the server to open a bidi stream then pipes it back to them
|
|
116
|
-
client = new WebTransport(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
58
|
+
client = new WebTransport(
|
|
59
|
+
`${process.env.SERVER_URL}/unidirectional_server_send`,
|
|
60
|
+
{
|
|
61
|
+
serverCertificateHashes: [
|
|
62
|
+
{
|
|
63
|
+
algorithm: 'sha-256',
|
|
64
|
+
value: readCertHash(process.env.CERT_HASH)
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
124
69
|
await client.ready
|
|
125
70
|
|
|
126
71
|
const stream = await getReaderValue(client.incomingUnidirectionalStreams)
|
|
127
|
-
const
|
|
128
|
-
expect(ui8.concat(
|
|
129
|
-
ui8.concat(
|
|
72
|
+
const output = await readStream(stream, KNOWN_BYTES_LENGTH)
|
|
73
|
+
expect(ui8.concat(KNOWN_BYTES)).to.deep.equal(
|
|
74
|
+
ui8.concat(output),
|
|
130
75
|
'Did not receive the same bytes we sent'
|
|
131
76
|
)
|
|
132
77
|
})
|
|
133
78
|
|
|
134
79
|
it('handles fin when paused due to backpressure', async function () {
|
|
135
|
-
this.timeout(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
client = new WebTransport(`${url}${SERVER_PATH}`, {
|
|
149
|
-
serverCertificateHashes: [
|
|
150
|
-
{
|
|
151
|
-
algorithm: 'sha-256',
|
|
152
|
-
value: certificate.hash
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
})
|
|
80
|
+
this.timeout(6000)
|
|
81
|
+
client = new WebTransport(
|
|
82
|
+
`${process.env.SERVER_URL}/unidirectional_server_delay_before_read`,
|
|
83
|
+
{
|
|
84
|
+
serverCertificateHashes: [
|
|
85
|
+
{
|
|
86
|
+
algorithm: 'sha-256',
|
|
87
|
+
value: readCertHash(process.env.CERT_HASH)
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
)
|
|
156
92
|
await client.ready
|
|
157
93
|
|
|
158
94
|
const clientStream = await client.createUnidirectionalStream()
|
|
159
95
|
|
|
160
|
-
const input = [
|
|
161
|
-
Uint8Array.from([0, 1, 2, 3, 4]),
|
|
162
|
-
Uint8Array.from([5, 6, 7, 8, 9]),
|
|
163
|
-
Uint8Array.from([10, 11, 12, 13, 14]),
|
|
164
|
-
Uint8Array.from([15, 16, 17, 18, 19]),
|
|
165
|
-
Uint8Array.from([20, 21, 22, 23, 24])
|
|
166
|
-
]
|
|
167
|
-
|
|
168
96
|
const writer = clientStream.getWriter()
|
|
169
97
|
|
|
170
|
-
for (const buf of
|
|
98
|
+
for (const buf of KNOWN_BYTES) {
|
|
99
|
+
await writer.ready
|
|
171
100
|
await writer.write(buf)
|
|
172
101
|
}
|
|
173
102
|
|
|
174
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
175
|
-
|
|
176
|
-
|
|
103
|
+
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
104
|
+
try {
|
|
105
|
+
await writer.ready
|
|
106
|
+
await writer.close()
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log('Ignore stop sending', error)
|
|
109
|
+
}
|
|
177
110
|
|
|
178
|
-
|
|
111
|
+
// the remote will close the session cleanly if everything was ok
|
|
112
|
+
await client.closed
|
|
179
113
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
expect(ui8.concat(received)).to.deep.equal(
|
|
185
|
-
ui8.concat(input),
|
|
186
|
-
'Did not receive the same bytes we sent'
|
|
187
|
-
)
|
|
114
|
+
// should receive the default close info, not true on chromium
|
|
115
|
+
// expect(result).to.have.property('reason', '')
|
|
116
|
+
// expect(result).to.have.property('closeCode', 0)
|
|
188
117
|
})
|
|
189
118
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"echoclient.d.ts","sourceRoot":"","sources":["../../test/echoclient.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"echoserver.d.ts","sourceRoot":"","sources":["../../test/echoserver.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop.spec.d.ts","sourceRoot":"","sources":["../../test/event-loop.spec.js"],"names":[],"mappings":""}
|
package/dist/test/test.d.ts
DELETED
package/dist/test/test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../test/test.js"],"names":[],"mappings":""}
|
package/dist/test/testsuite.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {import('../lib/dom').WebTransport} session
|
|
3
|
-
*/
|
|
4
|
-
export function incomingBidirectionalEchoTest(session: import('../lib/dom').WebTransport): Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* @param {import('../lib/dom').WebTransport} session
|
|
7
|
-
*/
|
|
8
|
-
export function outgoingBidirectionalEchoTest(session: import('../lib/dom').WebTransport): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* @param {import('../lib/dom').WebTransport} session
|
|
11
|
-
*/
|
|
12
|
-
export function unidirectionalEchoTest(session: import('../lib/dom').WebTransport): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* @param {import('../lib/dom').WebTransport} session
|
|
15
|
-
*/
|
|
16
|
-
export function datagramEchoTest(session: import('../lib/dom').WebTransport): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* @param {import('../lib').Http3Server} server
|
|
19
|
-
*/
|
|
20
|
-
export function runEchoServer(server: import('../lib').Http3Server): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* @param {import('../lib/dom').WebTransport} transport
|
|
23
|
-
*/
|
|
24
|
-
export function echoTestsConnection(transport: import('../lib/dom').WebTransport): Promise<void>;
|
|
25
|
-
//# sourceMappingURL=testsuite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testsuite.d.ts","sourceRoot":"","sources":["../../test/testsuite.js"],"names":[],"mappings":"AAIA;;GAEG;AACH,uDAFW,OAAO,YAAY,EAAE,YAAY,iBAsB3C;AAED;;GAEG;AACH,uDAFW,OAAO,YAAY,EAAE,YAAY,iBAS3C;AAED;;GAEG;AACH,gDAFW,OAAO,YAAY,EAAE,YAAY,iBAuB3C;AAED;;GAEG;AACH,0CAFW,OAAO,YAAY,EAAE,YAAY,iBAQ3C;AAED;;GAEG;AACH,sCAFW,OAAO,QAAQ,EAAE,WAAW,iBAmCtC;AAcD;;GAEG;AACH,+CAFW,OAAO,YAAY,EAAE,YAAY,iBAqM3C"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|