Skip to content

Commit 056387e

Browse files
committed
fix: cleaned up logging
* Related #14 [ci skip]
1 parent 31212dc commit 056387e

File tree

1 file changed

+6
-61
lines changed

1 file changed

+6
-61
lines changed

src/QUICStream.ts

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class QUICStream
5454
// This resolves when `streamRecv` results in a `StreamReset(u64)` or a fin flag indicating receiving has ended
5555
protected recvFinishedProm = utils.promise<void>();
5656

57-
protected sentBytes: number = 0;
58-
protected recvBytes: number = 0;
59-
6057
/**
6158
* For `reasonToCode`, return 0 means "unknown reason"
6259
* It is the catch-all for codes.
@@ -131,13 +128,6 @@ class QUICStream
131128
this.reasonToCode = reasonToCode;
132129
this.codeToReason = codeToReason;
133130

134-
this.sendFinishedProm.p.finally(() =>
135-
logger.info('sendFinishedProm resolved'),
136-
);
137-
this.recvFinishedProm.p.finally(() =>
138-
logger.info('recvFinishedProm resolved'),
139-
);
140-
141131
this.readable = new ReadableStream(
142132
{
143133
type: 'bytes',
@@ -146,7 +136,6 @@ class QUICStream
146136
this.readableController = controller;
147137
},
148138
pull: async () => {
149-
this.logger.info('doing pull');
150139
this._recvPaused = false;
151140
},
152141
cancel: async (reason) => {
@@ -173,7 +162,7 @@ class QUICStream
173162
// with the `fin` set to true
174163
// If this itself results in an error, we can continue
175164
// But continue to do the below
176-
this.logger.info('sending fin frame');
165+
this.logger.debug('sending fin frame');
177166
// This.sendFinishedProm.resolveP();
178167
await this.streamSend(Buffer.from([0]), true).catch((e) => {
179168
// Ignore send error if stream is already closed
@@ -350,15 +339,13 @@ class QUICStream
350339
void this.closeSend(true, err).catch(() => {});
351340
}
352341
});
353-
this.logger.debug('send FINISHED');
354342
return true;
355343
}
356344
}
357345

358346
protected async streamRecv(): Promise<void> {
359347
const buf = Buffer.alloc(1024);
360348
let recvLength: number, fin: boolean;
361-
this.logger.debug('trying receiving');
362349
while (true) {
363350
try {
364351
[recvLength, fin] = this.conn.streamRecv(this.streamId, buf);
@@ -374,7 +361,7 @@ class QUICStream
374361
// This should never be reported... (this branch should be dead code)
375362
return;
376363
} else {
377-
this.logger.info(`Stream recv reported: error ${e.message}`);
364+
this.logger.debug(`Stream recv reported: error ${e.message}`);
378365
// Signal receiving has ended
379366
this.recvFinishedProm.resolveP();
380367
if (!this._recvClosed) {
@@ -394,27 +381,20 @@ class QUICStream
394381
return;
395382
}
396383
}
397-
this.recvBytes += recvLength;
398-
this.logger.info(`recv bytes ${this.recvBytes}`);
399-
this.logger.info(`fin? ${fin}`);
400384
// If fin is true, then that means, the stream is CLOSED
401385
if (!fin) {
402386
// Send the data normally
403387
if (!this._recvClosed) {
404388
this.readableController.enqueue(buf.subarray(0, recvLength));
405389
}
406390
} else {
407-
this.logger.info('finishing');
408391
// Strip the end message, removing the null byte
409392
if (!this._recvClosed && recvLength > 1) {
410-
this.logger.info('finish contained message');
411393
this.readableController.enqueue(buf.subarray(0, recvLength - 1));
412394
}
413395
// This will render `stream.cancel` a noop
414-
this.logger.info('closing');
415396
if (!this._recvClosed) this.readableController.close();
416397
await this.closeRecv();
417-
this.logger.info('closed');
418398
// Signal receiving has ended
419399
this.recvFinishedProm.resolveP();
420400
return;
@@ -472,8 +452,6 @@ class QUICStream
472452
}
473453
}
474454
}
475-
if (sentLength > 0) this.sentBytes += sentLength;
476-
this.logger.info(`sent bytes ${this.sentBytes}`);
477455
if (sentLength < chunk.length) {
478456
const { p: writableP, resolveP: resolveWritableP } = utils.promise();
479457
this.resolveWritableP = resolveWritableP;
@@ -495,10 +473,10 @@ class QUICStream
495473
isError: boolean = false,
496474
reason?: any,
497475
): Promise<void> {
498-
if (isError) this.logger.info(`recv closed with error ${reason.message}`);
476+
if (isError) this.logger.debug(`recv closed with error ${reason.message}`);
499477
// Further closes are NOPs
500478
if (this._recvClosed) return;
501-
this.logger.info(`Close Recv`);
479+
this.logger.debug(`Close Recv`);
502480
// Indicate that the receiving side is closed
503481
this._recvClosed = true;
504482
const code = isError ? await this.reasonToCode('send', reason) : 0;
@@ -530,10 +508,10 @@ class QUICStream
530508
isError: boolean = false,
531509
reason?: any,
532510
): Promise<void> {
533-
if (isError) this.logger.info(`send closed with error ${reason.message}`);
511+
if (isError) this.logger.debug(`send closed with error ${reason.message}`);
534512
// Further closes are NOPs
535513
if (this._sendClosed) return;
536-
this.logger.info(`Close Send`);
514+
this.logger.debug(`Close Send`);
537515
// Indicate that the sending side is closed
538516
this._sendClosed = true;
539517
// If the QUIC stream is already closed
@@ -580,39 +558,6 @@ class QUICStream
580558
}
581559
return null;
582560
}
583-
584-
static checkStreamStates(
585-
conn: Connection,
586-
streamId: number,
587-
message: string,
588-
logger: Logger,
589-
) {
590-
const fin = conn.streamFinished(streamId);
591-
const read = conn.streamReadable(streamId);
592-
let write: boolean | string;
593-
try {
594-
write = conn.streamWritable(streamId, 0);
595-
} catch (e) {
596-
write = e.message;
597-
}
598-
let cap: number | string;
599-
try {
600-
cap = conn.streamCapacity(streamId);
601-
} catch (e) {
602-
cap = e.message;
603-
}
604-
let readIter = false;
605-
for (const id of conn.readable()) {
606-
if (streamId === id) readIter = true;
607-
}
608-
let writeIter = false;
609-
for (const id of conn.writable()) {
610-
if (streamId === id) writeIter = true;
611-
}
612-
logger.info(
613-
`Stream states (${message}) iterRW(${readIter}, ${writeIter}),finished(${fin}), read(${read}), write(${write}), capacity(${cap})`,
614-
);
615-
}
616561
}
617562

618563
export default QUICStream;

0 commit comments

Comments
 (0)