mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Add database method to reset retransmission times
Will be used to ensure messages are not stranded on a Mailbox, when such is added, removed, or otherwise changed. Closes #2190.
This commit is contained in:
@@ -757,6 +757,13 @@ interface Database<T> {
|
||||
*/
|
||||
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Resets the transmission count, expiry time and ETA of the given messages
|
||||
* with respect to the given contact.
|
||||
*/
|
||||
void resetExpiryTimeAndEta(T txn, ContactId c, Collection<MessageId> ids)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Sets the cleanup timer duration for the given message. This does not
|
||||
* start the message's cleanup timer.
|
||||
@@ -845,8 +852,8 @@ interface Database<T> {
|
||||
* of the given message with respect to the given contact, using the latency
|
||||
* of the transport over which it was sent.
|
||||
*/
|
||||
void updateExpiryTimeAndEta(T txn, ContactId c, MessageId m, long maxLatency)
|
||||
throws DbException;
|
||||
void updateExpiryTimeAndEta(T txn, ContactId c, MessageId m,
|
||||
long maxLatency) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores the given transport keys, deleting any keys they have replaced.
|
||||
|
||||
@@ -750,6 +750,18 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return db.getUnackedMessagesToSend(txn, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetUnackedMessagesToSend(Transaction transaction, ContactId c)
|
||||
throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsContact(txn, c))
|
||||
throw new NoSuchContactException();
|
||||
Collection<MessageId> unackedToSend =
|
||||
new ArrayList<>(db.getUnackedMessagesToSend(txn, c).keySet());
|
||||
if (unackedToSend.isEmpty()) return;
|
||||
db.resetExpiryTimeAndEta(txn, c, unackedToSend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnackedMessageBytesToSend(Transaction transaction,
|
||||
ContactId c) throws DbException {
|
||||
|
||||
@@ -3290,6 +3290,34 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetExpiryTimeAndEta(Connection txn, ContactId c,
|
||||
Collection<MessageId> ids)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "UPDATE statuses SET expiry = 0, txCount = 0, eta = 0"
|
||||
+ " WHERE contactId = ? AND messageId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
for (MessageId m : ids) {
|
||||
ps.setBytes(2, m.getBytes());
|
||||
ps.addBatch();
|
||||
}
|
||||
int[] batchAffected = ps.executeBatch();
|
||||
if (batchAffected.length != ids.size()) {
|
||||
throw new DbStateException();
|
||||
}
|
||||
for (int rows : batchAffected) {
|
||||
if (rows < 0 || rows > 1) throw new DbStateException();
|
||||
}
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCleanupTimerDuration(Connection txn, MessageId m,
|
||||
long duration) throws DbException {
|
||||
|
||||
Reference in New Issue
Block a user