Send message ACKs immediately after recv, instead of after process

This commit is contained in:
Matt Corallo 2015-12-04 14:29:49 +08:00 committed by lilia
parent a65166ae3b
commit dac084b604
2 changed files with 36 additions and 32 deletions

View file

@ -36789,29 +36789,31 @@ MessageReceiver.prototype = {
}); });
}, },
queueRequest: function(request) { queueRequest: function(request) {
var handleRequest = this.handleRequest.bind(this, request); // We do the message decryption here, instead of in the ordered pending queue,
this.pending = this.pending.then(handleRequest, handleRequest); // to avoid exposing the time it took us to process messages through the time-to-ack.
},
handleRequest: function(request) { // TODO: handle different types of requests. for now we blindly assume
// TODO: handle different types of requests. for now we only expect
// PUT /messages <encrypted IncomingPushMessageSignal> // PUT /messages <encrypted IncomingPushMessageSignal>
return textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) { textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) {
var envelope = textsecure.protobuf.Envelope.decode(plaintext);
// After this point, decoding errors are not the server's // After this point, decoding errors are not the server's
// fault, and we should handle them gracefully and tell the // fault, and we should handle them gracefully and tell the
// user they received an invalid message // user they received an invalid message
request.respond(200, 'OK'); request.respond(200, 'OK');
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) { var handleRequest = function() {
return this.onDeliveryReceipt(envelope); var envelope = textsecure.protobuf.Envelope.decode(plaintext);
} else if (envelope.content) {
return this.handleContentMessage(envelope);
} else if (envelope.legacyMessage) {
return this.handleLegacyMessage(envelope);
} else {
throw new Error('Received envelope with no content and no legacyMessage');
}
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
return this.onDeliveryReceipt(envelope);
} else if (envelope.content) {
return this.handleContentMessage(envelope);
} else if (envelope.legacyMessage) {
return this.handleLegacyMessage(envelope);
} else {
throw new Error('Received message with no content and no legacyMessage');
}
}.bind(this);
this.pending = this.pending.then(handleRequest, handleRequest);
}.bind(this)).catch(function(e) { }.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message'); request.respond(500, 'Bad encrypted websocket message');
console.log("Error handling incoming message:", e); console.log("Error handling incoming message:", e);

View file

@ -57,29 +57,31 @@ MessageReceiver.prototype = {
}); });
}, },
queueRequest: function(request) { queueRequest: function(request) {
var handleRequest = this.handleRequest.bind(this, request); // We do the message decryption here, instead of in the ordered pending queue,
this.pending = this.pending.then(handleRequest, handleRequest); // to avoid exposing the time it took us to process messages through the time-to-ack.
},
handleRequest: function(request) { // TODO: handle different types of requests. for now we blindly assume
// TODO: handle different types of requests. for now we only expect
// PUT /messages <encrypted IncomingPushMessageSignal> // PUT /messages <encrypted IncomingPushMessageSignal>
return textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) { textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) {
var envelope = textsecure.protobuf.Envelope.decode(plaintext);
// After this point, decoding errors are not the server's // After this point, decoding errors are not the server's
// fault, and we should handle them gracefully and tell the // fault, and we should handle them gracefully and tell the
// user they received an invalid message // user they received an invalid message
request.respond(200, 'OK'); request.respond(200, 'OK');
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) { var handleRequest = function() {
return this.onDeliveryReceipt(envelope); var envelope = textsecure.protobuf.Envelope.decode(plaintext);
} else if (envelope.content) {
return this.handleContentMessage(envelope);
} else if (envelope.legacyMessage) {
return this.handleLegacyMessage(envelope);
} else {
throw new Error('Received envelope with no content and no legacyMessage');
}
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
return this.onDeliveryReceipt(envelope);
} else if (envelope.content) {
return this.handleContentMessage(envelope);
} else if (envelope.legacyMessage) {
return this.handleLegacyMessage(envelope);
} else {
throw new Error('Received message with no content and no legacyMessage');
}
}.bind(this);
this.pending = this.pending.then(handleRequest, handleRequest);
}.bind(this)).catch(function(e) { }.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message'); request.respond(500, 'Bad encrypted websocket message');
console.log("Error handling incoming message:", e); console.log("Error handling incoming message:", e);