mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Renamed a load of things from 'connection' to 'stream'.
This commit is contained in:
@@ -36,11 +36,11 @@ 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.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionReader;
|
||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
||||
import org.briarproject.api.transport.ConnectionWriter;
|
||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamReader;
|
||||
import org.briarproject.api.transport.StreamReaderFactory;
|
||||
import org.briarproject.api.transport.StreamWriter;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.db.DatabaseModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
@@ -57,8 +57,8 @@ import com.google.inject.Injector;
|
||||
|
||||
public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
|
||||
private final ConnectionReaderFactory connectionReaderFactory;
|
||||
private final ConnectionWriterFactory connectionWriterFactory;
|
||||
private final StreamReaderFactory streamReaderFactory;
|
||||
private final StreamWriterFactory streamWriterFactory;
|
||||
private final PacketReaderFactory packetReaderFactory;
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
private final MessageVerifier messageVerifier;
|
||||
@@ -84,8 +84,8 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new ReliabilityModule(), new SerialModule(),
|
||||
new TransportModule());
|
||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
streamReaderFactory = i.getInstance(StreamReaderFactory.class);
|
||||
streamWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||
packetReaderFactory = i.getInstance(PacketReaderFactory.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
messageVerifier = i.getInstance(MessageVerifier.class);
|
||||
@@ -123,9 +123,9 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
|
||||
private byte[] write() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret.clone(), 0, true);
|
||||
ConnectionWriter conn = connectionWriterFactory.createConnectionWriter(
|
||||
StreamWriter conn = streamWriterFactory.createStreamWriter(
|
||||
out, MAX_FRAME_LENGTH, Long.MAX_VALUE, ctx, false, true);
|
||||
OutputStream out1 = conn.getOutputStream();
|
||||
PacketWriter writer = packetWriterFactory.createPacketWriter(out1,
|
||||
@@ -156,9 +156,9 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
||||
// FIXME: Check that the expected tag was received
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret.clone(), 0, false);
|
||||
ConnectionReader conn = connectionReaderFactory.createConnectionReader(
|
||||
StreamReader conn = streamReaderFactory.createStreamReader(
|
||||
in, MAX_FRAME_LENGTH, ctx, true, true);
|
||||
InputStream in1 = conn.getInputStream();
|
||||
PacketReader reader = packetReaderFactory.createPacketReader(in1);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class KeyDerivationTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionNumberAffectsDerivation() {
|
||||
public void testStreamNumberAffectsDerivation() {
|
||||
List<byte[]> secrets = new ArrayList<byte[]>();
|
||||
for(int i = 0; i < 20; i++) {
|
||||
secrets.add(crypto.deriveNextSecret(secret.clone(), i));
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.KeyParser;
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.crypto.PublicKey;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class KeyEncodingAndParsingTest extends BriarTestCase {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.Random;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SecretKeyImplTest extends BriarTestCase {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.Random;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -388,7 +388,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.incrementConnectionCounter(contactId, transportId, 0);
|
||||
db.incrementStreamCounter(contactId, transportId, 0);
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
@@ -453,7 +453,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
try {
|
||||
db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
fail();
|
||||
} catch(NoSuchContactException expected) {}
|
||||
|
||||
@@ -624,7 +624,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchTransportException expected) {}
|
||||
|
||||
try {
|
||||
db.incrementConnectionCounter(contactId, transportId, 0);
|
||||
db.incrementStreamCounter(contactId, transportId, 0);
|
||||
fail();
|
||||
} catch(NoSuchTransportException expected) {}
|
||||
|
||||
@@ -634,7 +634,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
} catch(NoSuchTransportException expected) {}
|
||||
|
||||
try {
|
||||
db.setConnectionWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
|
||||
fail();
|
||||
} catch(NoSuchTransportException expected) {}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExponentialBackoffTest extends BriarTestCase {
|
||||
|
||||
@@ -88,6 +88,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
contactId = new ContactId(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
testDir.mkdirs();
|
||||
@@ -465,6 +466,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
// In another thread, close the database
|
||||
Thread close = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
closing.countDown();
|
||||
@@ -501,6 +503,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
// In another thread, close the database
|
||||
Thread close = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
closing.countDown();
|
||||
@@ -1160,19 +1163,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(alice, s.getAlice());
|
||||
if(s.getPeriod() == 0) {
|
||||
assertArrayEquals(secret1, s.getSecret());
|
||||
assertEquals(outgoing1, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing1, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre1, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap1, s.getWindowBitmap());
|
||||
foundFirst = true;
|
||||
} else if(s.getPeriod() == 1) {
|
||||
assertArrayEquals(secret2, s.getSecret());
|
||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing2, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre2, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
||||
foundSecond = true;
|
||||
} else if(s.getPeriod() == 2) {
|
||||
assertArrayEquals(secret3, s.getSecret());
|
||||
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing3, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre3, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
||||
foundThird = true;
|
||||
@@ -1197,19 +1200,19 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(alice, s.getAlice());
|
||||
if(s.getPeriod() == 1) {
|
||||
assertArrayEquals(secret2, s.getSecret());
|
||||
assertEquals(outgoing2, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing2, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre2, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap2, s.getWindowBitmap());
|
||||
foundSecond = true;
|
||||
} else if(s.getPeriod() == 2) {
|
||||
assertArrayEquals(secret3, s.getSecret());
|
||||
assertEquals(outgoing3, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing3, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre3, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap3, s.getWindowBitmap());
|
||||
foundThird = true;
|
||||
} else if(s.getPeriod() == 3) {
|
||||
assertArrayEquals(secret4, s.getSecret());
|
||||
assertEquals(outgoing4, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing4, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre4, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap4, s.getWindowBitmap());
|
||||
foundFourth = true;
|
||||
@@ -1230,7 +1233,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementConnectionCounter() throws Exception {
|
||||
public void testIncrementStreamCounter() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, latency = 234;
|
||||
boolean alice = false;
|
||||
@@ -1245,7 +1248,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, the transport, the endpoint and the temporary secret
|
||||
// Add the contact, transport, endpoint and temporary secret
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId, latency);
|
||||
@@ -1260,14 +1263,14 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(period, s.getPeriod());
|
||||
assertArrayEquals(secret, s.getSecret());
|
||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||
|
||||
// Increment the connection counter twice and retrieve the secret again
|
||||
assertEquals(outgoing, db.incrementConnectionCounter(txn,
|
||||
// Increment the stream counter twice and retrieve the secret again
|
||||
assertEquals(outgoing, db.incrementStreamCounter(txn,
|
||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||
assertEquals(outgoing + 1, db.incrementConnectionCounter(txn,
|
||||
assertEquals(outgoing + 1, db.incrementStreamCounter(txn,
|
||||
s.getContactId(), s.getTransportId(), s.getPeriod()));
|
||||
secrets = db.getSecrets(txn);
|
||||
assertEquals(1, secrets.size());
|
||||
@@ -1276,7 +1279,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(period, s.getPeriod());
|
||||
assertArrayEquals(secret, s.getSecret());
|
||||
assertEquals(outgoing + 2, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing + 2, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||
|
||||
@@ -1285,7 +1288,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetConnectionWindow() throws Exception {
|
||||
public void testSetReorderingWindow() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, latency = 234;
|
||||
boolean alice = false;
|
||||
@@ -1300,7 +1303,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, the transport, the endpoint and the temporary secret
|
||||
// Add the contact, transport, endpoint and temporary secret
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
db.addTransport(txn, transportId, latency);
|
||||
@@ -1315,13 +1318,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(period, s.getPeriod());
|
||||
assertArrayEquals(secret, s.getSecret());
|
||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||
|
||||
// Update the connection window and retrieve the secret again
|
||||
// Update the reordering window and retrieve the secret again
|
||||
random.nextBytes(bitmap);
|
||||
db.setConnectionWindow(txn, contactId, transportId, period, centre,
|
||||
db.setReorderingWindow(txn, contactId, transportId, period, centre,
|
||||
bitmap);
|
||||
secrets = db.getSecrets(txn);
|
||||
assertEquals(1, secrets.size());
|
||||
@@ -1330,12 +1333,12 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(period, s.getPeriod());
|
||||
assertArrayEquals(secret, s.getSecret());
|
||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||
|
||||
// Updating a nonexistent window should not throw an exception
|
||||
db.setConnectionWindow(txn, contactId, transportId, period + 1, 1,
|
||||
db.setReorderingWindow(txn, contactId, transportId, period + 1, 1,
|
||||
bitmap);
|
||||
// The nonexistent window should not have been created
|
||||
secrets = db.getSecrets(txn);
|
||||
@@ -1345,7 +1348,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(transportId, s.getTransportId());
|
||||
assertEquals(period, s.getPeriod());
|
||||
assertArrayEquals(secret, s.getSecret());
|
||||
assertEquals(outgoing, s.getOutgoingConnectionCounter());
|
||||
assertEquals(outgoing, s.getOutgoingStreamCounter());
|
||||
assertEquals(centre, s.getWindowCentre());
|
||||
assertArrayEquals(bitmap, s.getWindowBitmap());
|
||||
|
||||
@@ -1354,7 +1357,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContactTransports() throws Exception {
|
||||
public void testEndpoints() throws Exception {
|
||||
// Create some endpoints
|
||||
long epoch1 = 123, latency1 = 234;
|
||||
long epoch2 = 345, latency2 = 456;
|
||||
@@ -1378,7 +1381,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addEndpoint(txn, ep1);
|
||||
db.addEndpoint(txn, ep2);
|
||||
|
||||
// Retrieve the contact transports
|
||||
// Retrieve the endpoints
|
||||
Collection<Endpoint> endpoints = db.getEndpoints(txn);
|
||||
assertEquals(2, endpoints.size());
|
||||
boolean foundFirst = false, foundSecond = false;
|
||||
@@ -1399,7 +1402,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertTrue(foundFirst);
|
||||
assertTrue(foundSecond);
|
||||
|
||||
// Removing the contact should remove the contact transports
|
||||
// Removing the contact should remove the endpoints
|
||||
db.removeContact(txn, contactId);
|
||||
assertEquals(Collections.emptyList(), db.getEndpoints(txn));
|
||||
|
||||
@@ -1646,6 +1649,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
return db;
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() {
|
||||
TestUtils.deleteTestDirectory(testDir);
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Set;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ShutdownManagerImplTest extends BriarTestCase {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.lifecycle;
|
||||
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WindowsShutdownManagerImplTest extends ShutdownManagerImplTest {
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.briarproject.api.crypto.MessageDigest;
|
||||
import org.briarproject.api.serial.CopyingConsumer;
|
||||
import org.briarproject.api.serial.CountingConsumer;
|
||||
import org.briarproject.api.serial.DigestingConsumer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConsumersTest extends BriarTestCase {
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.briarproject.api.serial.SerialComponent;
|
||||
import org.briarproject.api.serial.Writer;
|
||||
import org.briarproject.api.serial.WriterFactory;
|
||||
import org.briarproject.serial.SerialModule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.briarproject.messaging.simplex;
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -24,9 +24,9 @@ import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionRegistry;
|
||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
import org.briarproject.messaging.MessagingModule;
|
||||
@@ -49,7 +49,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
private final Mockery context;
|
||||
private final DatabaseComponent db;
|
||||
private final ConnectionRegistry connRegistry;
|
||||
private final ConnectionWriterFactory connWriterFactory;
|
||||
private final StreamWriterFactory connWriterFactory;
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
private final ContactId contactId;
|
||||
private final MessageId messageId;
|
||||
@@ -74,7 +74,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
connRegistry = i.getInstance(ConnectionRegistry.class);
|
||||
connWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
connWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
contactId = new ContactId(234);
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
@@ -88,7 +88,7 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||
out, MAX_PACKET_LENGTH, Long.MAX_VALUE);
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret, 0, true);
|
||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||
@@ -105,8 +105,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
public void testNothingToSend() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
out, MIN_STREAM_LENGTH, Long.MAX_VALUE);
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret, 0, true);
|
||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||
@@ -154,8 +154,8 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
public void testSomethingToSend() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||
out, MIN_CONNECTION_LENGTH, Long.MAX_VALUE);
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
out, MIN_STREAM_LENGTH, Long.MAX_VALUE);
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret, 0, true);
|
||||
OutgoingSimplexConnection connection = new OutgoingSimplexConnection(db,
|
||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.briarproject.api.messaging.MessageFactory;
|
||||
import org.briarproject.api.messaging.MessageVerifier;
|
||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionReaderFactory;
|
||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
||||
import org.briarproject.api.transport.ConnectionRegistry;
|
||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
||||
import org.briarproject.api.transport.Endpoint;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamReaderFactory;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
import org.briarproject.api.transport.TagRecogniser;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.db.DatabaseModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
@@ -144,13 +144,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ConnectionRegistry connRegistry =
|
||||
alice.getInstance(ConnectionRegistry.class);
|
||||
ConnectionWriterFactory connWriterFactory =
|
||||
alice.getInstance(ConnectionWriterFactory.class);
|
||||
StreamWriterFactory connWriterFactory =
|
||||
alice.getInstance(StreamWriterFactory.class);
|
||||
PacketWriterFactory packetWriterFactory =
|
||||
alice.getInstance(PacketWriterFactory.class);
|
||||
TestSimplexTransportWriter transport = new TestSimplexTransportWriter(
|
||||
out, Long.MAX_VALUE, Long.MAX_VALUE);
|
||||
ConnectionContext ctx = km.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx = km.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
OutgoingSimplexConnection simplex = new OutgoingSimplexConnection(db,
|
||||
connRegistry, connWriterFactory, packetWriterFactory, ctx,
|
||||
@@ -196,21 +196,21 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Set up an event listener
|
||||
MessageListener listener = new MessageListener();
|
||||
bob.getInstance(EventBus.class).addListener(listener);
|
||||
// Create a connection recogniser and recognise the connection
|
||||
// Create a tag recogniser and recognise the tag
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||
ConnectionRecogniser rec = bob.getInstance(ConnectionRecogniser.class);
|
||||
TagRecogniser rec = bob.getInstance(TagRecogniser.class);
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
int read = in.read(tag);
|
||||
assertEquals(tag.length, read);
|
||||
ConnectionContext ctx = rec.acceptConnection(transportId, tag);
|
||||
StreamContext ctx = rec.recogniseTag(transportId, tag);
|
||||
assertNotNull(ctx);
|
||||
// Create an incoming simplex connection
|
||||
MessageVerifier messageVerifier =
|
||||
bob.getInstance(MessageVerifier.class);
|
||||
ConnectionRegistry connRegistry =
|
||||
bob.getInstance(ConnectionRegistry.class);
|
||||
ConnectionReaderFactory connWriterFactory =
|
||||
bob.getInstance(ConnectionReaderFactory.class);
|
||||
StreamReaderFactory connWriterFactory =
|
||||
bob.getInstance(StreamReaderFactory.class);
|
||||
PacketReaderFactory packetWriterFactory =
|
||||
bob.getInstance(PacketReaderFactory.class);
|
||||
TestSimplexTransportReader transport =
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LinuxRemovableDriveFinderTest extends BriarTestCase {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MacRemovableDriveFinderTest extends BriarTestCase {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PollingRemovableDriveMonitorTest extends BriarTestCase {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -20,7 +20,6 @@ import org.briarproject.api.plugins.simplex.SimplexTransportWriter;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.plugins.ImmediateExecutor;
|
||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.After;
|
||||
@@ -344,10 +343,10 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
|
||||
File f = new File(testDir, "abcdefgh.dat");
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
out.write(new byte[MIN_CONNECTION_LENGTH]);
|
||||
out.write(new byte[MIN_STREAM_LENGTH]);
|
||||
out.flush();
|
||||
out.close();
|
||||
assertEquals(MIN_CONNECTION_LENGTH, f.length());
|
||||
assertEquals(MIN_STREAM_LENGTH, f.length());
|
||||
plugin.driveInserted(testDir);
|
||||
|
||||
context.assertIsSatisfied();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.plugins.modem;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CountryCodesTest extends BriarTestCase {
|
||||
|
||||
@@ -15,9 +15,9 @@ import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.Timer;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
||||
import org.briarproject.api.transport.Endpoint;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.TagRecogniser;
|
||||
import org.briarproject.api.transport.TemporarySecret;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
@@ -58,8 +58,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -95,8 +95,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -154,8 +154,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -195,7 +195,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
oneOf(connectionRecogniser).addSecret(s1);
|
||||
oneOf(connectionRecogniser).addSecret(s2);
|
||||
// getConnectionContext()
|
||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
||||
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||
will(returnValue(0L));
|
||||
// stop()
|
||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||
@@ -205,13 +205,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
|
||||
assertTrue(keyManager.start());
|
||||
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
||||
ConnectionContext ctx =
|
||||
keyManager.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx =
|
||||
keyManager.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret1, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
@@ -224,8 +224,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -273,8 +273,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -332,8 +332,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -393,8 +393,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -428,7 +428,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(EPOCH + 1));
|
||||
// getConnectionContext()
|
||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
||||
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||
will(returnValue(0L));
|
||||
// stop()
|
||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||
@@ -438,13 +438,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
|
||||
assertTrue(keyManager.start());
|
||||
keyManager.run();
|
||||
ConnectionContext ctx =
|
||||
keyManager.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx =
|
||||
keyManager.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret1, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
@@ -457,8 +457,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -503,7 +503,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
oneOf(db).addSecrets(Arrays.asList(s3));
|
||||
oneOf(connectionRecogniser).addSecret(s3);
|
||||
// getConnectionContext()
|
||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 2);
|
||||
oneOf(db).incrementStreamCounter(contactId, transportId, 2);
|
||||
will(returnValue(0L));
|
||||
// stop()
|
||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||
@@ -513,13 +513,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
|
||||
assertTrue(keyManager.start());
|
||||
keyManager.run();
|
||||
ConnectionContext ctx =
|
||||
keyManager.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx =
|
||||
keyManager.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret2, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
@@ -532,8 +532,8 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
context.mock(ConnectionRecogniser.class);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
context.mock(TagRecogniser.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
@@ -581,7 +581,7 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
oneOf(connectionRecogniser).addSecret(s3);
|
||||
oneOf(connectionRecogniser).addSecret(s4);
|
||||
// getConnectionContext()
|
||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 3);
|
||||
oneOf(db).incrementStreamCounter(contactId, transportId, 3);
|
||||
will(returnValue(0L));
|
||||
// stop()
|
||||
oneOf(eventBus).removeListener(with(any(EventListener.class)));
|
||||
@@ -591,13 +591,13 @@ public class KeyManagerImplTest extends BriarTestCase {
|
||||
|
||||
assertTrue(keyManager.start());
|
||||
keyManager.run();
|
||||
ConnectionContext ctx =
|
||||
keyManager.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx =
|
||||
keyManager.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret3, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.Timer;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionRecogniser;
|
||||
import org.briarproject.api.transport.Endpoint;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.TagRecogniser;
|
||||
import org.briarproject.api.transport.TemporarySecret;
|
||||
import org.briarproject.util.ByteUtils;
|
||||
import org.hamcrest.Description;
|
||||
@@ -78,8 +78,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
final Timer timer = context.mock(Timer.class);
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -117,8 +117,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -241,8 +241,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -308,7 +308,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
}
|
||||
oneOf(k2).erase();
|
||||
// getConnectionContext()
|
||||
oneOf(db).incrementConnectionCounter(contactId, transportId, 1);
|
||||
oneOf(db).incrementStreamCounter(contactId, transportId, 1);
|
||||
will(returnValue(0L));
|
||||
// stop()
|
||||
// The recogniser should derive the tags for period 0
|
||||
@@ -351,13 +351,13 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
|
||||
assertTrue(keyManager.start());
|
||||
keyManager.endpointAdded(ep, MAX_LATENCY, initialSecret.clone());
|
||||
ConnectionContext ctx =
|
||||
keyManager.getConnectionContext(contactId, transportId);
|
||||
StreamContext ctx =
|
||||
keyManager.getStreamContext(contactId, transportId);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret1, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
@@ -376,10 +376,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser tagRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
eventBus, tagRecogniser, clock, timer);
|
||||
|
||||
// The secrets for periods 0 - 2 should be derived
|
||||
Endpoint ep = new Endpoint(contactId, transportId, EPOCH, true);
|
||||
@@ -450,7 +450,7 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
will(new EncodeTagAction());
|
||||
oneOf(k2).getEncoded();
|
||||
will(returnValue(key2));
|
||||
oneOf(db).setConnectionWindow(contactId, transportId, 2, 1,
|
||||
oneOf(db).setReorderingWindow(contactId, transportId, 2, 1,
|
||||
new byte[] {0, 1, 0, 0});
|
||||
oneOf(k2).erase();
|
||||
// stop()
|
||||
@@ -497,13 +497,12 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
// Recognise the tag for connection 0 in period 2
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
encodeTag(tag, key2, 0);
|
||||
ConnectionContext ctx =
|
||||
connectionRecogniser.acceptConnection(transportId, tag);
|
||||
StreamContext ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret2, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(true, ctx.getAlice());
|
||||
keyManager.stop();
|
||||
|
||||
@@ -522,8 +521,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k1 = context.mock(SecretKey.class, "k1");
|
||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -637,8 +636,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k2 = context.mock(SecretKey.class, "k2");
|
||||
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -762,8 +761,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
final SecretKey k3 = context.mock(SecretKey.class, "k3");
|
||||
final SecretKey k4 = context.mock(SecretKey.class, "k4");
|
||||
|
||||
final ConnectionRecogniser connectionRecogniser =
|
||||
new ConnectionRecogniserImpl(crypto, db);
|
||||
final TagRecogniser connectionRecogniser =
|
||||
new TagRecogniserImpl(crypto, db);
|
||||
final KeyManagerImpl keyManager = new KeyManagerImpl(crypto, db,
|
||||
eventBus, connectionRecogniser, clock, timer);
|
||||
|
||||
@@ -877,10 +876,10 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void encodeTag(byte[] tag, byte[] rawKey, long connection) {
|
||||
// Encode a fake tag based on the key and connection number
|
||||
private void encodeTag(byte[] tag, byte[] rawKey, long streamNumber) {
|
||||
// Encode a fake tag based on the key and stream number
|
||||
System.arraycopy(rawKey, 0, tag, 0, tag.length);
|
||||
ByteUtils.writeUint32(connection, tag, 0);
|
||||
ByteUtils.writeUint32(streamNumber, tag, 0);
|
||||
}
|
||||
|
||||
private class EncodeTagAction implements Action {
|
||||
@@ -892,8 +891,8 @@ public class KeyRotationIntegrationTest extends BriarTestCase {
|
||||
public Object invoke(Invocation invocation) throws Throwable {
|
||||
byte[] tag = (byte[]) invocation.getParameter(0);
|
||||
SecretKey key = (SecretKey) invocation.getParameter(1);
|
||||
long connection = (Long) invocation.getParameter(2);
|
||||
encodeTag(tag, key.getEncoded(), connection);
|
||||
long streamNumber = (Long) invocation.getParameter(2);
|
||||
encodeTag(tag, key.getEncoded(), streamNumber);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package org.briarproject.transport;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.CONNECTION_WINDOW_SIZE;
|
||||
import static org.briarproject.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||
import static org.briarproject.util.ByteUtils.MAX_32_BIT_UNSIGNED;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConnectionWindowTest extends BriarTestCase {
|
||||
public class ReorderingWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowSliding() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
for(int i = 0; i < 100; i++) {
|
||||
assertFalse(w.isSeen(i));
|
||||
w.setSeen(i);
|
||||
@@ -24,7 +23,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowJumping() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
for(int i = 0; i < 100; i += 13) {
|
||||
assertFalse(w.isSeen(i));
|
||||
w.setSeen(i);
|
||||
@@ -34,7 +33,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowUpperLimit() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
// Centre is 0, highest value in window is 15
|
||||
w.setSeen(15);
|
||||
// Centre is 16, highest value in window is 31
|
||||
@@ -45,8 +44,8 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
fail();
|
||||
} catch(IllegalArgumentException expected) {}
|
||||
// Centre is max - 1, highest value in window is max
|
||||
byte[] bitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
||||
w = new ConnectionWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
|
||||
byte[] bitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
w = new ReorderingWindow(MAX_32_BIT_UNSIGNED - 1, bitmap);
|
||||
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED - 1));
|
||||
assertFalse(w.isSeen(MAX_32_BIT_UNSIGNED));
|
||||
// Values greater than max should never be allowed
|
||||
@@ -59,7 +58,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
// Centre should have moved to max + 1
|
||||
assertEquals(MAX_32_BIT_UNSIGNED + 1, w.getCentre());
|
||||
// The bit corresponding to max should be set
|
||||
byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
||||
byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
expectedBitmap[expectedBitmap.length / 2 - 1] = 1; // 00000001
|
||||
assertArrayEquals(expectedBitmap, w.getBitmap());
|
||||
// Values greater than max should never be allowed even if centre > max
|
||||
@@ -71,7 +70,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testWindowLowerLimit() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
// Centre is 0, negative values should never be allowed
|
||||
try {
|
||||
w.setSeen(-1);
|
||||
@@ -100,7 +99,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
// Centre should still be 26
|
||||
assertEquals(26, w.getCentre());
|
||||
// The bits corresponding to 10, 15, 16 and 25 should be set
|
||||
byte[] expectedBitmap = new byte[CONNECTION_WINDOW_SIZE / 8];
|
||||
byte[] expectedBitmap = new byte[REORDERING_WINDOW_SIZE / 8];
|
||||
expectedBitmap[0] = (byte) 134; // 10000110
|
||||
expectedBitmap[1] = 1; // 00000001
|
||||
assertArrayEquals(expectedBitmap, w.getBitmap());
|
||||
@@ -108,7 +107,7 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testCannotSetSeenTwice() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
w.setSeen(15);
|
||||
try {
|
||||
w.setSeen(15);
|
||||
@@ -117,8 +116,8 @@ public class ConnectionWindowTest extends BriarTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnseenConnectionNumbers() {
|
||||
ConnectionWindow w = new ConnectionWindow();
|
||||
public void testGetUnseenStreamNumbers() {
|
||||
ReorderingWindow w = new ReorderingWindow();
|
||||
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
|
||||
Collection<Long> unseen = w.getUnseen();
|
||||
assertEquals(16, unseen.size());
|
||||
@@ -2,13 +2,13 @@ package org.briarproject.transport;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConnectionReaderImplTest extends BriarTestCase {
|
||||
public class StreamReaderImplTest extends BriarTestCase {
|
||||
|
||||
private static final int FRAME_LENGTH = 1024;
|
||||
private static final int MAX_PAYLOAD_LENGTH =
|
||||
@@ -28,13 +28,13 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(-1)); // No more frames
|
||||
}});
|
||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
||||
assertEquals(0, c.read()); // Skip the first empty frame, read a byte
|
||||
assertEquals(0, c.read()); // Read another byte
|
||||
assertEquals(-1, c.read()); // Skip the second empty frame, reach EOF
|
||||
assertEquals(-1, c.read()); // Still at EOF
|
||||
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||
assertEquals(0, r.read()); // Skip the first empty frame, read a byte
|
||||
assertEquals(0, r.read()); // Read another byte
|
||||
assertEquals(-1, r.read()); // Skip the second empty frame, reach EOF
|
||||
assertEquals(-1, r.read()); // Still at EOF
|
||||
context.assertIsSatisfied();
|
||||
c.close();
|
||||
r.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -51,16 +51,16 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(-1)); // No more frames
|
||||
}});
|
||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
||||
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
||||
// Skip the first empty frame, read the two payload bytes
|
||||
assertEquals(2, c.read(buf));
|
||||
assertEquals(2, r.read(buf));
|
||||
// Skip the second empty frame, reach EOF
|
||||
assertEquals(-1, c.read(buf));
|
||||
assertEquals(-1, r.read(buf));
|
||||
// Still at EOF
|
||||
assertEquals(-1, c.read(buf));
|
||||
assertEquals(-1, r.read(buf));
|
||||
context.assertIsSatisfied();
|
||||
c.close();
|
||||
r.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,16 +73,16 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(-1)); // No more frames
|
||||
}});
|
||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
||||
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH / 2];
|
||||
// Read the first half of the payload
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf));
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
||||
// Read the second half of the payload
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf));
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf));
|
||||
// Reach EOF
|
||||
assertEquals(-1, c.read(buf, 0, buf.length));
|
||||
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||
context.assertIsSatisfied();
|
||||
c.close();
|
||||
r.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,17 +95,17 @@ public class ConnectionReaderImplTest extends BriarTestCase {
|
||||
oneOf(reader).readFrame(with(any(byte[].class)));
|
||||
will(returnValue(-1)); // No more frames
|
||||
}});
|
||||
ConnectionReaderImpl c = new ConnectionReaderImpl(reader, FRAME_LENGTH);
|
||||
StreamReaderImpl r = new StreamReaderImpl(reader, FRAME_LENGTH);
|
||||
byte[] buf = new byte[MAX_PAYLOAD_LENGTH];
|
||||
// Read the first half of the payload
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, MAX_PAYLOAD_LENGTH / 2,
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, MAX_PAYLOAD_LENGTH / 2,
|
||||
MAX_PAYLOAD_LENGTH / 2));
|
||||
// Read the second half of the payload
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, c.read(buf, 123,
|
||||
assertEquals(MAX_PAYLOAD_LENGTH / 2, r.read(buf, 123,
|
||||
MAX_PAYLOAD_LENGTH / 2));
|
||||
// Reach EOF
|
||||
assertEquals(-1, c.read(buf, 0, buf.length));
|
||||
assertEquals(-1, r.read(buf, 0, buf.length));
|
||||
context.assertIsSatisfied();
|
||||
c.close();
|
||||
r.close();
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package org.briarproject.transport;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
public class StreamWriterImplTest extends BriarTestCase {
|
||||
|
||||
private static final int FRAME_LENGTH = 1024;
|
||||
private static final int MAX_PAYLOAD_LENGTH =
|
||||
@@ -25,8 +25,8 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
// Flush the stream
|
||||
oneOf(writer).flush();
|
||||
}});
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
c.close();
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
w.close();
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
public void testFlushWithoutBufferedDataWritesFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
context.checking(new Expectations() {{
|
||||
// Flush the stream
|
||||
oneOf(writer).flush();
|
||||
}});
|
||||
c.flush();
|
||||
w.flush();
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
context.checking(new Expectations() {{
|
||||
// Write a non-final frame with one payload byte
|
||||
oneOf(writer).writeFrame(with(any(byte[].class)), with(1),
|
||||
@@ -56,8 +56,8 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
// Flush the stream
|
||||
oneOf(writer).flush();
|
||||
}});
|
||||
c.write(0);
|
||||
c.flush();
|
||||
w.write(0);
|
||||
w.flush();
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
public void testSingleByteWritesWriteFullFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
context.checking(new Expectations() {{
|
||||
// Write a full non-final frame
|
||||
oneOf(writer).writeFrame(with(any(byte[].class)),
|
||||
with(MAX_PAYLOAD_LENGTH), with(false));
|
||||
}});
|
||||
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) {
|
||||
c.write(0);
|
||||
w.write(0);
|
||||
}
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
public void testMultiByteWritesWriteFullFrames() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
||||
@@ -91,10 +91,10 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
assertEquals(0, MAX_PAYLOAD_LENGTH % 2);
|
||||
// Write two full payloads using four multi-byte writes
|
||||
byte[] b = new byte[MAX_PAYLOAD_LENGTH / 2];
|
||||
c.write(b);
|
||||
c.write(b);
|
||||
c.write(b);
|
||||
c.write(b);
|
||||
w.write(b);
|
||||
w.write(b);
|
||||
w.write(b);
|
||||
w.write(b);
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
public void testLargeMultiByteWriteWritesFullFrames() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final FrameWriter writer = context.mock(FrameWriter.class);
|
||||
ConnectionWriterImpl c = new ConnectionWriterImpl(writer, FRAME_LENGTH);
|
||||
StreamWriterImpl w = new StreamWriterImpl(writer, FRAME_LENGTH);
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
exactly(2).of(writer).writeFrame(with(any(byte[].class)),
|
||||
@@ -115,9 +115,9 @@ public class ConnectionWriterImplTest extends BriarTestCase {
|
||||
}});
|
||||
// Write two full payloads using one large multi-byte write
|
||||
byte[] b = new byte[MAX_PAYLOAD_LENGTH * 2 + 1];
|
||||
c.write(b);
|
||||
w.write(b);
|
||||
// There should be one byte left in the buffer
|
||||
c.close();
|
||||
w.close();
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.transport;
|
||||
|
||||
import static org.briarproject.api.messaging.MessagingConstants.MAX_PACKET_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -19,9 +19,9 @@ import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.ConnectionWriter;
|
||||
import org.briarproject.api.transport.ConnectionWriterFactory;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.StreamWriter;
|
||||
import org.briarproject.api.transport.StreamWriterFactory;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
private final int FRAME_LENGTH = 2048;
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
private final ConnectionWriterFactory connectionWriterFactory;
|
||||
private final StreamWriterFactory streamWriterFactory;
|
||||
private final ContactId contactId;
|
||||
private final TransportId transportId;
|
||||
private final AuthenticatedCipher frameCipher;
|
||||
@@ -45,15 +45,16 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
|
||||
public TransportIntegrationTest() {
|
||||
Module testModule = new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
bind(ConnectionWriterFactory.class).to(
|
||||
ConnectionWriterFactoryImpl.class);
|
||||
bind(StreamWriterFactory.class).to(
|
||||
StreamWriterFactoryImpl.class);
|
||||
}
|
||||
};
|
||||
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
||||
new TestLifecycleModule(), new TestSystemModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
streamWriterFactory = i.getInstance(StreamWriterFactory.class);
|
||||
contactId = new ContactId(234);
|
||||
transportId = new TransportId("id");
|
||||
frameCipher = crypto.getFrameCipher();
|
||||
@@ -86,7 +87,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
FrameWriter encryptionOut = new OutgoingEncryptionLayer(out,
|
||||
Long.MAX_VALUE, frameCipher, frameCopy, FRAME_LENGTH);
|
||||
ConnectionWriterImpl writer = new ConnectionWriterImpl(encryptionOut,
|
||||
StreamWriterImpl writer = new StreamWriterImpl(encryptionOut,
|
||||
FRAME_LENGTH);
|
||||
OutputStream out1 = writer.getOutputStream();
|
||||
out1.write(frame);
|
||||
@@ -99,7 +100,7 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(output);
|
||||
FrameReader encryptionIn = new IncomingEncryptionLayer(in, frameCipher,
|
||||
frameKey, FRAME_LENGTH);
|
||||
ConnectionReaderImpl reader = new ConnectionReaderImpl(encryptionIn,
|
||||
StreamReaderImpl reader = new StreamReaderImpl(encryptionIn,
|
||||
FRAME_LENGTH);
|
||||
InputStream in1 = reader.getInputStream();
|
||||
byte[] recovered = new byte[frame.length];
|
||||
@@ -127,42 +128,42 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testOverheadWithTag() throws Exception {
|
||||
ByteArrayOutputStream out =
|
||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
new ByteArrayOutputStream(MIN_STREAM_LENGTH);
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret, 0, true);
|
||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||
MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, true);
|
||||
StreamWriter w = streamWriterFactory.createStreamWriter(out,
|
||||
MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, true);
|
||||
// Check that the connection writer thinks there's room for a packet
|
||||
long capacity = w.getRemainingCapacity();
|
||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||
assertTrue(capacity < MIN_CONNECTION_LENGTH);
|
||||
assertTrue(capacity < MIN_STREAM_LENGTH);
|
||||
// Check that there really is room for a packet
|
||||
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
||||
w.getOutputStream().write(payload);
|
||||
w.getOutputStream().close();
|
||||
long used = out.size();
|
||||
assertTrue(used > MAX_PACKET_LENGTH);
|
||||
assertTrue(used <= MIN_CONNECTION_LENGTH);
|
||||
assertTrue(used <= MIN_STREAM_LENGTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverheadWithoutTag() throws Exception {
|
||||
ByteArrayOutputStream out =
|
||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||
ConnectionContext ctx = new ConnectionContext(contactId, transportId,
|
||||
new ByteArrayOutputStream(MIN_STREAM_LENGTH);
|
||||
StreamContext ctx = new StreamContext(contactId, transportId,
|
||||
secret, 0, true);
|
||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||
MAX_FRAME_LENGTH, MIN_CONNECTION_LENGTH, ctx, false, false);
|
||||
StreamWriter w = streamWriterFactory.createStreamWriter(out,
|
||||
MAX_FRAME_LENGTH, MIN_STREAM_LENGTH, ctx, false, false);
|
||||
// Check that the connection writer thinks there's room for a packet
|
||||
long capacity = w.getRemainingCapacity();
|
||||
assertTrue(capacity > MAX_PACKET_LENGTH);
|
||||
assertTrue(capacity < MIN_CONNECTION_LENGTH);
|
||||
assertTrue(capacity < MIN_STREAM_LENGTH);
|
||||
// Check that there really is room for a packet
|
||||
byte[] payload = new byte[MAX_PACKET_LENGTH];
|
||||
w.getOutputStream().write(payload);
|
||||
w.getOutputStream().close();
|
||||
long used = out.size();
|
||||
assertTrue(used > MAX_PACKET_LENGTH);
|
||||
assertTrue(used <= MIN_CONNECTION_LENGTH);
|
||||
assertTrue(used <= MIN_STREAM_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.transport.ConnectionContext;
|
||||
import org.briarproject.api.transport.StreamContext;
|
||||
import org.briarproject.api.transport.TemporarySecret;
|
||||
import org.briarproject.util.ByteUtils;
|
||||
import org.hamcrest.Description;
|
||||
@@ -21,7 +21,7 @@ import org.jmock.api.Action;
|
||||
import org.jmock.api.Invocation;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
public class TransportTagRecogniserTest extends BriarTestCase {
|
||||
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final TransportId transportId = new TransportId("id");
|
||||
@@ -57,15 +57,15 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
}});
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||
alice, 0, secret, 0, 0, new byte[4]);
|
||||
TransportConnectionRecogniser recogniser =
|
||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||
TransportTagRecogniser recogniser =
|
||||
new TransportTagRecogniser(crypto, db, transportId);
|
||||
recogniser.addSecret(s);
|
||||
recogniser.removeSecret(contactId, 0);
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcceptConnection() throws Exception {
|
||||
public void testRecogniseTag() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||
final byte[] secret = new byte[32];
|
||||
@@ -83,33 +83,35 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
will(new EncodeTagAction());
|
||||
}
|
||||
oneOf(tagKey).erase();
|
||||
// Accept connection 0
|
||||
// Recognise tag 0
|
||||
oneOf(crypto).deriveTagKey(secret, !alice);
|
||||
will(returnValue(tagKey));
|
||||
// The window should slide to include connection 16
|
||||
// The window should slide to include tag 16
|
||||
oneOf(crypto).encodeTag(with(any(byte[].class)), with(tagKey),
|
||||
with(16L));
|
||||
will(new EncodeTagAction());
|
||||
// The updated window should be stored
|
||||
oneOf(db).setConnectionWindow(contactId, transportId, 0, 1,
|
||||
oneOf(db).setReorderingWindow(contactId, transportId, 0, 1,
|
||||
new byte[] {0, 1, 0, 0});
|
||||
oneOf(tagKey).erase();
|
||||
// Accept connection again - no expectations
|
||||
// Recognise tag again - no expectations
|
||||
}});
|
||||
TemporarySecret s = new TemporarySecret(contactId, transportId, 123,
|
||||
alice, 0, secret, 0, 0, new byte[4]);
|
||||
TransportConnectionRecogniser recogniser =
|
||||
new TransportConnectionRecogniser(crypto, db, transportId);
|
||||
TransportTagRecogniser recogniser =
|
||||
new TransportTagRecogniser(crypto, db, transportId);
|
||||
recogniser.addSecret(s);
|
||||
// Connection 0 should be expected
|
||||
// Tag 0 should be expected
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
ConnectionContext ctx = recogniser.acceptConnection(tag);
|
||||
StreamContext ctx = recogniser.recogniseTag(tag);
|
||||
assertNotNull(ctx);
|
||||
assertEquals(contactId, ctx.getContactId());
|
||||
assertEquals(transportId, ctx.getTransportId());
|
||||
assertArrayEquals(secret, ctx.getSecret());
|
||||
assertEquals(0, ctx.getConnectionNumber());
|
||||
assertEquals(0, ctx.getStreamNumber());
|
||||
assertEquals(alice, ctx.getAlice());
|
||||
// Tag 0 should not be expected again
|
||||
assertNull(recogniser.recogniseTag(tag));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@@ -121,9 +123,9 @@ public class TransportConnectionRecogniserTest extends BriarTestCase {
|
||||
|
||||
public Object invoke(Invocation invocation) throws Throwable {
|
||||
byte[] tag = (byte[]) invocation.getParameter(0);
|
||||
long connection = (Long) invocation.getParameter(2);
|
||||
// Encode a fake tag based on the connection number
|
||||
ByteUtils.writeUint32(connection, tag, 0);
|
||||
long streamNumber = (Long) invocation.getParameter(2);
|
||||
// Encode a fake tag based on the stream number
|
||||
ByteUtils.writeUint32(streamNumber, tag, 0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.util;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ByteUtilsTest extends BriarTestCase {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.util;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import org.briarproject.BriarTestCase;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringUtilsTest extends BriarTestCase {
|
||||
|
||||
Reference in New Issue
Block a user