Skip to content

Commit 5fcdba4

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
tests: added tests for tolerating corrupt packet data
* Fixes #4 [ci skip]
1 parent 37b65ef commit 5fcdba4

File tree

3 files changed

+425
-25
lines changed

3 files changed

+425
-25
lines changed

src/QUICConnection.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ class QUICConnection extends EventTarget {
347347
}
348348
// Sending if
349349
await this.send();
350-
this.logger.debug(
351-
`state are draining: ${this.conn.isDraining()}, closed: ${this.conn.isClosed()}`,
352-
);
353350
// If it is not closed, it could still be draining
354351
this.logger.debug('Waiting for closeP');
355352
await this.closedP;
@@ -494,18 +491,11 @@ class QUICConnection extends EventTarget {
494491
}
495492
} finally {
496493
this.logger.debug('RECV FINALLY');
497-
this.logger.debug(
498-
` ________ ED: ${this.conn.isInEarlyData()} TO: ${this.conn.isTimedOut()} EST: ${this.conn.isEstablished()}`,
499-
);
500-
501494
// Set the timeout
502495
this.checkTimeout();
503496
// If this call wasn't executed in the midst of a destroy
504497
// and yet the connection is closed or is draining, then
505498
// we need to destroy this connection
506-
this.logger.debug(
507-
`state are draining: ${this.conn.isDraining()}, closed: ${this.conn.isClosed()}`,
508-
);
509499
if (
510500
this[status] !== 'destroying' &&
511501
(this.conn.isClosed() || this.conn.isDraining())
@@ -699,9 +689,6 @@ class QUICConnection extends EventTarget {
699689
this.deadline = Infinity;
700690
// Doing timeout actions
701691
this.conn.onTimeout();
702-
this.logger.debug(
703-
`state are draining: ${this.conn.isDraining()}, closed: ${this.conn.isClosed()}`,
704-
);
705692
if (this[destroyed] === false) await this.send();
706693
if (
707694
this[status] !== 'destroying' &&
@@ -728,36 +715,34 @@ class QUICConnection extends EventTarget {
728715
this.logger.debug('timeout checking timeout');
729716
// During construction, this ends up being null
730717
const time = this.conn.timeout();
731-
this.logger.debug(`timeout time ${time}`);
732718
if (time == null) {
733719
// Clear timeout
734-
this.logger.debug('timeout clearing timeout');
720+
if (this.timer != null) this.logger.debug('timeout clearing timeout');
735721
clearTimeout(this.timer);
736722
delete this.timer;
737723
this.deadline = Infinity;
738724
} else {
739725
const newDeadline = Date.now() + time;
740726
if (this.timer != null) {
741-
this.logger.debug('timeout already running');
742727
if (time === 0) {
743-
this.logger.debug('timeout instant timeout');
728+
this.logger.debug('timeout triggering instant timeout');
744729
// Skip timer and call onTimeout
745730
setImmediate(this.onTimeout);
746731
} else if (newDeadline < this.deadline) {
747-
this.logger.debug(`timeout updating timer`);
732+
this.logger.debug(`timeout updating timer with ${time} delay`);
748733
clearTimeout(this.timer);
749734
delete this.timer;
750735
this.deadline = newDeadline;
751736
this.timer = setTimeout(this.onTimeout, time);
752737
}
753738
} else {
754739
if (time === 0) {
755-
this.logger.debug('timeout instant timeout');
740+
this.logger.debug('timeout triggering instant timeout');
756741
// Skip timer and call onTimeout
757742
setImmediate(this.onTimeout);
758743
return;
759744
}
760-
this.logger.debug('timeout creating timer');
745+
this.logger.debug(`timeout creating timer with ${time} delay`);
761746
this.deadline = newDeadline;
762747
this.timer = setTimeout(this.onTimeout, time);
763748
}

src/QUICServer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,13 @@ class QUICServer extends EventTarget {
371371
this.addEventListener('connection', handleEstablished);
372372
try {
373373
while (!established && !timedOut) {
374-
await this.socket.send('hello!', remoteInfo.port, remoteInfo.host);
374+
const message = new ArrayBuffer(32);
375+
await this.crypto.ops.randomBytes(message);
376+
await this.socket.send(
377+
Buffer.from(message),
378+
remoteInfo.port,
379+
remoteInfo.host,
380+
);
375381
sleepProm = promise<void>();
376382
delayTimer = setTimeout(() => sleepProm!.resolveP(), delay);
377383
delay *= 2;

0 commit comments

Comments
 (0)