Add a write-through cache to the identity store.

This commit is contained in:
Greyson Parrelli
2021-08-25 13:39:59 -04:00
committed by GitHub
parent 28d86886bd
commit 0a67731830
17 changed files with 208 additions and 103 deletions

View File

@@ -8,6 +8,10 @@ import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.KbsEnclave;
import org.thoughtcrime.securesms.components.TypingStatusRepository;
import org.thoughtcrime.securesms.components.TypingStatusSender;
import org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.database.DatabaseObserver;
import org.thoughtcrime.securesms.database.PendingRetryReceiptCache;
import org.thoughtcrime.securesms.groups.GroupsV2Authorization;
@@ -90,6 +94,10 @@ public class ApplicationDependencies {
private static volatile PendingRetryReceiptCache pendingRetryReceiptCache;
private static volatile SignalWebSocket signalWebSocket;
private static volatile MessageNotifier messageNotifier;
private static volatile TextSecureIdentityKeyStore identityStore;
private static volatile TextSecureSessionStore sessionStore;
private static volatile TextSecurePreKeyStore preKeyStore;
private static volatile SignalSenderKeyStore senderKeyStore;
@MainThread
public static void init(@NonNull Application application, @NonNull Provider provider) {
@@ -499,6 +507,50 @@ public class ApplicationDependencies {
return signalWebSocket;
}
public static @NonNull TextSecureIdentityKeyStore getIdentityStore() {
if (identityStore == null) {
synchronized (LOCK) {
if (identityStore == null) {
identityStore = provider.provideIdentityStore();
}
}
}
return identityStore;
}
public static @NonNull TextSecureSessionStore getSessionStore() {
if (sessionStore == null) {
synchronized (LOCK) {
if (sessionStore == null) {
sessionStore = provider.provideSessionStore();
}
}
}
return sessionStore;
}
public static @NonNull TextSecurePreKeyStore getPreKeyStore() {
if (preKeyStore == null) {
synchronized (LOCK) {
if (preKeyStore == null) {
preKeyStore = provider.providePreKeyStore();
}
}
}
return preKeyStore;
}
public static @NonNull SignalSenderKeyStore getSenderKeyStore() {
if (senderKeyStore == null) {
synchronized (LOCK) {
if (senderKeyStore == null) {
senderKeyStore = provider.provideSenderKeyStore();
}
}
}
return senderKeyStore;
}
public interface Provider {
@NonNull GroupsV2Operations provideGroupsV2Operations();
@NonNull SignalServiceAccountManager provideSignalServiceAccountManager();
@@ -527,5 +579,9 @@ public class ApplicationDependencies {
@NonNull PendingRetryReceiptManager providePendingRetryReceiptManager();
@NonNull PendingRetryReceiptCache providePendingRetryReceiptCache();
@NonNull SignalWebSocket provideSignalWebSocket();
@NonNull TextSecureIdentityKeyStore provideIdentityStore();
@NonNull TextSecureSessionStore provideSessionStore();
@NonNull TextSecurePreKeyStore providePreKeyStore();
@NonNull SignalSenderKeyStore provideSenderKeyStore();
}
}

View File

@@ -11,6 +11,10 @@ import org.thoughtcrime.securesms.components.TypingStatusRepository;
import org.thoughtcrime.securesms.components.TypingStatusSender;
import org.thoughtcrime.securesms.crypto.ReentrantSessionLock;
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
import org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.database.DatabaseObserver;
import org.thoughtcrime.securesms.database.JobDatabase;
import org.thoughtcrime.securesms.database.PendingRetryReceiptCache;
@@ -54,6 +58,7 @@ import org.thoughtcrime.securesms.util.EarlyMessageCache;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.FrameRateTracker;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
@@ -259,6 +264,26 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
return signalWebSocket;
}
@Override
public @NonNull TextSecureIdentityKeyStore provideIdentityStore() {
return new TextSecureIdentityKeyStore(context);
}
@Override
public @NonNull TextSecureSessionStore provideSessionStore() {
return new TextSecureSessionStore(context);
}
@Override
public @NonNull TextSecurePreKeyStore providePreKeyStore() {
return new TextSecurePreKeyStore(context);
}
@Override
public @NonNull SignalSenderKeyStore provideSenderKeyStore() {
return new SignalSenderKeyStore(context);
}
private @NonNull WebSocketFactory provideWebSocketFactory(@NonNull SignalWebSocketHealthMonitor healthMonitor) {
return new WebSocketFactory() {
@Override