Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
velzie committed Dec 26, 2024
2 parents 4327699 + aec72bc commit ea429ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/connection/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ export class Decryptor {
seed(iv: Uint8Array) {
// this.roundkeys = keygen(iv);
// this.feedback = new Uint8Array(iv);
const start = performance.now();
this.aesCfb = new CFBDecryptor(iv, iv, 1);
console.log("Took " + (performance.now() - start) + " to seed Decryptor");
}

constructor() {
Expand All @@ -422,7 +424,9 @@ export class Decryptor {
controller.enqueue(chunk);
return;
}
const start = performance.now();
controller.enqueue(new Buffer(this.aesCfb.decrypt(chunk.inner)));
console.log("Took " + (performance.now() - start) + " to transform chunk of size " + chunk.length + " (Decryption)");
},
});
}
Expand All @@ -437,7 +441,9 @@ export class Encryptor {
seed(iv: Uint8Array) {
// this.roundkeys = keygen(iv);
// this.feedback = new Uint8Array(iv);
const start = performance.now();
this.aesCfb = new CFBEncryptor(iv, iv, 1);
console.log("Took " + (performance.now() - start) + " to seed Encryptor");
}

transform(chunk: Buffer): Buffer {
Expand All @@ -448,7 +454,11 @@ export class Encryptor {
//
// return new Buffer(out);
if (!this.aesCfb) return chunk;
return new Buffer(this.aesCfb.encrypt(chunk.inner));
const start = performance.now();
const retobj = new Buffer(this.aesCfb.encrypt(chunk.inner));
console.log("Took " + (performance.now() - start) + " to transform chunk of size " + chunk.length + " (Encryption)");
return retobj;

}
}

Expand Down
7 changes: 7 additions & 0 deletions src/connection/framer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function bufferTransformer(): TransformStream<Uint8Array, Buffer> {
return new TransformStream({
transform(chunk, controller) {
controller.enqueue(new Buffer(chunk));
console.log("Got a packet of size " + chunk.length +" (bufferTransformer)");
},
});
}
Expand All @@ -76,8 +77,10 @@ export function lengthTransformer(): TransformStream<Buffer> {
let currentSize = -1;
return new TransformStream({
transform(chunk, controller) {
const start = performance.now();
currentPacket.extend(chunk);
while (true) {

if (currentSize === -1) {
let size: number;
try {
Expand All @@ -96,7 +99,9 @@ export function lengthTransformer(): TransformStream<Buffer> {
const pkt = currentPacket.take(currentSize);
controller.enqueue(pkt);
currentSize = -1;

}
console.log("Took " + (performance.now() - start) + " to lengthTransform packet");
},
});
}
Expand All @@ -109,6 +114,7 @@ export class Decompressor {
const self = this;
this.transform = new TransformStream({
async transform(chunk, controller) {
const start = performance.now();
if (self.compressionThresh === -1) {
controller.enqueue(chunk);
return;
Expand All @@ -125,6 +131,7 @@ export class Decompressor {
"Decompressor: server sent compressed packet below threshold"
);
}
console.log("Took " + (performance.now() - start) + " to decompress packet");
},
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ export class Connection {

// setInterval(() => console.log("eagler backlog ", backlog), 1000);
while (true) {
const start = performance.now();
const { done, value } = await reader.read();
if (done || !value) return;

await impl.eaglerRead(value);
console.log("Took " + (performance.now() - start) + " to eaglerRead packet");
backlog--;
}

Expand Down

0 comments on commit ea429ae

Please sign in to comment.