mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Moved classes from messaging package to sync package.
This commit is contained in:
@@ -11,22 +11,22 @@ import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupFactory;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageFactory;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.MessageVerifier;
|
||||
import org.briarproject.api.messaging.Offer;
|
||||
import org.briarproject.api.messaging.PacketReader;
|
||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||
import org.briarproject.api.messaging.PacketWriter;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.api.messaging.Request;
|
||||
import org.briarproject.api.messaging.SubscriptionUpdate;
|
||||
import org.briarproject.api.messaging.TransportUpdate;
|
||||
import org.briarproject.api.messaging.UnverifiedMessage;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageFactory;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.MessageVerifier;
|
||||
import org.briarproject.api.sync.Offer;
|
||||
import org.briarproject.api.sync.PacketReader;
|
||||
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.sync.TransportUpdate;
|
||||
import org.briarproject.api.sync.UnverifiedMessage;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamReaderFactory;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
@@ -34,7 +34,7 @@ import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.data.DataModule;
|
||||
import org.briarproject.db.DatabaseModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
import org.briarproject.messaging.MessagingModule;
|
||||
import org.briarproject.sync.MessagingModule;
|
||||
import org.briarproject.transport.TransportModule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.briarproject;
|
||||
|
||||
import org.briarproject.api.Author;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -33,19 +33,19 @@ import org.briarproject.api.event.MessagesSentEvent;
|
||||
import org.briarproject.api.event.SubscriptionAddedEvent;
|
||||
import org.briarproject.api.event.SubscriptionRemovedEvent;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupId;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.Offer;
|
||||
import org.briarproject.api.messaging.Request;
|
||||
import org.briarproject.api.messaging.RetentionAck;
|
||||
import org.briarproject.api.messaging.RetentionUpdate;
|
||||
import org.briarproject.api.messaging.SubscriptionAck;
|
||||
import org.briarproject.api.messaging.SubscriptionUpdate;
|
||||
import org.briarproject.api.messaging.TransportAck;
|
||||
import org.briarproject.api.messaging.TransportUpdate;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
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.RetentionAck;
|
||||
import org.briarproject.api.sync.RetentionUpdate;
|
||||
import org.briarproject.api.sync.SubscriptionAck;
|
||||
import org.briarproject.api.sync.SubscriptionUpdate;
|
||||
import org.briarproject.api.sync.TransportAck;
|
||||
import org.briarproject.api.sync.TransportUpdate;
|
||||
import org.briarproject.api.transport.IncomingKeys;
|
||||
import org.briarproject.api.transport.OutgoingKeys;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
@@ -58,7 +58,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -335,137 +335,187 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
try {
|
||||
db.addTransportKeys(contactId, createTransportKeys());
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateAck(contactId, 123);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateBatch(contactId, 123, 456);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateOffer(contactId, 123, 456);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateRetentionAck(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateRetentionUpdate(contactId, 123);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateSubscriptionAck(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateSubscriptionUpdate(contactId, 123);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateTransportAcks(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.generateTransportUpdates(contactId, 123);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getContact(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getInboxGroupId(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.incrementStreamCounter(contactId, transportId, 0);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
Ack a = new Ack(Collections.singletonList(messageId));
|
||||
db.receiveAck(contactId, a);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.receiveMessage(contactId, message);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
Offer o = new Offer(Collections.singletonList(messageId));
|
||||
db.receiveOffer(contactId, o);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
RetentionAck a = new RetentionAck(0);
|
||||
db.receiveRetentionAck(contactId, a);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
RetentionUpdate u = new RetentionUpdate(0, 1);
|
||||
db.receiveRetentionUpdate(contactId, u);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
SubscriptionAck a = new SubscriptionAck(0);
|
||||
db.receiveSubscriptionAck(contactId, a);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
SubscriptionUpdate u = new SubscriptionUpdate(
|
||||
Collections.<Group>emptyList(), 1);
|
||||
db.receiveSubscriptionUpdate(contactId, u);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
TransportAck a = new TransportAck(transportId, 0);
|
||||
db.receiveTransportAck(contactId, a);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
TransportUpdate u = new TransportUpdate(transportId,
|
||||
transportProperties, 1);
|
||||
db.receiveTransportUpdate(contactId, u);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.removeContact(contactId);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.setInboxGroup(contactId, group);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {}
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -496,17 +546,23 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
try {
|
||||
db.addContact(author, localAuthorId);
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {}
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getLocalAuthor(localAuthorId);
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {}
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.removeLocalAuthor(localAuthorId);
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {}
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -534,27 +590,37 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
try {
|
||||
db.getGroup(groupId);
|
||||
fail();
|
||||
} catch (NoSuchSubscriptionException expected) {}
|
||||
} catch (NoSuchSubscriptionException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getMessageHeaders(groupId);
|
||||
fail();
|
||||
} catch (NoSuchSubscriptionException expected) {}
|
||||
} catch (NoSuchSubscriptionException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getVisibility(groupId);
|
||||
fail();
|
||||
} catch (NoSuchSubscriptionException expected) {}
|
||||
} catch (NoSuchSubscriptionException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.removeGroup(group);
|
||||
fail();
|
||||
} catch (NoSuchSubscriptionException expected) {}
|
||||
} catch (NoSuchSubscriptionException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.setVisibility(groupId, Collections.<ContactId>emptyList());
|
||||
fail();
|
||||
} catch (NoSuchSubscriptionException expected) {}
|
||||
} catch (NoSuchSubscriptionException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -606,42 +672,58 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
try {
|
||||
db.getConfig(transportId);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getLocalProperties(transportId);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.getTransportKeys(transportId);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.mergeConfig(transportId, new TransportConfig());
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.mergeLocalProperties(transportId, new TransportProperties());
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.incrementStreamCounter(contactId, transportId, 0);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.removeTransport(transportId);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
fail();
|
||||
} catch (NoSuchTransportException expected) {}
|
||||
} catch (NoSuchTransportException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupId;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.transport.IncomingKeys;
|
||||
import org.briarproject.api.transport.OutgoingKeys;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
@@ -44,7 +44,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.api.db.MessageHeader.State.STORED;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.messaging;
|
||||
package org.briarproject.sync;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
@@ -17,18 +17,18 @@ import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.crypto.Signature;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupFactory;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageFactory;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.Offer;
|
||||
import org.briarproject.api.messaging.PacketWriter;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.api.messaging.Request;
|
||||
import org.briarproject.api.messaging.SubscriptionUpdate;
|
||||
import org.briarproject.api.messaging.TransportUpdate;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageFactory;
|
||||
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.api.sync.TransportUpdate;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.data.DataModule;
|
||||
import org.briarproject.db.DatabaseModule;
|
||||
@@ -46,11 +46,11 @@ import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
|
||||
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
|
||||
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
|
||||
import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_BODY_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_GROUP_NAME_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_SUBSCRIPTIONS;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ConstantsTest extends BriarTestCase {
|
||||
@@ -65,7 +65,7 @@ public class ConstantsTest extends BriarTestCase {
|
||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||
new TestLifecycleModule(), new TestSystemModule(),
|
||||
new CryptoModule(), new DatabaseModule(), new EventModule(),
|
||||
new MessagingModule(), new DataModule());
|
||||
new org.briarproject.sync.MessagingModule(), new DataModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
groupFactory = i.getInstance(GroupFactory.class);
|
||||
authorFactory = i.getInstance(AuthorFactory.class);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.messaging;
|
||||
package org.briarproject.sync;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.FormatException;
|
||||
@@ -23,7 +23,8 @@ public class ConsumersTest extends BriarTestCase {
|
||||
messageDigest.update(data);
|
||||
byte[] dig = messageDigest.digest();
|
||||
// Check that feeding a DigestingConsumer generates the same digest
|
||||
DigestingConsumer dc = new DigestingConsumer(messageDigest);
|
||||
org.briarproject.sync.DigestingConsumer
|
||||
dc = new org.briarproject.sync.DigestingConsumer(messageDigest);
|
||||
dc.write(data[0]);
|
||||
dc.write(data, 1, data.length - 2);
|
||||
dc.write(data[data.length - 1]);
|
||||
@@ -34,7 +35,8 @@ public class ConsumersTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testCountingConsumer() throws Exception {
|
||||
byte[] data = new byte[1234];
|
||||
CountingConsumer cc = new CountingConsumer(data.length);
|
||||
org.briarproject.sync.CountingConsumer
|
||||
cc = new org.briarproject.sync.CountingConsumer(data.length);
|
||||
cc.write(data[0]);
|
||||
cc.write(data, 1, data.length - 2);
|
||||
cc.write(data[data.length - 1]);
|
||||
@@ -42,7 +44,9 @@ public class ConsumersTest extends BriarTestCase {
|
||||
try {
|
||||
cc.write((byte) 0);
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +54,8 @@ public class ConsumersTest extends BriarTestCase {
|
||||
byte[] data = new byte[1234];
|
||||
new Random().nextBytes(data);
|
||||
// Check that a CopyingConsumer creates a faithful copy
|
||||
CopyingConsumer cc = new CopyingConsumer();
|
||||
org.briarproject.sync.CopyingConsumer
|
||||
cc = new org.briarproject.sync.CopyingConsumer();
|
||||
cc.write(data[0]);
|
||||
cc.write(data, 1, data.length - 2);
|
||||
cc.write(data[data.length - 1]);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.messaging;
|
||||
package org.briarproject.sync;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
@@ -18,11 +18,11 @@ import java.io.ByteArrayOutputStream;
|
||||
|
||||
import static org.briarproject.api.data.DataConstants.LIST_END_LENGTH;
|
||||
import static org.briarproject.api.data.DataConstants.UNIQUE_ID_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
|
||||
import static org.briarproject.api.messaging.PacketTypes.ACK;
|
||||
import static org.briarproject.api.messaging.PacketTypes.OFFER;
|
||||
import static org.briarproject.api.messaging.PacketTypes.REQUEST;
|
||||
import static org.briarproject.api.sync.MessagingConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
|
||||
import static org.briarproject.api.sync.PacketTypes.ACK;
|
||||
import static org.briarproject.api.sync.PacketTypes.OFFER;
|
||||
import static org.briarproject.api.sync.PacketTypes.REQUEST;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -43,19 +43,23 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testFormatExceptionIfAckIsTooLarge() throws Exception {
|
||||
byte[] b = createAck(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readAck();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
|
||||
byte[] b = createAck(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
reader.readAck();
|
||||
}
|
||||
@@ -64,31 +68,38 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyAck() throws Exception {
|
||||
byte[] b = createEmptyAck();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readAck();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
|
||||
byte[] b = createOffer(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readOffer();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception {
|
||||
byte[] b = createOffer(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
reader.readOffer();
|
||||
}
|
||||
@@ -97,31 +108,38 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyOffer() throws Exception {
|
||||
byte[] b = createEmptyOffer();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readOffer();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||
byte[] b = createRequest(true);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readRequest();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
||||
byte[] b = createRequest(false);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
reader.readRequest();
|
||||
}
|
||||
@@ -130,12 +148,15 @@ public class PacketReaderImplTest extends BriarTestCase {
|
||||
public void testEmptyRequest() throws Exception {
|
||||
byte[] b = createEmptyRequest();
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null,
|
||||
org.briarproject.sync.PacketReaderImpl
|
||||
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
|
||||
null, in);
|
||||
try {
|
||||
reader.readRequest();
|
||||
fail();
|
||||
} catch (FormatException expected) {}
|
||||
} catch (FormatException expected) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] createAck(boolean tooBig) throws Exception {
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.messaging;
|
||||
package org.briarproject.sync;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
@@ -20,16 +20,16 @@ import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.MessageAddedEvent;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupFactory;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageFactory;
|
||||
import org.briarproject.api.messaging.MessageVerifier;
|
||||
import org.briarproject.api.messaging.MessagingSession;
|
||||
import org.briarproject.api.messaging.PacketReader;
|
||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||
import org.briarproject.api.messaging.PacketWriter;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageFactory;
|
||||
import org.briarproject.api.sync.MessageVerifier;
|
||||
import org.briarproject.api.sync.MessagingSession;
|
||||
import org.briarproject.api.sync.PacketReader;
|
||||
import org.briarproject.api.sync.PacketReaderFactory;
|
||||
import org.briarproject.api.sync.PacketWriter;
|
||||
import org.briarproject.api.sync.PacketWriterFactory;
|
||||
import org.briarproject.api.transport.KeyManager;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamReaderFactory;
|
||||
@@ -53,7 +53,7 @@ import java.io.OutputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
|
||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -87,7 +87,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
return Guice.createInjector(new TestDatabaseModule(dir),
|
||||
new TestLifecycleModule(), new TestSystemModule(),
|
||||
new CryptoModule(), new DatabaseModule(), new EventModule(),
|
||||
new MessagingModule(), new DataModule(),
|
||||
new org.briarproject.sync.MessagingModule(), new DataModule(),
|
||||
new TransportModule());
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
alice.getInstance(PacketWriterFactory.class);
|
||||
PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
|
||||
streamWriter);
|
||||
MessagingSession session = new SimplexOutgoingSession(db,
|
||||
MessagingSession session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
||||
new ImmediateExecutor(), eventBus, contactId, transportId,
|
||||
MAX_LATENCY, packetWriter);
|
||||
// Write whatever needs to be written
|
||||
@@ -216,7 +216,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
bob.getInstance(PacketReaderFactory.class);
|
||||
PacketReader packetReader = packetReaderFactory.createPacketReader(
|
||||
streamReader);
|
||||
MessagingSession session = new IncomingSession(db,
|
||||
MessagingSession session = new org.briarproject.sync.IncomingSession(db,
|
||||
new ImmediateExecutor(), new ImmediateExecutor(), eventBus,
|
||||
messageVerifier, contactId, transportId, packetReader);
|
||||
// No messages should have been added yet
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.messaging;
|
||||
package org.briarproject.sync;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestUtils;
|
||||
@@ -6,15 +6,16 @@ import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.PacketWriter;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.PacketWriter;
|
||||
import org.briarproject.plugins.ImmediateExecutor;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
@@ -45,7 +46,8 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testNothingToSend() throws Exception {
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
final org.briarproject.sync.SimplexOutgoingSession
|
||||
session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
||||
packetWriter);
|
||||
context.checking(new Expectations() {{
|
||||
@@ -89,9 +91,10 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testSomethingToSend() throws Exception {
|
||||
final Ack ack = new Ack(Arrays.asList(messageId));
|
||||
final Ack ack = new Ack(Collections.singletonList(messageId));
|
||||
final byte[] raw = new byte[1234];
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
final org.briarproject.sync.SimplexOutgoingSession
|
||||
session = new org.briarproject.sync.SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, contactId, transportId, maxLatency,
|
||||
packetWriter);
|
||||
context.checking(new Expectations() {{
|
||||
Reference in New Issue
Block a user