From fea66f0f9e7d64237a6689a75b641bfbfec42cee Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Fri, 16 May 2025 13:21:31 -0500 Subject: [PATCH] Fallback to global media tier CDN number Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com> --- ts/RemoteConfig.ts | 1 + ts/test-electron/util/downloadAttachment_test.ts | 14 ++++++++++++-- ts/test-mock/bootstrap.ts | 1 + ts/textsecure/downloadAttachment.ts | 9 ++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ts/RemoteConfig.ts b/ts/RemoteConfig.ts index 71fd292ed1..c1c55de252 100644 --- a/ts/RemoteConfig.ts +++ b/ts/RemoteConfig.ts @@ -41,6 +41,7 @@ export type ConfigKeyType = | 'desktop.releaseNotes.dev' | 'global.attachments.maxBytes' | 'global.attachments.maxReceiveBytes' + | 'global.backups.mediaTierFallbackCdnNumber' | 'global.calling.maxGroupCallRingSize' | 'global.groupsv2.groupSizeHardLimit' | 'global.groupsv2.maxGroupSize' diff --git a/ts/test-electron/util/downloadAttachment_test.ts b/ts/test-electron/util/downloadAttachment_test.ts index 042bba8b97..e62a4371dd 100644 --- a/ts/test-electron/util/downloadAttachment_test.ts +++ b/ts/test-electron/util/downloadAttachment_test.ts @@ -17,6 +17,7 @@ import { AttachmentVariant, AttachmentPermanentlyUndownloadableError, } from '../../types/Attachment'; +import { updateRemoteConfig } from '../../test-both/helpers/RemoteConfigStub'; describe('utils/downloadAttachment', () => { const baseAttachment = { @@ -300,7 +301,8 @@ describe('utils/downloadAttachment', () => { describe('getCdnNumberForBackupTier', () => { let sandbox: sinon.SinonSandbox; - beforeEach(() => { + beforeEach(async () => { + await DataWriter.removeAll(); sandbox = sinon.createSandbox(); sandbox.stub(window.storage, 'get').callsFake(key => { if (key === 'masterKey') { @@ -311,11 +313,19 @@ describe('getCdnNumberForBackupTier', () => { } return undefined; }); + await updateRemoteConfig([ + { + name: 'global.backups.mediaTierFallbackCdnNumber', + enabled: true, + value: '42', + }, + ]); }); afterEach(async () => { await DataWriter.clearAllBackupCdnObjectMetadata(); sandbox.restore(); + await updateRemoteConfig([]); }); const baseAttachment = { @@ -334,7 +344,7 @@ describe('getCdnNumberForBackupTier', () => { ...baseAttachment, backupLocator: { mediaName: 'mediaName' }, }); - assert.equal(result, 3); + assert.equal(result, 42); }); it('uses cdn number in DB if none on attachment', async () => { await DataWriter.saveBackupCdnObjectMetadata([ diff --git a/ts/test-mock/bootstrap.ts b/ts/test-mock/bootstrap.ts index 0522f97bf0..166023893e 100644 --- a/ts/test-mock/bootstrap.ts +++ b/ts/test-mock/bootstrap.ts @@ -176,6 +176,7 @@ const DEFAULT_REMOTE_CONFIG = [ ['desktop.internalUser', { enabled: true }], ['desktop.releaseNotes', { enabled: true }], ['desktop.senderKey.retry', { enabled: true }], + ['global.backups.mediaTierFallbackCdnNumber', { enabled: true, value: '3' }], ['global.groupsv2.groupSizeHardLimit', { enabled: true, value: '64' }], ['global.groupsv2.maxGroupSize', { enabled: true, value: '32' }], ] as const; diff --git a/ts/textsecure/downloadAttachment.ts b/ts/textsecure/downloadAttachment.ts index 41a671f655..a23cbc9b00 100644 --- a/ts/textsecure/downloadAttachment.ts +++ b/ts/textsecure/downloadAttachment.ts @@ -46,8 +46,8 @@ import { MAX_BACKUP_THUMBNAIL_SIZE } from '../types/VisualAttachment'; import { missingCaseError } from '../util/missingCaseError'; import { IV_LENGTH, MAC_LENGTH } from '../types/Crypto'; import { BackupCredentialType } from '../types/backups'; - -const DEFAULT_BACKUP_CDN_NUMBER = 3; +import { getValue } from '../RemoteConfig'; +import { parseIntOrThrow } from '../util/parseIntOrThrow'; export function getCdnKey(attachment: ProcessedAttachment): string { const cdnKey = attachment.cdnId || attachment.cdnKey; @@ -93,7 +93,10 @@ export async function getCdnNumberForBackupTier( if (backupCdnInfo.isInBackupTier) { backupCdnNumber = backupCdnInfo.cdnNumber; } else { - backupCdnNumber = DEFAULT_BACKUP_CDN_NUMBER; + backupCdnNumber = parseIntOrThrow( + getValue('global.backups.mediaTierFallbackCdnNumber'), + 'global.backups.mediaTierFallbackCdnNumber must be set' + ); } } return backupCdnNumber;