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 { 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;
}

@ -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,

@ -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() {

@ -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);
};

Loading…
Cancel
Save