@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.
Files changed (101) hide show
  1. package/CMakeLists.txt +3 -0
  2. package/dist/lib/client.d.ts +7 -3
  3. package/dist/lib/client.d.ts.map +1 -1
  4. package/dist/lib/dom.d.ts +15 -4
  5. package/dist/lib/dom.d.ts.map +1 -1
  6. package/dist/lib/error.d.ts +8 -0
  7. package/dist/lib/error.d.ts.map +1 -0
  8. package/dist/lib/event-loop.d.ts +4 -2
  9. package/dist/lib/event-loop.d.ts.map +1 -1
  10. package/dist/lib/native.d.ts.map +1 -1
  11. package/dist/lib/server.d.ts +5 -2
  12. package/dist/lib/server.d.ts.map +1 -1
  13. package/dist/lib/session.d.ts +36 -23
  14. package/dist/lib/session.d.ts.map +1 -1
  15. package/dist/lib/stream.d.ts +15 -4
  16. package/dist/lib/stream.d.ts.map +1 -1
  17. package/dist/lib/transport.d.ts +12 -3
  18. package/dist/lib/transport.d.ts.map +1 -1
  19. package/dist/lib/types.d.ts +43 -4
  20. package/dist/lib/types.d.ts.map +1 -1
  21. package/dist/lib/utils.d.ts +5 -0
  22. package/dist/lib/utils.d.ts.map +1 -1
  23. package/dist/lib/webtransport.d.ts +11 -21
  24. package/dist/lib/webtransport.d.ts.map +1 -1
  25. package/dist/test/datagrams.spec.d.ts.map +1 -1
  26. package/dist/test/event-loop.node.d.ts +2 -0
  27. package/dist/test/event-loop.node.d.ts.map +1 -0
  28. package/dist/test/fixtures/chai.d.ts.map +1 -1
  29. package/dist/test/fixtures/known-bytes.d.ts +6 -0
  30. package/dist/test/fixtures/known-bytes.d.ts.map +1 -0
  31. package/dist/test/fixtures/read-cert-hash.d.ts +6 -0
  32. package/dist/test/fixtures/read-cert-hash.d.ts.map +1 -0
  33. package/dist/test/fixtures/read-stream.d.ts +10 -1
  34. package/dist/test/fixtures/read-stream.d.ts.map +1 -1
  35. package/dist/test/fixtures/reader-value.d.ts +16 -1
  36. package/dist/test/fixtures/reader-value.d.ts.map +1 -1
  37. package/dist/test/fixtures/server.d.ts +0 -5
  38. package/dist/test/fixtures/server.d.ts.map +1 -1
  39. package/dist/test/fixtures/webtransport.browser.d.ts +3 -0
  40. package/dist/test/fixtures/webtransport.browser.d.ts.map +1 -0
  41. package/dist/test/fixtures/webtransport.d.ts +3 -0
  42. package/dist/test/fixtures/webtransport.d.ts.map +1 -0
  43. package/dist/test/fixtures/write-stream.d.ts.map +1 -1
  44. package/dist/test/index.d.ts +2 -0
  45. package/dist/test/index.d.ts.map +1 -0
  46. package/dist/test/session.spec.d.ts +5 -0
  47. package/dist/test/session.spec.d.ts.map +1 -0
  48. package/dist/test/unidirectional-streams.spec.d.ts +1 -4
  49. package/dist/test/unidirectional-streams.spec.d.ts.map +1 -1
  50. package/lib/client.js +57 -43
  51. package/lib/dom.ts +18 -4
  52. package/lib/error.js +10 -0
  53. package/lib/event-loop.js +8 -5
  54. package/lib/native.js +4 -1
  55. package/lib/server.js +18 -10
  56. package/lib/session.js +145 -32
  57. package/lib/stream.js +52 -24
  58. package/lib/transport.js +48 -10
  59. package/lib/types.ts +53 -5
  60. package/lib/utils.js +13 -0
  61. package/lib/webtransport.js +10 -18
  62. package/{test → old_test}/echoserver.js +1 -2
  63. package/{test → old_test}/test.js +5 -3
  64. package/package.json +16 -5
  65. package/readme.md +64 -0
  66. package/src/http3client.cc +2 -2
  67. package/src/http3dispatcher.cc +3 -2
  68. package/src/http3dispatcher.h +2 -1
  69. package/src/http3eventloop.cc +106 -2
  70. package/src/http3eventloop.h +13 -0
  71. package/src/http3wtsessionvisitor.cc +2 -0
  72. package/src/http3wtsessionvisitor.h +41 -1
  73. package/test/bidirectional-streams.spec.js +41 -97
  74. package/test/datagrams.spec.js +50 -99
  75. package/test/fixtures/chai.js +2 -0
  76. package/test/fixtures/known-bytes.js +15 -0
  77. package/test/fixtures/read-cert-hash.js +7 -0
  78. package/test/fixtures/read-stream.js +5 -0
  79. package/test/fixtures/reader-value.js +32 -0
  80. package/test/fixtures/server.js +237 -21
  81. package/test/fixtures/webtransport.browser.js +2 -0
  82. package/test/fixtures/webtransport.js +3 -0
  83. package/test/fixtures/write-stream.js +8 -1
  84. package/test/index.js +87 -0
  85. package/test/session.spec.js +159 -0
  86. package/test/unidirectional-streams.spec.js +67 -138
  87. package/tsconfig.json +0 -1
  88. package/dist/test/echoclient.d.ts +0 -2
  89. package/dist/test/echoclient.d.ts.map +0 -1
  90. package/dist/test/echoserver.d.ts +0 -2
  91. package/dist/test/echoserver.d.ts.map +0 -1
  92. package/dist/test/event-loop.spec.d.ts +0 -2
  93. package/dist/test/event-loop.spec.d.ts.map +0 -1
  94. package/dist/test/test.d.ts +0 -2
  95. package/dist/test/test.d.ts.map +0 -1
  96. package/dist/test/testsuite.d.ts +0 -25
  97. package/dist/test/testsuite.d.ts.map +0 -1
  98. package/platform/base/strings/utf_ostream_operators.h +0 -5
  99. /package/{test → old_test}/echoclient.js +0 -0
  100. /package/{test → old_test}/testsuite.js +0 -0
  101. /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 { WebTransport } from '../lib/index.js'
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 { defer } from '../lib/utils.js'
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
- client = new WebTransport(`${url}${SERVER_PATH}`, {
79
- serverCertificateHashes: [
26
+ try {
27
+ client = new WebTransport(
28
+ `${process.env.SERVER_URL}/unidirectional_client_send`,
80
29
  {
81
- algorithm: 'sha-256',
82
- value: certificate.hash
30
+ serverCertificateHashes: [
31
+ {
32
+ algorithm: 'sha-256',
33
+ value: readCertHash(process.env.CERT_HASH)
34
+ }
35
+ ]
83
36
  }
84
- ]
85
- })
86
- await client.ready
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
- await writeStream(stream, input)
45
+ // correct test
46
+ await writeStream(stream, KNOWN_BYTES)
90
47
 
91
- const received = await serverData.promise
92
- expect(ui8.concat(received)).to.deep.equal(
93
- ui8.concat(input),
94
- 'Server did not receive the same bytes we sent'
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(`${url}${SERVER_PATH}`, {
117
- serverCertificateHashes: [
118
- {
119
- algorithm: 'sha-256',
120
- value: certificate.hash
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 received = await readStream(stream, ui8.concat(input).length)
128
- expect(ui8.concat(received)).to.deep.equal(
129
- ui8.concat(input),
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(10000)
136
-
137
- /** @type {Deferred<ReadableStream>} */
138
- const serverStream = defer()
139
-
140
- Promise.resolve().then(async () => {
141
- const session = await getReaderValue(server.sessionStream(SERVER_PATH))
142
- if (!session) throw new Error('Got no session')
143
- const stream = await getReaderValue(session.incomingUnidirectionalStreams)
144
-
145
- serverStream.resolve(stream)
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 input) {
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, 1000))
175
-
176
- await writer.close()
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
- await new Promise((resolve) => setTimeout(resolve, 1000))
111
+ // the remote will close the session cleanly if everything was ok
112
+ await client.closed
179
113
 
180
- const received = await readStream(
181
- await serverStream.promise,
182
- ui8.concat(input).length
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
@@ -27,7 +27,6 @@
27
27
  "noUnusedLocals": true,
28
28
  "noUnusedParameters": false,
29
29
  // advanced
30
- "importsNotUsedAsValues": "error",
31
30
  "forceConsistentCasingInFileNames": true,
32
31
  "skipLibCheck": true,
33
32
  "stripInternal": true,
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=echoclient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"echoclient.d.ts","sourceRoot":"","sources":["../../test/echoclient.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=echoserver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"echoserver.d.ts","sourceRoot":"","sources":["../../test/echoserver.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=event-loop.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-loop.spec.d.ts","sourceRoot":"","sources":["../../test/event-loop.spec.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../test/test.js"],"names":[],"mappings":""}
@@ -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"}
@@ -1,5 +0,0 @@
1
- // adds string to the includes of google url
2
- #include <string>
3
- #warning "Fake utf_stream_operators.h included"
4
-
5
- #include "third_party/googleurl/base/strings/utf_ostream_operators.h"
File without changes
File without changes
File without changes