Revert "Use protocol buffer module for libtextsecure"

This does not work with `ArrayBuffer` out of the box and will need to be
investigated and tested more before switching.

Some APIs also seemed to have changed:
- Before (OOP): `new textsecure.protobuf.WebSocketMessage(…).encode();`
- After (functional):
  ```
  textsecure.protobuf.WebSocketMessage.encode(
    new textsecure.protobuf.WebSocketMessage(…)
  );
  ```

This reverts commit d758119d9de4f99742ea941e86180b1d600c2f22.
This commit is contained in:
Daniel Gasienica 2018-05-07 19:12:53 -04:00
parent 60077d0b7b
commit ba4d8952c6
7 changed files with 4389 additions and 9 deletions

View file

@ -56,6 +56,7 @@ module.exports = function(grunt) {
'libtextsecure/storage/user.js',
'libtextsecure/storage/groups.js',
'libtextsecure/storage/unprocessed.js',
'libtextsecure/protobufs.js',
'libtextsecure/helpers.js',
'libtextsecure/stringview.js',
'libtextsecure/event_target.js',

View file

@ -8,6 +8,7 @@
"jquery": "liliakai/jquery#2.1.1-ajax-nativetransport",
"underscore": "~1.7.0",
"backbone": "~1.1.2",
"protobuf": "~3.8.0",
"mustache": "~0.8.2",
"qrcode": "https://github.com/davidshimjs/qrcodejs.git#1c78ccd71",
"indexeddb-backbonejs-adapter": "*",
@ -32,6 +33,9 @@
"bytebuffer": [
"dist/ByteBufferAB.js"
],
"protobuf": [
"dist/ProtoBuf.js"
],
"mustache": [
"mustache.js"
],
@ -85,6 +89,7 @@
"jquery",
"long",
"bytebuffer",
"protobuf",
"mustache",
"underscore",
"backbone",
@ -97,7 +102,8 @@
],
"libtextsecure": [
"long",
"bytebuffer"
"bytebuffer",
"protobuf"
]
}
}

4335
components/protobuf/dist/ProtoBuf.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,42 @@
(function() {
'use strict';
window.textsecure = window.textsecure || {};
window.textsecure.protobuf = {};
function loadProtoBufs(filename) {
return dcodeIO.ProtoBuf.loadProtoFile(
{ root: window.PROTO_ROOT, file: filename },
function(error, result) {
if (error) {
var text =
'Error loading protos from ' +
filename +
' (root: ' +
window.PROTO_ROOT +
') ' +
(error && error.stack ? error.stack : error);
console.log(text);
throw error;
}
var protos = result.build('signalservice');
if (!protos) {
var text =
'Error loading protos from ' +
filename +
' (root: ' +
window.PROTO_ROOT +
')';
console.log(text);
throw new Error(text);
}
for (var protoName in protos) {
textsecure.protobuf[protoName] = protos[protoName];
}
}
);
}
loadProtoBufs('SignalService.proto');
loadProtoBufs('SubProtocol.proto');
loadProtoBufs('DeviceMessages.proto');
})();

View file

@ -18,6 +18,7 @@
<script type="text/javascript" src="../components.js"></script>
<script type="text/javascript" src="../libsignal-protocol.js"></script>
<script type="text/javascript" src="../crypto.js"></script>
<script type="text/javascript" src="../protobufs.js" data-cover></script>
<script type="text/javascript" src="../errors.js" data-cover></script>
<script type="text/javascript" src="../storage.js" data-cover></script>
<script type="text/javascript" src="../protocol_wrapper.js" data-cover></script>

View file

@ -18,12 +18,10 @@
"generate": "yarn icon-gen && yarn grunt",
"build": "build --config.extraMetadata.environment=$SIGNAL_ENV",
"build-release": "SIGNAL_ENV=production npm run build -- --config.directories.output=release",
"build-libtextsecure-protobuf": "pbjs --target static-module --root signalservice --out libtextsecure/protobuf-compiled.js protos/DeviceMessages.proto protos/SubProtocol.proto protos/SignalService.proto",
"clean-libtextsecure-protobuf": "rm -f libtextsecure/protobuf-compiled.js",
"build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js",
"clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js",
"build-protobuf": "yarn build-libtextsecure-protobuf && yarn build-module-protobuf",
"clean-protobuf": "yarn clean-libtextsecure-protobuf && yarn clean-module-protobuf",
"build-protobuf": "yarn build-module-protobuf",
"clean-protobuf": "yarn clean-module-protobuf",
"prepare-beta-build": "node prepare_beta_build.js",
"prepare-import-build": "node prepare_import_build.js",
"publish-to-apt": "NAME=$npm_package_name VERSION=$npm_package_version ./aptly.sh",

View file

@ -9,7 +9,6 @@ const Attachment = require('./js/modules/types/attachment');
const Attachments = require('./app/attachments');
const Message = require('./js/modules/types/message');
const { deferredToPromise } = require('./js/modules/deferred_to_promise');
const { SignalService } = require('./ts/protobuf');
const { app } = electron.remote;
@ -99,13 +98,11 @@ window.filesize = require('filesize');
window.libphonenumber = require('google-libphonenumber').PhoneNumberUtil.getInstance();
window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat;
window.loadImage = require('blueimp-load-image');
window.nodeBuffer = Buffer;
window.nodeFetch = require('node-fetch');
window.ProxyAgent = require('proxy-agent');
window.textsecure = window.textsecure || {};
window.textsecure.protobuf = SignalService;
// Note: when modifying this file, consider whether our React Components or Backbone Views
// will need these things to render in the Style Guide. If so, go update one of these
// two locations: