mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-19 16:19:33 +01:00
Several sender key performance improvements.
- Remove extra unnecessary sync message - Add a bulk session retrieval method - Do the encrypt in a transaction
This commit is contained in:
committed by
Alex Hart
parent
194975d068
commit
2068fa8041
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.crypto.storage;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
import org.whispersystems.libsignal.IdentityKeyPair;
|
||||
@@ -102,6 +103,11 @@ public class SignalProtocolStoreImpl implements SignalServiceDataStore {
|
||||
return sessionStore.getSubDeviceSessions(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) {
|
||||
return sessionStore.getAllAddressesWithActiveSessions(addressNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeSession(SignalProtocolAddress axolotlAddress, SessionRecord record) {
|
||||
sessionStore.storeSession(axolotlAddress, record);
|
||||
@@ -181,4 +187,13 @@ public class SignalProtocolStoreImpl implements SignalServiceDataStore {
|
||||
public boolean isMultiDevice() {
|
||||
return TextSecurePreferences.isMultiDevice(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transaction beginTransaction() {
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().beginTransaction();
|
||||
return () -> {
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().setTransactionSuccessful();
|
||||
DatabaseFactory.getInstance(context).getRawDatabase().endTransaction();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.crypto.storage;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@@ -16,6 +17,8 @@ import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
@@ -97,6 +100,17 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SignalProtocolAddress> getAllAddressesWithActiveSessions(List<String> addressNames) {
|
||||
synchronized (LOCK) {
|
||||
List<SessionDatabase.SessionRow> rows = DatabaseFactory.getSessionDatabase(context).getAllFor(addressNames);
|
||||
return rows.stream()
|
||||
.filter(row -> isActive(row.getRecord()))
|
||||
.map(row -> new SignalProtocolAddress(row.getAddress(), row.getDeviceId()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void archiveSession(SignalProtocolAddress address) {
|
||||
synchronized (LOCK) {
|
||||
@@ -145,4 +159,10 @@ public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isActive(@Nullable SessionRecord record) {
|
||||
return record != null &&
|
||||
record.hasSenderChain() &&
|
||||
record.getSessionVersion() == CiphertextMessage.CURRENT_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user