From a29d5efd93c22a64a71baa874bcd4380926fae61 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Tue, 18 Sep 2018 14:48:04 +0100 Subject: [PATCH] Fix off-by-one error in expiry calculation. --- .../java/org/briarproject/bramble/db/JdbcDatabase.java | 6 +++--- .../org/briarproject/bramble/db/JdbcDatabaseTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java b/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java index cf368e1ed..f31582da0 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java @@ -1882,7 +1882,7 @@ abstract class JdbcDatabase implements Database { + " AND groupShared = TRUE AND messageShared = TRUE" + " AND deleted = FALSE" + " AND seen = FALSE AND requested = FALSE" - + " AND (expiry < ? OR eta > ?)" + + " AND (expiry <= ? OR eta > ?)" + " ORDER BY timestamp LIMIT ?"; ps = txn.prepareStatement(sql); ps.setInt(1, c.getInt()); @@ -1941,7 +1941,7 @@ abstract class JdbcDatabase implements Database { + " AND groupShared = TRUE AND messageShared = TRUE" + " AND deleted = FALSE" + " AND seen = FALSE" - + " AND (expiry < ? OR eta > ?)" + + " AND (expiry <= ? OR eta > ?)" + " ORDER BY timestamp"; ps = txn.prepareStatement(sql); ps.setInt(1, c.getInt()); @@ -2072,7 +2072,7 @@ abstract class JdbcDatabase implements Database { + " AND groupShared = TRUE AND messageShared = TRUE" + " AND deleted = FALSE" + " AND seen = FALSE AND requested = TRUE" - + " AND (expiry < ? OR eta > ?)" + + " AND (expiry <= ? OR eta > ?)" + " ORDER BY timestamp"; ps = txn.prepareStatement(sql); ps.setInt(1, c.getInt()); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java b/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java index 3f929e9cf..9e6a0d273 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java @@ -1818,8 +1818,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { @Test public void testMessageRetransmission() throws Exception { long now = System.currentTimeMillis(); - long steps[] = {now, now, now + MAX_LATENCY * 2, - now + MAX_LATENCY * 2 + 1}; + long steps[] = {now, now, now + MAX_LATENCY * 2 - 1, + now + MAX_LATENCY * 2}; Database db = open(false, new TestMessageFactory(), new ArrayClock(steps)); Connection txn = db.startTransaction(); @@ -1845,12 +1845,12 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // The message should expire after 2 * MAX_LATENCY assertEquals(now + MAX_LATENCY * 2, db.getNextSendTime(txn, contactId)); - // Time: now + MAX_LATENCY * 2 + // Time: now + MAX_LATENCY * 2 - 1 // The message should not yet be sendable ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY); assertTrue(ids.isEmpty()); - // Time: now + MAX_LATENCY * 2 + 1 + // Time: now + MAX_LATENCY * 2 // The message should have expired and should now be sendable ids = db.getMessagesToSend(txn, contactId, ONE_MEGABYTE, MAX_LATENCY); assertEquals(singletonList(messageId), ids);