mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Renamed a load of things from 'connection' to 'stream'.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user