Provisioning socket events don't block AccountManager tasks
// FREEBIE
This commit is contained in:
parent
38a830c561
commit
7cbaac5590
2 changed files with 76 additions and 66 deletions
|
@ -37961,30 +37961,35 @@ var TextSecureServer = (function() {
|
||||||
var registrationDone = this.registrationDone.bind(this);
|
var registrationDone = this.registrationDone.bind(this);
|
||||||
var registerKeys = this.server.registerKeys.bind(this.server);
|
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||||
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
||||||
return this.queueTask(function() {
|
var queueTask = this.queueTask.bind(this);
|
||||||
var provisioningCipher = new libsignal.ProvisioningCipher();
|
var provisioningCipher = new libsignal.ProvisioningCipher();
|
||||||
return provisioningCipher.getPublicKey().then(function(pubKey) {
|
var gotProvisionEnvelope = false;
|
||||||
return new Promise(function(resolve, reject) {
|
return provisioningCipher.getPublicKey().then(function(pubKey) {
|
||||||
var socket = getSocket();
|
return new Promise(function(resolve, reject) {
|
||||||
socket.onclose = function(e) {
|
var socket = getSocket();
|
||||||
console.log('websocket closed', e.code);
|
socket.onclose = function(e) {
|
||||||
|
console.log('websocket closed', e.code);
|
||||||
|
if (!gotProvisionEnvelope) {
|
||||||
reject(new Error('websocket closed'));
|
reject(new Error('websocket closed'));
|
||||||
};
|
}
|
||||||
var wsr = new WebSocketResource(socket, {
|
};
|
||||||
keepalive: { path: '/v1/keepalive/provisioning' },
|
var wsr = new WebSocketResource(socket, {
|
||||||
handleRequest: function(request) {
|
keepalive: { path: '/v1/keepalive/provisioning' },
|
||||||
if (request.path === "/v1/address" && request.verb === "PUT") {
|
handleRequest: function(request) {
|
||||||
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
if (request.path === "/v1/address" && request.verb === "PUT") {
|
||||||
setProvisioningUrl([
|
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
||||||
'tsdevice:/?uuid=', proto.uuid, '&pub_key=',
|
setProvisioningUrl([
|
||||||
encodeURIComponent(btoa(getString(pubKey)))
|
'tsdevice:/?uuid=', proto.uuid, '&pub_key=',
|
||||||
].join(''));
|
encodeURIComponent(btoa(getString(pubKey)))
|
||||||
request.respond(200, 'OK');
|
].join(''));
|
||||||
} else if (request.path === "/v1/message" && request.verb === "PUT") {
|
request.respond(200, 'OK');
|
||||||
var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary');
|
} else if (request.path === "/v1/message" && request.verb === "PUT") {
|
||||||
request.respond(200, 'OK');
|
var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary');
|
||||||
wsr.close();
|
request.respond(200, 'OK');
|
||||||
resolve(provisioningCipher.decrypt(envelope).then(function(provisionMessage) {
|
gotProvisionEnvelope = true;
|
||||||
|
wsr.close();
|
||||||
|
resolve(provisioningCipher.decrypt(envelope).then(function(provisionMessage) {
|
||||||
|
return queueTask(function() {
|
||||||
return confirmNumber(provisionMessage.number).then(function(deviceName) {
|
return confirmNumber(provisionMessage.number).then(function(deviceName) {
|
||||||
if (typeof deviceName !== 'string' || deviceName.length === 0) {
|
if (typeof deviceName !== 'string' || deviceName.length === 0) {
|
||||||
throw new Error('Invalid device name');
|
throw new Error('Invalid device name');
|
||||||
|
@ -37995,19 +38000,19 @@ var TextSecureServer = (function() {
|
||||||
provisionMessage.identityKeyPair,
|
provisionMessage.identityKeyPair,
|
||||||
deviceName,
|
deviceName,
|
||||||
provisionMessage.userAgent
|
provisionMessage.userAgent
|
||||||
);
|
).then(generateKeys).
|
||||||
|
then(registerKeys).
|
||||||
|
then(registrationDone);
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
} else {
|
}));
|
||||||
console.log('Unknown websocket message', request.path);
|
} else {
|
||||||
}
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}).then(generateKeys).
|
});
|
||||||
then(registerKeys).
|
});
|
||||||
then(registrationDone);
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
refreshPreKeys: function() {
|
refreshPreKeys: function() {
|
||||||
var generateKeys = this.generateKeys.bind(this, 100);
|
var generateKeys = this.generateKeys.bind(this, 100);
|
||||||
|
|
|
@ -43,30 +43,35 @@
|
||||||
var registrationDone = this.registrationDone.bind(this);
|
var registrationDone = this.registrationDone.bind(this);
|
||||||
var registerKeys = this.server.registerKeys.bind(this.server);
|
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||||
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
||||||
return this.queueTask(function() {
|
var queueTask = this.queueTask.bind(this);
|
||||||
var provisioningCipher = new libsignal.ProvisioningCipher();
|
var provisioningCipher = new libsignal.ProvisioningCipher();
|
||||||
return provisioningCipher.getPublicKey().then(function(pubKey) {
|
var gotProvisionEnvelope = false;
|
||||||
return new Promise(function(resolve, reject) {
|
return provisioningCipher.getPublicKey().then(function(pubKey) {
|
||||||
var socket = getSocket();
|
return new Promise(function(resolve, reject) {
|
||||||
socket.onclose = function(e) {
|
var socket = getSocket();
|
||||||
console.log('websocket closed', e.code);
|
socket.onclose = function(e) {
|
||||||
|
console.log('websocket closed', e.code);
|
||||||
|
if (!gotProvisionEnvelope) {
|
||||||
reject(new Error('websocket closed'));
|
reject(new Error('websocket closed'));
|
||||||
};
|
}
|
||||||
var wsr = new WebSocketResource(socket, {
|
};
|
||||||
keepalive: { path: '/v1/keepalive/provisioning' },
|
var wsr = new WebSocketResource(socket, {
|
||||||
handleRequest: function(request) {
|
keepalive: { path: '/v1/keepalive/provisioning' },
|
||||||
if (request.path === "/v1/address" && request.verb === "PUT") {
|
handleRequest: function(request) {
|
||||||
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
if (request.path === "/v1/address" && request.verb === "PUT") {
|
||||||
setProvisioningUrl([
|
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
||||||
'tsdevice:/?uuid=', proto.uuid, '&pub_key=',
|
setProvisioningUrl([
|
||||||
encodeURIComponent(btoa(getString(pubKey)))
|
'tsdevice:/?uuid=', proto.uuid, '&pub_key=',
|
||||||
].join(''));
|
encodeURIComponent(btoa(getString(pubKey)))
|
||||||
request.respond(200, 'OK');
|
].join(''));
|
||||||
} else if (request.path === "/v1/message" && request.verb === "PUT") {
|
request.respond(200, 'OK');
|
||||||
var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary');
|
} else if (request.path === "/v1/message" && request.verb === "PUT") {
|
||||||
request.respond(200, 'OK');
|
var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary');
|
||||||
wsr.close();
|
request.respond(200, 'OK');
|
||||||
resolve(provisioningCipher.decrypt(envelope).then(function(provisionMessage) {
|
gotProvisionEnvelope = true;
|
||||||
|
wsr.close();
|
||||||
|
resolve(provisioningCipher.decrypt(envelope).then(function(provisionMessage) {
|
||||||
|
return queueTask(function() {
|
||||||
return confirmNumber(provisionMessage.number).then(function(deviceName) {
|
return confirmNumber(provisionMessage.number).then(function(deviceName) {
|
||||||
if (typeof deviceName !== 'string' || deviceName.length === 0) {
|
if (typeof deviceName !== 'string' || deviceName.length === 0) {
|
||||||
throw new Error('Invalid device name');
|
throw new Error('Invalid device name');
|
||||||
|
@ -77,19 +82,19 @@
|
||||||
provisionMessage.identityKeyPair,
|
provisionMessage.identityKeyPair,
|
||||||
deviceName,
|
deviceName,
|
||||||
provisionMessage.userAgent
|
provisionMessage.userAgent
|
||||||
);
|
).then(generateKeys).
|
||||||
|
then(registerKeys).
|
||||||
|
then(registrationDone);
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
} else {
|
}));
|
||||||
console.log('Unknown websocket message', request.path);
|
} else {
|
||||||
}
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}).then(generateKeys).
|
});
|
||||||
then(registerKeys).
|
});
|
||||||
then(registrationDone);
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
refreshPreKeys: function() {
|
refreshPreKeys: function() {
|
||||||
var generateKeys = this.generateKeys.bind(this, 100);
|
var generateKeys = this.generateKeys.bind(this, 100);
|
||||||
|
|
Loading…
Reference in a new issue