diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java index 34a2928f3..3869e71a6 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java @@ -208,7 +208,7 @@ public interface DatabaseComponent extends TransactionManager { */ @Nullable Collection generateBatch(Transaction txn, ContactId c, - int capacity, long maxLatency) throws DbException; + long capacity, long maxLatency) throws DbException; /** * Returns an offer for the given contact for transmission over a @@ -237,7 +237,7 @@ public interface DatabaseComponent extends TransactionManager { */ @Nullable Collection generateRequestedBatch(Transaction txn, ContactId c, - int capacity, long maxLatency) throws DbException; + long capacity, long maxLatency) throws DbException; /** * Returns the contact with the given ID. @@ -363,7 +363,7 @@ public interface DatabaseComponent extends TransactionManager { * Read-only. */ Collection getMessagesToSend(Transaction txn, ContactId c, - int capacity, long maxLatency) throws DbException; + long capacity, long maxLatency) throws DbException; /** * Returns the IDs of any messages that need to be validated. @@ -498,7 +498,7 @@ public interface DatabaseComponent extends TransactionManager { * Returns the IDs of all messages that are eligible to be sent to the * given contact. *

- * Unlike {@link #getMessagesToSend(Transaction, ContactId, int, long)} + * Unlike {@link #getMessagesToSend(Transaction, ContactId, long, long)} * this method may return messages that have already been sent and are * not yet due for retransmission. *

diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java b/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java index 1d0c6bedc..e0aaaecc3 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/Database.java @@ -511,14 +511,14 @@ interface Database { *

* Read-only. */ - Collection getMessagesToSend(T txn, ContactId c, int capacity, + Collection getMessagesToSend(T txn, ContactId c, long capacity, long maxLatency) throws DbException; /** * Returns the IDs of all messages that are eligible to be sent to the * given contact. *

- * Unlike {@link #getMessagesToSend(Object, ContactId, int, long)} this + * Unlike {@link #getMessagesToSend(Object, ContactId, long, long)} this * method may return messages that have already been sent and are not yet * due for retransmission. *

@@ -612,7 +612,7 @@ interface Database { * Read-only. */ Collection getRequestedMessagesToSend(T txn, ContactId c, - int capacity, long maxLatency) throws DbException; + long capacity, long maxLatency) throws DbException; /** * Returns all settings in the given namespace. diff --git a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java index 895e4a0ce..64b6fc3c3 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java @@ -424,7 +424,7 @@ class DatabaseComponentImpl implements DatabaseComponent { @Nullable @Override public Collection generateBatch(Transaction transaction, - ContactId c, int capacity, long maxLatency) throws DbException { + ContactId c, long capacity, long maxLatency) throws DbException { if (transaction.isReadOnly()) throw new IllegalArgumentException(); T txn = unbox(transaction); if (!db.containsContact(txn, c)) @@ -479,7 +479,7 @@ class DatabaseComponentImpl implements DatabaseComponent { @Nullable @Override public Collection generateRequestedBatch(Transaction transaction, - ContactId c, int capacity, long maxLatency) throws DbException { + ContactId c, long capacity, long maxLatency) throws DbException { if (transaction.isReadOnly()) throw new IllegalArgumentException(); T txn = unbox(transaction); if (!db.containsContact(txn, c)) @@ -620,7 +620,7 @@ class DatabaseComponentImpl implements DatabaseComponent { @Override public Collection getMessagesToSend(Transaction transaction, - ContactId c, int capacity, long maxLatency) throws DbException { + ContactId c, long capacity, long maxLatency) throws DbException { T txn = unbox(transaction); if (!db.containsContact(txn, c)) throw new NoSuchContactException(); 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 52d92eb9f..fc988c441 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 @@ -2253,7 +2253,7 @@ abstract class JdbcDatabase implements Database { @Override public Collection getMessagesToSend(Connection txn, - ContactId c, int capacity, long maxLatency) throws DbException { + ContactId c, long capacity, long maxLatency) throws DbException { long now = clock.currentTimeMillis(); PreparedStatement ps = null; ResultSet rs = null; @@ -2548,7 +2548,7 @@ abstract class JdbcDatabase implements Database { @Override public Collection getRequestedMessagesToSend(Connection txn, - ContactId c, int capacity, long maxLatency) throws DbException { + ContactId c, long capacity, long maxLatency) throws DbException { long now = clock.currentTimeMillis(); PreparedStatement ps = null; ResultSet rs = null; diff --git a/bramble-core/src/main/java/org/briarproject/bramble/sync/MailboxOutgoingSession.java b/bramble-core/src/main/java/org/briarproject/bramble/sync/MailboxOutgoingSession.java index a8250475f..5d4e06fb4 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/sync/MailboxOutgoingSession.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/sync/MailboxOutgoingSession.java @@ -42,7 +42,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession { getLogger(MailboxOutgoingSession.class.getName()); private final DeferredSendHandler deferredSendHandler; - private final int initialCapacity; + private final long initialCapacity; MailboxOutgoingSession(DatabaseComponent db, EventBus eventBus, @@ -52,7 +52,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession { StreamWriter streamWriter, SyncRecordWriter recordWriter, DeferredSendHandler deferredSendHandler, - int capacity) { + long capacity) { super(db, eventBus, contactId, transportId, maxLatency, streamWriter, recordWriter); this.deferredSendHandler = deferredSendHandler; @@ -71,10 +71,10 @@ class MailboxOutgoingSession extends SimplexOutgoingSession { } private Collection loadMessageIdsToAck() throws DbException { - int idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES) + long idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES) / MessageId.LENGTH; if (idCapacity <= 0) return emptyList(); // Out of capacity - int maxMessageIds = min(idCapacity, MAX_MESSAGE_IDS); + int maxMessageIds = (int) min(idCapacity, MAX_MESSAGE_IDS); Collection ids = db.transactionWithResult(true, txn -> db.getMessagesToAck(txn, contactId, maxMessageIds)); if (LOG.isLoggable(INFO)) { @@ -83,8 +83,8 @@ class MailboxOutgoingSession extends SimplexOutgoingSession { return ids; } - private int getRemainingCapacity() { - return initialCapacity - (int) recordWriter.getBytesWritten(); + private long getRemainingCapacity() { + return initialCapacity - recordWriter.getBytesWritten(); } @Override @@ -102,7 +102,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession { } private Collection loadMessageIdsToSend() throws DbException { - int capacity = getRemainingCapacity(); + long capacity = getRemainingCapacity(); if (capacity < RECORD_HEADER_BYTES + MESSAGE_HEADER_LENGTH) { return emptyList(); // Out of capacity } 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 c52dfba8f..567a89c60 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 @@ -350,7 +350,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase { // The message is sendable, but too large to send assertOneMessageToSendLazily(db, txn); assertOneMessageToSendEagerly(db, txn); - int capacity = RECORD_HEADER_BYTES + message.getRawLength() - 1; + long capacity = RECORD_HEADER_BYTES + message.getRawLength() - 1; Collection ids = db.getMessagesToSend(txn, contactId, capacity, MAX_LATENCY); assertTrue(ids.isEmpty()); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/sync/MailboxOutgoingSessionTest.java b/bramble-core/src/test/java/org/briarproject/bramble/sync/MailboxOutgoingSessionTest.java index 0130e25a6..904882847 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/sync/MailboxOutgoingSessionTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/sync/MailboxOutgoingSessionTest.java @@ -61,7 +61,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase { Transaction noAckIdTxn = new Transaction(null, true); Transaction noMsgIdTxn = new Transaction(null, true); - int capacityForMessages = MAX_FILE_PAYLOAD_BYTES - versionRecordBytes; + long capacityForMessages = MAX_FILE_PAYLOAD_BYTES - versionRecordBytes; context.checking(new DbExpectations() {{ // Add listener @@ -107,7 +107,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase { Transaction msgTxn = new Transaction(null, true); int ackRecordBytes = RECORD_HEADER_BYTES + MessageId.LENGTH; - int capacityForMessages = + long capacityForMessages = MAX_FILE_PAYLOAD_BYTES - versionRecordBytes - ackRecordBytes; context.checking(new DbExpectations() {{ @@ -164,7 +164,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase { public void testAllCapacityUsedByAcks() throws Exception { // The file has enough capacity for a max-size ack record, another // ack record with one message ID, and a few bytes left over - int capacity = RECORD_HEADER_BYTES + MessageId.LENGTH * MAX_MESSAGE_IDS + long capacity = RECORD_HEADER_BYTES + MessageId.LENGTH * MAX_MESSAGE_IDS + RECORD_HEADER_BYTES + MessageId.LENGTH + MessageId.LENGTH - 1; MailboxOutgoingSession session = new MailboxOutgoingSession(db,