mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 08:06:47 +00:00
Add an experiment to skip envelope expansion
This commit is contained in:
1 parent
69a954e889
commit
3b1087d36b
2 files changed
+37
No files matched your search
@@ -24,6 +24,9 @@ public class EnvelopeUtil {
|
||||
@VisibleForTesting
|
||||
static final String INCLUDE_BINARY_SERVICE_ID_EXPERIMENT_NAME = "envelopeIncludeBinaryServiceIdentifier";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String SKIP_EXPANSION_EXPERIMENT_NAME = "skipEnvelopeExpansion";
|
||||
|
||||
/**
|
||||
* Converts all "compressible" UUID-like fields in the given envelope to more compact binary representations.
|
||||
*
|
||||
@@ -77,6 +80,7 @@ public class EnvelopeUtil {
|
||||
final ExperimentEnrollmentManager experimentEnrollmentManager) {
|
||||
|
||||
final boolean includeBinaryServiceIdentifiers;
|
||||
final boolean skipEnvelopeExpansion;
|
||||
|
||||
if (envelope.hasDestinationServiceIdBinary() || envelope.hasDestinationServiceId()) {
|
||||
final ServiceIdentifier destinationIdentifier = envelope.hasDestinationServiceIdBinary()
|
||||
@@ -85,8 +89,16 @@ public class EnvelopeUtil {
|
||||
|
||||
includeBinaryServiceIdentifiers =
|
||||
experimentEnrollmentManager.isEnrolled(destinationIdentifier.uuid(), INCLUDE_BINARY_SERVICE_ID_EXPERIMENT_NAME);
|
||||
|
||||
skipEnvelopeExpansion =
|
||||
experimentEnrollmentManager.isEnrolled(destinationIdentifier.uuid(), SKIP_EXPANSION_EXPERIMENT_NAME);
|
||||
} else {
|
||||
includeBinaryServiceIdentifiers = false;
|
||||
skipEnvelopeExpansion = false;
|
||||
}
|
||||
|
||||
if (skipEnvelopeExpansion) {
|
||||
return envelope;
|
||||
}
|
||||
|
||||
final MessageProtos.Envelope.Builder builder = envelope.toBuilder();
|
||||
|
||||
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.when;
|
||||
import com.google.protobuf.ByteString;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
@@ -116,6 +117,30 @@ class EnvelopeUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void compressExpandSkipExpansion() {
|
||||
final ExperimentEnrollmentManager experimentEnrollmentManager = mock(ExperimentEnrollmentManager.class);
|
||||
when(experimentEnrollmentManager.isEnrolled(any(UUID.class), eq(EnvelopeUtil.SKIP_EXPANSION_EXPERIMENT_NAME)))
|
||||
.thenReturn(true);
|
||||
|
||||
final ServiceIdentifier sourceServiceId = generateRandomServiceIdentifier();
|
||||
final ServiceIdentifier destinationServiceId = generateRandomServiceIdentifier();
|
||||
final UUID serverGuid = UUID.randomUUID();
|
||||
final UUID updatedPni = UUID.randomUUID();
|
||||
|
||||
final MessageProtos.Envelope compressed = generateRandomMessageBuilder()
|
||||
.setSourceServiceIdBinary(ServiceIdentifierUtil.toCompactByteString(sourceServiceId))
|
||||
.setDestinationServiceIdBinary(ServiceIdentifierUtil.toCompactByteString(destinationServiceId))
|
||||
.setServerGuidBinary(UUIDUtil.toByteString(serverGuid))
|
||||
.setUpdatedPniBinary(UUIDUtil.toByteString(updatedPni))
|
||||
.build();
|
||||
|
||||
final MessageProtos.Envelope expanded = EnvelopeUtil.expand(compressed, experimentEnrollmentManager);
|
||||
|
||||
assertEquals(compressed, expanded,
|
||||
"Compressed message should be returned unchanged when enrolled in 'skip expansion' experiment");
|
||||
}
|
||||
|
||||
private static ServiceIdentifier generateRandomServiceIdentifier() {
|
||||
final IdentityType identityType = ThreadLocalRandom.current().nextBoolean() ? IdentityType.ACI : IdentityType.PNI;
|
||||
|
||||
|
||||
Reference in new issue
Block a user