Merge pull request #115 from Mikunj/PoW-fixes

Pow fixes
pull/117/head
sachaaaaa 7 years ago committed by GitHub
commit e6cdcc981c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -148,7 +148,7 @@
<div class='attachment-previews'></div> <div class='attachment-previews'></div>
<div class='flex'> <div class='flex'>
<button class='emoji' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button> <button class='emoji' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
<textarea class='send-message' placeholder='{{ send-message }}' rows='1' dir='auto' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></textarea> <textarea maxlength='2000' class='send-message' placeholder='{{ send-message }}' rows='1' dir='auto' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></textarea>
<div class='capture-audio hide'> <div class='capture-audio hide'>
<button class='microphone' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button> <button class='microphone' {{#disable-inputs}} disabled="disabled" {{/disable-inputs}}></button>
</div> </div>

@ -846,7 +846,8 @@
e.name === 'OutgoingMessageError' || e.name === 'OutgoingMessageError' ||
e.name === 'SendMessageNetworkError' || e.name === 'SendMessageNetworkError' ||
e.name === 'SignedPreKeyRotationError' || e.name === 'SignedPreKeyRotationError' ||
e.name === 'OutgoingIdentityKeyError' e.name === 'OutgoingIdentityKeyError' ||
e.name === 'PoWError'
); );
}, },

@ -15,8 +15,9 @@ class TimedOutError extends Error {
} }
class WorkerInterface { class WorkerInterface {
constructor(path) { constructor(path, timeout = WORKER_TIMEOUT) {
this._utilWorker = new Worker(path); this._utilWorker = new Worker(path);
this.timeout = timeout;
this._jobs = Object.create(null); this._jobs = Object.create(null);
this._DEBUG = false; this._DEBUG = false;
this._jobCounter = 0; this._jobCounter = 0;
@ -112,7 +113,7 @@ class WorkerInterface {
setTimeout( setTimeout(
() => reject(new TimedOutError(`Worker job ${jobId} (${fnName}) timed out`)), () => reject(new TimedOutError(`Worker job ${jobId} (${fnName}) timed out`)),
WORKER_TIMEOUT this.timeout
); );
}); });
}; };

@ -1623,7 +1623,10 @@
} }
const input = this.$messageField; const input = this.$messageField;
const message = window.Signal.Emoji.replaceColons(input.val()).trim(); const inputMessage = window.Signal.Emoji.replaceColons(input.val()).trim();
// Limit the message to 2000 characters
const message = inputMessage.substring(0, Math.min(2000, inputMessage.length));
try { try {
if (!message.length && !this.fileInput.hasFiles()) { if (!message.length && !this.fileInput.hasFiles()) {

@ -127,6 +127,21 @@
} }
inherit(Error, UnregisteredUserError); inherit(Error, UnregisteredUserError);
function PoWError(number, error) {
// eslint-disable-next-line prefer-destructuring
this.number = number.split('.')[0];
ReplayableError.call(this, {
name: 'PoWError',
message: 'Failed to calculate PoW',
});
if (error) {
appendStack(this, error);
}
}
inherit(ReplayableError, PoWError);
window.textsecure.UnregisteredUserError = UnregisteredUserError; window.textsecure.UnregisteredUserError = UnregisteredUserError;
window.textsecure.SendMessageNetworkError = SendMessageNetworkError; window.textsecure.SendMessageNetworkError = SendMessageNetworkError;
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError; window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
@ -135,4 +150,5 @@
window.textsecure.OutgoingMessageError = OutgoingMessageError; window.textsecure.OutgoingMessageError = OutgoingMessageError;
window.textsecure.MessageError = MessageError; window.textsecure.MessageError = MessageError;
window.textsecure.SignedPreKeyRotationError = SignedPreKeyRotationError; window.textsecure.SignedPreKeyRotationError = SignedPreKeyRotationError;
window.textsecure.PoWError = PoWError;
})(); })();

@ -195,6 +195,8 @@ OutgoingMessage.prototype = {
throw new textsecure.UnregisteredUserError(number, e); throw new textsecure.UnregisteredUserError(number, e);
} }
throw new textsecure.SendMessageNetworkError(number, '', e, timestamp); throw new textsecure.SendMessageNetworkError(number, '', e, timestamp);
} else if (e.name === 'TimedOutError') {
throw new textsecure.PoWError(number, e);
} }
throw e; throw e;
} }

@ -7,7 +7,7 @@
window.textsecure = window.textsecure || {}; window.textsecure = window.textsecure || {};
window.textsecure.createTaskWithTimeout = (task, id, options = {}) => { window.textsecure.createTaskWithTimeout = (task, id, options = {}) => {
const timeout = options.timeout || 1000 * 60 * 2; // two minutes const timeout = options.timeout || 1000 * 60 * 3; // three minutes
const errorForStack = new Error('for stack'); const errorForStack = new Error('for stack');
return () => return () =>

@ -269,8 +269,9 @@ window.LokiAPI = new LokiServer({
window.mnemonic = require('./libloki/mnemonic'); window.mnemonic = require('./libloki/mnemonic');
const { WorkerInterface } = require('./js/modules/util_worker_interface'); const { WorkerInterface } = require('./js/modules/util_worker_interface');
// A Worker with a 3 minute timeout
const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js'); const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js');
const utilWorker = new WorkerInterface(utilWorkerPath); const utilWorker = new WorkerInterface(utilWorkerPath, 3 * 60 * 1000);
window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args); window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args);
// Linux seems to periodically let the event loop stop, so this is a global workaround // Linux seems to periodically let the event loop stop, so this is a global workaround

Loading…
Cancel
Save