Remove Envelope.source

This commit is contained in:
Chris Eager authored and Chris Eager committed 2022-08-02 08:34:20 -07:00
1 parent 2575372639
commit 3d2f7e731f
15 files changed
+52 -79

No files matched your search

@@ -446,8 +446,8 @@ public class MessageController {
long size = 0;
for (final OutgoingMessageEntity message : messageList.messages()) {
size += message.content() == null ? 0 : message.content().length;
size += Util.isEmpty(message.source()) ? 0 : message.source().length();
size += message.content() == null ? 0 : message.content().length;
size += message.sourceUuid() == null ? 0 : 36;
}
return size;
@@ -5,11 +5,11 @@
package org.whispersystems.textsecuregcm.entities;
import com.google.protobuf.ByteString;
import org.apache.commons.lang3.StringUtils;
import org.whispersystems.textsecuregcm.storage.Account;
import javax.annotation.Nullable;
import java.util.Base64;
import java.util.UUID;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.whispersystems.textsecuregcm.storage.Account;
public record IncomingMessage(int type, long destinationDeviceId, int destinationRegistrationId, String content) {
@@ -28,8 +28,7 @@ public record IncomingMessage(int type, long destinationDeviceId, int destinatio
.setDestinationUuid(destinationUuid.toString());
if (sourceAccount != null && sourceDeviceId != null) {
envelopeBuilder.setSource(sourceAccount.getNumber())
.setSourceUuid(sourceAccount.getUuid().toString())
envelopeBuilder.setSourceUuid(sourceAccount.getUuid().toString())
.setSourceDevice(sourceDeviceId.intValue());
}
@@ -6,15 +6,14 @@
package org.whispersystems.textsecuregcm.entities;
import com.google.protobuf.ByteString;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nullable;
public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullable String source,
@Nullable UUID sourceUuid, int sourceDevice, UUID destinationUuid,
@Nullable UUID updatedPni, byte[] content, long serverTimestamp) {
public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullable UUID sourceUuid, int sourceDevice,
UUID destinationUuid, @Nullable UUID updatedPni, byte[] content,
long serverTimestamp) {
public MessageProtos.Envelope toEnvelope() {
final MessageProtos.Envelope.Builder builder = MessageProtos.Envelope.newBuilder()
@@ -24,13 +23,9 @@ public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullab
.setDestinationUuid(destinationUuid().toString())
.setServerGuid(guid().toString());
if (StringUtils.isNotEmpty(source())) {
builder.setSource(source())
.setSourceDevice(sourceDevice());
if (sourceUuid() != null) {
builder.setSourceUuid(sourceUuid().toString());
}
if (sourceUuid() != null) {
builder.setSourceUuid(sourceUuid().toString());
builder.setSourceDevice(sourceDevice());
}
if (content() != null) {
@@ -49,7 +44,6 @@ public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullab
UUID.fromString(envelope.getServerGuid()),
envelope.getType().getNumber(),
envelope.getTimestamp(),
envelope.hasSource() ? envelope.getSource() : null,
envelope.hasSourceUuid() ? UUID.fromString(envelope.getSourceUuid()) : null,
envelope.getSourceDevice(),
envelope.hasDestinationUuid() ? UUID.fromString(envelope.getDestinationUuid()) : null,
@@ -68,14 +62,14 @@ public record OutgoingMessageEntity(UUID guid, int type, long timestamp, @Nullab
}
final OutgoingMessageEntity that = (OutgoingMessageEntity) o;
return type == that.type && timestamp == that.timestamp && sourceDevice == that.sourceDevice
&& serverTimestamp == that.serverTimestamp && guid.equals(that.guid) && Objects.equals(source, that.source)
&& serverTimestamp == that.serverTimestamp && guid.equals(that.guid)
&& Objects.equals(sourceUuid, that.sourceUuid) && destinationUuid.equals(that.destinationUuid)
&& Objects.equals(updatedPni, that.updatedPni) && Arrays.equals(content, that.content);
}
@Override
public int hashCode() {
int result = Objects.hash(guid, type, timestamp, source, sourceUuid, sourceDevice, destinationUuid, updatedPni,
int result = Objects.hash(guid, type, timestamp, sourceUuid, sourceDevice, destinationUuid, updatedPni,
serverTimestamp);
result = 31 * result + Arrays.hashCode(content);
return result;
@@ -49,7 +49,6 @@ public class ReceiptSender {
final Envelope.Builder message = Envelope.newBuilder()
.setServerTimestamp(System.currentTimeMillis())
.setSource(sourceAccount.getNumber())
.setSourceUuid(sourceAccount.getUuid().toString())
.setSourceDevice((int) source.getAuthenticatedDevice().getId())
.setDestinationUuid(destinationUuid.toString())
@@ -6,12 +6,6 @@ package org.whispersystems.textsecuregcm.storage;
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,6 +19,12 @@ import org.whispersystems.textsecuregcm.entities.SignedPreKey;
import org.whispersystems.textsecuregcm.push.MessageSender;
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
import org.whispersystems.textsecuregcm.util.DestinationDeviceValidator;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class ChangeNumberManager {
private static final Logger logger = LoggerFactory.getLogger(AccountController.class);
@@ -92,10 +92,10 @@ public class ChangeNumberManager {
void sendMessageToSelf(
Account sourceAndDestinationAccount, Optional<Device> destinationDevice, IncomingMessage message) {
Optional<byte[]> contents = MessageController.getMessageContent(message);
if (!contents.isPresent()) {
if (contents.isEmpty()) {
logger.debug("empty message contents sending to self, ignoring");
return;
} else if (!destinationDevice.isPresent()) {
} else if (destinationDevice.isEmpty()) {
logger.debug("destination device not present");
return;
}
@@ -107,7 +107,6 @@ public class ChangeNumberManager {
.setServerTimestamp(serverTimestamp)
.setDestinationUuid(sourceAndDestinationAccount.getUuid().toString())
.setContent(ByteString.copyFrom(contents.get()))
.setSource(sourceAndDestinationAccount.getNumber())
.setSourceUuid(sourceAndDestinationAccount.getUuid().toString())
.setSourceDevice((int) Device.MASTER_ID)
.setUpdatedPni(sourceAndDestinationAccount.getPhoneNumberIdentifier().toString())
@@ -57,11 +57,6 @@ public class MessagesDynamoDb extends AbstractDynamoDbStore {
@Deprecated
private static final String KEY_TIMESTAMP = "TS";
@Deprecated
private static final String KEY_SOURCE = "SN";
@Deprecated
private static final String KEY_SOURCE_UUID = "SU";
@Deprecated
@@ -276,14 +271,13 @@ public class MessagesDynamoDb extends AbstractDynamoDbStore {
final UUID messageUuid = convertLocalIndexMessageUuidSortKey(item.get(LOCAL_INDEX_MESSAGE_UUID_KEY_SORT).b().asByteArray());
final int type = AttributeValues.getInt(item, KEY_TYPE, 0);
final long timestamp = AttributeValues.getLong(item, KEY_TIMESTAMP, 0L);
final String source = AttributeValues.getString(item, KEY_SOURCE, null);
final UUID sourceUuid = AttributeValues.getUUID(item, KEY_SOURCE_UUID, null);
final int sourceDevice = AttributeValues.getInt(item, KEY_SOURCE_DEVICE, 0);
final UUID destinationUuid = AttributeValues.getUUID(item, KEY_DESTINATION_UUID, null);
final byte[] content = AttributeValues.getByteArray(item, KEY_CONTENT, null);
final UUID updatedPni = AttributeValues.getUUID(item, KEY_UPDATED_PNI, null);
envelope = new OutgoingMessageEntity(messageUuid, type, timestamp, source, sourceUuid, sourceDevice, destinationUuid,
envelope = new OutgoingMessageEntity(messageUuid, type, timestamp, sourceUuid, sourceDevice, destinationUuid,
updatedPni, content, sortKey.getServerTimestamp()).toEnvelope();
GET_MESSAGE_WITH_ATTRIBUTES_COUNTER.increment();
@@ -39,8 +39,6 @@ import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
import org.whispersystems.textsecuregcm.controllers.MessageController;
import org.whispersystems.textsecuregcm.controllers.NoSuchUserException;
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntity;
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntityList;
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
import org.whispersystems.textsecuregcm.push.DisplacedPresenceListener;
import org.whispersystems.textsecuregcm.push.ReceiptSender;
@@ -228,7 +226,9 @@ public class WebSocketConnection implements MessageAvailabilityListener, Displac
}
private void sendDeliveryReceiptFor(Envelope message) {
if (!message.hasSource()) return;
if (!message.hasSourceUuid()) {
return;
}
try {
receiptSender.sendReceipt(auth, UUID.fromString(message.getSourceUuid()), message.getTimestamp());
-1
View File
@@ -32,7 +32,6 @@ message Envelope {
}
optional Type type = 1;
optional string source = 2;
optional string source_uuid = 11;
optional uint32 source_device = 7;
optional uint64 timestamp = 5;
@@ -34,7 +34,6 @@ import io.dropwizard.testing.junit5.ResourceExtension;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import java.util.Arrays;
import java.util.Base64;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -44,7 +43,6 @@ import java.util.stream.Stream;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -207,7 +205,7 @@ class MessageControllerTest {
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
assertTrue(captor.getValue().hasSource());
assertTrue(captor.getValue().hasSourceUuid());
assertTrue(captor.getValue().hasSourceDevice());
}
@@ -227,7 +225,7 @@ class MessageControllerTest {
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
assertTrue(captor.getValue().hasSource());
assertTrue(captor.getValue().hasSourceUuid());
assertTrue(captor.getValue().hasSourceDevice());
}
@@ -260,7 +258,7 @@ class MessageControllerTest {
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
assertFalse(captor.getValue().hasSource());
assertFalse(captor.getValue().hasSourceUuid());
assertFalse(captor.getValue().hasSourceDevice());
}
@@ -381,8 +379,10 @@ class MessageControllerTest {
final UUID updatedPniOne = UUID.randomUUID();
List<Envelope> messages = List.of(
generateEnvelope(messageGuidOne, Envelope.Type.CIPHERTEXT_VALUE, timestampOne, "+14152222222", sourceUuid, 2, AuthHelper.VALID_UUID, updatedPniOne, "hi there".getBytes(), 0),
generateEnvelope(messageGuidTwo, Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE, timestampTwo, "+14152222222", sourceUuid, 2, AuthHelper.VALID_UUID, null, null, 0)
generateEnvelope(messageGuidOne, Envelope.Type.CIPHERTEXT_VALUE, timestampOne, sourceUuid, 2,
AuthHelper.VALID_UUID, updatedPniOne, "hi there".getBytes(), 0),
generateEnvelope(messageGuidTwo, Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE, timestampTwo, sourceUuid, 2,
AuthHelper.VALID_UUID, null, null, 0)
);
OutgoingMessageEntityList messagesList = new OutgoingMessageEntityList(messages.stream()
@@ -420,8 +420,10 @@ class MessageControllerTest {
final long timestampTwo = 313388;
final List<Envelope> messages = List.of(
generateEnvelope(UUID.randomUUID(), Envelope.Type.CIPHERTEXT_VALUE, timestampOne, "+14152222222", UUID.randomUUID(), 2, AuthHelper.VALID_UUID, null, "hi there".getBytes(), 0),
generateEnvelope(UUID.randomUUID(), Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE, timestampTwo, "+14152222222", UUID.randomUUID(), 2, AuthHelper.VALID_UUID, null, null, 0)
generateEnvelope(UUID.randomUUID(), Envelope.Type.CIPHERTEXT_VALUE, timestampOne, UUID.randomUUID(), 2,
AuthHelper.VALID_UUID, null, "hi there".getBytes(), 0),
generateEnvelope(UUID.randomUUID(), Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE, timestampTwo,
UUID.randomUUID(), 2, AuthHelper.VALID_UUID, null, null, 0)
);
when(messagesManager.getMessagesForDevice(eq(AuthHelper.VALID_UUID), eq(1L), anyString(), anyBoolean()))
@@ -446,12 +448,12 @@ class MessageControllerTest {
UUID uuid1 = UUID.randomUUID();
when(messagesManager.delete(AuthHelper.VALID_UUID, 1, uuid1, null)).thenReturn(Optional.of(generateEnvelope(
uuid1, Envelope.Type.CIPHERTEXT_VALUE,
timestamp, "+14152222222", sourceUuid, 1, AuthHelper.VALID_UUID, null, "hi".getBytes(), 0)));
timestamp, sourceUuid, 1, AuthHelper.VALID_UUID, null, "hi".getBytes(), 0)));
UUID uuid2 = UUID.randomUUID();
when(messagesManager.delete(AuthHelper.VALID_UUID, 1, uuid2, null)).thenReturn(Optional.of(generateEnvelope(
uuid2, Envelope.Type.SERVER_DELIVERY_RECEIPT_VALUE,
System.currentTimeMillis(), "+14152222222", sourceUuid, 1, AuthHelper.VALID_UUID, null, null, 0)));
System.currentTimeMillis(), sourceUuid, 1, AuthHelper.VALID_UUID, null, null, 0)));
UUID uuid3 = UUID.randomUUID();
when(messagesManager.delete(AuthHelper.VALID_UUID, 1, uuid3, null)).thenReturn(Optional.empty());
@@ -631,8 +633,8 @@ class MessageControllerTest {
Arguments.of("fixtures/current_message_single_device_server_receipt_type.json", false)
);
}
private static Envelope generateEnvelope(UUID guid, int type, long timestamp, String source, UUID sourceUuid,
private static Envelope generateEnvelope(UUID guid, int type, long timestamp, UUID sourceUuid,
int sourceDevice, UUID destinationUuid, UUID updatedPni, byte[] content, long serverTimestamp) {
final MessageProtos.Envelope.Builder builder = MessageProtos.Envelope.newBuilder()
@@ -642,13 +644,9 @@ class MessageControllerTest {
.setDestinationUuid(destinationUuid.toString())
.setServerGuid(guid.toString());
if (StringUtils.isNotEmpty(source)) {
builder.setSource(source)
.setSourceDevice(sourceDevice);
if (sourceUuid != null) {
builder.setSourceUuid(sourceUuid.toString());
}
if (sourceUuid != null) {
builder.setSourceUuid(sourceUuid.toString());
builder.setSourceDevice(sourceDevice);
}
if (content != null) {
@@ -20,7 +20,7 @@ class OutgoingMessageEntityTest {
@ParameterizedTest
@MethodSource
void toFromEnvelope(@Nullable final String source, @Nullable final UUID sourceUuid, @Nullable final UUID updatedPni) {
void toFromEnvelope(@Nullable final UUID sourceUuid, @Nullable final UUID updatedPni) {
final byte[] messageContent = new byte[16];
new Random().nextBytes(messageContent);
@@ -30,9 +30,8 @@ class OutgoingMessageEntityTest {
final OutgoingMessageEntity outgoingMessageEntity = new OutgoingMessageEntity(UUID.randomUUID(),
MessageProtos.Envelope.Type.CIPHERTEXT_VALUE,
messageTimestamp,
source,
sourceUuid,
source != null ? (int) Device.MASTER_ID : 0,
UUID.randomUUID(),
sourceUuid != null ? (int) Device.MASTER_ID : 0,
UUID.randomUUID(),
updatedPni,
messageContent,
@@ -43,8 +42,8 @@ class OutgoingMessageEntityTest {
private static Stream<Arguments> toFromEnvelope() {
return Stream.of(
Arguments.of("+18005551234", UUID.randomUUID(), UUID.randomUUID()),
Arguments.of("+18005551234", UUID.randomUUID(), null),
Arguments.of(null, null, UUID.randomUUID()));
Arguments.of(UUID.randomUUID(), UUID.randomUUID()),
Arguments.of(UUID.randomUUID(), null),
Arguments.of(null, UUID.randomUUID()));
}
}
@@ -130,7 +130,6 @@ public class ChangeNumberManagerTest {
assertEquals(aci, UUID.fromString(envelope.getDestinationUuid()));
assertEquals(aci, UUID.fromString(envelope.getSourceUuid()));
assertEquals(changedE164, envelope.getSource());
assertEquals(Device.MASTER_ID, envelope.getSourceDevice());
assertEquals(updatedPhoneNumberIdentifiersByAccount.get(account), UUID.fromString(envelope.getUpdatedPni()));
}
@@ -227,7 +227,7 @@ class MessagesCacheTest {
if (!sealedSender) {
envelopeBuilder.setSourceDevice(random.nextInt(256))
.setSource("+1" + RandomStringUtils.randomNumeric(10));
.setSourceUuid(UUID.randomUUID().toString());
}
return envelopeBuilder.build();
@@ -39,7 +39,6 @@ class MessagesDynamoDbTest {
MESSAGE1 = builder.build();
builder.setType(MessageProtos.Envelope.Type.CIPHERTEXT);
builder.setSource("12348675309");
builder.setSourceUuid(UUID.randomUUID().toString());
builder.setSourceDevice(1);
builder.setContent(ByteString.copyFromUtf8("MOO"));
@@ -50,7 +49,6 @@ class MessagesDynamoDbTest {
MESSAGE2 = builder.build();
builder.setType(MessageProtos.Envelope.Type.UNIDENTIFIED_SENDER);
builder.clearSource();
builder.clearSourceUuid();
builder.clearSourceDevice();
builder.setContent(ByteString.copyFromUtf8("COW"));
@@ -28,10 +28,8 @@ class MessagesManagerTest {
@Test
void insert() {
final String sourceNumber = "+12025551212";
final UUID sourceAci = UUID.randomUUID();
final Envelope message = Envelope.newBuilder()
.setSource(sourceNumber)
.setSourceUuid(sourceAci.toString())
.build();
@@ -272,7 +272,6 @@ class WebSocketConnectionTest {
final Envelope firstMessage = Envelope.newBuilder()
.setServerGuid(UUID.randomUUID().toString())
.setSource("sender1")
.setSourceUuid(UUID.randomUUID().toString())
.setDestinationUuid(UUID.randomUUID().toString())
.setUpdatedPni(UUID.randomUUID().toString())
@@ -283,7 +282,6 @@ class WebSocketConnectionTest {
final Envelope secondMessage = Envelope.newBuilder()
.setServerGuid(UUID.randomUUID().toString())
.setSource("sender2")
.setSourceUuid(senderTwoUuid.toString())
.setDestinationUuid(UUID.randomUUID().toString())
.setTimestamp(System.currentTimeMillis())
@@ -854,7 +852,6 @@ class WebSocketConnectionTest {
.setType(Envelope.Type.CIPHERTEXT)
.setTimestamp(timestamp)
.setServerTimestamp(0)
.setSource(sender)
.setSourceUuid(senderUuid.toString())
.setSourceDevice(1)
.setDestinationUuid(destinationUuid.toString())