mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Removed SubscriptionUpdate and SubscriptionAck.
This commit is contained in:
@@ -19,7 +19,6 @@ import org.briarproject.api.sync.PacketReaderFactory;
|
||||
import org.briarproject.api.sync.PacketWriter;
|
||||
import org.briarproject.api.sync.PacketWriterFactory;
|
||||
import org.briarproject.api.sync.Request;
|
||||
import org.briarproject.api.sync.SubscriptionUpdate;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamReaderFactory;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
@@ -37,7 +36,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||
@@ -56,7 +54,6 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
private final ContactId contactId;
|
||||
private final TransportId transportId;
|
||||
private final SecretKey tagKey, headerKey;
|
||||
private final Group group;
|
||||
private final Message message, message1;
|
||||
private final Collection<MessageId> messageIds;
|
||||
|
||||
@@ -79,7 +76,7 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
GroupFactory groupFactory = i.getInstance(GroupFactory.class);
|
||||
ClientId clientId = new ClientId(TestUtils.getRandomId());
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
group = groupFactory.createGroup(clientId, descriptor);
|
||||
Group group = groupFactory.createGroup(clientId, descriptor);
|
||||
// Add two messages to the group
|
||||
MessageFactory messageFactory = i.getInstance(MessageFactory.class);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
@@ -114,10 +111,6 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
|
||||
packetWriter.writeRequest(new Request(messageIds));
|
||||
|
||||
SubscriptionUpdate su = new SubscriptionUpdate(
|
||||
Collections.singletonList(group), 1);
|
||||
packetWriter.writeSubscriptionUpdate(su);
|
||||
|
||||
streamWriter.flush();
|
||||
return out.toByteArray();
|
||||
}
|
||||
@@ -158,12 +151,6 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
Request req = packetReader.readRequest();
|
||||
assertEquals(messageIds, req.getMessageIds());
|
||||
|
||||
// Read the subscription update
|
||||
assertTrue(packetReader.hasSubscriptionUpdate());
|
||||
SubscriptionUpdate su = packetReader.readSubscriptionUpdate();
|
||||
assertEquals(Collections.singletonList(group), su.getGroups());
|
||||
assertEquals(1, su.getVersion());
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.Offer;
|
||||
import org.briarproject.api.sync.Request;
|
||||
import org.briarproject.api.sync.SubscriptionAck;
|
||||
import org.briarproject.api.sync.SubscriptionUpdate;
|
||||
import org.briarproject.api.transport.IncomingKeys;
|
||||
import org.briarproject.api.transport.OutgoingKeys;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
@@ -60,7 +58,6 @@ import static org.briarproject.api.sync.ValidationManager.Validity.VALID;
|
||||
import static org.briarproject.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
@@ -300,11 +297,11 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the contact is in the DB (which it's not)
|
||||
exactly(17).of(database).startTransaction();
|
||||
exactly(13).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(17).of(database).containsContact(txn, contactId);
|
||||
exactly(13).of(database).containsContact(txn, contactId);
|
||||
will(returnValue(false));
|
||||
exactly(17).of(database).abortTransaction(txn);
|
||||
exactly(13).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
@@ -337,20 +334,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateSubscriptionAck(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateSubscriptionUpdate(contactId, 123);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getContact(contactId);
|
||||
fail();
|
||||
@@ -402,23 +385,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
SubscriptionAck a = new SubscriptionAck(0);
|
||||
db.receiveSubscriptionAck(contactId, a);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
SubscriptionUpdate u = new SubscriptionUpdate(
|
||||
Collections.<Group>emptyList(), 1);
|
||||
db.receiveSubscriptionUpdate(contactId, u);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.removeContact(contactId);
|
||||
fail();
|
||||
@@ -856,58 +822,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateSubscriptionUpdateNoUpdateDue() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
assertNull(db.generateSubscriptionUpdate(contactId, maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateSubscriptionUpdate() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(new SubscriptionUpdate(
|
||||
Collections.singletonList(group), 1)));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
SubscriptionUpdate u = db.generateSubscriptionUpdate(contactId,
|
||||
maxLatency);
|
||||
assertEquals(Collections.singletonList(group), u.getGroups());
|
||||
assertEquals(1, u.getVersion());
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveAck() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@@ -1103,56 +1017,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveSubscriptionAck() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setSubscriptionUpdateAcked(txn, contactId, 1);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
SubscriptionAck a = new SubscriptionAck(1);
|
||||
db.receiveSubscriptionAck(contactId, a);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveSubscriptionUpdate() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@SuppressWarnings("unchecked")
|
||||
final Database<Object> database = context.mock(Database.class);
|
||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).setGroups(txn, contactId,
|
||||
Collections.singletonList(group), 1);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
|
||||
SubscriptionUpdate u = new SubscriptionUpdate(
|
||||
Collections.singletonList(group), 1);
|
||||
db.receiveSubscriptionUpdate(contactId, u);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangingVisibilityCallsListeners() throws Exception {
|
||||
final ContactId contactId1 = new ContactId(123);
|
||||
|
||||
@@ -22,16 +22,12 @@ import org.briarproject.api.messaging.MessagingConstants;
|
||||
import org.briarproject.api.messaging.PrivateMessage;
|
||||
import org.briarproject.api.messaging.PrivateMessageFactory;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.Offer;
|
||||
import org.briarproject.api.sync.PacketWriter;
|
||||
import org.briarproject.api.sync.PacketWriterFactory;
|
||||
import org.briarproject.api.sync.Request;
|
||||
import org.briarproject.api.sync.SubscriptionUpdate;
|
||||
import org.briarproject.contact.ContactModule;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.data.DataModule;
|
||||
@@ -52,9 +48,7 @@ import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENG
|
||||
import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_GROUP_DESCRIPTOR_LENGTH;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_PACKET_PAYLOAD_LENGTH;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_SUBSCRIPTIONS;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConstantsTest extends BriarTestCase {
|
||||
@@ -62,7 +56,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
// TODO: Break this up into tests that are relevant for each package
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
private final GroupFactory groupFactory;
|
||||
private final AuthorFactory authorFactory;
|
||||
private final PrivateMessageFactory privateMessageFactory;
|
||||
private final ForumPostFactory forumPostFactory;
|
||||
@@ -75,7 +68,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
new DataModule(), new EventModule(), new ForumModule(),
|
||||
new IdentityModule(), new MessagingModule(), new SyncModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
groupFactory = i.getInstance(GroupFactory.class);
|
||||
authorFactory = i.getInstance(AuthorFactory.class);
|
||||
privateMessageFactory = i.getInstance(PrivateMessageFactory.class);
|
||||
forumPostFactory = i.getInstance(ForumPostFactory.class);
|
||||
@@ -188,27 +180,6 @@ public class ConstantsTest extends BriarTestCase {
|
||||
testMessageIdsFitIntoRequest(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGroupsFitIntoSubscriptionUpdate() throws Exception {
|
||||
// Create the maximum number of maximum-length groups
|
||||
Random random = new Random();
|
||||
ClientId clientId = new ClientId(TestUtils.getRandomId());
|
||||
Collection<Group> groups = new ArrayList<Group>();
|
||||
for (int i = 0; i < MAX_SUBSCRIPTIONS; i++) {
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
random.nextBytes(descriptor);
|
||||
groups.add(groupFactory.createGroup(clientId, descriptor));
|
||||
}
|
||||
// Create a maximum-length subscription update
|
||||
SubscriptionUpdate u = new SubscriptionUpdate(groups, Long.MAX_VALUE);
|
||||
// Serialise the update
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out);
|
||||
writer.writeSubscriptionUpdate(u);
|
||||
// Check the size of the serialised subscription update
|
||||
assertTrue(out.size() <= MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
private void testMessageIdsFitIntoAck(int length) throws Exception {
|
||||
// Create an ack with as many message IDs as possible
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testFormatExceptionIfAckIsTooLarge() throws Exception {
|
||||
byte[] b = createAck(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
|
||||
byte[] b = createAck(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyAck() throws Exception {
|
||||
byte[] b = createEmptyAck();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readAck();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
|
||||
byte[] b = createOffer(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception {
|
||||
byte[] b = createOffer(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyOffer() throws Exception {
|
||||
byte[] b = createEmptyOffer();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readOffer();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||
byte[] b = createRequest(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
||||
byte[] b = createRequest(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyRequest() throws Exception {
|
||||
byte[] b = createEmptyRequest();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, null, null, in);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(null, in);
|
||||
reader.readRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,12 +52,6 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// No subscription ack to send
|
||||
oneOf(db).generateSubscriptionAck(contactId);
|
||||
will(returnValue(null));
|
||||
// No subscription update to send
|
||||
oneOf(db).generateSubscriptionUpdate(contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
// No acks to send
|
||||
oneOf(packetWriter).getMaxMessagesForAck(with(any(long.class)));
|
||||
will(returnValue(MAX_MESSAGES_PER_ACK));
|
||||
@@ -86,12 +80,6 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// No subscription ack to send
|
||||
oneOf(db).generateSubscriptionAck(contactId);
|
||||
will(returnValue(null));
|
||||
// No subscription update to send
|
||||
oneOf(db).generateSubscriptionUpdate(contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
// One ack to send
|
||||
oneOf(packetWriter).getMaxMessagesForAck(with(any(long.class)));
|
||||
will(returnValue(MAX_MESSAGES_PER_ACK));
|
||||
|
||||
Reference in New Issue
Block a user