Call refreshPreKeys on same cadence as rotateSignedPreKey

This commit is contained in:
Scott Nonnenberg 2023-06-08 18:08:24 -07:00 committed by GitHub
parent 6e1916030d
commit 22fb69bbb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -326,13 +326,20 @@ export default class AccountManager extends EventTarget {
async refreshPreKeys(uuidKind: UUIDKind): Promise<void> {
return this.queueTask(async () => {
const preKeyCount = await this.server.getMyKeys(uuidKind);
log.info(`prekey count ${preKeyCount}`);
log.info(
`refreshPreKeys(${uuidKind}): Server prekey count is ${preKeyCount}`
);
if (preKeyCount >= 10) {
return;
}
const keys = await this.generateKeys(SIGNED_KEY_GEN_BATCH_SIZE, uuidKind);
await this.server.registerKeys(keys, uuidKind);
await this.confirmKeys(keys, uuidKind);
const updatedCount = await this.server.getMyKeys(uuidKind);
log.info(
`refreshPreKeys(${uuidKind}): Successfully updated; server count is now ${updatedCount}`
);
});
}

View file

@ -58,6 +58,13 @@ export class RotateSignedPreKeyListener {
accountManager.rotateSignedPreKey(UUIDKind.ACI),
accountManager.rotateSignedPreKey(UUIDKind.PNI),
]);
// We try to update this whenever we remove a preKey; this is a fail-safe to ensure
// we're always in good shape
await Promise.all([
accountManager.refreshPreKeys(UUIDKind.ACI),
accountManager.refreshPreKeys(UUIDKind.PNI),
]);
this.scheduleNextRotation();
this.setTimeoutForNextRun();
} catch (error) {