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