Removed some repetetive logs, made the polling time a variable and lower the polling time and PoW difficulty if we are in debug mode

pull/60/head
Beaudan 7 years ago
parent f67c71bda1
commit b515fc41e7

@ -4,6 +4,8 @@ const fetch = require('node-fetch');
const is = require('@sindresorhus/is'); const is = require('@sindresorhus/is');
const { fork } = require('child_process'); const { fork } = require('child_process');
const development = (window.getEnvironment() !== 'production');
function getPoWNonce(timestamp, ttl, pubKey, data) { function getPoWNonce(timestamp, ttl, pubKey, data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Create forked node process to calculate PoW without blocking main process // Create forked node process to calculate PoW without blocking main process
@ -15,6 +17,7 @@ function getPoWNonce(timestamp, ttl, pubKey, data) {
ttl, ttl,
pubKey, pubKey,
data, data,
development,
}); });
// Handle child process error (should never happen) // Handle child process error (should never happen)
@ -73,8 +76,6 @@ class LokiServer {
timeout: undefined, timeout: undefined,
}; };
log.debug(options.type, options.url);
const fetchOptions = { const fetchOptions = {
method: options.type, method: options.type,
body: data64, body: data64,
@ -108,7 +109,6 @@ class LokiServer {
} }
if (response.status >= 0 && response.status < 400) { if (response.status >= 0 && response.status < 400) {
log.debug(options.type, options.url, response.status, 'Success');
return result; return result;
} }
log.error(options.type, options.url, response.status, 'Error'); log.error(options.type, options.url, response.status, 'Error');
@ -126,8 +126,6 @@ class LokiServer {
timeout: undefined, timeout: undefined,
}; };
log.debug(options.type, options.url);
const headers = { const headers = {
'X-Loki-recipient': pubKey, 'X-Loki-recipient': pubKey,
}; };
@ -163,7 +161,6 @@ class LokiServer {
} }
if (response.status >= 0 && response.status < 400) { if (response.status >= 0 && response.status < 400) {
log.debug(options.type, options.url, response.status, 'Success');
if (result.lastHash) { if (result.lastHash) {
currentNode.lastHash = result.lastHash; currentNode.lastHash = result.lastHash;
} }

@ -4,7 +4,7 @@ const { BigInteger } = require('jsbn');
const NONCE_LEN = 8; const NONCE_LEN = 8;
// Modify this value for difficulty scaling // Modify this value for difficulty scaling
const NONCE_TRIALS = 1000; let NONCE_TRIALS = 1000;
// Increment Uint8Array nonce by 1 with carrying // Increment Uint8Array nonce by 1 with carrying
function incrementNonce(nonce) { function incrementNonce(nonce) {
@ -107,6 +107,8 @@ function calcPoW(timestamp, ttl, pubKey, data) {
// Start calculation in child process when main process sends message data // Start calculation in child process when main process sends message data
process.on('message', msg => { process.on('message', msg => {
if (msg.development)
NONCE_TRIALS = 10;
process.send({ process.send({
nonce: calcPoW( nonce: calcPoW(
msg.timestamp, msg.timestamp,

@ -3,6 +3,8 @@
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function () { (function () {
let server; let server;
const development = (window.getEnvironment() !== 'production');
const pollTime = development ? 100 : 5000;
function stringToArrayBufferBase64(string) { function stringToArrayBufferBase64(string) {
return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer(); return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer();
@ -69,14 +71,14 @@
connected = true; connected = true;
} catch (err) { } catch (err) {
connected = false; connected = false;
setTimeout(() => { pollServer(callBack); }, 5000); setTimeout(() => { pollServer(callBack); }, pollTime);
return; return;
} }
if (typeof callBack === 'function') { if (typeof callBack === 'function') {
callBack(connected); callBack(connected);
} }
if (!result.messages) { if (!result.messages) {
setTimeout(() => { pollServer(callBack); }, 5000); setTimeout(() => { pollServer(callBack); }, pollTime);
return; return;
} }
const newMessages = await filterIncomingMessages(result.messages); const newMessages = await filterIncomingMessages(result.messages);
@ -95,7 +97,7 @@
); );
} }
}); });
setTimeout(() => { pollServer(callBack); }, 5000); setTimeout(() => { pollServer(callBack); }, pollTime);
}; };
this.isConnected = function isConnected() { this.isConnected = function isConnected() {

@ -365,7 +365,6 @@ MessageReceiver.prototype.extend({
this.incoming = []; this.incoming = [];
const dispatchEmpty = () => { const dispatchEmpty = () => {
window.log.debug("MessageReceiver: emitting 'empty' event");
const ev = new Event('empty'); const ev = new Event('empty');
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}; };

Loading…
Cancel
Save