Drop `PqKeysUtil`
This commit is contained in:
parent
b400d49e77
commit
b95d08aaea
|
@ -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<Account> getAccountsWithoutPqKeys(final Flux<Account> 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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue