Move envelope decode before ack
We should not ack envelope protobufs that fail to decode correctly. If the server happens to send us such a thing it probably indicates a protocol mismatch between it and the client, in which case the client needs to update and re-receive the failed message. // FREEBIE
This commit is contained in:
parent
44824df6cb
commit
96520e9fd4
2 changed files with 6 additions and 8 deletions
|
@ -36795,11 +36795,12 @@ MessageReceiver.prototype = {
|
||||||
// TODO: handle different types of requests. for now we blindly assume
|
// TODO: handle different types of requests. for now we blindly assume
|
||||||
// PUT /messages <encrypted Envelope>
|
// PUT /messages <encrypted Envelope>
|
||||||
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');
|
||||||
this.queueEnvelope(plaintext);
|
this.queueEnvelope(envelope);
|
||||||
|
|
||||||
}.bind(this)).catch(function(e) {
|
}.bind(this)).catch(function(e) {
|
||||||
request.respond(500, 'Bad encrypted websocket message');
|
request.respond(500, 'Bad encrypted websocket message');
|
||||||
|
@ -36813,9 +36814,7 @@ MessageReceiver.prototype = {
|
||||||
var handleEnvelope = this.handleEnvelope.bind(this, envelope);
|
var handleEnvelope = this.handleEnvelope.bind(this, envelope);
|
||||||
this.pending = this.pending.then(handleEnvelope, handleEnvelope);
|
this.pending = this.pending.then(handleEnvelope, handleEnvelope);
|
||||||
},
|
},
|
||||||
handleEnvelope: function(encodedEnvelope) {
|
handleEnvelope: function(envelope) {
|
||||||
var envelope = textsecure.protobuf.Envelope.decode(encodedEnvelope);
|
|
||||||
|
|
||||||
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
|
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
|
||||||
return this.onDeliveryReceipt(envelope);
|
return this.onDeliveryReceipt(envelope);
|
||||||
} else if (envelope.content) {
|
} else if (envelope.content) {
|
||||||
|
|
|
@ -63,11 +63,12 @@ MessageReceiver.prototype = {
|
||||||
// TODO: handle different types of requests. for now we blindly assume
|
// TODO: handle different types of requests. for now we blindly assume
|
||||||
// PUT /messages <encrypted Envelope>
|
// PUT /messages <encrypted Envelope>
|
||||||
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');
|
||||||
this.queueEnvelope(plaintext);
|
this.queueEnvelope(envelope);
|
||||||
|
|
||||||
}.bind(this)).catch(function(e) {
|
}.bind(this)).catch(function(e) {
|
||||||
request.respond(500, 'Bad encrypted websocket message');
|
request.respond(500, 'Bad encrypted websocket message');
|
||||||
|
@ -81,9 +82,7 @@ MessageReceiver.prototype = {
|
||||||
var handleEnvelope = this.handleEnvelope.bind(this, envelope);
|
var handleEnvelope = this.handleEnvelope.bind(this, envelope);
|
||||||
this.pending = this.pending.then(handleEnvelope, handleEnvelope);
|
this.pending = this.pending.then(handleEnvelope, handleEnvelope);
|
||||||
},
|
},
|
||||||
handleEnvelope: function(encodedEnvelope) {
|
handleEnvelope: function(envelope) {
|
||||||
var envelope = textsecure.protobuf.Envelope.decode(encodedEnvelope);
|
|
||||||
|
|
||||||
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
|
if (envelope.type === textsecure.protobuf.Envelope.Type.RECEIPT) {
|
||||||
return this.onDeliveryReceipt(envelope);
|
return this.onDeliveryReceipt(envelope);
|
||||||
} else if (envelope.content) {
|
} else if (envelope.content) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue