diff --git a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityChecker.java b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityChecker.java index 6abe9e607..54fcbfea3 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityChecker.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityChecker.java @@ -4,11 +4,13 @@ import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.TransactionManager; import org.briarproject.bramble.api.mailbox.MailboxProperties; import org.briarproject.bramble.api.mailbox.MailboxSettingsManager; +import org.briarproject.bramble.api.mailbox.MailboxVersion; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.mailbox.MailboxApi.ApiException; import java.io.IOException; +import java.util.List; import java.util.logging.Logger; import javax.annotation.concurrent.ThreadSafe; @@ -55,11 +57,12 @@ class OwnMailboxConnectivityChecker extends ConnectivityCheckerImpl { private boolean checkConnectivityAndStoreResult( MailboxProperties properties) throws DbException { try { - if (!mailboxApi.checkStatus(properties)) throw new ApiException(); + List serverSupports = + mailboxApi.getServerSupports(properties); LOG.info("Own mailbox is reachable"); long now = clock.currentTimeMillis(); db.transaction(false, txn -> mailboxSettingsManager - .recordSuccessfulConnection(txn, now)); + .recordSuccessfulConnection(txn, now, serverSupports)); // Call the observers and cache the result onConnectivityCheckSucceeded(now); return false; // Don't retry diff --git a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityCheckerTest.java b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityCheckerTest.java index 159d0262f..7c2dd1881 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityCheckerTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/mailbox/OwnMailboxConnectivityCheckerTest.java @@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.TransactionManager; import org.briarproject.bramble.api.mailbox.MailboxProperties; import org.briarproject.bramble.api.mailbox.MailboxSettingsManager; +import org.briarproject.bramble.api.mailbox.MailboxVersion; import org.briarproject.bramble.api.system.Clock; import org.briarproject.bramble.mailbox.ConnectivityChecker.ConnectivityObserver; import org.briarproject.bramble.test.BrambleMockTestCase; @@ -15,8 +16,10 @@ import org.jmock.lib.action.DoAllAction; import org.junit.Test; import java.io.IOException; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import static java.util.Collections.singletonList; import static org.briarproject.bramble.api.mailbox.MailboxConstants.CLIENT_SUPPORTS; import static org.briarproject.bramble.test.TestUtils.getMailboxProperties; import static org.junit.Assert.assertFalse; @@ -39,6 +42,8 @@ public class OwnMailboxConnectivityCheckerTest extends BrambleMockTestCase { private final MailboxProperties properties = getMailboxProperties(true, CLIENT_SUPPORTS); private final long now = System.currentTimeMillis(); + private final List serverSupports = + singletonList(new MailboxVersion(123, 456)); @Test public void testObserverIsCalledWhenCheckSucceeds() throws Exception { @@ -62,12 +67,13 @@ public class OwnMailboxConnectivityCheckerTest extends BrambleMockTestCase { // When the check succeeds, the success should be recorded in the DB // and the observer should be called context.checking(new DbExpectations() {{ - oneOf(mailboxApi).checkStatus(properties); - will(returnValue(true)); + oneOf(mailboxApi).getServerSupports(properties); + will(returnValue(serverSupports)); oneOf(clock).currentTimeMillis(); will(returnValue(now)); oneOf(db).transaction(with(false), withDbRunnable(txn)); - oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, now); + oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, now, + serverSupports); oneOf(observer).onConnectivityCheckSucceeded(); }}); @@ -97,7 +103,7 @@ public class OwnMailboxConnectivityCheckerTest extends BrambleMockTestCase { // When the check fails, the failure should be recorded in the DB and // the observer should not be called context.checking(new DbExpectations() {{ - oneOf(mailboxApi).checkStatus(properties); + oneOf(mailboxApi).getServerSupports(properties); will(throwException(new IOException())); oneOf(clock).currentTimeMillis(); will(returnValue(now));