Support for global.messageQueueTimeInSeconds

This commit is contained in:
Fedor Indutny 2024-10-15 15:43:06 -07:00 committed by GitHub
parent 568c09c579
commit f5257ed5a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 57 additions and 31 deletions

View file

@ -59,6 +59,7 @@ import * as log from '../logging/log';
import type { StorageAccessType } from '../types/Storage';
import { getRelativePath, createName } from '../util/attachmentPath';
import { isBackupEnabled } from '../util/isBackupEnabled';
import { getMessageQueueTime } from '../util/getMessageQueueTime';
type StorageKeyByServiceIdKind = {
[kind in ServiceIdKind]: keyof StorageAccessType;
@ -77,7 +78,6 @@ export const KYBER_KEY_ID_KEY: StorageKeyByServiceIdKind = {
[ServiceIdKind.PNI]: 'maxKyberPreKeyIdPNI',
};
const LAST_RESORT_KEY_ARCHIVE_AGE = 30 * DAY;
const LAST_RESORT_KEY_ROTATION_AGE = DAY * 1.5;
const LAST_RESORT_KEY_MINIMUM = 5;
const LAST_RESORT_KEY_UPDATE_TIME_KEY: StorageKeyByServiceIdKind = {
@ -96,7 +96,6 @@ const PRE_KEY_ID_KEY: StorageKeyByServiceIdKind = {
};
const PRE_KEY_MINIMUM = 10;
const SIGNED_PRE_KEY_ARCHIVE_AGE = 30 * DAY;
export const SIGNED_PRE_KEY_ID_KEY: StorageKeyByServiceIdKind = {
[ServiceIdKind.ACI]: 'signedKeyId',
[ServiceIdKind.Unknown]: 'signedKeyId',
@ -756,7 +755,7 @@ export default class AccountManager extends EventTarget {
'confirmed'
);
// Keep SIGNED_PRE_KEY_MINIMUM keys, drop if older than SIGNED_PRE_KEY_ARCHIVE_AGE
// Keep SIGNED_PRE_KEY_MINIMUM keys, drop if older than message queue time
const toDelete: Array<number> = [];
sortedKeys.forEach((key, index) => {
@ -765,7 +764,7 @@ export default class AccountManager extends EventTarget {
}
const createdAt = key.created_at || 0;
if (isOlderThan(createdAt, SIGNED_PRE_KEY_ARCHIVE_AGE)) {
if (isOlderThan(createdAt, getMessageQueueTime())) {
const timestamp = new Date(createdAt).toJSON();
const confirmedText = key.confirmed ? ' (confirmed)' : '';
log.info(
@ -813,7 +812,7 @@ export default class AccountManager extends EventTarget {
'confirmed'
);
// Keep LAST_RESORT_KEY_MINIMUM keys, drop if older than LAST_RESORT_KEY_ARCHIVE_AGE
// Keep LAST_RESORT_KEY_MINIMUM keys, drop if older than message queue time
const toDelete: Array<number> = [];
sortedKeys.forEach((key, index) => {
@ -822,7 +821,7 @@ export default class AccountManager extends EventTarget {
}
const createdAt = key.createdAt || 0;
if (isOlderThan(createdAt, LAST_RESORT_KEY_ARCHIVE_AGE)) {
if (isOlderThan(createdAt, getMessageQueueTime())) {
const timestamp = new Date(createdAt).toJSON();
const confirmedText = key.isConfirmed ? ' (confirmed)' : '';
log.info(