From b48f50e8197d6d1258776750c40ecd8684e794b4 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 3 Oct 2021 12:14:57 +0100 Subject: [PATCH] Tidy up logging --- src/lib/transport/Connection.mjs | 8 ++++---- src/lib/transport/FramedTransport.mjs | 2 +- src/lib/transport/rekey.mjs | 3 +-- src/subcommands/test-client/test-client.mjs | 5 +++-- src/subcommands/test-server/test-server.mjs | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/transport/Connection.mjs b/src/lib/transport/Connection.mjs index 98990ac..c9ecf2e 100644 --- a/src/lib/transport/Connection.mjs +++ b/src/lib/transport/Connection.mjs @@ -92,7 +92,7 @@ class Connection extends EventEmitter { } async destroy() { - l.info(`Killing connection to ${this.address}:${this.port}`, new Error().stack); + l.notice(`Killing connection to ${this.address}:${this.port}`, new Error().stack); if(this.framer instanceof FramedTransport) await this.framer.destroy(); else { @@ -104,7 +104,7 @@ class Connection extends EventEmitter { async handle_frame(bytes) { try { - l.info(`FRAME length`, bytes.length, `frame`, bytes); + // l.info(`FRAME length`, bytes.length, `frame`, bytes); let decrypted = decrypt_bytes(this.session_key, bytes); if(decrypted === null) { l.warn(`Decryption of message failed`); @@ -121,7 +121,7 @@ class Connection extends EventEmitter { async handle_message(msg_text) { const msg = JSON.parse(msg_text); - l.info(`RECEIVE:${msg.event}`, msg.message); + l.debug(`RECEIVE:${msg.event}`, msg.message); if(msg.event == "rekey" && !this.rekey_in_progress) { // Set and forget here @@ -134,7 +134,7 @@ class Connection extends EventEmitter { async send(event, message) { if(typeof event !== "string") throw new Error(`Error: Expected string for event name, but got value of type ${typeof event}.`); - l.info(`SEND event`, event, `message`, message); + l.debug(`SEND event`, event, `message`, message); // Rekey at semi-regular intervals, but only if we're not already in the process of doing so if(new Date() - this.rekey_last > this.rekey_interval && !this.rekey_in_progress) diff --git a/src/lib/transport/FramedTransport.mjs b/src/lib/transport/FramedTransport.mjs index c2ecf3c..1d18b3b 100644 --- a/src/lib/transport/FramedTransport.mjs +++ b/src/lib/transport/FramedTransport.mjs @@ -42,7 +42,7 @@ class FramedTransport extends EventEmitter { * @return {void} */ handle_chunk(chunk) { - l.debug(`CHUNK length`, chunk.length, `buffer length`, this.buffer === null ? 0 : this.buffer.length); + // l.debug(`CHUNK length`, chunk.length, `buffer length`, this.buffer === null ? 0 : this.buffer.length); if(this.buffer instanceof Buffer) { this.buffer = Buffer.concat([ this.buffer, chunk ]); diff --git a/src/lib/transport/rekey.mjs b/src/lib/transport/rekey.mjs index c37e25d..a767ea5 100644 --- a/src/lib/transport/rekey.mjs +++ b/src/lib/transport/rekey.mjs @@ -33,8 +33,7 @@ export default async function rekey(connection, secret_join) { // 3: Compute new shared key const their_round2 = (await once(connection, "message-rekey"))[0]; - l.debug(`THEIR_ROUND2`, their_round2); - + if(typeof their_round2 !== "object" || their_round2.round !== 2 || typeof their_round2.content !== "string") diff --git a/src/subcommands/test-client/test-client.mjs b/src/subcommands/test-client/test-client.mjs index cb87816..ca77570 100644 --- a/src/subcommands/test-client/test-client.mjs +++ b/src/subcommands/test-client/test-client.mjs @@ -22,8 +22,9 @@ export default async function() { const socket = await Connection.Create(test_key, "::1", settings.cli.port); - socket.on("message", (event, msg) => { - l.notice(`<<< ${event}: ${JSON.stringify(msg)}`); + socket.on("message", (_event, _msg) => { + // noop + // l.notice(`<<< ${event}: ${JSON.stringify(msg)}`); }); diff --git a/src/subcommands/test-server/test-server.mjs b/src/subcommands/test-server/test-server.mjs index 47a2861..4804ad5 100644 --- a/src/subcommands/test-server/test-server.mjs +++ b/src/subcommands/test-server/test-server.mjs @@ -14,8 +14,9 @@ export default async function() { l.notice("client connected"); const connection = await Connection.Wrap(test_key, client); connection.send("test-server", "hello\n"); - connection.on("message", (event, msg) => { - l.notice(`<<< ${event}: ${JSON.stringify(msg)}`); + connection.on("message", (_event, _msg) => { + // noop + //l.notice(`<<< ${event}: ${JSON.stringify(msg)}`); }); let id = setInterval(async () => { const rt = await connection.send("test-server", (new Date()).toString());