Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quic"
version = "1.3.10"
version = "1.3.12"
authors = ["Roger Qiu <[email protected]>"]
license-file = "LICENSE"
edition = "2021"
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matrixai/quic",
"version": "1.3.10",
"version": "1.3.12",
"author": "Matrix AI",
"contributors": [
{
Expand Down Expand Up @@ -48,11 +48,11 @@
"ip-num": "^1.5.0"
},
"optionalDependencies": {
"@matrixai/quic-darwin-arm64": "1.3.10",
"@matrixai/quic-darwin-universal": "1.3.10",
"@matrixai/quic-darwin-x64": "1.3.10",
"@matrixai/quic-linux-x64": "1.3.10",
"@matrixai/quic-win32-x64": "1.3.10"
"@matrixai/quic-darwin-arm64": "1.3.12",
"@matrixai/quic-darwin-universal": "1.3.12",
"@matrixai/quic-darwin-x64": "1.3.12",
"@matrixai/quic-linux-x64": "1.3.12",
"@matrixai/quic-win32-x64": "1.3.12"
},
"devDependencies": {
"@fast-check/jest": "^1.1.0",
Expand Down
122 changes: 82 additions & 40 deletions src/QUICConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ class QUICConnection {
*/
protected streamIdServerUni: StreamId = 0b11 as StreamId;

/**
* Tracks the highest StreamId that has a created QUICStream for clientBidi
*/
protected streamIdUsedClientBidi = -1 as StreamId;

/**
* Tracks the highest StreamId that has a created QUICStream for serverBidi
*/
protected streamIdUsedServerBidi = -1 as StreamId;

/**
* Tracks the highest StreamId that has a created QUICStream for clientUni
*/
protected streamIdUsedClientUni = -1 as StreamId;

/**
* Tracks the highest StreamId that has a created QUICStream for clientUni
*/
protected streamIdUsedServerUni = -1 as StreamId;

/**
* Quiche connection timer. This performs time delayed state transitions.
*/
Expand Down Expand Up @@ -967,6 +987,30 @@ class QUICConnection {
}
}

protected isStreamUsed(streamId: StreamId): boolean {
const type = 0b11 & streamId;
switch (type) {
case 0b00:
if (streamId <= this.streamIdUsedClientBidi) return true;
this.streamIdUsedClientBidi = streamId;
return false;
case 0b01:
if (streamId <= this.streamIdUsedServerBidi) return true;
this.streamIdUsedServerBidi = streamId;
return false;
case 0b10:
if (streamId <= this.streamIdUsedClientUni) return true;
this.streamIdUsedClientUni = streamId;
return false;
case 0b11:
if (streamId <= this.streamIdUsedServerUni) return true;
this.streamIdUsedServerUni = streamId;
return false;
default:
utils.never('got an unexpected ID type');
}
}

protected processStreams() {
for (const streamId of this.conn.readable() as Iterable<StreamId>) {
let quicStream = this.streamMap.get(streamId);
Expand All @@ -985,7 +1029,9 @@ class QUICConnection {
);
continue;
}

if (this.isStreamUsed(streamId)) {
utils.never('We should never repeat streamIds when creating streams');
}
quicStream = QUICStream.createQUICStream({
initiated: 'peer',
streamId,
Expand Down Expand Up @@ -1029,47 +1075,40 @@ class QUICConnection {
);
continue;
}
try {
this.conn.streamSend(streamId, Buffer.alloc(0), false);
utils.never(
'We never expect the stream to be writable if it was created during the writable iterator',
);
} catch (e) {
// If we got `FinalSize` during the writable iterator then we cleaned up an errant stream
if (e.message === 'FinalSize') continue;
if (utils.isStreamStopped(e) !== false) {
// In this case it was a stream that was created but errored out. We want to create a new stream for this one case.
quicStream = QUICStream.createQUICStream({
initiated: 'peer',
streamId,
config: this.config,
connection: this,
codeToReason: this.codeToReason,
reasonToCode: this.reasonToCode,
logger: this.logger.getChild(`${QUICStream.name} ${streamId}`),
});
this.streamMap.set(quicStream.streamId, quicStream);
quicStream.addEventListener(
events.EventQUICStreamSend.name,
this.handleEventQUICStreamSend,
);
quicStream.addEventListener(
events.EventQUICStreamDestroyed.name,
this.handleEventQUICStreamDestroyed,
{ once: true },
);
quicStream.addEventListener(
EventAll.name,
this.handleEventQUICStream,
);
this.dispatchEvent(
new events.EventQUICConnectionStream({ detail: quicStream }),
);
quicStream.write();
continue;
if (this.isStreamUsed(streamId)) {
try {
this.conn.streamSend(streamId, new Uint8Array(), false);
} catch (e) {
// Both `StreamStopped()` and `FinalSize` errors means that the stream has ended and we cleaned up state
if (utils.isStreamStopped(e) !== false) continue;
if (e.message === 'FinalSize') continue;
throw e;
}
utils.never(`Expected to throw "FinalSize", got ${e.message}`);
utils.never('We never expect a duplicate stream to be readable');
}
quicStream = QUICStream.createQUICStream({
initiated: 'peer',
streamId,
config: this.config,
connection: this,
codeToReason: this.codeToReason,
reasonToCode: this.reasonToCode,
logger: this.logger.getChild(`${QUICStream.name} ${streamId}`),
});
this.streamMap.set(quicStream.streamId, quicStream);
quicStream.addEventListener(
events.EventQUICStreamSend.name,
this.handleEventQUICStreamSend,
);
quicStream.addEventListener(
events.EventQUICStreamDestroyed.name,
this.handleEventQUICStreamDestroyed,
{ once: true },
);
quicStream.addEventListener(EventAll.name, this.handleEventQUICStream);
this.dispatchEvent(
new events.EventQUICConnectionStream({ detail: quicStream }),
);
}
quicStream.write();
}
Expand Down Expand Up @@ -1178,6 +1217,9 @@ class QUICConnection {
} else if (this.type === 'server' && type === 'uni') {
streamId = this.streamIdServerUni;
}
if (this.isStreamUsed(streamId!)) {
utils.never('We should never repeat streamIds when creating streams');
}
const quicStream = QUICStream.createQUICStream({
initiated: 'local',
streamId: streamId!,
Expand Down
2 changes: 1 addition & 1 deletion tests/QUICStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as testsUtils from './utils';
import { generateTLSConfig, sleep } from './utils';

describe(QUICStream.name, () => {
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.INFO, [
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.WARN, [
new StreamHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
),
Expand Down
Loading