diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/PqKeysUtil.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/PqKeysUtil.java deleted file mode 100644 index 0293bd7d3..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/PqKeysUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2025 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.workers; - -import java.time.Duration; -import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.whispersystems.textsecuregcm.identity.IdentityType; -import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.KeysManager; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.util.retry.Retry; - -class PqKeysUtil { - - private final KeysManager keysManager; - private final int maxConcurrency; - private final int maxRetries; - - private static final Logger log = LoggerFactory.getLogger(PqKeysUtil.class); - - PqKeysUtil(final KeysManager keysManager, final int maxConcurrency, final int maxRetries) { - this.keysManager = keysManager; - this.maxConcurrency = maxConcurrency; - this.maxRetries = maxRetries; - } - - public Flux getAccountsWithoutPqKeys(final Flux accounts) { - return accounts.flatMap(account -> Mono.fromFuture( - () -> keysManager.getLastResort(account.getIdentifier(IdentityType.ACI), Device.PRIMARY_ID)) - .retryWhen(Retry.backoff(maxRetries, Duration.ofSeconds(1)) - .onRetryExhaustedThrow((spec, rs) -> rs.failure())) - .onErrorResume(throwable -> { - log.warn("Failed to get last-resort key for {}", account.getIdentifier(IdentityType.ACI), throwable); - return Mono.empty(); - }) - .filter(Optional::isEmpty) - .map(ignored -> account), - maxConcurrency); - } -} diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/workers/PqKeysUtilTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/workers/PqKeysUtilTest.java deleted file mode 100644 index 5521c027c..000000000 --- a/service/src/test/java/org/whispersystems/textsecuregcm/workers/PqKeysUtilTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2025 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.workers; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyByte; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.whispersystems.textsecuregcm.entities.KEMSignedPreKey; -import org.whispersystems.textsecuregcm.identity.IdentityType; -import org.whispersystems.textsecuregcm.storage.Account; -import org.whispersystems.textsecuregcm.storage.Device; -import org.whispersystems.textsecuregcm.storage.KeysManager; -import reactor.core.publisher.Flux; - -class PqKeysUtilTest { - - private KeysManager keysManager; - private PqKeysUtil pqKeysUtil; - - @BeforeEach - void setUp() { - keysManager = mock(KeysManager.class); - pqKeysUtil = new PqKeysUtil(keysManager, 16, 3); - } - - @Test - void getAccountsWithoutPqKeys() { - final UUID aciWithPqKeys = UUID.randomUUID(); - - final Account accountWithPqKeys = mock(Account.class); - when(accountWithPqKeys.getIdentifier(IdentityType.ACI)).thenReturn(aciWithPqKeys); - - final Account accountWithoutPqKeys = mock(Account.class); - when(accountWithoutPqKeys.getIdentifier(IdentityType.ACI)).thenReturn(UUID.randomUUID()); - - when(keysManager.getLastResort(any(), anyByte())).thenReturn(CompletableFuture.completedFuture(Optional.empty())); - when(keysManager.getLastResort(aciWithPqKeys, Device.PRIMARY_ID)) - .thenReturn(CompletableFuture.completedFuture(Optional.of(mock(KEMSignedPreKey.class)))); - - assertEquals(List.of(accountWithoutPqKeys), - Flux.just(accountWithPqKeys, accountWithoutPqKeys) - .transform(pqKeysUtil::getAccountsWithoutPqKeys) - .collectList() - .block()); - } -}