Archive sessions on 409/410 instead of deleting them.
This commit is contained in:
parent
2a3f85008b
commit
2751076089
5 changed files with 53 additions and 14 deletions
|
@ -14,15 +14,17 @@ import org.whispersystems.libsignal.state.SessionStore;
|
|||
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyRecord;
|
||||
import org.whispersystems.libsignal.state.SignedPreKeyStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceProtocolStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SignalProtocolStoreImpl implements SignalProtocolStore {
|
||||
public class SignalProtocolStoreImpl implements SignalServiceProtocolStore {
|
||||
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final SignedPreKeyStore signedPreKeyStore;
|
||||
private final IdentityKeyStore identityKeyStore;
|
||||
private final SessionStore sessionStore;
|
||||
private final PreKeyStore preKeyStore;
|
||||
private final SignedPreKeyStore signedPreKeyStore;
|
||||
private final IdentityKeyStore identityKeyStore;
|
||||
private final SignalServiceSessionStore sessionStore;
|
||||
|
||||
public SignalProtocolStoreImpl(Context context) {
|
||||
this.preKeyStore = new TextSecurePreKeyStore(context);
|
||||
|
@ -106,6 +108,11 @@ public class SignalProtocolStoreImpl implements SignalProtocolStore {
|
|||
sessionStore.deleteAllSessions(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void archiveSession(SignalProtocolAddress address) {
|
||||
sessionStore.archiveSession(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
|
||||
return signedPreKeyStore.loadSignedPreKey(signedPreKeyId);
|
||||
|
|
|
@ -12,12 +12,12 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
|
|||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.protocol.CiphertextMessage;
|
||||
import org.whispersystems.libsignal.state.SessionRecord;
|
||||
import org.whispersystems.libsignal.state.SessionStore;
|
||||
import org.whispersystems.signalservice.api.SignalServiceSessionStore;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TextSecureSessionStore implements SessionStore {
|
||||
public class TextSecureSessionStore implements SignalServiceSessionStore {
|
||||
|
||||
private static final String TAG = TextSecureSessionStore.class.getSimpleName();
|
||||
|
||||
|
@ -103,6 +103,16 @@ public class TextSecureSessionStore implements SessionStore {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void archiveSession(SignalProtocolAddress address) {
|
||||
synchronized (FILE_LOCK) {
|
||||
if (DatabaseFactory.getRecipientDatabase(context).containsPhoneOrUuid(address.getName())) {
|
||||
RecipientId recipientId = Recipient.external(context, address.getName()).getId();
|
||||
archiveSession(recipientId, address.getDeviceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void archiveSession(@NonNull RecipientId recipientId, int deviceId) {
|
||||
synchronized (FILE_LOCK) {
|
||||
SessionRecord session = DatabaseFactory.getSessionDatabase(context).load(recipientId, deviceId);
|
||||
|
|
|
@ -119,7 +119,7 @@ public class SignalServiceMessageSender {
|
|||
private static final int RETRY_COUNT = 4;
|
||||
|
||||
private final PushServiceSocket socket;
|
||||
private final SignalProtocolStore store;
|
||||
private final SignalServiceProtocolStore store;
|
||||
private final SignalServiceAddress localAddress;
|
||||
private final Optional<EventListener> eventListener;
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class SignalServiceMessageSender {
|
|||
*/
|
||||
public SignalServiceMessageSender(SignalServiceConfiguration urls,
|
||||
UUID uuid, String e164, String password,
|
||||
SignalProtocolStore store,
|
||||
SignalServiceProtocolStore store,
|
||||
String signalAgent,
|
||||
boolean isMultiDevice,
|
||||
Optional<SignalServiceMessagePipe> pipe,
|
||||
|
@ -158,7 +158,7 @@ public class SignalServiceMessageSender {
|
|||
|
||||
public SignalServiceMessageSender(SignalServiceConfiguration urls,
|
||||
CredentialsProvider credentialsProvider,
|
||||
SignalProtocolStore store,
|
||||
SignalServiceProtocolStore store,
|
||||
String signalAgent,
|
||||
boolean isMultiDevice,
|
||||
Optional<SignalServiceMessagePipe> pipe,
|
||||
|
@ -1587,10 +1587,10 @@ public class SignalServiceMessageSender {
|
|||
try {
|
||||
for (int extraDeviceId : mismatchedDevices.getExtraDevices()) {
|
||||
if (recipient.getUuid().isPresent()) {
|
||||
store.deleteSession(new SignalProtocolAddress(recipient.getUuid().get().toString(), extraDeviceId));
|
||||
store.archiveSession(new SignalProtocolAddress(recipient.getUuid().get().toString(), extraDeviceId));
|
||||
}
|
||||
if (recipient.getNumber().isPresent()) {
|
||||
store.deleteSession(new SignalProtocolAddress(recipient.getNumber().get(), extraDeviceId));
|
||||
store.archiveSession(new SignalProtocolAddress(recipient.getNumber().get(), extraDeviceId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1612,10 +1612,10 @@ public class SignalServiceMessageSender {
|
|||
private void handleStaleDevices(SignalServiceAddress recipient, StaleDevices staleDevices) {
|
||||
for (int staleDeviceId : staleDevices.getStaleDevices()) {
|
||||
if (recipient.getUuid().isPresent()) {
|
||||
store.deleteSession(new SignalProtocolAddress(recipient.getUuid().get().toString(), staleDeviceId));
|
||||
store.archiveSession(new SignalProtocolAddress(recipient.getUuid().get().toString(), staleDeviceId));
|
||||
}
|
||||
if (recipient.getNumber().isPresent()) {
|
||||
store.deleteSession(new SignalProtocolAddress(recipient.getNumber().get(), staleDeviceId));
|
||||
store.archiveSession(new SignalProtocolAddress(recipient.getNumber().get(), staleDeviceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.whispersystems.signalservice.api;
|
||||
|
||||
import org.whispersystems.libsignal.state.SignalProtocolStore;
|
||||
|
||||
/**
|
||||
* And extension of the normal protocol store interface that has additional methods that are needed
|
||||
* in the service layer, but not the protocol layer.
|
||||
*/
|
||||
public interface SignalServiceProtocolStore extends SignalProtocolStore, SignalServiceSessionStore {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package org.whispersystems.signalservice.api;
|
||||
|
||||
import org.whispersystems.libsignal.SignalProtocolAddress;
|
||||
import org.whispersystems.libsignal.state.SessionStore;
|
||||
|
||||
/**
|
||||
* And extension of the normal protocol session store interface that has additional methods that are
|
||||
* needed in the service layer, but not the protocol layer.
|
||||
*/
|
||||
public interface SignalServiceSessionStore extends SessionStore {
|
||||
void archiveSession(SignalProtocolAddress address);
|
||||
}
|
Loading…
Add table
Reference in a new issue