Store each connection window slot as a database row.

This is less memory-efficient but necessary for the coming forward
secrecy changes.
This commit is contained in:
akwizgran
2011-11-15 13:08:20 +00:00
parent cf49a28c95
commit df054b1743
19 changed files with 152 additions and 140 deletions

View File

@@ -84,7 +84,7 @@ public class ConnectionDecrypterImplTest extends TestCase {
out.write(ciphertextMac);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// Use a ConnectionDecrypter to decrypt the ciphertext
ConnectionDecrypter d = new ConnectionDecrypterImpl(in,
ConnectionDecrypter d = new ConnectionDecrypterImpl(in,
IvEncoder.encodeIv(initiator, transportIndex, connection),
frameCipher, frameKey);
// First frame

View File

@@ -49,7 +49,7 @@ public class ConnectionRecogniserImplTest extends TestCase {
Transport transport = new Transport(transportId, localIndex,
Collections.singletonMap("foo", "bar"));
transports = Collections.singletonList(transport);
connectionWindow = new ConnectionWindowImpl(0L, 0);
connectionWindow = new ConnectionWindowImpl();
}
@Test
@@ -120,8 +120,7 @@ public class ConnectionRecogniserImplTest extends TestCase {
// Second time - the IV should no longer be expected
assertNull(c.acceptConnection(encryptedIv));
// The window should have advanced
assertEquals(4L, connectionWindow.getCentre());
Collection<Long> unseen = connectionWindow.getUnseenConnectionNumbers();
Collection<Long> unseen = connectionWindow.getUnseen();
assertEquals(19, unseen.size());
for(int i = 0; i < 19; i++) {
if(i == 3) continue;

View File

@@ -1,18 +1,18 @@
package net.sf.briar.transport;
import java.util.ArrayList;
import java.util.Collection;
import junit.framework.TestCase;
import net.sf.briar.util.ByteUtils;
import org.junit.Test;
public class ConnectionWindowImplTest extends TestCase {
private static final long MAX_32_BIT_UNSIGNED = 4294967295L; // 2^32 - 1
@Test
public void testWindowSliding() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
for(int i = 0; i < 100; i++) {
assertFalse(w.isSeen(i));
w.setSeen(i);
@@ -22,7 +22,7 @@ public class ConnectionWindowImplTest extends TestCase {
@Test
public void testWindowJumping() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
for(int i = 0; i < 100; i += 13) {
assertFalse(w.isSeen(i));
w.setSeen(i);
@@ -32,7 +32,7 @@ public class ConnectionWindowImplTest extends TestCase {
@Test
public void testWindowUpperLimit() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
// Centre is 0, highest value in window is 15
w.setSeen(15);
// Centre is 16, highest value in window is 31
@@ -42,18 +42,22 @@ public class ConnectionWindowImplTest extends TestCase {
w.setSeen(48);
fail();
} catch(IllegalArgumentException expected) {}
w = new ConnectionWindowImpl(MAX_32_BIT_UNSIGNED - 1, 0);
// Values greater than 2^31 - 1 should never be allowed
w.setSeen(MAX_32_BIT_UNSIGNED);
// Values greater than 2^32 - 1 should never be allowed
Collection<Long> unseen = new ArrayList<Long>();
for(int i = 0; i < 32; i++) {
unseen.add(ByteUtils.MAX_32_BIT_UNSIGNED - i);
}
w = new ConnectionWindowImpl(unseen);
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED);
try {
w.setSeen(MAX_32_BIT_UNSIGNED + 1);
w.setSeen(ByteUtils.MAX_32_BIT_UNSIGNED + 1);
fail();
} catch(IllegalArgumentException expected) {}
}
@Test
public void testWindowLowerLimit() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
// Centre is 0, negative values should never be allowed
try {
w.setSeen(-1);
@@ -83,7 +87,7 @@ public class ConnectionWindowImplTest extends TestCase {
@Test
public void testCannotSetSeenTwice() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
w.setSeen(15);
try {
w.setSeen(15);
@@ -93,9 +97,9 @@ public class ConnectionWindowImplTest extends TestCase {
@Test
public void testGetUnseenConnectionNumbers() {
ConnectionWindowImpl w = new ConnectionWindowImpl(0L, 0);
ConnectionWindowImpl w = new ConnectionWindowImpl();
// Centre is 0; window should cover 0 to 15, inclusive, with none seen
Collection<Long> unseen = w.getUnseenConnectionNumbers();
Collection<Long> unseen = w.getUnseen();
assertEquals(16, unseen.size());
for(int i = 0; i < 16; i++) {
assertTrue(unseen.contains(Long.valueOf(i)));
@@ -104,7 +108,7 @@ public class ConnectionWindowImplTest extends TestCase {
w.setSeen(3);
w.setSeen(4);
// Centre is 5; window should cover 0 to 20, inclusive, with two seen
unseen = w.getUnseenConnectionNumbers();
unseen = w.getUnseen();
assertEquals(19, unseen.size());
for(int i = 0; i < 21; i++) {
if(i == 3 || i == 4) {
@@ -117,7 +121,7 @@ public class ConnectionWindowImplTest extends TestCase {
}
w.setSeen(19);
// Centre is 20; window should cover 4 to 35, inclusive, with two seen
unseen = w.getUnseenConnectionNumbers();
unseen = w.getUnseen();
assertEquals(30, unseen.size());
for(int i = 4; i < 36; i++) {
if(i == 4 || i == 19) {