mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Remove redundant method for recording successful connection.
This commit is contained in:
@@ -32,9 +32,6 @@ public interface MailboxSettingsManager {
|
|||||||
|
|
||||||
MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException;
|
MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException;
|
||||||
|
|
||||||
void recordSuccessfulConnection(Transaction txn, long now)
|
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
void recordSuccessfulConnection(Transaction txn, long now,
|
void recordSuccessfulConnection(Transaction txn, long now,
|
||||||
List<MailboxVersion> versions) throws DbException;
|
List<MailboxVersion> versions) throws DbException;
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,8 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
|||||||
db.transaction(false, txn -> {
|
db.transaction(false, txn -> {
|
||||||
mailboxSettingsManager
|
mailboxSettingsManager
|
||||||
.setOwnMailboxProperties(txn, ownerProperties);
|
.setOwnMailboxProperties(txn, ownerProperties);
|
||||||
mailboxSettingsManager.recordSuccessfulConnection(txn, time);
|
mailboxSettingsManager.recordSuccessfulConnection(txn, time,
|
||||||
|
ownerProperties.getServerSupports());
|
||||||
// A (possibly new) mailbox is paired. Reset message retransmission
|
// A (possibly new) mailbox is paired. Reset message retransmission
|
||||||
// timers for contacts who doesn't have their own mailbox. This way,
|
// timers for contacts who doesn't have their own mailbox. This way,
|
||||||
// data stranded on our old mailbox will be re-uploaded to our new.
|
// data stranded on our old mailbox will be re-uploaded to our new.
|
||||||
|
|||||||
@@ -112,34 +112,18 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
serverSupports);
|
serverSupports);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void recordSuccessfulConnection(Transaction txn, long now)
|
|
||||||
throws DbException {
|
|
||||||
recordSuccessfulConnection(txn, now, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recordSuccessfulConnection(Transaction txn, long now,
|
public void recordSuccessfulConnection(Transaction txn, long now,
|
||||||
@Nullable List<MailboxVersion> versions) throws DbException {
|
List<MailboxVersion> versions) throws DbException {
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
// fetch version that the server supports first
|
// record the successful connection
|
||||||
List<MailboxVersion> serverSupports;
|
|
||||||
if (versions == null) {
|
|
||||||
Settings oldSettings =
|
|
||||||
settingsManager.getSettings(txn, SETTINGS_NAMESPACE);
|
|
||||||
serverSupports = parseServerSupports(oldSettings);
|
|
||||||
} else {
|
|
||||||
serverSupports = versions;
|
|
||||||
// store new versions
|
|
||||||
encodeServerSupports(serverSupports, s);
|
|
||||||
}
|
|
||||||
// now record the successful connection
|
|
||||||
s.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
|
s.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
|
||||||
s.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
|
s.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
|
||||||
s.putInt(SETTINGS_KEY_ATTEMPTS, 0);
|
s.putInt(SETTINGS_KEY_ATTEMPTS, 0);
|
||||||
|
encodeServerSupports(versions, s);
|
||||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||||
// broadcast status event
|
// broadcast status event
|
||||||
MailboxStatus status = new MailboxStatus(now, now, 0, serverSupports);
|
MailboxStatus status = new MailboxStatus(now, now, 0, versions);
|
||||||
txn.attach(new OwnMailboxConnectionStatusEvent(status));
|
txn.attach(new OwnMailboxConnectionStatusEvent(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).transaction(with(false), withDbRunnable(txn));
|
oneOf(db).transaction(with(false), withDbRunnable(txn));
|
||||||
oneOf(mailboxSettingsManager).setOwnMailboxProperties(
|
oneOf(mailboxSettingsManager).setOwnMailboxProperties(
|
||||||
with(txn), with(matches(ownerProperties)));
|
with(txn), with(matches(ownerProperties)));
|
||||||
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time);
|
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time,
|
||||||
|
ownerProperties.getServerSupports());
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
will(returnValue(singletonList(contact1)));
|
will(returnValue(singletonList(contact1)));
|
||||||
oneOf(mailboxUpdateManager).getRemoteUpdate(txn,
|
oneOf(mailboxUpdateManager).getRemoteUpdate(txn,
|
||||||
|
|||||||
@@ -147,22 +147,19 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testRecordsSuccess() throws Exception {
|
public void testRecordsSuccess() throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
Settings oldSettings = new Settings();
|
|
||||||
oldSettings
|
|
||||||
.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, serverSupportsInts);
|
|
||||||
Settings expectedSettings = new Settings();
|
Settings expectedSettings = new Settings();
|
||||||
expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
|
expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
|
||||||
expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
|
expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
|
||||||
expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0);
|
expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0);
|
||||||
|
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
||||||
|
serverSupportsInts);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(settingsManager).getSettings(txn, SETTINGS_NAMESPACE);
|
|
||||||
will(returnValue(oldSettings));
|
|
||||||
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
||||||
SETTINGS_NAMESPACE);
|
SETTINGS_NAMESPACE);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
manager.recordSuccessfulConnection(txn, now);
|
manager.recordSuccessfulConnection(txn, now, serverSupports);
|
||||||
assertTrue(hasEvent(txn, OwnMailboxConnectionStatusEvent.class));
|
assertTrue(hasEvent(txn, OwnMailboxConnectionStatusEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user