From b515fc41e78e34202a77d89d55c2abf35c9c99c5 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Mon, 26 Nov 2018 16:01:13 +1100 Subject: [PATCH] Removed some repetetive logs, made the polling time a variable and lower the polling time and PoW difficulty if we are in debug mode --- js/modules/loki_message_api.js | 9 +++------ libloki/proof-of-work.js | 4 +++- libtextsecure/http-resources.js | 8 +++++--- libtextsecure/message_receiver.js | 1 - 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index e524cbf6c..e36d6823e 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -4,6 +4,8 @@ const fetch = require('node-fetch'); const is = require('@sindresorhus/is'); const { fork } = require('child_process'); +const development = (window.getEnvironment() !== 'production'); + function getPoWNonce(timestamp, ttl, pubKey, data) { return new Promise((resolve, reject) => { // Create forked node process to calculate PoW without blocking main process @@ -15,6 +17,7 @@ function getPoWNonce(timestamp, ttl, pubKey, data) { ttl, pubKey, data, + development, }); // Handle child process error (should never happen) @@ -73,8 +76,6 @@ class LokiServer { timeout: undefined, }; - log.debug(options.type, options.url); - const fetchOptions = { method: options.type, body: data64, @@ -108,7 +109,6 @@ class LokiServer { } if (response.status >= 0 && response.status < 400) { - log.debug(options.type, options.url, response.status, 'Success'); return result; } log.error(options.type, options.url, response.status, 'Error'); @@ -126,8 +126,6 @@ class LokiServer { timeout: undefined, }; - log.debug(options.type, options.url); - const headers = { 'X-Loki-recipient': pubKey, }; @@ -163,7 +161,6 @@ class LokiServer { } if (response.status >= 0 && response.status < 400) { - log.debug(options.type, options.url, response.status, 'Success'); if (result.lastHash) { currentNode.lastHash = result.lastHash; } diff --git a/libloki/proof-of-work.js b/libloki/proof-of-work.js index 3adab32b2..494c4987a 100644 --- a/libloki/proof-of-work.js +++ b/libloki/proof-of-work.js @@ -4,7 +4,7 @@ const { BigInteger } = require('jsbn'); const NONCE_LEN = 8; // Modify this value for difficulty scaling -const NONCE_TRIALS = 1000; +let NONCE_TRIALS = 1000; // Increment Uint8Array nonce by 1 with carrying function incrementNonce(nonce) { @@ -107,6 +107,8 @@ function calcPoW(timestamp, ttl, pubKey, data) { // Start calculation in child process when main process sends message data process.on('message', msg => { + if (msg.development) + NONCE_TRIALS = 10; process.send({ nonce: calcPoW( msg.timestamp, diff --git a/libtextsecure/http-resources.js b/libtextsecure/http-resources.js index 8a17c2e7f..ffeb2c071 100644 --- a/libtextsecure/http-resources.js +++ b/libtextsecure/http-resources.js @@ -3,6 +3,8 @@ // eslint-disable-next-line func-names (function () { let server; + const development = (window.getEnvironment() !== 'production'); + const pollTime = development ? 100 : 5000; function stringToArrayBufferBase64(string) { return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer(); @@ -69,14 +71,14 @@ connected = true; } catch (err) { connected = false; - setTimeout(() => { pollServer(callBack); }, 5000); + setTimeout(() => { pollServer(callBack); }, pollTime); return; } if (typeof callBack === 'function') { callBack(connected); } if (!result.messages) { - setTimeout(() => { pollServer(callBack); }, 5000); + setTimeout(() => { pollServer(callBack); }, pollTime); return; } const newMessages = await filterIncomingMessages(result.messages); @@ -95,7 +97,7 @@ ); } }); - setTimeout(() => { pollServer(callBack); }, 5000); + setTimeout(() => { pollServer(callBack); }, pollTime); }; this.isConnected = function isConnected() { diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index a969155f2..1666f425d 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -365,7 +365,6 @@ MessageReceiver.prototype.extend({ this.incoming = []; const dispatchEmpty = () => { - window.log.debug("MessageReceiver: emitting 'empty' event"); const ev = new Event('empty'); return this.dispatchAndWait(ev); };