mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
1 Commits
print-db-s
...
545-log-db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63ae199be3 |
@@ -1,14 +1,8 @@
|
||||
package org.briarproject.bramble.api;
|
||||
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class StringMap extends Hashtable<String, String> {
|
||||
|
||||
protected StringMap(Map<String, String> m) {
|
||||
@@ -58,31 +52,4 @@ public abstract class StringMap extends Hashtable<String, String> {
|
||||
public void putLong(String key, long value) {
|
||||
put(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public int[] getIntArray(String key) {
|
||||
String s = get(key);
|
||||
if (s == null) return null;
|
||||
// Handle empty string because "".split(",") returns {""}
|
||||
if (s.length() == 0) return new int[0];
|
||||
String[] intStrings = s.split(",");
|
||||
int[] ints = new int[intStrings.length];
|
||||
try {
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i] = Integer.parseInt(intStrings[i]);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
public void putIntArray(String key, int[] value) {
|
||||
List<String> intStrings = new ArrayList<>();
|
||||
for (int integer : value) {
|
||||
intStrings.add(String.valueOf(integer));
|
||||
}
|
||||
// Puts empty string if input array value is empty
|
||||
put(key, StringUtils.join(intStrings, ","));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,6 +746,4 @@ public interface DatabaseComponent extends TransactionManager {
|
||||
*/
|
||||
void updateTransportKeys(Transaction txn, Collection<TransportKeySet> keys)
|
||||
throws DbException;
|
||||
|
||||
void printStats(Transaction txn) throws DbException;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@@ -13,14 +11,12 @@ public class MailboxProperties {
|
||||
private final String baseUrl;
|
||||
private final MailboxAuthToken authToken;
|
||||
private final boolean owner;
|
||||
private final List<MailboxVersion> serverSupports;
|
||||
|
||||
public MailboxProperties(String baseUrl, MailboxAuthToken authToken,
|
||||
boolean owner, List<MailboxVersion> serverSupports) {
|
||||
boolean owner) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.authToken = authToken;
|
||||
this.owner = owner;
|
||||
this.serverSupports = serverSupports;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
@@ -39,8 +35,4 @@ public class MailboxProperties {
|
||||
public boolean isOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public List<MailboxVersion> getServerSupports() {
|
||||
return serverSupports;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.briarproject.bramble.api.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class MailboxVersion implements Comparable<MailboxVersion> {
|
||||
|
||||
private final int major;
|
||||
private final int minor;
|
||||
|
||||
public MailboxVersion(int major, int minor) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof MailboxVersion) {
|
||||
MailboxVersion v = (MailboxVersion) o;
|
||||
return major == v.major && minor == v.minor;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MailboxVersion v) {
|
||||
int c = major - v.major;
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
return minor - v.minor;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxPropertiesUpdate;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
@@ -292,18 +291,6 @@ public class TestUtils {
|
||||
a.getOutboxId().equals(b.getOutboxId());
|
||||
}
|
||||
|
||||
public static boolean mailboxPropertiesEqual(
|
||||
@Nullable MailboxProperties a,
|
||||
@Nullable MailboxProperties b) {
|
||||
if (a == null || b == null) {
|
||||
return a == b;
|
||||
}
|
||||
return a.getOnion().equals(b.getOnion()) &&
|
||||
a.getAuthToken().equals(b.getAuthToken()) &&
|
||||
a.isOwner() == b.isOwner() &&
|
||||
a.getServerSupports().equals(b.getServerSupports());
|
||||
}
|
||||
|
||||
public static boolean hasEvent(Transaction txn,
|
||||
Class<? extends Event> eventClass) {
|
||||
for (CommitAction action : txn.getActions()) {
|
||||
|
||||
@@ -862,6 +862,4 @@ interface Database<T> {
|
||||
* Stores the given transport keys, deleting any keys they have replaced.
|
||||
*/
|
||||
void updateTransportKeys(T txn, TransportKeySet ks) throws DbException;
|
||||
|
||||
void printStats(T txn) throws DbException;
|
||||
}
|
||||
|
||||
@@ -1256,12 +1256,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStats(Transaction transaction) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
db.printStats(txn);
|
||||
}
|
||||
|
||||
private class CommitActionVisitor implements Visitor {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,12 +13,8 @@ import org.briarproject.bramble.util.StringUtils;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -30,7 +26,6 @@ import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.IoUtils.isNonEmptyDirectory;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.logFileOrDir;
|
||||
|
||||
/**
|
||||
@@ -106,73 +101,6 @@ class H2Database extends JdbcDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStats(Connection txn) throws DbException {
|
||||
List<String> names = printNames(txn);
|
||||
for (String table : names) {
|
||||
tryPrintStats(txn, table);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> printNames(Connection txn) throws DbException {
|
||||
List<String> names = new ArrayList<>();
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql =
|
||||
"SELECT table_catalog, table_schema, table_name FROM INFORMATION_SCHEMA.TABLES";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String catalog = rs.getString(1);
|
||||
String schema = rs.getString(2);
|
||||
String name = rs.getString(3);
|
||||
LOG.info(
|
||||
String.format("Table %s %s %s", catalog, schema, name));
|
||||
names.add(schema + "." + name);
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private void tryPrintStats(Connection txn, String table) {
|
||||
try {
|
||||
printStats(txn, table);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void printStats(Connection txn, String table) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "CALL DISK_SPACE_USED(?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, table);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
long size = rs.getLong(1);
|
||||
if (rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
ps.close();
|
||||
LOG.info(String.format("Size of table %s: %d", table, size));
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Connection createConnection() throws DbException, SQLException {
|
||||
SecretKey key = this.key;
|
||||
|
||||
@@ -93,11 +93,6 @@ class HyperSqlDatabase extends JdbcDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStats(Connection txn) throws DbException {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Connection createConnection() throws DbException, SQLException {
|
||||
SecretKey key = this.key;
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
package org.briarproject.bramble.db;
|
||||
|
||||
import static org.briarproject.bramble.api.db.DatabaseComponent.NO_CLEANUP_DEADLINE;
|
||||
import static org.briarproject.bramble.api.db.DatabaseComponent.TIMER_NOT_STARTED;
|
||||
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.DB_SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.DIRTY_KEY;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.SCHEMA_VERSION_KEY;
|
||||
import static org.briarproject.bramble.db.ExponentialBackoff.calculateExpiry;
|
||||
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
import static java.sql.Types.BINARY;
|
||||
import static java.sql.Types.BOOLEAN;
|
||||
import static java.sql.Types.INTEGER;
|
||||
import static java.sql.Types.VARCHAR;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.PendingContact;
|
||||
@@ -65,33 +92,6 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
|
||||
import static java.sql.Types.BINARY;
|
||||
import static java.sql.Types.BOOLEAN;
|
||||
import static java.sql.Types.INTEGER;
|
||||
import static java.sql.Types.VARCHAR;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.db.DatabaseComponent.NO_CLEANUP_DEADLINE;
|
||||
import static org.briarproject.bramble.api.db.DatabaseComponent.TIMER_NOT_STARTED;
|
||||
import static org.briarproject.bramble.api.db.Metadata.REMOVE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.DB_SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.DIRTY_KEY;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.SCHEMA_VERSION_KEY;
|
||||
import static org.briarproject.bramble.db.ExponentialBackoff.calculateExpiry;
|
||||
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
/**
|
||||
* A generic database implementation that can be used with any JDBC-compatible
|
||||
* database library.
|
||||
@@ -415,6 +415,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
createIndexes(txn);
|
||||
setDirty(txn, true);
|
||||
if (LOG.isLoggable(INFO)) countAndLogRows(txn);
|
||||
commitTransaction(txn);
|
||||
} catch (DbException e) {
|
||||
abortTransaction(txn);
|
||||
@@ -565,6 +566,40 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
private void countAndLogRows(Connection txn) throws DbException {
|
||||
Statement s = null;
|
||||
try {
|
||||
s = txn.createStatement();
|
||||
countAndLogRows(s, "settings");
|
||||
countAndLogRows(s, "localAuthors");
|
||||
countAndLogRows(s, "contacts");
|
||||
countAndLogRows(s, "groups");
|
||||
countAndLogRows(s, "groupMetadata");
|
||||
countAndLogRows(s, "groupVisibilities");
|
||||
countAndLogRows(s, "messages");
|
||||
countAndLogRows(s, "messageMetadata");
|
||||
countAndLogRows(s, "messageDependencies");
|
||||
countAndLogRows(s, "offers");
|
||||
countAndLogRows(s, "statuses");
|
||||
countAndLogRows(s, "transports");
|
||||
countAndLogRows(s, "incomingKeys");
|
||||
countAndLogRows(s, "outgoingKeys");
|
||||
s.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(s, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void countAndLogRows(Statement s, String tableName)
|
||||
throws SQLException {
|
||||
ResultSet rs = s.executeQuery("SELECT COUNT (*) FROM " + tableName);
|
||||
if (rs.next())
|
||||
LOG.info("Table " + tableName + ": " + rs.getInt(1) + " rows");
|
||||
else LOG.warning("Table " + tableName + " could not be counted");
|
||||
rs.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection startTransaction() throws DbException {
|
||||
Connection txn;
|
||||
|
||||
@@ -25,7 +25,7 @@ interface MailboxApi {
|
||||
* @return the owner token
|
||||
* @throws ApiException for 401 response.
|
||||
*/
|
||||
MailboxProperties setup(MailboxProperties properties)
|
||||
MailboxAuthToken setup(MailboxProperties properties)
|
||||
throws IOException, ApiException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.mailbox.MailboxFileId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxId;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.File;
|
||||
@@ -57,7 +56,7 @@ class MailboxApiImpl implements MailboxApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailboxProperties setup(MailboxProperties properties)
|
||||
public MailboxAuthToken setup(MailboxProperties properties)
|
||||
throws IOException, ApiException {
|
||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||
Request request = getRequestBuilder(properties.getAuthToken())
|
||||
@@ -76,27 +75,8 @@ class MailboxApiImpl implements MailboxApi {
|
||||
if (tokenNode == null) {
|
||||
throw new ApiException();
|
||||
}
|
||||
List<MailboxVersion> serverSupports = new ArrayList<>();
|
||||
ArrayNode serverSupportsNode = getArray(node, "serverSupports");
|
||||
for (JsonNode versionNode : serverSupportsNode) {
|
||||
if (!versionNode.isObject()) throw new ApiException();
|
||||
ObjectNode objectNode = (ObjectNode) versionNode;
|
||||
JsonNode majorNode = objectNode.get("major");
|
||||
JsonNode minorNode = objectNode.get("minor");
|
||||
if (majorNode == null || !majorNode.isNumber()) {
|
||||
throw new ApiException();
|
||||
}
|
||||
if (minorNode == null || !minorNode.isNumber()) {
|
||||
throw new ApiException();
|
||||
}
|
||||
int major = majorNode.asInt();
|
||||
int minor = minorNode.asInt();
|
||||
if (major < 0 || minor < 0) throw new ApiException();
|
||||
serverSupports.add(new MailboxVersion(major, minor));
|
||||
}
|
||||
return new MailboxProperties(properties.getBaseUrl(),
|
||||
MailboxAuthToken.fromString(tokenNode.textValue()),
|
||||
true, serverSupports);
|
||||
String ownerToken = tokenNode.textValue();
|
||||
return MailboxAuthToken.fromString(ownerToken);
|
||||
} catch (JacksonException | InvalidMailboxIdException e) {
|
||||
throw new ApiException();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,9 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
||||
private void pairMailbox() throws IOException, ApiException, DbException {
|
||||
MailboxProperties mailboxProperties = decodeQrCodePayload(payload);
|
||||
setState(new MailboxPairingState.Pairing());
|
||||
MailboxProperties ownerProperties = api.setup(mailboxProperties);
|
||||
MailboxAuthToken ownerToken = api.setup(mailboxProperties);
|
||||
MailboxProperties ownerProperties = new MailboxProperties(
|
||||
mailboxProperties.getBaseUrl(), ownerToken, true);
|
||||
long time = clock.currentTimeMillis();
|
||||
db.transaction(false, txn -> {
|
||||
mailboxSettingsManager
|
||||
@@ -180,8 +182,7 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
||||
String baseUrl = "http://" + onion + ".onion";
|
||||
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, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,13 +8,11 @@ import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||
import org.briarproject.bramble.api.mailbox.OwnMailboxConnectionStatusEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -32,7 +30,6 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
||||
static final String SETTINGS_NAMESPACE = "mailbox";
|
||||
static final String SETTINGS_KEY_ONION = "onion";
|
||||
static final String SETTINGS_KEY_TOKEN = "token";
|
||||
static final String SETTINGS_KEY_SERVER_SUPPORTS = "serverSupports";
|
||||
static final String SETTINGS_KEY_LAST_ATTEMPT = "lastAttempt";
|
||||
static final String SETTINGS_KEY_LAST_SUCCESS = "lastSuccess";
|
||||
static final String SETTINGS_KEY_ATTEMPTS = "attempts";
|
||||
@@ -58,19 +55,9 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
||||
String onion = s.get(SETTINGS_KEY_ONION);
|
||||
String token = s.get(SETTINGS_KEY_TOKEN);
|
||||
if (isNullOrEmpty(onion) || isNullOrEmpty(token)) return null;
|
||||
int[] ints = s.getIntArray(SETTINGS_KEY_SERVER_SUPPORTS);
|
||||
// We know we were paired, so we must have proper serverSupports
|
||||
// TODO is throwing sensible? But it's done like that below on "parse error"
|
||||
if (ints == null || ints.length == 0 || ints.length % 2 != 0) {
|
||||
throw new DbException();
|
||||
}
|
||||
List<MailboxVersion> serverSupports = new ArrayList<>();
|
||||
for (int i = 0; i < ints.length - 1; i += 2) {
|
||||
serverSupports.add(new MailboxVersion(ints[i], ints[i + 1]));
|
||||
}
|
||||
try {
|
||||
MailboxAuthToken tokenId = MailboxAuthToken.fromString(token);
|
||||
return new MailboxProperties(onion, tokenId, true, serverSupports);
|
||||
return new MailboxProperties(onion, tokenId, true);
|
||||
} catch (InvalidMailboxIdException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
@@ -82,14 +69,6 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
||||
Settings s = new Settings();
|
||||
s.put(SETTINGS_KEY_ONION, p.getBaseUrl());
|
||||
s.put(SETTINGS_KEY_TOKEN, p.getAuthToken().toString());
|
||||
List<MailboxVersion> serverSupports = p.getServerSupports();
|
||||
int[] ints = new int[serverSupports.size() * 2];
|
||||
int i = 0;
|
||||
for (MailboxVersion v : serverSupports) {
|
||||
ints[i++] = v.getMajor();
|
||||
ints[i++] = v.getMinor();
|
||||
}
|
||||
s.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, ints);
|
||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||
for (MailboxHook hook : hooks) {
|
||||
hook.mailboxPaired(txn, p.getOnion());
|
||||
|
||||
@@ -37,7 +37,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContactId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.mailboxPropertiesEqual;
|
||||
import static org.briarproject.bramble.test.TestUtils.readBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.writeBytes;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
@@ -81,20 +80,11 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testSetup() throws Exception {
|
||||
String validVersions = "[ {\"major\":1,\"minor\":0} ]";
|
||||
String validResponse = makeSetupResponse(
|
||||
"\"" + token2 + "\"", validVersions);
|
||||
String validResponse = "{\"token\":\"" + token2 + "\"}";
|
||||
String invalidResponse = "{\"foo\":\"bar\"}";
|
||||
String invalidTokenResponse = makeSetupResponse(
|
||||
"{\"foo\":\"bar\"}", validVersions);
|
||||
String invalidTokenResponse2 = makeSetupResponse(
|
||||
"\"" + getRandomString(64) + "\"", validVersions);
|
||||
String invalidVersionsResponse = makeSetupResponse(
|
||||
"\"" + token2 + "\"", "42");
|
||||
String invalidVersionsResponse2 = makeSetupResponse(
|
||||
"\"" + token2 + "\"", "[ 1,0 ]");
|
||||
String invalidVersionsResponse3 = makeSetupResponse(
|
||||
"\"" + token2 + "\"", "[ {\"major\":1, \"minor\":-1} ]");
|
||||
String invalidTokenResponse = "{\"token\":{\"foo\":\"bar\"}}";
|
||||
String invalidTokenResponse2 =
|
||||
"{\"token\":\"" + getRandomString(64) + "\"}";
|
||||
|
||||
MockWebServer server = new MockWebServer();
|
||||
server.enqueue(new MockResponse().setBody(validResponse));
|
||||
@@ -104,18 +94,15 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.enqueue(new MockResponse().setResponseCode(500));
|
||||
server.enqueue(new MockResponse().setBody(invalidTokenResponse));
|
||||
server.enqueue(new MockResponse().setBody(invalidTokenResponse2));
|
||||
server.enqueue(new MockResponse().setBody(invalidVersionsResponse));
|
||||
server.enqueue(new MockResponse().setBody(invalidVersionsResponse2));
|
||||
server.enqueue(new MockResponse().setBody(invalidVersionsResponse3));
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
MailboxProperties properties2 =
|
||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token2, true);
|
||||
|
||||
// valid response with valid token
|
||||
mailboxPropertiesEqual(properties2, api.setup(properties));
|
||||
assertEquals(token2, api.setup(properties));
|
||||
RecordedRequest request1 = server.takeRequest();
|
||||
assertEquals("/setup", request1.getPath());
|
||||
assertEquals("PUT", request1.getMethod());
|
||||
@@ -162,38 +149,12 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
assertEquals("/setup", request7.getPath());
|
||||
assertEquals("PUT", request7.getMethod());
|
||||
assertToken(request7, token);
|
||||
|
||||
// invalid non-array serverSupports response
|
||||
assertThrows(ApiException.class, () -> api.setup(properties));
|
||||
RecordedRequest request8 = server.takeRequest();
|
||||
assertEquals("/setup", request8.getPath());
|
||||
assertEquals("PUT", request8.getMethod());
|
||||
assertToken(request8, token);
|
||||
|
||||
// invalid non-object in serverSupports array response
|
||||
assertThrows(ApiException.class, () -> api.setup(properties));
|
||||
RecordedRequest request9 = server.takeRequest();
|
||||
assertEquals("/setup", request9.getPath());
|
||||
assertEquals("PUT", request9.getMethod());
|
||||
assertToken(request9, token);
|
||||
|
||||
// invalid negative minor version in serverSupports response
|
||||
assertThrows(ApiException.class, () -> api.setup(properties));
|
||||
RecordedRequest request10 = server.takeRequest();
|
||||
assertEquals("/setup", request10.getPath());
|
||||
assertEquals("PUT", request10.getMethod());
|
||||
assertToken(request10, token);
|
||||
}
|
||||
|
||||
private String makeSetupResponse(String token, String versions) {
|
||||
return "{\"token\":" + token + "," +
|
||||
"\"serverSupports\":" + versions + "}";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetupOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> api.setup(properties)
|
||||
@@ -209,9 +170,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
MailboxProperties properties2 =
|
||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token2, true);
|
||||
|
||||
assertTrue(api.checkStatus(properties));
|
||||
RecordedRequest request1 = server.takeRequest();
|
||||
@@ -232,7 +193,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testStatusOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> api.checkStatus(properties)
|
||||
@@ -249,9 +210,9 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
MailboxProperties properties2 =
|
||||
new MailboxProperties(baseUrl, token2, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token2, true);
|
||||
|
||||
api.wipeMailbox(properties);
|
||||
RecordedRequest request1 = server.takeRequest();
|
||||
@@ -281,7 +242,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testWipeOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
api.wipeMailbox(properties));
|
||||
}
|
||||
@@ -295,7 +256,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// contact gets added as expected
|
||||
api.addContact(properties, mailboxContact);
|
||||
@@ -327,7 +288,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testAddContactOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
api.addContact(properties, mailboxContact));
|
||||
}
|
||||
@@ -342,7 +303,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// contact gets deleted as expected
|
||||
api.deleteContact(properties, contactId);
|
||||
@@ -379,7 +340,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testDeleteContactOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
api.deleteContact(properties, contactId));
|
||||
}
|
||||
@@ -406,7 +367,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// valid response with two contacts
|
||||
assertEquals(singletonList(contactId), api.getContacts(properties));
|
||||
@@ -471,7 +432,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testGetContactsOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> api.getContacts(properties)
|
||||
@@ -491,7 +452,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// file gets uploaded as expected
|
||||
api.addFile(properties, contactInboxId, file);
|
||||
@@ -550,7 +511,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// valid response with one file
|
||||
List<MailboxFile> received1 = api.getFiles(properties, contactInboxId);
|
||||
@@ -646,7 +607,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// file gets downloaded as expected
|
||||
api.getFile(properties, contactOutboxId, name, file1);
|
||||
@@ -690,7 +651,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// file gets deleted as expected
|
||||
api.deleteFile(properties, contactInboxId, name);
|
||||
@@ -754,7 +715,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
server.start();
|
||||
String baseUrl = getBaseUrl(server);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(baseUrl, token, true, new ArrayList<>());
|
||||
new MailboxProperties(baseUrl, token, true);
|
||||
|
||||
// valid response with one folders
|
||||
assertEquals(singletonList(id1), api.getFolders(properties));
|
||||
@@ -823,7 +784,7 @@ public class MailboxApiTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testGetFoldersOnlyForOwner() {
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties("", token, false, new ArrayList<>());
|
||||
new MailboxProperties("", token, false);
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
api.getFolders(properties));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -90,16 +89,17 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
||||
assumeTrue(isOptionalTestEnabled(MailboxIntegrationTest.class));
|
||||
|
||||
if (ownerProperties != null) return;
|
||||
MailboxProperties setupProperties = new MailboxProperties(
|
||||
URL_BASE, SETUP_TOKEN, true, new ArrayList<>());
|
||||
ownerProperties = api.setup(setupProperties);
|
||||
MailboxProperties setupProperties =
|
||||
new MailboxProperties(URL_BASE, SETUP_TOKEN, true);
|
||||
MailboxAuthToken ownerToken = api.setup(setupProperties);
|
||||
ownerProperties = new MailboxProperties(URL_BASE, ownerToken, true);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
// we can't test wiping as a regular test as it stops the mailbox
|
||||
public static void wipe() throws IOException, ApiException {
|
||||
if (!isOptionalTestEnabled(MailboxIntegrationTest.class)) return;
|
||||
|
||||
|
||||
api.wipeMailbox(ownerProperties);
|
||||
|
||||
// check doesn't work anymore
|
||||
@@ -107,8 +107,8 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
||||
api.checkStatus(ownerProperties));
|
||||
|
||||
// new setup doesn't work as mailbox is stopping
|
||||
MailboxProperties setupProperties = new MailboxProperties(
|
||||
URL_BASE, SETUP_TOKEN, true, new ArrayList<>());
|
||||
MailboxProperties setupProperties =
|
||||
new MailboxProperties(URL_BASE, SETUP_TOKEN, true);
|
||||
assertThrows(ApiException.class, () -> api.setup(setupProperties));
|
||||
}
|
||||
|
||||
@@ -151,8 +151,7 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
||||
ContactId contactId = new ContactId(1);
|
||||
MailboxContact contact = getMailboxContact(contactId);
|
||||
MailboxProperties contactProperties = new MailboxProperties(
|
||||
ownerProperties.getBaseUrl(), contact.token, false,
|
||||
new ArrayList<>());
|
||||
ownerProperties.getBaseUrl(), contact.token, false);
|
||||
api.addContact(ownerProperties, contact);
|
||||
|
||||
// upload a file for our contact
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -62,10 +61,10 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
||||
new MailboxAuthToken(getRandomId());
|
||||
private final String validPayload = getValidPayload();
|
||||
private final long time = System.currentTimeMillis();
|
||||
private final MailboxProperties setupProperties = new MailboxProperties(
|
||||
onionAddress, setupToken, true, new ArrayList<>());
|
||||
private final MailboxProperties ownerProperties = new MailboxProperties(
|
||||
onionAddress, ownerToken, true, new ArrayList<>());
|
||||
private final MailboxProperties setupProperties =
|
||||
new MailboxProperties(onionAddress, setupToken, true);
|
||||
private final MailboxProperties ownerProperties =
|
||||
new MailboxProperties(onionAddress, ownerToken, true);
|
||||
|
||||
@Test
|
||||
public void testInitialQrCodeReceivedState() {
|
||||
@@ -99,7 +98,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
||||
oneOf(crypto).encodeOnion(onionBytes);
|
||||
will(returnValue(onion));
|
||||
oneOf(api).setup(with(matches(setupProperties)));
|
||||
will(returnValue(ownerProperties));
|
||||
will(returnValue(ownerToken));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(time));
|
||||
}});
|
||||
@@ -175,7 +174,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
||||
oneOf(crypto).encodeOnion(onionBytes);
|
||||
will(returnValue(onion));
|
||||
oneOf(api).setup(with(matches(setupProperties)));
|
||||
will(returnValue(ownerProperties));
|
||||
will(returnValue(ownerToken));
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(time));
|
||||
}});
|
||||
@@ -207,8 +206,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
||||
return new PredicateMatcher<>(MailboxProperties.class, p1 ->
|
||||
p1.getAuthToken().equals(p2.getAuthToken()) &&
|
||||
p1.getBaseUrl().equals(p2.getBaseUrl()) &&
|
||||
p1.isOwner() == p2.isOwner() &&
|
||||
p1.getServerSupports().equals(p2.getServerSupports()));
|
||||
p1.isOwner() == p2.isOwner());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -77,7 +76,7 @@ public class MailboxPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
public MailboxPropertyManagerImplTest() {
|
||||
ownProps = new MailboxProperties("http://bar.onion",
|
||||
new MailboxAuthToken(getRandomId()), true, new ArrayList<>());
|
||||
new MailboxAuthToken(getRandomId()), true);
|
||||
props = new MailboxPropertiesUpdate(ownProps.getOnion(),
|
||||
new MailboxAuthToken(getRandomId()),
|
||||
new MailboxFolderId(getRandomId()),
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxProperties;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxStatus;
|
||||
import org.briarproject.bramble.api.mailbox.MailboxVersion;
|
||||
import org.briarproject.bramble.api.mailbox.OwnMailboxConnectionStatusEvent;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
@@ -14,15 +13,12 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_ATTEMPTS;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_ATTEMPT;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_SUCCESS;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_ONION;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_SERVER_SUPPORTS;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_TOKEN;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_UPLOADS_NAMESPACE;
|
||||
@@ -44,9 +40,6 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
||||
private final Random random = new Random();
|
||||
private final String onion = getRandomString(64);
|
||||
private final MailboxAuthToken token = new MailboxAuthToken(getRandomId());
|
||||
private final List<MailboxVersion> serverSupports =
|
||||
asList(new MailboxVersion(1, 0), new MailboxVersion(1, 1));
|
||||
private final int[] serverSupportsInts = {1, 0, 1, 1};
|
||||
private final ContactId contactId1 = new ContactId(random.nextInt());
|
||||
private final ContactId contactId2 = new ContactId(random.nextInt());
|
||||
private final ContactId contactId3 = new ContactId(random.nextInt());
|
||||
@@ -74,7 +67,6 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
||||
Settings settings = new Settings();
|
||||
settings.put(SETTINGS_KEY_ONION, onion);
|
||||
settings.put(SETTINGS_KEY_TOKEN, token.toString());
|
||||
settings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, serverSupportsInts);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(settingsManager).getSettings(txn, SETTINGS_NAMESPACE);
|
||||
@@ -85,7 +77,6 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
||||
assertNotNull(properties);
|
||||
assertEquals(onion, properties.getBaseUrl());
|
||||
assertEquals(token, properties.getAuthToken());
|
||||
assertEquals(serverSupports, properties.getServerSupports());
|
||||
assertTrue(properties.isOwner());
|
||||
}
|
||||
|
||||
@@ -95,10 +86,8 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
||||
Settings expectedSettings = new Settings();
|
||||
expectedSettings.put(SETTINGS_KEY_ONION, onion);
|
||||
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
|
||||
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
|
||||
serverSupportsInts);
|
||||
MailboxProperties properties = new MailboxProperties(onion, token, true,
|
||||
serverSupports);
|
||||
MailboxProperties properties =
|
||||
new MailboxProperties(onion, token, true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
|
||||
|
||||
@@ -215,7 +215,6 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
if (IS_DEBUG_BUILD || shouldWarnOldAndroidExpiry()) {
|
||||
navDrawerViewModel.checkExpiryWarning();
|
||||
}
|
||||
navDrawerViewModel.printStats();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.TransactionManager;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
@@ -41,7 +41,6 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
private static final String SHOW_TRANSPORTS_ONBOARDING =
|
||||
"showTransportsOnboarding";
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final SettingsManager settingsManager;
|
||||
|
||||
private final MutableLiveData<Boolean> showExpiryWarning =
|
||||
@@ -55,11 +54,10 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
NavDrawerViewModel(Application app,
|
||||
@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager,
|
||||
DatabaseComponent db,
|
||||
TransactionManager db,
|
||||
AndroidExecutor androidExecutor,
|
||||
SettingsManager settingsManager) {
|
||||
super(app, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||
this.db = db;
|
||||
this.settingsManager = settingsManager;
|
||||
}
|
||||
|
||||
@@ -176,16 +174,4 @@ public class NavDrawerViewModel extends DbViewModel {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void printStats() {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
db.printStats(txn);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user