mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Use longs to represent session capacity.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user