mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-26 11:08:02 +00:00
Rename GV2 "version" to "revision".
This commit is contained in:

committed by
Greyson Parrelli

parent
c634c24afb
commit
a99c0d438e
@@ -336,7 +336,7 @@ public final class GroupDatabase extends Database {
|
||||
}
|
||||
groupId.requireV2();
|
||||
contentValues.put(V2_MASTER_KEY, groupMasterKey.serialize());
|
||||
contentValues.put(V2_REVISION, groupState.getVersion());
|
||||
contentValues.put(V2_REVISION, groupState.getRevision());
|
||||
contentValues.put(V2_DECRYPTED_GROUP, groupState.toByteArray());
|
||||
contentValues.put(MEMBERS, serializeV2GroupMembers(groupState));
|
||||
} else {
|
||||
@@ -394,7 +394,7 @@ public final class GroupDatabase extends Database {
|
||||
UUID uuid = Recipient.self().getUuid().get();
|
||||
|
||||
contentValues.put(TITLE, title);
|
||||
contentValues.put(V2_REVISION, decryptedGroup.getVersion());
|
||||
contentValues.put(V2_REVISION, decryptedGroup.getRevision());
|
||||
contentValues.put(V2_DECRYPTED_GROUP, decryptedGroup.toByteArray());
|
||||
contentValues.put(MEMBERS, serializeV2GroupMembers(decryptedGroup));
|
||||
contentValues.put(ACTIVE, DecryptedGroupUtil.findMemberByUuid(decryptedGroup.getMembersList(), uuid).isPresent() ||
|
||||
|
@@ -56,7 +56,7 @@ final class GroupsV2UpdateMessageProducer {
|
||||
return context.getString(R.string.MessageRecord_s_invited_you_to_the_group, describe(selfPending.get().getAddedByUuid()));
|
||||
}
|
||||
|
||||
if (group.getVersion() == 0) {
|
||||
if (group.getRevision() == 0) {
|
||||
Optional<DecryptedMember> foundingMember = DecryptedGroupUtil.firstMember(group.getMembersList());
|
||||
if (foundingMember.isPresent()) {
|
||||
ByteString foundingMemberUuid = foundingMember.get().getUuid();
|
||||
|
@@ -157,7 +157,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
DecryptedGroupV2Context decryptedGroupV2Context = DecryptedGroupV2Context.parseFrom(decoded);
|
||||
GroupsV2UpdateMessageProducer updateMessageProducer = new GroupsV2UpdateMessageProducer(context, descriptionStrategy, Recipient.self().getUuid().get());
|
||||
|
||||
if (decryptedGroupV2Context.hasChange() && decryptedGroupV2Context.getGroupState().getVersion() > 0) {
|
||||
if (decryptedGroupV2Context.hasChange() && decryptedGroupV2Context.getGroupState().getRevision() > 0) {
|
||||
DecryptedGroupChange change = decryptedGroupV2Context.getChange();
|
||||
List<String> strings = updateMessageProducer.describeChange(change);
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
@@ -147,13 +147,13 @@ public final class GroupManager {
|
||||
@WorkerThread
|
||||
public static void updateGroupFromServer(@NonNull Context context,
|
||||
@NonNull GroupMasterKey groupMasterKey,
|
||||
int version,
|
||||
int revision,
|
||||
long timestamp,
|
||||
@Nullable byte[] signedGroupChange)
|
||||
throws GroupChangeBusyException, IOException, GroupNotAMemberException
|
||||
{
|
||||
try (GroupManagerV2.GroupUpdater updater = new GroupManagerV2(context).updater(groupMasterKey)) {
|
||||
updater.updateLocalToServerVersion(version, timestamp, signedGroupChange);
|
||||
updater.updateLocalToServerRevision(revision, timestamp, signedGroupChange);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -375,7 +375,7 @@ final class GroupManagerV2 {
|
||||
final GroupDatabase.GroupRecord groupRecord = groupDatabase.requireGroup(groupId);
|
||||
final GroupDatabase.V2GroupProperties v2GroupProperties = groupRecord.requireV2GroupProperties();
|
||||
final int nextRevision = v2GroupProperties.getGroupRevision() + 1;
|
||||
final GroupChange.Actions changeActions = change.setVersion(nextRevision).build();
|
||||
final GroupChange.Actions changeActions = change.setRevision(nextRevision).build();
|
||||
final DecryptedGroupChange decryptedChange;
|
||||
final DecryptedGroup decryptedGroupState;
|
||||
|
||||
@@ -427,11 +427,11 @@ final class GroupManagerV2 {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
void updateLocalToServerVersion(int version, long timestamp, @Nullable byte[] signedGroupChange)
|
||||
void updateLocalToServerRevision(int revision, long timestamp, @Nullable byte[] signedGroupChange)
|
||||
throws IOException, GroupNotAMemberException
|
||||
{
|
||||
new GroupsV2StateProcessor(context).forGroup(groupMasterKey)
|
||||
.updateLocalGroupToRevision(version, timestamp, getDecryptedGroupChange(signedGroupChange));
|
||||
.updateLocalGroupToRevision(revision, timestamp, getDecryptedGroupChange(signedGroupChange));
|
||||
}
|
||||
|
||||
private DecryptedGroupChange getDecryptedGroupChange(@Nullable byte[] signedGroupChange) {
|
||||
|
@@ -15,11 +15,11 @@ import org.signal.storageservice.protos.groups.local.DecryptedMember;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.signal.zkgroup.util.UUIDUtil;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.DecryptedGroupV2Context;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -29,19 +29,19 @@ public final class GroupProtoUtil {
|
||||
private GroupProtoUtil() {
|
||||
}
|
||||
|
||||
public static int findVersionWeWereAdded(@NonNull DecryptedGroup group, @NonNull UUID uuid)
|
||||
public static int findRevisionWeWereAdded(@NonNull DecryptedGroup group, @NonNull UUID uuid)
|
||||
throws GroupNotAMemberException
|
||||
{
|
||||
ByteString bytes = UuidUtil.toByteString(uuid);
|
||||
for (DecryptedMember decryptedMember : group.getMembersList()) {
|
||||
if (decryptedMember.getUuid().equals(bytes)) {
|
||||
return decryptedMember.getJoinedAtVersion();
|
||||
return decryptedMember.getJoinedAtRevision();
|
||||
}
|
||||
}
|
||||
for (DecryptedPendingMember decryptedMember : group.getPendingMembersList()) {
|
||||
if (decryptedMember.getUuid().equals(bytes)) {
|
||||
// Assume latest, we don't have any information about when pending members were invited
|
||||
return group.getVersion();
|
||||
return group.getRevision();
|
||||
}
|
||||
}
|
||||
throw new GroupNotAMemberException();
|
||||
@@ -52,10 +52,10 @@ public final class GroupProtoUtil {
|
||||
@Nullable DecryptedGroupChange plainGroupChange,
|
||||
@Nullable GroupChange signedServerChange)
|
||||
{
|
||||
int version = plainGroupChange != null ? plainGroupChange.getVersion() : decryptedGroup.getVersion();
|
||||
int revision = plainGroupChange != null ? plainGroupChange.getRevision() : decryptedGroup.getRevision();
|
||||
SignalServiceProtos.GroupContextV2.Builder contextBuilder = SignalServiceProtos.GroupContextV2.newBuilder()
|
||||
.setMasterKey(ByteString.copyFrom(masterKey.serialize()))
|
||||
.setRevision(version);
|
||||
.setRevision(revision);
|
||||
|
||||
if (signedServerChange != null) {
|
||||
contextBuilder.setGroupChange(signedServerChange.toByteString());
|
||||
|
@@ -31,13 +31,13 @@ final class GlobalGroupState {
|
||||
return history;
|
||||
}
|
||||
|
||||
int getLatestVersionNumber() {
|
||||
int getLatestRevisionNumber() {
|
||||
if (history.isEmpty()) {
|
||||
if (localState == null) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
return localState.getVersion();
|
||||
return localState.getRevision();
|
||||
}
|
||||
return history.get(history.size() - 1).getGroup().getVersion();
|
||||
return history.get(history.size() - 1).getGroup().getRevision();
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ final class GroupLogEntry {
|
||||
@Nullable private final DecryptedGroupChange change;
|
||||
|
||||
GroupLogEntry(@NonNull DecryptedGroup group, @Nullable DecryptedGroupChange change) {
|
||||
if (change != null && group.getVersion() != change.getVersion()) {
|
||||
if (change != null && group.getRevision() != change.getRevision()) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
@@ -12,20 +12,20 @@ final class GroupStateMapper {
|
||||
|
||||
static final int LATEST = Integer.MAX_VALUE;
|
||||
|
||||
private static final Comparator<GroupLogEntry> BY_VERSION = (o1, o2) -> Integer.compare(o1.getGroup().getVersion(), o2.getGroup().getVersion());
|
||||
private static final Comparator<GroupLogEntry> BY_REVISION = (o1, o2) -> Integer.compare(o1.getGroup().getRevision(), o2.getGroup().getRevision());
|
||||
|
||||
private GroupStateMapper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an input {@link GlobalGroupState} and a {@param maximumVersionToApply}, returns a result
|
||||
* containing what the new local group state should be, and any remaining version history to apply.
|
||||
* Given an input {@link GlobalGroupState} and a {@param maximumRevisionToApply}, returns a result
|
||||
* containing what the new local group state should be, and any remaining revision history to apply.
|
||||
* <p>
|
||||
* Function is pure.
|
||||
* @param maximumVersionToApply Use {@link #LATEST} to apply the very latest.
|
||||
* @param maximumRevisionToApply Use {@link #LATEST} to apply the very latest.
|
||||
*/
|
||||
static @NonNull AdvanceGroupStateResult partiallyAdvanceGroupState(@NonNull GlobalGroupState inputState,
|
||||
int maximumVersionToApply)
|
||||
int maximumRevisionToApply)
|
||||
{
|
||||
final ArrayList<GroupLogEntry> statesToApplyNow = new ArrayList<>(inputState.getHistory().size());
|
||||
final ArrayList<GroupLogEntry> statesToApplyLater = new ArrayList<>(inputState.getHistory().size());
|
||||
@@ -34,20 +34,20 @@ final class GroupStateMapper {
|
||||
|
||||
for (GroupLogEntry entry : inputState.getHistory()) {
|
||||
if (inputState.getLocalState() != null &&
|
||||
inputState.getLocalState().getVersion() >= entry.getGroup().getVersion())
|
||||
inputState.getLocalState().getRevision() >= entry.getGroup().getRevision())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.getGroup().getVersion() > maximumVersionToApply) {
|
||||
if (entry.getGroup().getRevision() > maximumRevisionToApply) {
|
||||
statesToApplyLater.add(entry);
|
||||
} else {
|
||||
statesToApplyNow.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(statesToApplyNow, BY_VERSION);
|
||||
Collections.sort(statesToApplyLater, BY_VERSION);
|
||||
Collections.sort(statesToApplyNow, BY_REVISION);
|
||||
Collections.sort(statesToApplyLater, BY_REVISION);
|
||||
|
||||
if (statesToApplyNow.size() > 0) {
|
||||
newLocalState = statesToApplyNow.get(statesToApplyNow.size() - 1)
|
||||
|
@@ -13,7 +13,6 @@ import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
||||
import org.signal.zkgroup.VerificationFailedException;
|
||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.signal.zkgroup.groups.GroupSecretParams;
|
||||
import org.signal.zkgroup.util.UUIDUtil;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
@@ -150,8 +149,8 @@ public final class GroupsV2StateProcessor {
|
||||
|
||||
if (signedGroupChange != null &&
|
||||
localState != null &&
|
||||
localState.getVersion() + 1 == signedGroupChange.getVersion() &&
|
||||
revision == signedGroupChange.getVersion())
|
||||
localState.getRevision() + 1 == signedGroupChange.getRevision() &&
|
||||
revision == signedGroupChange.getRevision())
|
||||
{
|
||||
try {
|
||||
Log.i(TAG, "Applying P2P group change");
|
||||
@@ -188,7 +187,7 @@ public final class GroupsV2StateProcessor {
|
||||
|
||||
GlobalGroupState remainingWork = advanceGroupStateResult.getNewGlobalGroupState();
|
||||
if (remainingWork.getHistory().size() > 0) {
|
||||
Log.i(TAG, String.format(Locale.US, "There are more versions on the server for this group, not applying at this time, V[%d..%d]", newLocalState.getVersion() + 1, remainingWork.getLatestVersionNumber()));
|
||||
Log.i(TAG, String.format(Locale.US, "There are more revisions on the server for this group, not applying at this time, V[%d..%d]", newLocalState.getRevision() + 1, remainingWork.getLatestRevisionNumber()));
|
||||
}
|
||||
|
||||
return new GroupUpdateResult(GroupState.GROUP_UPDATED, newLocalState);
|
||||
@@ -206,10 +205,10 @@ public final class GroupsV2StateProcessor {
|
||||
.requireV2GroupProperties()
|
||||
.getDecryptedGroup();
|
||||
|
||||
DecryptedGroup simulatedGroupState = DecryptedGroupUtil.removeMember(decryptedGroup, selfUuid, decryptedGroup.getVersion() + 1);
|
||||
DecryptedGroup simulatedGroupState = DecryptedGroupUtil.removeMember(decryptedGroup, selfUuid, decryptedGroup.getRevision() + 1);
|
||||
DecryptedGroupChange simulatedGroupChange = DecryptedGroupChange.newBuilder()
|
||||
.setEditor(UuidUtil.toByteString(UuidUtil.UNKNOWN_UUID))
|
||||
.setVersion(simulatedGroupState.getVersion())
|
||||
.setRevision(simulatedGroupState.getRevision())
|
||||
.addDeleteMembers(UuidUtil.toByteString(selfUuid))
|
||||
.build();
|
||||
|
||||
@@ -315,8 +314,8 @@ public final class GroupsV2StateProcessor {
|
||||
if (latestOnly || !GroupProtoUtil.isMember(selfUuid, latestServerGroup.getMembersList())) {
|
||||
history = Collections.singletonList(new GroupLogEntry(latestServerGroup, null));
|
||||
} else {
|
||||
int versionWeWereAdded = GroupProtoUtil.findVersionWeWereAdded(latestServerGroup, selfUuid);
|
||||
int logsNeededFrom = localState != null ? Math.max(localState.getVersion(), versionWeWereAdded) : versionWeWereAdded;
|
||||
int revisionWeWereAdded = GroupProtoUtil.findRevisionWeWereAdded(latestServerGroup, selfUuid);
|
||||
int logsNeededFrom = localState != null ? Math.max(localState.getRevision(), revisionWeWereAdded) : revisionWeWereAdded;
|
||||
|
||||
history = getFullMemberHistory(selfUuid, logsNeededFrom);
|
||||
}
|
||||
@@ -324,9 +323,9 @@ public final class GroupsV2StateProcessor {
|
||||
return new GlobalGroupState(localState, history);
|
||||
}
|
||||
|
||||
private List<GroupLogEntry> getFullMemberHistory(@NonNull UUID selfUuid, int logsNeededFrom) throws IOException {
|
||||
private List<GroupLogEntry> getFullMemberHistory(@NonNull UUID selfUuid, int logsNeededFromRevision) throws IOException {
|
||||
try {
|
||||
Collection<DecryptedGroupHistoryEntry> groupStatesFromRevision = groupsV2Api.getGroupHistory(groupSecretParams, logsNeededFrom, groupsV2Authorization.getAuthorizationForToday(selfUuid, groupSecretParams));
|
||||
Collection<DecryptedGroupHistoryEntry> groupStatesFromRevision = groupsV2Api.getGroupHistory(groupSecretParams, logsNeededFromRevision, groupsV2Authorization.getAuthorizationForToday(selfUuid, groupSecretParams));
|
||||
ArrayList<GroupLogEntry> history = new ArrayList<>(groupStatesFromRevision.size());
|
||||
|
||||
for (DecryptedGroupHistoryEntry entry : groupStatesFromRevision) {
|
||||
|
@@ -545,9 +545,9 @@ public final class GroupsV2UpdateMessageProducerTest {
|
||||
|
||||
private final DecryptedGroup.Builder builder;
|
||||
|
||||
GroupStateBuilder(@NonNull UUID foundingMember, int version) {
|
||||
GroupStateBuilder(@NonNull UUID foundingMember, int revision) {
|
||||
builder = DecryptedGroup.newBuilder()
|
||||
.setVersion(version)
|
||||
.setRevision(revision)
|
||||
.addMembers(DecryptedMember.newBuilder()
|
||||
.setUuid(UuidUtil.toByteString(foundingMember)));
|
||||
}
|
||||
|
@@ -14,32 +14,32 @@ public final class GlobalGroupStateTest {
|
||||
public void cannot_ask_latestVersionNumber_of_empty_state() {
|
||||
GlobalGroupState emptyState = new GlobalGroupState(null, emptyList());
|
||||
|
||||
emptyState.getLatestVersionNumber();
|
||||
emptyState.getLatestRevisionNumber();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void latestVersionNumber_of_state_and_empty_list() {
|
||||
public void latestRevisionNumber_of_state_and_empty_list() {
|
||||
GlobalGroupState emptyState = new GlobalGroupState(state(10), emptyList());
|
||||
|
||||
assertEquals(10, emptyState.getLatestVersionNumber());
|
||||
assertEquals(10, emptyState.getLatestRevisionNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void latestVersionNumber_of_state_and_list() {
|
||||
public void latestRevisionNumber_of_state_and_list() {
|
||||
GlobalGroupState emptyState = new GlobalGroupState(state(2), asList(logEntry(3), logEntry(4)));
|
||||
|
||||
assertEquals(4, emptyState.getLatestVersionNumber());
|
||||
assertEquals(4, emptyState.getLatestRevisionNumber());
|
||||
}
|
||||
|
||||
private static GroupLogEntry logEntry(int version) {
|
||||
return new GroupLogEntry(state(version), change(version));
|
||||
private static GroupLogEntry logEntry(int revision) {
|
||||
return new GroupLogEntry(state(revision), change(revision));
|
||||
}
|
||||
|
||||
private static DecryptedGroup state(int version) {
|
||||
return DecryptedGroup.newBuilder().setVersion(version).build();
|
||||
private static DecryptedGroup state(int revision) {
|
||||
return DecryptedGroup.newBuilder().setRevision(revision).build();
|
||||
}
|
||||
|
||||
private static DecryptedGroupChange change(int version) {
|
||||
return DecryptedGroupChange.newBuilder().setVersion(version).build();
|
||||
private static DecryptedGroupChange change(int revision) {
|
||||
return DecryptedGroupChange.newBuilder().setRevision(revision).build();
|
||||
}
|
||||
}
|
||||
|
@@ -115,7 +115,7 @@ public final class GroupStateMapperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apply_maximum_group_versions() {
|
||||
public void apply_maximum_group_revisions() {
|
||||
DecryptedGroup currentState = state(Integer.MAX_VALUE - 2);
|
||||
GroupLogEntry log1 = logEntry(Integer.MAX_VALUE - 1);
|
||||
GroupLogEntry log2 = logEntry(Integer.MAX_VALUE);
|
||||
@@ -132,15 +132,15 @@ public final class GroupStateMapperTest {
|
||||
assertThat(actual.getHistory(), is(expected.getHistory()));
|
||||
}
|
||||
|
||||
private static GroupLogEntry logEntry(int version) {
|
||||
return new GroupLogEntry(state(version), change(version));
|
||||
private static GroupLogEntry logEntry(int revision) {
|
||||
return new GroupLogEntry(state(revision), change(revision));
|
||||
}
|
||||
|
||||
private static DecryptedGroup state(int version) {
|
||||
return DecryptedGroup.newBuilder().setVersion(version).build();
|
||||
private static DecryptedGroup state(int revision) {
|
||||
return DecryptedGroup.newBuilder().setRevision(revision).build();
|
||||
}
|
||||
|
||||
private static DecryptedGroupChange change(int version) {
|
||||
return DecryptedGroupChange.newBuilder().setVersion(version).build();
|
||||
private static DecryptedGroupChange change(int revision) {
|
||||
return DecryptedGroupChange.newBuilder().setRevision(revision).build();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user