mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Address mailbox pairing backend review feedback
This commit is contained in:
@@ -51,8 +51,8 @@ public abstract class MailboxPairingState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AssertionError extends MailboxPairingState {
|
public static class UnexpectedError extends MailboxPairingState {
|
||||||
public AssertionError(String qrCodePayload) {
|
public UnexpectedError(String qrCodePayload) {
|
||||||
super(qrCodePayload);
|
super(qrCodePayload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,30 +98,28 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
onMailboxError(e, new MailboxPairingState.ConnectionError(payload));
|
onMailboxError(e, new MailboxPairingState.ConnectionError(payload));
|
||||||
} catch (ApiException | DbException e) {
|
} catch (ApiException | DbException e) {
|
||||||
onMailboxError(e, new MailboxPairingState.AssertionError(payload));
|
onMailboxError(e, new MailboxPairingState.UnexpectedError(payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pairMailbox() throws IOException, ApiException, DbException {
|
private void pairMailbox() throws IOException, ApiException, DbException {
|
||||||
MailboxProperties mailboxProperties = decodeQrCodePayload(payload);
|
MailboxProperties mailboxProperties = decodeQrCodePayload(payload);
|
||||||
synchronized (lock) {
|
setState(new MailboxPairingState.Pairing(payload));
|
||||||
this.state = new MailboxPairingState.Pairing(payload);
|
|
||||||
notifyObservers();
|
|
||||||
}
|
|
||||||
MailboxAuthToken ownerToken = api.setup(mailboxProperties);
|
MailboxAuthToken ownerToken = api.setup(mailboxProperties);
|
||||||
MailboxProperties ownerProperties = new MailboxProperties(
|
MailboxProperties ownerProperties = new MailboxProperties(
|
||||||
mailboxProperties.getBaseUrl(), ownerToken, true);
|
mailboxProperties.getBaseUrl(), ownerToken, true);
|
||||||
db.transaction(false, txn -> mailboxSettingsManager
|
db.transaction(false, txn -> mailboxSettingsManager
|
||||||
.setOwnMailboxProperties(txn, ownerProperties));
|
.setOwnMailboxProperties(txn, ownerProperties));
|
||||||
synchronized (lock) {
|
setState(new MailboxPairingState.Paired());
|
||||||
this.state = new MailboxPairingState.Paired();
|
|
||||||
notifyObservers();
|
|
||||||
}
|
|
||||||
// TODO already do mailboxSettingsManager.setOwnMailboxStatus() ?
|
// TODO already do mailboxSettingsManager.setOwnMailboxStatus() ?
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMailboxError(Exception e, MailboxPairingState state) {
|
private void onMailboxError(Exception e, MailboxPairingState state) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
|
setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setState(MailboxPairingState state) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.bramble.plugin.file;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.file.RemovableDriveTask;
|
import org.briarproject.bramble.api.plugin.file.RemovableDriveTask;
|
||||||
|
|
||||||
|
@Deprecated // We can simply remove tasks when they finish
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
interface RemovableDriveTaskRegistry {
|
interface RemovableDriveTaskRegistry {
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
new MailboxPairingTaskFactoryImpl(executor, db, crypto, api,
|
new MailboxPairingTaskFactoryImpl(executor, db, crypto, api,
|
||||||
mailboxSettingsManager);
|
mailboxSettingsManager);
|
||||||
|
|
||||||
private final String onion = getRandomString(64);
|
private final String onion = getRandomString(56);
|
||||||
private final byte[] onionBytes = getRandomBytes(32);
|
private final byte[] onionBytes = getRandomBytes(32);
|
||||||
private final String onionAddress = "http://" + onion + ".onion";
|
private final String onionAddress = "http://" + onion + ".onion";
|
||||||
private final MailboxAuthToken setupToken =
|
private final MailboxAuthToken setupToken =
|
||||||
@@ -73,8 +73,8 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
assertTrue(state instanceof MailboxPairingState.InvalidQrCode)
|
assertTrue(state instanceof MailboxPairingState.InvalidQrCode)
|
||||||
);
|
);
|
||||||
|
|
||||||
MailboxPairingTask task2 =
|
String goodLength = "00" + getRandomString(63);
|
||||||
factory.createPairingTask(getRandomString(65));
|
MailboxPairingTask task2 = factory.createPairingTask(goodLength);
|
||||||
task2.run();
|
task2.run();
|
||||||
task2.addObserver(state ->
|
task2.addObserver(state ->
|
||||||
assertTrue(state instanceof MailboxPairingState.InvalidQrCode)
|
assertTrue(state instanceof MailboxPairingState.InvalidQrCode)
|
||||||
@@ -123,7 +123,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testMailboxApiException() throws Exception {
|
public void testMailboxApiException() throws Exception {
|
||||||
testApiException(new MailboxApi.ApiException(),
|
testApiException(new MailboxApi.ApiException(),
|
||||||
MailboxPairingState.AssertionError.class);
|
MailboxPairingState.UnexpectedError.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -165,7 +165,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
MailboxPairingTask task = factory.createPairingTask(validPayload);
|
MailboxPairingTask task = factory.createPairingTask(validPayload);
|
||||||
task.run();
|
task.run();
|
||||||
task.addObserver(state -> assertEquals(state.getClass(),
|
task.addObserver(state -> assertEquals(state.getClass(),
|
||||||
MailboxPairingState.AssertionError.class));
|
MailboxPairingState.UnexpectedError.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getValidPayload() {
|
private String getValidPayload() {
|
||||||
|
|||||||
Reference in New Issue
Block a user