From 7d0aeac8cb4eb87e412228725f57745ac6946a94 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 4 May 2015 11:55:47 -0700 Subject: [PATCH] Use a worker to facilitate key generation --- Gruntfile.js | 2 +- {libtextsecure => js}/libaxolotl-worker.js | 0 js/libtextsecure.js | 13 +++++-------- libtextsecure/account_manager.js | 4 +++- libtextsecure/axolotl_wrapper.js | 13 +++++-------- 5 files changed, 14 insertions(+), 18 deletions(-) rename {libtextsecure => js}/libaxolotl-worker.js (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 47decfd6..20b1baff 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -139,7 +139,7 @@ module.exports = function(grunt) { }, jscs: { all: { - src: ['js/**/*.js', '!js/libtextsecure.js', '!js/components.js', 'test/**/*.js'] + src: ['js/**/*.js', '!js/libtextsecure.js', '!js/libaxolotl-worker.js', '!js/components.js', 'test/**/*.js'] } }, watch: { diff --git a/libtextsecure/libaxolotl-worker.js b/js/libaxolotl-worker.js similarity index 100% rename from libtextsecure/libaxolotl-worker.js rename to js/libaxolotl-worker.js diff --git a/js/libtextsecure.js b/js/libtextsecure.js index e963e8ab..1b409aca 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37828,14 +37828,11 @@ axolotlInternal.RecipientRecord = function() { encryptMessageFor: function(deviceObject, pushMessageContent) { return axolotlInstance.encryptMessageFor(deviceObject, pushMessageContent); }, - generateKeys: function(count, progressCallback) { - if (textsecure.worker_path) { - axolotlInstance.startWorker(textsecure.worker_path); - } - return generateKeys(count, progressCallback).then(function(result) { - axolotlInstance.stopWorker(); - return result; - }); + startWorker: function() { + axolotlInstance.startWorker('/js/libaxolotl-worker.js'); + }, + stopWorker: function() { + axolotlInstance.stopWorker(); }, createIdentityKeyRecvSocket: function() { return axolotlInstance.createIdentityKeyRecvSocket(); diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 6915791f..d74393e4 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -79,7 +79,6 @@ }); } }; - function createAccount(number, verificationCode, identityKeyPair, single_device) { textsecure.storage.put('identityKey', identityKeyPair); @@ -119,6 +118,8 @@ function generateKeys(count, progressCallback) { throw new Error('Invalid signedKeyId'); } + textsecure.protocol_wrapper.startWorker(); + var store = textsecure.storage.axolotl; var identityKey = store.getMyIdentityKey(); var result = { preKeys: [], identityKey: identityKey.pubKey }; @@ -152,6 +153,7 @@ function generateKeys(count, progressCallback) { textsecure.storage.put('maxPreKeyId', startId + count); textsecure.storage.put('signedKeyId', signedKeyId + 1); return Promise.all(promises).then(function() { + textsecure.protocol_wrapper.stopWorker(); return result; }); } diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 1af8ebe7..0219315b 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -55,14 +55,11 @@ encryptMessageFor: function(deviceObject, pushMessageContent) { return axolotlInstance.encryptMessageFor(deviceObject, pushMessageContent); }, - generateKeys: function(count, progressCallback) { - if (textsecure.worker_path) { - axolotlInstance.startWorker(textsecure.worker_path); - } - return generateKeys(count, progressCallback).then(function(result) { - axolotlInstance.stopWorker(); - return result; - }); + startWorker: function() { + axolotlInstance.startWorker('/js/libaxolotl-worker.js'); + }, + stopWorker: function() { + axolotlInstance.stopWorker(); }, createIdentityKeyRecvSocket: function() { return axolotlInstance.createIdentityKeyRecvSocket();