mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Cache group credentials in memory
This commit is contained in:
parent
e83f43065e
commit
e92d37e3a5
1 changed files with 10 additions and 9 deletions
|
@ -21,6 +21,7 @@ import org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo;
|
||||||
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
||||||
import org.signal.zkgroup.InvalidInputException;
|
import org.signal.zkgroup.InvalidInputException;
|
||||||
import org.signal.zkgroup.VerificationFailedException;
|
import org.signal.zkgroup.VerificationFailedException;
|
||||||
|
import org.signal.zkgroup.auth.AuthCredentialResponse;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.signal.zkgroup.groups.GroupSecretParams;
|
import org.signal.zkgroup.groups.GroupSecretParams;
|
||||||
import org.signal.zkgroup.groups.UuidCiphertext;
|
import org.signal.zkgroup.groups.UuidCiphertext;
|
||||||
|
@ -43,6 +44,7 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -53,17 +55,14 @@ public class GroupV2Helper {
|
||||||
private final static Logger logger = LoggerFactory.getLogger(GroupV2Helper.class);
|
private final static Logger logger = LoggerFactory.getLogger(GroupV2Helper.class);
|
||||||
|
|
||||||
private final ProfileKeyCredentialProvider profileKeyCredentialProvider;
|
private final ProfileKeyCredentialProvider profileKeyCredentialProvider;
|
||||||
|
|
||||||
private final ProfileProvider profileProvider;
|
private final ProfileProvider profileProvider;
|
||||||
|
|
||||||
private final SelfRecipientIdProvider selfRecipientIdProvider;
|
private final SelfRecipientIdProvider selfRecipientIdProvider;
|
||||||
|
|
||||||
private final GroupsV2Operations groupsV2Operations;
|
private final GroupsV2Operations groupsV2Operations;
|
||||||
|
|
||||||
private final GroupsV2Api groupsV2Api;
|
private final GroupsV2Api groupsV2Api;
|
||||||
|
|
||||||
private final SignalServiceAddressResolver addressResolver;
|
private final SignalServiceAddressResolver addressResolver;
|
||||||
|
|
||||||
|
private HashMap<Integer, AuthCredentialResponse> groupApiCredentials;
|
||||||
|
|
||||||
public GroupV2Helper(
|
public GroupV2Helper(
|
||||||
final ProfileKeyCredentialProvider profileKeyCredentialProvider,
|
final ProfileKeyCredentialProvider profileKeyCredentialProvider,
|
||||||
final ProfileProvider profileProvider,
|
final ProfileProvider profileProvider,
|
||||||
|
@ -508,10 +507,12 @@ public class GroupV2Helper {
|
||||||
final GroupSecretParams groupSecretParams
|
final GroupSecretParams groupSecretParams
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
final var today = currentTimeDays();
|
final var today = currentTimeDays();
|
||||||
// Returns credentials for the next 7 days
|
if (groupApiCredentials == null || !groupApiCredentials.containsKey(today)) {
|
||||||
final var credentials = groupsV2Api.getCredentials(today);
|
// Returns credentials for the next 7 days
|
||||||
// TODO cache credentials until they expire
|
groupApiCredentials = groupsV2Api.getCredentials(today);
|
||||||
var authCredentialResponse = credentials.get(today);
|
// TODO cache credentials on disk until they expire
|
||||||
|
}
|
||||||
|
var authCredentialResponse = groupApiCredentials.get(today);
|
||||||
final var aci = getSelfAci();
|
final var aci = getSelfAci();
|
||||||
try {
|
try {
|
||||||
return groupsV2Api.getGroupsV2AuthorizationString(aci, today, groupSecretParams, authCredentialResponse);
|
return groupsV2Api.getGroupsV2AuthorizationString(aci, today, groupSecretParams, authCredentialResponse);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue