mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Check periodically for retransmittable packets. Bug #46.
This commit is contained in:
@@ -75,6 +75,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
protected final Message message, message1;
|
||||
protected final TransportId transportId;
|
||||
protected final TransportProperties transportProperties;
|
||||
protected final int maxLatency;
|
||||
protected final ContactId contactId;
|
||||
protected final Contact contact;
|
||||
protected final Endpoint endpoint;
|
||||
@@ -102,6 +103,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
transportId = new TransportId("id");
|
||||
transportProperties = new TransportProperties(Collections.singletonMap(
|
||||
"bar", "baz"));
|
||||
maxLatency = Integer.MAX_VALUE;
|
||||
contactId = new ContactId(234);
|
||||
contact = new Contact(contactId, author, localAuthorId);
|
||||
endpoint = new Endpoint(contactId, transportId, 123, true);
|
||||
@@ -691,11 +693,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -703,7 +705,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
eventBus, shutdown);
|
||||
|
||||
assertEquals(messages, db.generateBatch(contactId, size * 2,
|
||||
Long.MAX_VALUE));
|
||||
maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -726,15 +728,15 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getMessagesToOffer(txn, contactId, 123);
|
||||
will(returnValue(ids));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
eventBus, shutdown);
|
||||
|
||||
Offer o = db.generateOffer(contactId, 123, Long.MAX_VALUE);
|
||||
Offer o = db.generateOffer(contactId, 123, maxLatency);
|
||||
assertEquals(ids, o.getMessageIds());
|
||||
|
||||
context.assertIsSatisfied();
|
||||
@@ -791,11 +793,11 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
oneOf(database).getRawMessage(txn, messageId);
|
||||
will(returnValue(raw));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).getRawMessage(txn, messageId1);
|
||||
will(returnValue(raw1));
|
||||
oneOf(database).updateExpiryTime(txn, contactId, messageId1,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
oneOf(database).lowerRequestedFlag(txn, contactId, ids);
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -803,7 +805,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
eventBus, shutdown);
|
||||
|
||||
assertEquals(messages, db.generateRequestedBatch(contactId, size * 2,
|
||||
Long.MAX_VALUE));
|
||||
maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -821,14 +823,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getRetentionUpdate(txn, contactId, Long.MAX_VALUE);
|
||||
oneOf(database).getRetentionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
eventBus, shutdown);
|
||||
|
||||
assertNull(db.generateRetentionUpdate(contactId, Long.MAX_VALUE));
|
||||
assertNull(db.generateRetentionUpdate(contactId, maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -846,15 +848,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getRetentionUpdate(txn, contactId, Long.MAX_VALUE);
|
||||
oneOf(database).getRetentionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(new RetentionUpdate(0, 1)));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
eventBus, shutdown);
|
||||
|
||||
RetentionUpdate u = db.generateRetentionUpdate(contactId,
|
||||
Long.MAX_VALUE);
|
||||
RetentionUpdate u = db.generateRetentionUpdate(contactId, maxLatency);
|
||||
assertEquals(0, u.getRetentionTime());
|
||||
assertEquals(1, u.getVersion());
|
||||
|
||||
@@ -874,15 +875,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
eventBus, shutdown);
|
||||
|
||||
assertNull(db.generateSubscriptionUpdate(contactId, Long.MAX_VALUE));
|
||||
assertNull(db.generateSubscriptionUpdate(contactId, maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -900,8 +900,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId,
|
||||
Long.MAX_VALUE);
|
||||
oneOf(database).getSubscriptionUpdate(txn, contactId, maxLatency);
|
||||
will(returnValue(new SubscriptionUpdate(Arrays.asList(group), 1)));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
@@ -909,7 +908,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
eventBus, shutdown);
|
||||
|
||||
SubscriptionUpdate u = db.generateSubscriptionUpdate(contactId,
|
||||
Long.MAX_VALUE);
|
||||
maxLatency);
|
||||
assertEquals(Arrays.asList(group), u.getGroups());
|
||||
assertEquals(1, u.getVersion());
|
||||
|
||||
@@ -929,14 +928,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getTransportUpdates(txn, contactId, Long.MAX_VALUE);
|
||||
oneOf(database).getTransportUpdates(txn, contactId, maxLatency);
|
||||
will(returnValue(null));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||
eventBus, shutdown);
|
||||
|
||||
assertNull(db.generateTransportUpdates(contactId, Long.MAX_VALUE));
|
||||
assertNull(db.generateTransportUpdates(contactId, maxLatency));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -954,7 +953,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsContact(txn, contactId);
|
||||
will(returnValue(true));
|
||||
oneOf(database).getTransportUpdates(txn, contactId, Long.MAX_VALUE);
|
||||
oneOf(database).getTransportUpdates(txn, contactId, maxLatency);
|
||||
will(returnValue(Arrays.asList(new TransportUpdate(transportId,
|
||||
transportProperties, 1))));
|
||||
oneOf(database).commitTransaction(txn);
|
||||
@@ -963,7 +962,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
||||
eventBus, shutdown);
|
||||
|
||||
Collection<TransportUpdate> updates =
|
||||
db.generateTransportUpdates(contactId, Long.MAX_VALUE);
|
||||
db.generateTransportUpdates(contactId, maxLatency);
|
||||
assertNotNull(updates);
|
||||
assertEquals(1, updates.size());
|
||||
TransportUpdate u = updates.iterator().next();
|
||||
|
||||
@@ -32,32 +32,30 @@ public class ExponentialBackoffTest extends BriarTestCase {
|
||||
assertEquals(now, fromNow - fromZero);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundTripTimeOverflow() {
|
||||
long maxLatency = Long.MAX_VALUE / 2 + 1; // RTT will overflow
|
||||
long expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 0);
|
||||
assertEquals(Long.MAX_VALUE, expiry); // Overflow caught
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransmissionCountOverflow() {
|
||||
long maxLatency = (Long.MAX_VALUE - 1) / 2; // RTT will not overflow
|
||||
int maxLatency = Integer.MAX_VALUE; // RTT will not overflow
|
||||
long expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 0);
|
||||
assertEquals(Long.MAX_VALUE - 1, expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 1);
|
||||
assertEquals(Integer.MAX_VALUE * 2L, expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 31);
|
||||
assertEquals(Integer.MAX_VALUE * (2L << 31), expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 32);
|
||||
assertEquals(Long.MAX_VALUE, expiry); // Overflow caught
|
||||
expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 2);
|
||||
expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 33);
|
||||
assertEquals(Long.MAX_VALUE, expiry); // Overflow caught
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentTimeOverflow() {
|
||||
long maxLatency = (Long.MAX_VALUE - 1) / 2; // RTT will not overflow
|
||||
long expiry = ExponentialBackoff.calculateExpiry(0, maxLatency, 0);
|
||||
int maxLatency = Integer.MAX_VALUE; // RTT will not overflow
|
||||
long now = Long.MAX_VALUE - (Integer.MAX_VALUE * (2L << 31));
|
||||
long expiry = ExponentialBackoff.calculateExpiry(now, maxLatency, 0);
|
||||
assertEquals(now + Integer.MAX_VALUE * 2L, expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(now - 1, maxLatency, 31);
|
||||
assertEquals(Long.MAX_VALUE - 1, expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(1, maxLatency, 0);
|
||||
expiry = ExponentialBackoff.calculateExpiry(now, maxLatency, 31);
|
||||
assertEquals(Long.MAX_VALUE, expiry); // No overflow
|
||||
expiry = ExponentialBackoff.calculateExpiry(2, maxLatency, 0);
|
||||
expiry = ExponentialBackoff.calculateExpiry(now + 1, maxLatency, 32);
|
||||
assertEquals(Long.MAX_VALUE, expiry); // Overflow caught
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(messageId, it.next());
|
||||
assertFalse(it.hasNext());
|
||||
db.updateExpiryTime(txn, contactId, messageId, Long.MAX_VALUE);
|
||||
db.updateExpiryTime(txn, contactId, messageId, Integer.MAX_VALUE);
|
||||
|
||||
// The message should no longer be sendable
|
||||
it = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE).iterator();
|
||||
@@ -1109,7 +1109,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testTemporarySecrets() throws Exception {
|
||||
// Create an endpoint and four consecutive temporary secrets
|
||||
long epoch = 123, latency = 234;
|
||||
long epoch = 123;
|
||||
int latency = 234;
|
||||
boolean alice = false;
|
||||
long outgoing1 = 345, centre1 = 456;
|
||||
long outgoing2 = 567, centre2 = 678;
|
||||
@@ -1235,7 +1236,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testIncrementStreamCounter() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, latency = 234;
|
||||
long epoch = 123;
|
||||
int latency = 234;
|
||||
boolean alice = false;
|
||||
long period = 345, outgoing = 456, centre = 567;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, alice);
|
||||
@@ -1290,7 +1292,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSetReorderingWindow() throws Exception {
|
||||
// Create an endpoint and a temporary secret
|
||||
long epoch = 123, latency = 234;
|
||||
long epoch = 123;
|
||||
int latency = 234;
|
||||
boolean alice = false;
|
||||
long period = 345, outgoing = 456, centre = 567;
|
||||
Endpoint ep = new Endpoint(contactId, transportId, epoch, alice);
|
||||
@@ -1359,8 +1362,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testEndpoints() throws Exception {
|
||||
// Create some endpoints
|
||||
long epoch1 = 123, latency1 = 234;
|
||||
long epoch2 = 345, latency2 = 456;
|
||||
long epoch1 = 123, epoch2 = 234;
|
||||
int latency1 = 345, latency2 = 456;
|
||||
boolean alice1 = true, alice2 = false;
|
||||
TransportId transportId1 = new TransportId("bar");
|
||||
TransportId transportId2 = new TransportId("baz");
|
||||
|
||||
Reference in New Issue
Block a user