mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Use longs to represent session capacity.
This commit is contained in:
@@ -208,7 +208,7 @@ public interface DatabaseComponent extends TransactionManager {
|
||||
*/
|
||||
@Nullable
|
||||
Collection<Message> 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<Message> 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<MessageId> 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p/>
|
||||
|
||||
@@ -511,14 +511,14 @@ interface Database<T> {
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<MessageId> getMessagesToSend(T txn, ContactId c, int capacity,
|
||||
Collection<MessageId> 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.
|
||||
* <p/>
|
||||
* 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.
|
||||
* <p/>
|
||||
@@ -612,7 +612,7 @@ interface Database<T> {
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<MessageId> getRequestedMessagesToSend(T txn, ContactId c,
|
||||
int capacity, long maxLatency) throws DbException;
|
||||
long capacity, long maxLatency) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all settings in the given namespace.
|
||||
|
||||
@@ -424,7 +424,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<Message> 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<T> implements DatabaseComponent {
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<Message> 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<T> implements DatabaseComponent {
|
||||
|
||||
@Override
|
||||
public Collection<MessageId> 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();
|
||||
|
||||
@@ -2253,7 +2253,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
@Override
|
||||
public Collection<MessageId> 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<Connection> {
|
||||
|
||||
@Override
|
||||
public Collection<MessageId> 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;
|
||||
|
||||
@@ -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<MessageId> 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<MessageId> 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<MessageId> loadMessageIdsToSend() throws DbException {
|
||||
int capacity = getRemainingCapacity();
|
||||
long capacity = getRemainingCapacity();
|
||||
if (capacity < RECORD_HEADER_BYTES + MESSAGE_HEADER_LENGTH) {
|
||||
return emptyList(); // Out of capacity
|
||||
}
|
||||
|
||||
@@ -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<MessageId> ids =
|
||||
db.getMessagesToSend(txn, contactId, capacity, MAX_LATENCY);
|
||||
assertTrue(ids.isEmpty());
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user