@fails-components/webtransport 1.6.8 → 1.6.10
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/lib/http2/browser/browserparser.d.ts +12 -15
- package/dist/lib/http2/browser/browserparser.d.ts.map +1 -1
- package/dist/lib/http2/bufferHelper.d.ts +178 -0
- package/dist/lib/http2/bufferHelper.d.ts.map +1 -0
- package/dist/lib/http2/node/capsuleparser.d.ts +12 -6
- package/dist/lib/http2/node/capsuleparser.d.ts.map +1 -1
- package/dist/lib/http2/node/websocketparser.d.ts +24 -14
- package/dist/lib/http2/node/websocketparser.d.ts.map +1 -1
- package/dist/lib/http2/parserbase.d.ts +2 -7
- package/dist/lib/http2/parserbase.d.ts.map +1 -1
- package/dist/lib/http2/parserbasehttp2.d.ts +0 -25
- package/dist/lib/http2/parserbasehttp2.d.ts.map +1 -1
- package/dist/lib/http2/stream.d.ts +2 -2
- package/dist/lib/http2/stream.d.ts.map +1 -1
- package/eslint.config.js +1 -1
- package/lib/http2/browser/browserparser.js +53 -89
- package/lib/http2/bufferHelper.js +269 -0
- package/lib/http2/node/capsuleparser.js +69 -61
- package/lib/http2/node/server.js +1 -1
- package/lib/http2/node/websocketparser.js +266 -253
- package/lib/http2/parserbase.js +13 -18
- package/lib/http2/parserbasehttp2.js +12 -67
- package/lib/http2/stream.js +19 -9
- package/lib/session.js +1 -1
- package/package.json +1 -1
package/lib/http2/parserbase.js
CHANGED
|
@@ -5,18 +5,6 @@ import { PriorityScheduler } from './priorityscheduler.js'
|
|
|
5
5
|
const pid = typeof process !== 'undefined' ? process.pid : 0
|
|
6
6
|
const log = logger(`webtransport:parserbase(${pid})`)
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @param{Number|bigint} int
|
|
10
|
-
* @returns {Number}
|
|
11
|
-
*/
|
|
12
|
-
export function lengthVarInt(int) {
|
|
13
|
-
if (BigInt(int) < 64n) return 1
|
|
14
|
-
if (BigInt(int) < 16384n) return 2
|
|
15
|
-
if (BigInt(int) < 1073741824n) return 4
|
|
16
|
-
/* if (BigInt(int) < 4611686018427387904 ) */
|
|
17
|
-
return 8
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
export class ParserBase {
|
|
21
9
|
static PADDING = 0x190b4d38
|
|
22
10
|
static WT_RESET_STREAM = 0x190b4d39
|
|
@@ -66,7 +54,7 @@ export class ParserBase {
|
|
|
66
54
|
|
|
67
55
|
/**
|
|
68
56
|
* @abstract
|
|
69
|
-
* @param {
|
|
57
|
+
* @param {Uint8Array[]} data
|
|
70
58
|
*/
|
|
71
59
|
// eslint-disable-next-line no-unused-vars
|
|
72
60
|
parseData(data) {
|
|
@@ -282,10 +270,17 @@ export class ParserBase {
|
|
|
282
270
|
* @param {{code: number, reason: string}} opts
|
|
283
271
|
*/
|
|
284
272
|
onCloseWebTransportSession({ code, reason }) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
273
|
+
if (
|
|
274
|
+
!(
|
|
275
|
+
this.session.jsobj.state === 'failed' ||
|
|
276
|
+
this.session.jsobj.state === 'closed'
|
|
277
|
+
)
|
|
278
|
+
) {
|
|
279
|
+
this.session.jsobj.onClose({
|
|
280
|
+
errorcode: code,
|
|
281
|
+
error: reason
|
|
282
|
+
})
|
|
283
|
+
}
|
|
289
284
|
this.closeHttp2Stream(code) // is this necessary
|
|
290
285
|
}
|
|
291
286
|
|
|
@@ -315,7 +310,7 @@ export class ParserBase {
|
|
|
315
310
|
*/
|
|
316
311
|
removeStream(streamid) {
|
|
317
312
|
this.scheduler.Unregister(streamid)
|
|
318
|
-
|
|
313
|
+
this.wtstreams.delete(streamid)
|
|
319
314
|
}
|
|
320
315
|
|
|
321
316
|
/**
|
|
@@ -4,68 +4,6 @@ import { ParserBase } from './parserbase.js'
|
|
|
4
4
|
* @typedef {import('node:http2').Http2Stream} Http2Stream
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @param{{offset: Number, buffer: Buffer, size: Number}} bs
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export function readUint32(bs) {
|
|
12
|
-
if (bs.offset + 4 > bs.size) return undefined
|
|
13
|
-
const toret = bs.buffer.readUInt32BE(bs.offset)
|
|
14
|
-
bs.offset += 4
|
|
15
|
-
return toret
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param{{offset: Number, buffer: Buffer, size: Number}} bs
|
|
20
|
-
*/
|
|
21
|
-
export function readVarInt(bs) {
|
|
22
|
-
if (bs.offset + 1 > bs.size) return undefined
|
|
23
|
-
let val = BigInt(bs.buffer.readUInt8(bs.offset))
|
|
24
|
-
bs.offset++
|
|
25
|
-
const prefix = Number(val) >>> 6
|
|
26
|
-
const intlength = 1 << prefix
|
|
27
|
-
|
|
28
|
-
if (bs.offset + intlength - 1 > bs.size) {
|
|
29
|
-
return undefined
|
|
30
|
-
}
|
|
31
|
-
val = val & 0x3fn
|
|
32
|
-
for (let i = 0; i < intlength - 1; i++) {
|
|
33
|
-
val = (val << 8n) | BigInt(bs.buffer.readUInt8(bs.offset))
|
|
34
|
-
bs.offset++
|
|
35
|
-
}
|
|
36
|
-
return val
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param{{offset: Number, buffer: Buffer, size: Number}} bs
|
|
41
|
-
* @param{Number|bigint} int
|
|
42
|
-
*/
|
|
43
|
-
export function writeVarInt(bs, int) {
|
|
44
|
-
let numbytes = 8n
|
|
45
|
-
let msb = 0xc0n
|
|
46
|
-
const bint = BigInt(int)
|
|
47
|
-
if (bint < 64) {
|
|
48
|
-
numbytes = 1n
|
|
49
|
-
msb = 0x0n
|
|
50
|
-
} else if (bint < 16384) {
|
|
51
|
-
numbytes = 2n
|
|
52
|
-
msb = 0x40n
|
|
53
|
-
} else if (bint < 1073741824) {
|
|
54
|
-
numbytes = 4n
|
|
55
|
-
msb = 0x80n
|
|
56
|
-
}
|
|
57
|
-
bs.buffer.writeUInt8(
|
|
58
|
-
Number(msb | ((bint >> ((numbytes - 1n) * 8n)) & 0xffn)),
|
|
59
|
-
bs.offset
|
|
60
|
-
)
|
|
61
|
-
bs.offset++
|
|
62
|
-
|
|
63
|
-
for (let i = numbytes - 2n; i >= 0; i--) {
|
|
64
|
-
bs.buffer.writeUInt8(Number((bint >> (i * 8n)) & 0xffn), bs.offset)
|
|
65
|
-
bs.offset++
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
7
|
export class ParserBaseHttp2 extends ParserBase {
|
|
70
8
|
/**
|
|
71
9
|
* @param {import('../types').ParserHttp2Init} stream
|
|
@@ -96,7 +34,7 @@ export class ParserBaseHttp2 extends ParserBase {
|
|
|
96
34
|
this.stream.on('readable', () => {
|
|
97
35
|
let data
|
|
98
36
|
while ((data = this.stream.read()) !== null) {
|
|
99
|
-
this.parseData(data)
|
|
37
|
+
this.parseData([data])
|
|
100
38
|
}
|
|
101
39
|
})
|
|
102
40
|
|
|
@@ -110,10 +48,17 @@ export class ParserBaseHttp2 extends ParserBase {
|
|
|
110
48
|
* @param {Error} error
|
|
111
49
|
*/ (error) => {
|
|
112
50
|
// readable error
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
51
|
+
if (
|
|
52
|
+
!(
|
|
53
|
+
this.session.jsobj.state === 'failed' ||
|
|
54
|
+
this.session.jsobj.state === 'closed'
|
|
55
|
+
)
|
|
56
|
+
) {
|
|
57
|
+
this.session.jsobj.onClose({
|
|
58
|
+
errorcode: this.stream.rstCode,
|
|
59
|
+
error: error.toString()
|
|
60
|
+
})
|
|
61
|
+
}
|
|
117
62
|
}
|
|
118
63
|
)
|
|
119
64
|
|
package/lib/http2/stream.js
CHANGED
|
@@ -92,17 +92,26 @@ export class Http2WebTransportStream {
|
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* @param {Object} obj
|
|
95
|
-
* @param {Uint8Array|undefined} obj.data
|
|
95
|
+
* @param {Uint8Array[]|undefined} obj.data
|
|
96
96
|
* @param {Boolean} obj.fin
|
|
97
97
|
*/
|
|
98
98
|
recvData({ data, fin }) {
|
|
99
|
-
|
|
100
|
-
if (data
|
|
101
|
-
const
|
|
102
|
-
data
|
|
103
|
-
|
|
99
|
+
let datasize = 0
|
|
100
|
+
if (data) {
|
|
101
|
+
const newincomdata = data.map((el, ind, array) => ({
|
|
102
|
+
data: el,
|
|
103
|
+
fin: fin && ind + 1 === array.length
|
|
104
|
+
}))
|
|
105
|
+
datasize = data.reduce((acc, curVal) => acc + curVal.byteLength, 0)
|
|
106
|
+
this.incomdata.push(...newincomdata)
|
|
107
|
+
} else if (fin) {
|
|
108
|
+
this.incomdata.push({ data: undefined, fin })
|
|
109
|
+
}
|
|
110
|
+
if (datasize > 0) {
|
|
111
|
+
const checkstream =
|
|
112
|
+
this.flowController.updateHighestReceivedOffset(datasize)
|
|
104
113
|
const checksession =
|
|
105
|
-
this.sessionFlowController.updateHighestReceivedOffset(
|
|
114
|
+
this.sessionFlowController.updateHighestReceivedOffset(datasize)
|
|
106
115
|
if (checksession && checkstream) {
|
|
107
116
|
// As the highest received offset has changed, check to see if this is a
|
|
108
117
|
// violation of flow control.
|
|
@@ -242,13 +251,14 @@ export class Http2WebTransportStream {
|
|
|
242
251
|
onClose() {
|
|
243
252
|
// ok, inform our session id manager
|
|
244
253
|
this.streamIdManager.onStreamClosed(this.streamid)
|
|
254
|
+
// also remove from capsule parser
|
|
255
|
+
this.capsuleParser.removeStream(this.streamid)
|
|
245
256
|
}
|
|
246
257
|
|
|
247
258
|
/**
|
|
248
259
|
* @param {Number} code
|
|
249
260
|
*/
|
|
250
261
|
stopSending(code) {
|
|
251
|
-
this.closeIncoming()
|
|
252
262
|
this.capsuleParser.writeCapsule({
|
|
253
263
|
type: ParserBase.WT_STOP_SENDING,
|
|
254
264
|
headerVints: [this.streamid, code],
|
|
@@ -366,7 +376,7 @@ export class Http2WebTransportStream {
|
|
|
366
376
|
}
|
|
367
377
|
}
|
|
368
378
|
if (finsend) {
|
|
369
|
-
this.
|
|
379
|
+
this.closeOutgoing()
|
|
370
380
|
return
|
|
371
381
|
}
|
|
372
382
|
|
package/lib/session.js
CHANGED
|
@@ -545,7 +545,7 @@ export class HttpWTSession {
|
|
|
545
545
|
onClose(args) {
|
|
546
546
|
delete this.objint // not valid any more
|
|
547
547
|
|
|
548
|
-
if (this.state !== 'connected') {
|
|
548
|
+
if (this.state !== 'connected' && this.state !== 'draining') {
|
|
549
549
|
log.error(
|
|
550
550
|
'session was closed before state was "connected" - it was "%s"',
|
|
551
551
|
this.state
|