mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Use longs to represent session capacity.
This commit is contained in:
@@ -208,7 +208,7 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Collection<Message> generateBatch(Transaction txn, ContactId c,
|
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
|
* Returns an offer for the given contact for transmission over a
|
||||||
@@ -237,7 +237,7 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Collection<Message> generateRequestedBatch(Transaction txn, ContactId c,
|
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.
|
* Returns the contact with the given ID.
|
||||||
@@ -363,7 +363,7 @@ public interface DatabaseComponent extends TransactionManager {
|
|||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getMessagesToSend(Transaction txn, ContactId c,
|
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.
|
* 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
|
* Returns the IDs of all messages that are eligible to be sent to the
|
||||||
* given contact.
|
* given contact.
|
||||||
* <p>
|
* <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
|
* this method may return messages that have already been sent and are
|
||||||
* not yet due for retransmission.
|
* not yet due for retransmission.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
|||||||
@@ -511,14 +511,14 @@ interface Database<T> {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getMessagesToSend(T txn, ContactId c, int capacity,
|
Collection<MessageId> getMessagesToSend(T txn, ContactId c, long capacity,
|
||||||
long maxLatency) throws DbException;
|
long maxLatency) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of all messages that are eligible to be sent to the
|
* Returns the IDs of all messages that are eligible to be sent to the
|
||||||
* given contact.
|
* given contact.
|
||||||
* <p/>
|
* <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
|
* method may return messages that have already been sent and are not yet
|
||||||
* due for retransmission.
|
* due for retransmission.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -612,7 +612,7 @@ interface Database<T> {
|
|||||||
* Read-only.
|
* Read-only.
|
||||||
*/
|
*/
|
||||||
Collection<MessageId> getRequestedMessagesToSend(T txn, ContactId c,
|
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.
|
* Returns all settings in the given namespace.
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Collection<Message> generateBatch(Transaction transaction,
|
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();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsContact(txn, c))
|
if (!db.containsContact(txn, c))
|
||||||
@@ -479,7 +479,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Collection<Message> generateRequestedBatch(Transaction transaction,
|
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();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsContact(txn, c))
|
if (!db.containsContact(txn, c))
|
||||||
@@ -620,7 +620,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MessageId> getMessagesToSend(Transaction transaction,
|
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);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsContact(txn, c))
|
if (!db.containsContact(txn, c))
|
||||||
throw new NoSuchContactException();
|
throw new NoSuchContactException();
|
||||||
|
|||||||
@@ -2253,7 +2253,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MessageId> getMessagesToSend(Connection txn,
|
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();
|
long now = clock.currentTimeMillis();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@@ -2548,7 +2548,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<MessageId> getRequestedMessagesToSend(Connection txn,
|
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();
|
long now = clock.currentTimeMillis();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
|
|||||||
getLogger(MailboxOutgoingSession.class.getName());
|
getLogger(MailboxOutgoingSession.class.getName());
|
||||||
|
|
||||||
private final DeferredSendHandler deferredSendHandler;
|
private final DeferredSendHandler deferredSendHandler;
|
||||||
private final int initialCapacity;
|
private final long initialCapacity;
|
||||||
|
|
||||||
MailboxOutgoingSession(DatabaseComponent db,
|
MailboxOutgoingSession(DatabaseComponent db,
|
||||||
EventBus eventBus,
|
EventBus eventBus,
|
||||||
@@ -52,7 +52,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
|
|||||||
StreamWriter streamWriter,
|
StreamWriter streamWriter,
|
||||||
SyncRecordWriter recordWriter,
|
SyncRecordWriter recordWriter,
|
||||||
DeferredSendHandler deferredSendHandler,
|
DeferredSendHandler deferredSendHandler,
|
||||||
int capacity) {
|
long capacity) {
|
||||||
super(db, eventBus, contactId, transportId, maxLatency, streamWriter,
|
super(db, eventBus, contactId, transportId, maxLatency, streamWriter,
|
||||||
recordWriter);
|
recordWriter);
|
||||||
this.deferredSendHandler = deferredSendHandler;
|
this.deferredSendHandler = deferredSendHandler;
|
||||||
@@ -71,10 +71,10 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Collection<MessageId> loadMessageIdsToAck() throws DbException {
|
private Collection<MessageId> loadMessageIdsToAck() throws DbException {
|
||||||
int idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES)
|
long idCapacity = (getRemainingCapacity() - RECORD_HEADER_BYTES)
|
||||||
/ MessageId.LENGTH;
|
/ MessageId.LENGTH;
|
||||||
if (idCapacity <= 0) return emptyList(); // Out of capacity
|
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 ->
|
Collection<MessageId> ids = db.transactionWithResult(true, txn ->
|
||||||
db.getMessagesToAck(txn, contactId, maxMessageIds));
|
db.getMessagesToAck(txn, contactId, maxMessageIds));
|
||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
@@ -83,8 +83,8 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getRemainingCapacity() {
|
private long getRemainingCapacity() {
|
||||||
return initialCapacity - (int) recordWriter.getBytesWritten();
|
return initialCapacity - recordWriter.getBytesWritten();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,7 +102,7 @@ class MailboxOutgoingSession extends SimplexOutgoingSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Collection<MessageId> loadMessageIdsToSend() throws DbException {
|
private Collection<MessageId> loadMessageIdsToSend() throws DbException {
|
||||||
int capacity = getRemainingCapacity();
|
long capacity = getRemainingCapacity();
|
||||||
if (capacity < RECORD_HEADER_BYTES + MESSAGE_HEADER_LENGTH) {
|
if (capacity < RECORD_HEADER_BYTES + MESSAGE_HEADER_LENGTH) {
|
||||||
return emptyList(); // Out of capacity
|
return emptyList(); // Out of capacity
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
// The message is sendable, but too large to send
|
// The message is sendable, but too large to send
|
||||||
assertOneMessageToSendLazily(db, txn);
|
assertOneMessageToSendLazily(db, txn);
|
||||||
assertOneMessageToSendEagerly(db, txn);
|
assertOneMessageToSendEagerly(db, txn);
|
||||||
int capacity = RECORD_HEADER_BYTES + message.getRawLength() - 1;
|
long capacity = RECORD_HEADER_BYTES + message.getRawLength() - 1;
|
||||||
Collection<MessageId> ids =
|
Collection<MessageId> ids =
|
||||||
db.getMessagesToSend(txn, contactId, capacity, MAX_LATENCY);
|
db.getMessagesToSend(txn, contactId, capacity, MAX_LATENCY);
|
||||||
assertTrue(ids.isEmpty());
|
assertTrue(ids.isEmpty());
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase {
|
|||||||
Transaction noAckIdTxn = new Transaction(null, true);
|
Transaction noAckIdTxn = new Transaction(null, true);
|
||||||
Transaction noMsgIdTxn = 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() {{
|
context.checking(new DbExpectations() {{
|
||||||
// Add listener
|
// Add listener
|
||||||
@@ -107,7 +107,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase {
|
|||||||
Transaction msgTxn = new Transaction(null, true);
|
Transaction msgTxn = new Transaction(null, true);
|
||||||
|
|
||||||
int ackRecordBytes = RECORD_HEADER_BYTES + MessageId.LENGTH;
|
int ackRecordBytes = RECORD_HEADER_BYTES + MessageId.LENGTH;
|
||||||
int capacityForMessages =
|
long capacityForMessages =
|
||||||
MAX_FILE_PAYLOAD_BYTES - versionRecordBytes - ackRecordBytes;
|
MAX_FILE_PAYLOAD_BYTES - versionRecordBytes - ackRecordBytes;
|
||||||
|
|
||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
@@ -164,7 +164,7 @@ public class MailboxOutgoingSessionTest extends BrambleMockTestCase {
|
|||||||
public void testAllCapacityUsedByAcks() throws Exception {
|
public void testAllCapacityUsedByAcks() throws Exception {
|
||||||
// The file has enough capacity for a max-size ack record, another
|
// The file has enough capacity for a max-size ack record, another
|
||||||
// ack record with one message ID, and a few bytes left over
|
// 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;
|
+ RECORD_HEADER_BYTES + MessageId.LENGTH + MessageId.LENGTH - 1;
|
||||||
|
|
||||||
MailboxOutgoingSession session = new MailboxOutgoingSession(db,
|
MailboxOutgoingSession session = new MailboxOutgoingSession(db,
|
||||||
|
|||||||
Reference in New Issue
Block a user