mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +01:00
Fix MessageId calculation for deprecated MessageQueue
This was preventing introduction messages from getting ACKed. The introduction tests were modified to check for this.
This commit is contained in:
@@ -668,7 +668,9 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
acked.add(m);
|
acked.add(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transaction.attach(new MessagesAckedEvent(c, acked));
|
if (acked.size() > 0) {
|
||||||
|
transaction.attach(new MessagesAckedEvent(c, acked));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.MAX_MESSAGE_LENGTH;
|
||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_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.MAX_QUEUE_MESSAGE_BODY_LENGTH;
|
||||||
import static org.briarproject.briar.api.client.QueueMessage.QUEUE_MESSAGE_HEADER_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);
|
ByteUtils.writeUint64(queuePosition, raw, MESSAGE_HEADER_LENGTH);
|
||||||
System.arraycopy(body, 0, raw, QUEUE_MESSAGE_HEADER_LENGTH,
|
System.arraycopy(body, 0, raw, QUEUE_MESSAGE_HEADER_LENGTH,
|
||||||
body.length);
|
body.length);
|
||||||
byte[] timeBytes = new byte[ByteUtils.INT_64_BYTES];
|
byte[] timeBytes = new byte[INT_64_BYTES];
|
||||||
ByteUtils.writeUint64(timestamp, timeBytes, 0);
|
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(
|
MessageId id = new MessageId(
|
||||||
crypto.hash(MessageId.LABEL, groupId.getBytes(), timeBytes,
|
crypto.hash(MessageId.LABEL, groupId.getBytes(), timeBytes,
|
||||||
body));
|
bodyBytes));
|
||||||
return new QueueMessage(id, groupId, timestamp, queuePosition, raw);
|
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.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
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.TransportProperties;
|
||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
@@ -360,6 +361,14 @@ public class IntroductionIntegrationTest
|
|||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
assertTrue(listener0.response1Received);
|
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
|
// sync second response
|
||||||
sync2To0(1, true);
|
sync2To0(1, true);
|
||||||
eventWaiter.await(TIMEOUT, 1);
|
eventWaiter.await(TIMEOUT, 1);
|
||||||
@@ -836,14 +845,32 @@ public class IntroductionIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertDefaultUiMessages() throws DbException {
|
private void assertDefaultUiMessages() throws DbException {
|
||||||
assertEquals(2, introductionManager0.getIntroductionMessages(
|
Collection<IntroductionMessage> messages =
|
||||||
contactId1From0).size());
|
introductionManager0.getIntroductionMessages(contactId1From0);
|
||||||
assertEquals(2, introductionManager0.getIntroductionMessages(
|
assertEquals(2, messages.size());
|
||||||
contactId2From0).size());
|
assertMessagesAreAcked(messages);
|
||||||
assertEquals(2, introductionManager1.getIntroductionMessages(
|
|
||||||
contactId0From1).size());
|
messages = introductionManager0.getIntroductionMessages(
|
||||||
assertEquals(2, introductionManager2.getIntroductionMessages(
|
contactId2From0);
|
||||||
contactId0From2).size());
|
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) {
|
private void addListeners(boolean accept1, boolean accept2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user