Simplify envelope drop due to stopped processing
This commit is contained in:
parent
0e7f641dc1
commit
fff4e9e97f
2 changed files with 29 additions and 23 deletions
|
@ -22,8 +22,16 @@ describe('MessageReceiver', () => {
|
|||
const uuid = 'aaaaaaaa-bbbb-4ccc-9ddd-eeeeeeeeeeee';
|
||||
const deviceId = 1;
|
||||
|
||||
beforeEach(async () => {
|
||||
await window.storage.protocol.hydrateCaches();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await window.storage.protocol.removeAllUnprocessed();
|
||||
});
|
||||
|
||||
describe('connecting', () => {
|
||||
it('generates decryption-error event when it cannot decrypt', done => {
|
||||
it('generates decryption-error event when it cannot decrypt', async () => {
|
||||
const messageReceiver = new MessageReceiver({
|
||||
server: {} as WebAPIType,
|
||||
storage: window.storage,
|
||||
|
@ -52,14 +60,18 @@ describe('MessageReceiver', () => {
|
|||
)
|
||||
);
|
||||
|
||||
messageReceiver.addEventListener(
|
||||
'decryption-error',
|
||||
(error: DecryptionErrorEvent) => {
|
||||
assert.strictEqual(error.decryptionError.senderUuid, uuid);
|
||||
assert.strictEqual(error.decryptionError.senderDevice, deviceId);
|
||||
done();
|
||||
}
|
||||
);
|
||||
await new Promise<void>(resolve => {
|
||||
messageReceiver.addEventListener(
|
||||
'decryption-error',
|
||||
(error: DecryptionErrorEvent) => {
|
||||
assert.strictEqual(error.decryptionError.senderUuid, uuid);
|
||||
assert.strictEqual(error.decryptionError.senderDevice, deviceId);
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
await messageReceiver.drain();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -795,7 +795,8 @@ export default class MessageReceiver
|
|||
|
||||
window.log.info(
|
||||
'MessageReceiver.decryptAndCacheBatch storing ' +
|
||||
`${decrypted.length} decrypted envelopes`
|
||||
`${decrypted.length} decrypted envelopes, keeping ` +
|
||||
`${failed.length} failed envelopes.`
|
||||
);
|
||||
|
||||
// Store both decrypted and failed unprocessed envelopes
|
||||
|
@ -926,10 +927,6 @@ export default class MessageReceiver
|
|||
|
||||
const task = createTaskWithTimeout(async (): Promise<DecryptResult> => {
|
||||
const unsealedEnvelope = await this.unsealEnvelope(stores, envelope);
|
||||
if (!unsealedEnvelope) {
|
||||
// Envelope was dropped
|
||||
return { envelope, plaintext: undefined };
|
||||
}
|
||||
|
||||
logId = this.getEnvelopeId(unsealedEnvelope);
|
||||
|
||||
|
@ -950,10 +947,7 @@ export default class MessageReceiver
|
|||
} else {
|
||||
window.log.error(...args);
|
||||
}
|
||||
return {
|
||||
plaintext: undefined,
|
||||
envelope,
|
||||
};
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1002,12 +996,12 @@ export default class MessageReceiver
|
|||
private async unsealEnvelope(
|
||||
stores: LockedStores,
|
||||
envelope: ProcessedEnvelope
|
||||
): Promise<UnsealedEnvelope | undefined> {
|
||||
): Promise<UnsealedEnvelope> {
|
||||
const logId = this.getEnvelopeId(envelope);
|
||||
|
||||
if (this.stoppingProcessing) {
|
||||
window.log.info(`MessageReceiver.unsealEnvelope(${logId}): dropping`);
|
||||
return undefined;
|
||||
window.log.warn(`MessageReceiver.unsealEnvelope(${logId}): dropping`);
|
||||
throw new Error('Sealed envelope dropped due to stopping processing');
|
||||
}
|
||||
|
||||
if (envelope.type !== Proto.Envelope.Type.UNIDENTIFIED_SENDER) {
|
||||
|
@ -1068,10 +1062,10 @@ export default class MessageReceiver
|
|||
const logId = this.getEnvelopeId(envelope);
|
||||
|
||||
if (this.stoppingProcessing) {
|
||||
window.log.info(
|
||||
window.log.warn(
|
||||
`MessageReceiver.decryptEnvelope(${logId}): dropping unsealed`
|
||||
);
|
||||
return { plaintext: undefined, envelope };
|
||||
throw new Error('Unsealed envelope dropped due to stopping processing');
|
||||
}
|
||||
|
||||
if (envelope.type === Proto.Envelope.Type.RECEIPT) {
|
||||
|
|
Loading…
Reference in a new issue