From cb185a65527bdd3cd5a1dc6576746a93007a2192 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 8 Jan 2014 16:45:37 -1000 Subject: [PATCH] Remove very overzealous protobuf change. --- protobuf/OutgoingMessageSignal.proto | 1 - .../controllers/MessageController.java | 12 +- .../textsecuregcm/entities/MessageProtos.java | 190 ++---------------- .../textsecuregcm/entities/RelayMessage.java | 1 + 4 files changed, 25 insertions(+), 179 deletions(-) diff --git a/protobuf/OutgoingMessageSignal.proto b/protobuf/OutgoingMessageSignal.proto index f89daf3b..06cf1460 100644 --- a/protobuf/OutgoingMessageSignal.proto +++ b/protobuf/OutgoingMessageSignal.proto @@ -24,7 +24,6 @@ message OutgoingMessageSignal { optional string source = 2; optional string relay = 3; repeated string destinations = 4; - repeated uint64 destinationDeviceIds = 7; optional uint64 timestamp = 5; optional bytes message = 6; } \ No newline at end of file diff --git a/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index ea56815e..163c561e 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -52,8 +52,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.IOException; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -191,6 +193,9 @@ public class MessageController extends HttpServlet { List incomingMessages) { List outgoingMessages = new LinkedList<>(); + Set destinations = new HashSet<>(); + for (IncomingMessage incoming : incomingMessages) + destinations.add(incoming.getDestination()); for (IncomingMessage incoming : incomingMessages) { OutgoingMessageSignal.Builder outgoingMessage = OutgoingMessageSignal.newBuilder(); @@ -207,10 +212,9 @@ public class MessageController extends HttpServlet { int index = 0; - for (IncomingMessage sub : incomingMessages) { - if (sub != incoming) { - outgoingMessage.setDestinationDeviceIds(index, sub.getDestinationDeviceId()); - outgoingMessage.setDestinations(index++, sub.getDestination()); + for (String destination : destinations) { + if (!destination.equals(incoming.getDestination())) { + outgoingMessage.setDestinations(index++, destination); } } diff --git a/src/main/java/org/whispersystems/textsecuregcm/entities/MessageProtos.java b/src/main/java/org/whispersystems/textsecuregcm/entities/MessageProtos.java index b308aea5..86cc5fae 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/entities/MessageProtos.java +++ b/src/main/java/org/whispersystems/textsecuregcm/entities/MessageProtos.java @@ -71,20 +71,6 @@ public final class MessageProtos { com.google.protobuf.ByteString getDestinationsBytes(int index); - // repeated uint64 destinationDeviceIds = 7; - /** - * repeated uint64 destinationDeviceIds = 7; - */ - java.util.List getDestinationDeviceIdsList(); - /** - * repeated uint64 destinationDeviceIds = 7; - */ - int getDestinationDeviceIdsCount(); - /** - * repeated uint64 destinationDeviceIds = 7; - */ - long getDestinationDeviceIds(int index); - // optional uint64 timestamp = 5; /** * optional uint64 timestamp = 5; @@ -189,27 +175,6 @@ public final class MessageProtos { message_ = input.readBytes(); break; } - case 56: { - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) { - destinationDeviceIds_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; - } - destinationDeviceIds_.add(input.readUInt64()); - break; - } - case 58: { - int length = input.readRawVarint32(); - int limit = input.pushLimit(length); - if (!((mutable_bitField0_ & 0x00000010) == 0x00000010) && input.getBytesUntilLimit() > 0) { - destinationDeviceIds_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000010; - } - while (input.getBytesUntilLimit() > 0) { - destinationDeviceIds_.add(input.readUInt64()); - } - input.popLimit(limit); - break; - } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -221,9 +186,6 @@ public final class MessageProtos { if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { destinations_ = new com.google.protobuf.UnmodifiableLazyStringList(destinations_); } - if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) { - destinationDeviceIds_ = java.util.Collections.unmodifiableList(destinationDeviceIds_); - } this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } @@ -388,29 +350,6 @@ public final class MessageProtos { return destinations_.getByteString(index); } - // repeated uint64 destinationDeviceIds = 7; - public static final int DESTINATIONDEVICEIDS_FIELD_NUMBER = 7; - private java.util.List destinationDeviceIds_; - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public java.util.List - getDestinationDeviceIdsList() { - return destinationDeviceIds_; - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public int getDestinationDeviceIdsCount() { - return destinationDeviceIds_.size(); - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public long getDestinationDeviceIds(int index) { - return destinationDeviceIds_.get(index); - } - // optional uint64 timestamp = 5; public static final int TIMESTAMP_FIELD_NUMBER = 5; private long timestamp_; @@ -448,7 +387,6 @@ public final class MessageProtos { source_ = ""; relay_ = ""; destinations_ = com.google.protobuf.LazyStringArrayList.EMPTY; - destinationDeviceIds_ = java.util.Collections.emptyList(); timestamp_ = 0L; message_ = com.google.protobuf.ByteString.EMPTY; } @@ -482,9 +420,6 @@ public final class MessageProtos { if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeBytes(6, message_); } - for (int i = 0; i < destinationDeviceIds_.size(); i++) { - output.writeUInt64(7, destinationDeviceIds_.get(i)); - } getUnknownFields().writeTo(output); } @@ -523,15 +458,6 @@ public final class MessageProtos { size += com.google.protobuf.CodedOutputStream .computeBytesSize(6, message_); } - { - int dataSize = 0; - for (int i = 0; i < destinationDeviceIds_.size(); i++) { - dataSize += com.google.protobuf.CodedOutputStream - .computeUInt64SizeNoTag(destinationDeviceIds_.get(i)); - } - size += dataSize; - size += 1 * getDestinationDeviceIdsList().size(); - } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -656,12 +582,10 @@ public final class MessageProtos { bitField0_ = (bitField0_ & ~0x00000004); destinations_ = com.google.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000008); - destinationDeviceIds_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); timestamp_ = 0L; - bitField0_ = (bitField0_ & ~0x00000020); + bitField0_ = (bitField0_ & ~0x00000010); message_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000040); + bitField0_ = (bitField0_ & ~0x00000020); return this; } @@ -708,16 +632,11 @@ public final class MessageProtos { bitField0_ = (bitField0_ & ~0x00000008); } result.destinations_ = destinations_; - if (((bitField0_ & 0x00000010) == 0x00000010)) { - destinationDeviceIds_ = java.util.Collections.unmodifiableList(destinationDeviceIds_); - bitField0_ = (bitField0_ & ~0x00000010); - } - result.destinationDeviceIds_ = destinationDeviceIds_; - if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { to_bitField0_ |= 0x00000008; } result.timestamp_ = timestamp_; - if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { to_bitField0_ |= 0x00000010; } result.message_ = message_; @@ -760,16 +679,6 @@ public final class MessageProtos { } onChanged(); } - if (!other.destinationDeviceIds_.isEmpty()) { - if (destinationDeviceIds_.isEmpty()) { - destinationDeviceIds_ = other.destinationDeviceIds_; - bitField0_ = (bitField0_ & ~0x00000010); - } else { - ensureDestinationDeviceIdsIsMutable(); - destinationDeviceIds_.addAll(other.destinationDeviceIds_); - } - onChanged(); - } if (other.hasTimestamp()) { setTimestamp(other.getTimestamp()); } @@ -1077,79 +986,13 @@ public final class MessageProtos { return this; } - // repeated uint64 destinationDeviceIds = 7; - private java.util.List destinationDeviceIds_ = java.util.Collections.emptyList(); - private void ensureDestinationDeviceIdsIsMutable() { - if (!((bitField0_ & 0x00000010) == 0x00000010)) { - destinationDeviceIds_ = new java.util.ArrayList(destinationDeviceIds_); - bitField0_ |= 0x00000010; - } - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public java.util.List - getDestinationDeviceIdsList() { - return java.util.Collections.unmodifiableList(destinationDeviceIds_); - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public int getDestinationDeviceIdsCount() { - return destinationDeviceIds_.size(); - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public long getDestinationDeviceIds(int index) { - return destinationDeviceIds_.get(index); - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public Builder setDestinationDeviceIds( - int index, long value) { - ensureDestinationDeviceIdsIsMutable(); - destinationDeviceIds_.set(index, value); - onChanged(); - return this; - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public Builder addDestinationDeviceIds(long value) { - ensureDestinationDeviceIdsIsMutable(); - destinationDeviceIds_.add(value); - onChanged(); - return this; - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public Builder addAllDestinationDeviceIds( - java.lang.Iterable values) { - ensureDestinationDeviceIdsIsMutable(); - super.addAll(values, destinationDeviceIds_); - onChanged(); - return this; - } - /** - * repeated uint64 destinationDeviceIds = 7; - */ - public Builder clearDestinationDeviceIds() { - destinationDeviceIds_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000010); - onChanged(); - return this; - } - // optional uint64 timestamp = 5; private long timestamp_ ; /** * optional uint64 timestamp = 5; */ public boolean hasTimestamp() { - return ((bitField0_ & 0x00000020) == 0x00000020); + return ((bitField0_ & 0x00000010) == 0x00000010); } /** * optional uint64 timestamp = 5; @@ -1161,7 +1004,7 @@ public final class MessageProtos { * optional uint64 timestamp = 5; */ public Builder setTimestamp(long value) { - bitField0_ |= 0x00000020; + bitField0_ |= 0x00000010; timestamp_ = value; onChanged(); return this; @@ -1170,7 +1013,7 @@ public final class MessageProtos { * optional uint64 timestamp = 5; */ public Builder clearTimestamp() { - bitField0_ = (bitField0_ & ~0x00000020); + bitField0_ = (bitField0_ & ~0x00000010); timestamp_ = 0L; onChanged(); return this; @@ -1182,7 +1025,7 @@ public final class MessageProtos { * optional bytes message = 6; */ public boolean hasMessage() { - return ((bitField0_ & 0x00000040) == 0x00000040); + return ((bitField0_ & 0x00000020) == 0x00000020); } /** * optional bytes message = 6; @@ -1197,7 +1040,7 @@ public final class MessageProtos { if (value == null) { throw new NullPointerException(); } - bitField0_ |= 0x00000040; + bitField0_ |= 0x00000020; message_ = value; onChanged(); return this; @@ -1206,7 +1049,7 @@ public final class MessageProtos { * optional bytes message = 6; */ public Builder clearMessage() { - bitField0_ = (bitField0_ & ~0x00000040); + bitField0_ = (bitField0_ & ~0x00000020); message_ = getDefaultInstance().getMessage(); onChanged(); return this; @@ -1238,12 +1081,11 @@ public final class MessageProtos { static { java.lang.String[] descriptorData = { "\n\033OutgoingMessageSignal.proto\022\ntextsecur" + - "e\"\234\001\n\025OutgoingMessageSignal\022\014\n\004type\030\001 \001(" + - "\r\022\016\n\006source\030\002 \001(\t\022\r\n\005relay\030\003 \001(\t\022\024\n\014dest" + - "inations\030\004 \003(\t\022\034\n\024destinationDeviceIds\030\007" + - " \003(\004\022\021\n\ttimestamp\030\005 \001(\004\022\017\n\007message\030\006 \001(\014" + - "B:\n)org.whispersystems.textsecuregcm.ent" + - "itiesB\rMessageProtos" + "e\"~\n\025OutgoingMessageSignal\022\014\n\004type\030\001 \001(\r" + + "\022\016\n\006source\030\002 \001(\t\022\r\n\005relay\030\003 \001(\t\022\024\n\014desti" + + "nations\030\004 \003(\t\022\021\n\ttimestamp\030\005 \001(\004\022\017\n\007mess" + + "age\030\006 \001(\014B:\n)org.whispersystems.textsecu" + + "regcm.entitiesB\rMessageProtos" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -1255,7 +1097,7 @@ public final class MessageProtos { internal_static_textsecure_OutgoingMessageSignal_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_textsecure_OutgoingMessageSignal_descriptor, - new java.lang.String[] { "Type", "Source", "Relay", "Destinations", "DestinationDeviceIds", "Timestamp", "Message", }); + new java.lang.String[] { "Type", "Source", "Relay", "Destinations", "Timestamp", "Message", }); return null; } }; diff --git a/src/main/java/org/whispersystems/textsecuregcm/entities/RelayMessage.java b/src/main/java/org/whispersystems/textsecuregcm/entities/RelayMessage.java index 411eb5d8..6faf2573 100644 --- a/src/main/java/org/whispersystems/textsecuregcm/entities/RelayMessage.java +++ b/src/main/java/org/whispersystems/textsecuregcm/entities/RelayMessage.java @@ -46,6 +46,7 @@ public class RelayMessage { public RelayMessage(String destination, long destinationDeviceId, byte[] outgoingMessageSignal) { this.destination = destination; + this.destinationDeviceId = destinationDeviceId; this.outgoingMessageSignal = outgoingMessageSignal; }