Refactor MailboxProperties and MailboxUpdateWithMailbox.

This commit is contained in:
akwizgran
2022-05-26 12:53:15 +01:00
parent 8ec998f645
commit ef6e3bb2a7
15 changed files with 152 additions and 137 deletions

View File

@@ -25,6 +25,7 @@ import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion;
@@ -455,9 +456,11 @@ class ClientHelperImpl implements ClientHelper {
checkLength(inboxId, UniqueId.LENGTH);
byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID);
checkLength(outboxId, UniqueId.LENGTH);
return new MailboxUpdateWithMailbox(clientSupportsList,
serverSupportsList, onion, new MailboxAuthToken(authToken),
String baseUrl = "http://" + onion + ".onion"; // TODO
MailboxProperties props = new MailboxProperties(baseUrl,
new MailboxAuthToken(authToken), serverSupportsList,
new MailboxFolderId(inboxId), new MailboxFolderId(outboxId));
return new MailboxUpdateWithMailbox(clientSupportsList, props);
}
@Override

View File

@@ -95,7 +95,7 @@ class MailboxApiImpl implements MailboxApi {
}
return new MailboxProperties(properties.getBaseUrl(),
MailboxAuthToken.fromString(tokenNode.textValue()),
true, parseServerSupports(node));
parseServerSupports(node));
} catch (JacksonException | InvalidMailboxIdException e) {
throw new ApiException();
}

View File

@@ -177,11 +177,10 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
LOG.info("QR code is valid");
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
String onion = crypto.encodeOnion(onionPubKey);
String baseUrl = "http://" + onion + ".onion";
String baseUrl = "http://" + onion + ".onion"; // TODO
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
return new MailboxProperties(baseUrl, setupToken, true,
new ArrayList<>());
return new MailboxProperties(baseUrl, setupToken, new ArrayList<>());
}
}

View File

@@ -30,6 +30,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
// Package access for testing
static final String SETTINGS_NAMESPACE = "mailbox";
// TODO: This currently stores the base URL, not the 56-char onion address
static final String SETTINGS_KEY_ONION = "onion";
static final String SETTINGS_KEY_TOKEN = "token";
static final String SETTINGS_KEY_SERVER_SUPPORTS = "serverSupports";
@@ -69,7 +70,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
}
try {
MailboxAuthToken tokenId = MailboxAuthToken.fromString(token);
return new MailboxProperties(onion, tokenId, true, serverSupports);
return new MailboxProperties(onion, tokenId, serverSupports);
} catch (InvalidMailboxIdException e) {
throw new DbException(e);
}

View File

@@ -242,11 +242,14 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
private void createAndSendUpdateWithMailbox(Transaction txn, Contact c,
List<MailboxVersion> serverSupports, String ownOnion)
throws DbException {
MailboxUpdate u = new MailboxUpdateWithMailbox(
clientSupports, serverSupports, ownOnion,
String baseUrl = "http://" + ownOnion + ".onion"; // TODO
MailboxProperties properties = new MailboxProperties(baseUrl,
new MailboxAuthToken(crypto.generateUniqueId().getBytes()),
serverSupports,
new MailboxFolderId(crypto.generateUniqueId().getBytes()),
new MailboxFolderId(crypto.generateUniqueId().getBytes()));
MailboxUpdate u =
new MailboxUpdateWithMailbox(clientSupports, properties);
Group g = getContactGroup(c);
storeMessageReplaceLatest(txn, g.getId(), u);
}
@@ -325,11 +328,12 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
BdfList serverSupports = new BdfList();
if (u.hasMailbox()) {
MailboxUpdateWithMailbox um = (MailboxUpdateWithMailbox) u;
serverSupports = encodeSupportsList(um.getServerSupports());
dict.put(PROP_KEY_ONION, um.getOnion());
dict.put(PROP_KEY_AUTHTOKEN, um.getAuthToken().getBytes());
dict.put(PROP_KEY_INBOXID, um.getInboxId().getBytes());
dict.put(PROP_KEY_OUTBOXID, um.getOutboxId().getBytes());
MailboxProperties properties = um.getMailboxProperties();
serverSupports = encodeSupportsList(properties.getServerSupports());
dict.put(PROP_KEY_ONION, properties.getOnion());
dict.put(PROP_KEY_AUTHTOKEN, properties.getAuthToken());
dict.put(PROP_KEY_INBOXID, properties.getInboxId());
dict.put(PROP_KEY_OUTBOXID, properties.getOutboxId());
}
return BdfList.of(version, encodeSupportsList(u.getClientSupports()),
serverSupports, dict);