Add the ability to have separate ACI and PNI protocol stores.

This commit is contained in:
Greyson Parrelli
2022-01-26 16:22:19 -05:00
committed by Cody Henthorne
parent dd7a2834bc
commit 33f4bb0000
33 changed files with 204 additions and 188 deletions
@@ -0,0 +1,16 @@
package org.whispersystems.signalservice.api;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import java.io.Closeable;
/**
* 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 SignalServiceAccountDataStore extends SignalProtocolStore, SignalServiceSessionStore, SignalServiceSenderKeyStore {
/**
* @return True if the user has linked devices, otherwise false.
*/
boolean isMultiDevice();
}
@@ -1,25 +1,30 @@
package org.whispersystems.signalservice.api;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import java.io.Closeable;
import org.whispersystems.signalservice.api.push.AccountIdentifier;
/**
* 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 SignalServiceDataStore extends SignalProtocolStore, SignalServiceSessionStore, SignalServiceSenderKeyStore {
public interface SignalServiceDataStore {
/**
* @return True if the active account has or is a linked device, otherwise false.
* @return A {@link SignalServiceAccountDataStore} for the specified account.
*/
SignalServiceAccountDataStore get(AccountIdentifier accountIdentifier);
/**
* @return A {@link SignalServiceAccountDataStore} for the ACI account.
*/
SignalServiceAccountDataStore aci();
/**
* @return A {@link SignalServiceAccountDataStore} for the PNI account.
*/
SignalServiceAccountDataStore pni();
/**
* @return True if the user has linked devices, otherwise false.
*/
boolean isMultiDevice();
/**
* @return Begins a transaction to improve the performance of multiple storage operations happening in a row.
*/
Transaction beginTransaction();
interface Transaction extends Closeable {
void close();
}
}
@@ -148,12 +148,12 @@ public class SignalServiceMessageSender {
private static final int RETRY_COUNT = 4;
private final PushServiceSocket socket;
private final SignalServiceDataStore store;
private final SignalSessionLock sessionLock;
private final SignalServiceAddress localAddress;
private final int localDeviceId;
private final Optional<EventListener> eventListener;
private final PushServiceSocket socket;
private final SignalServiceAccountDataStore store;
private final SignalSessionLock sessionLock;
private final SignalServiceAddress localAddress;
private final int localDeviceId;
private final Optional<EventListener> eventListener;
private final AttachmentService attachmentService;
private final MessagingService messagingService;
@@ -174,7 +174,7 @@ public class SignalServiceMessageSender {
boolean automaticNetworkRetry)
{
this.socket = new PushServiceSocket(urls, credentialsProvider, signalAgent, clientZkProfileOperations, automaticNetworkRetry);
this.store = store;
this.store = store.aci();
this.sessionLock = sessionLock;
this.localAddress = new SignalServiceAddress(credentialsProvider.getAci(), credentialsProvider.getE164());
this.localDeviceId = credentialsProvider.getDeviceId();