Fix MessageId calculation for deprecated MessageQueue

This was preventing introduction messages from getting ACKed.
The introduction tests were modified to check for this.
parent 0827b067
......@@ -668,7 +668,9 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
acked.add(m);
}
}
transaction.attach(new MessagesAckedEvent(c, acked));
if (acked.size() > 0) {
transaction.attach(new MessagesAckedEvent(c, acked));
}
}
@Override
......
......@@ -14,6 +14,7 @@ import javax.inject.Inject;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_LENGTH;
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
import static org.briarproject.bramble.util.ByteUtils.INT_64_BYTES;
import static org.briarproject.briar.api.client.QueueMessage.MAX_QUEUE_MESSAGE_BODY_LENGTH;
import static org.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_LENGTH;
......@@ -39,11 +40,14 @@ class QueueMessageFactoryImpl implements QueueMessageFactory {
ByteUtils.writeUint64(queuePosition, raw, MESSAGE_HEADER_LENGTH);
System.arraycopy(body, 0, raw, QUEUE_MESSAGE_HEADER_LENGTH,
body.length);
byte[] timeBytes = new byte[ByteUtils.INT_64_BYTES];
byte[] timeBytes = new byte[INT_64_BYTES];
ByteUtils.writeUint64(timestamp, timeBytes, 0);
byte[] bodyBytes = new byte[body.length + INT_64_BYTES];
System.arraycopy(raw, MESSAGE_HEADER_LENGTH, bodyBytes, 0,
body.length + INT_64_BYTES);
MessageId id = new MessageId(
crypto.hash(MessageId.LABEL, groupId.getBytes(), timeBytes,
body));
bodyBytes));
return new QueueMessage(id, groupId, timestamp, queuePosition, raw);
}
......
......@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.event.EventListener;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.properties.TransportPropertyManager;
import org.briarproject.bramble.api.sync.Group;
......@@ -360,6 +361,14 @@ public class IntroductionIntegrationTest
eventWaiter.await(TIMEOUT, 1);
assertTrue(listener0.response1Received);
// sync fake transport properties back to 1, so Message ACK can arrive
// and the assertDefaultUiMessages() check at the end will not fail
TransportProperties tp = new TransportProperties(
Collections.singletonMap("key", "value"));
c0.getTransportPropertyManager()
.mergeLocalProperties(new TransportId("fake"), tp);
sync0To1(1, true);
// sync second response
sync2To0(1, true);
eventWaiter.await(TIMEOUT, 1);
......@@ -836,14 +845,32 @@ public class IntroductionIntegrationTest
}
private void assertDefaultUiMessages() throws DbException {
assertEquals(2, introductionManager0.getIntroductionMessages(
contactId1From0).size());
assertEquals(2, introductionManager0.getIntroductionMessages(
contactId2From0).size());
assertEquals(2, introductionManager1.getIntroductionMessages(
contactId0From1).size());
assertEquals(2, introductionManager2.getIntroductionMessages(
contactId0From2).size());
Collection<IntroductionMessage> messages =
introductionManager0.getIntroductionMessages(contactId1From0);
assertEquals(2, messages.size());
assertMessagesAreAcked(messages);
messages = introductionManager0.getIntroductionMessages(
contactId2From0);
assertEquals(2, messages.size());
assertMessagesAreAcked(messages);
messages = introductionManager1.getIntroductionMessages(
contactId0From1);
assertEquals(2, messages.size());
assertMessagesAreAcked(messages);
messages = introductionManager2.getIntroductionMessages(
contactId0From2);
assertEquals(2, messages.size());
assertMessagesAreAcked(messages);
}
private void assertMessagesAreAcked(
Collection<IntroductionMessage> messages) {
for (IntroductionMessage msg : messages) {
if (msg.isLocal()) assertTrue(msg.isSeen());
}
}
private void addListeners(boolean accept1, boolean accept2) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment