mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Remove Device ID
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
package org.briarproject.api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type-safe wrapper for a byte array that uniquely identifies a device.
|
|
||||||
*/
|
|
||||||
public class DeviceId extends UniqueId {
|
|
||||||
|
|
||||||
public DeviceId(byte[] id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return o instanceof DeviceId && super.equals(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.api.db;
|
package org.briarproject.api.db;
|
||||||
|
|
||||||
import org.briarproject.api.DeviceId;
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
@@ -205,13 +204,6 @@ public interface DatabaseComponent {
|
|||||||
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique ID for this device.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
DeviceId getDeviceId(Transaction txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the group with the given ID.
|
* Returns the group with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.db;
|
package org.briarproject.db;
|
||||||
|
|
||||||
import org.briarproject.api.DeviceId;
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
@@ -227,13 +226,6 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
Collection<ContactId> getContacts(T txn, AuthorId a) throws DbException;
|
Collection<ContactId> getContacts(T txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique ID for this device.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
DeviceId getDeviceId(T txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the amount of free storage space available to the database, in
|
* Returns the amount of free storage space available to the database, in
|
||||||
* bytes. This is based on the minimum of the space available on the device
|
* bytes. This is based on the minimum of the space available on the device
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.db;
|
package org.briarproject.db;
|
||||||
|
|
||||||
import org.briarproject.api.DeviceId;
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
@@ -414,12 +413,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.getContacts(txn, a);
|
return db.getContacts(txn, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DeviceId getDeviceId(Transaction transaction) throws DbException {
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
return db.getDeviceId(txn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Group getGroup(Transaction transaction, GroupId g)
|
public Group getGroup(Transaction transaction, GroupId g)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
|||||||
@@ -29,15 +29,4 @@ interface DatabaseConstants {
|
|||||||
*/
|
*/
|
||||||
String MIN_SCHEMA_VERSION_KEY = "minSchemaVersion";
|
String MIN_SCHEMA_VERSION_KEY = "minSchemaVersion";
|
||||||
|
|
||||||
/**
|
|
||||||
* The namespace of the {@link Settings Settings}
|
|
||||||
* where the unique device ID is stored.
|
|
||||||
*/
|
|
||||||
String DEVICE_SETTINGS_NAMESPACE = "device";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Settings Settings} key under which the
|
|
||||||
* unique device ID is stored.
|
|
||||||
*/
|
|
||||||
String DEVICE_ID_KEY = "deviceId";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.briarproject.api.event.EventBus;
|
|||||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||||
import org.briarproject.api.system.Clock;
|
import org.briarproject.api.system.Clock;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -19,9 +18,8 @@ public class DatabaseModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Database<Connection> provideDatabase(DatabaseConfig config,
|
Database<Connection> provideDatabase(DatabaseConfig config, Clock clock) {
|
||||||
SecureRandom random, Clock clock) {
|
return new H2Database(config, clock);
|
||||||
return new H2Database(config, random, clock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.briarproject.api.system.Clock;
|
|||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -26,8 +25,8 @@ class H2Database extends JdbcDatabase {
|
|||||||
private final String url;
|
private final String url;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
H2Database(DatabaseConfig config, SecureRandom random, Clock clock) {
|
H2Database(DatabaseConfig config, Clock clock) {
|
||||||
super(HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE, random, clock);
|
super(HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE, clock);
|
||||||
this.config = config;
|
this.config = config;
|
||||||
File dir = config.getDatabaseDirectory();
|
File dir = config.getDatabaseDirectory();
|
||||||
String path = new File(dir, "db").getAbsolutePath();
|
String path = new File(dir, "db").getAbsolutePath();
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.briarproject.db;
|
package org.briarproject.db;
|
||||||
|
|
||||||
import org.briarproject.api.DeviceId;
|
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.UniqueId;
|
|
||||||
import org.briarproject.api.contact.Contact;
|
import org.briarproject.api.contact.Contact;
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
@@ -25,10 +23,8 @@ import org.briarproject.api.system.Clock;
|
|||||||
import org.briarproject.api.transport.IncomingKeys;
|
import org.briarproject.api.transport.IncomingKeys;
|
||||||
import org.briarproject.api.transport.OutgoingKeys;
|
import org.briarproject.api.transport.OutgoingKeys;
|
||||||
import org.briarproject.api.transport.TransportKeys;
|
import org.briarproject.api.transport.TransportKeys;
|
||||||
import org.briarproject.util.StringUtils;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -59,8 +55,6 @@ import static org.briarproject.api.sync.ValidationManager.State.INVALID;
|
|||||||
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
import static org.briarproject.api.sync.ValidationManager.State.PENDING;
|
||||||
import static org.briarproject.api.sync.ValidationManager.State.UNKNOWN;
|
import static org.briarproject.api.sync.ValidationManager.State.UNKNOWN;
|
||||||
import static org.briarproject.db.DatabaseConstants.DB_SETTINGS_NAMESPACE;
|
import static org.briarproject.db.DatabaseConstants.DB_SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.db.DatabaseConstants.DEVICE_ID_KEY;
|
|
||||||
import static org.briarproject.db.DatabaseConstants.DEVICE_SETTINGS_NAMESPACE;
|
|
||||||
import static org.briarproject.db.DatabaseConstants.MIN_SCHEMA_VERSION_KEY;
|
import static org.briarproject.db.DatabaseConstants.MIN_SCHEMA_VERSION_KEY;
|
||||||
import static org.briarproject.db.DatabaseConstants.SCHEMA_VERSION_KEY;
|
import static org.briarproject.db.DatabaseConstants.SCHEMA_VERSION_KEY;
|
||||||
import static org.briarproject.db.ExponentialBackoff.calculateExpiry;
|
import static org.briarproject.db.ExponentialBackoff.calculateExpiry;
|
||||||
@@ -240,7 +234,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
// Different database libraries use different names for certain types
|
// Different database libraries use different names for certain types
|
||||||
private final String hashType, binaryType, counterType, secretType;
|
private final String hashType, binaryType, counterType, secretType;
|
||||||
private final SecureRandom random;
|
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
private final LinkedList<Connection> connections =
|
private final LinkedList<Connection> connections =
|
||||||
@@ -255,12 +248,11 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
private final Condition connectionsChanged = connectionsLock.newCondition();
|
private final Condition connectionsChanged = connectionsLock.newCondition();
|
||||||
|
|
||||||
JdbcDatabase(String hashType, String binaryType, String counterType,
|
JdbcDatabase(String hashType, String binaryType, String counterType,
|
||||||
String secretType, SecureRandom random, Clock clock) {
|
String secretType, Clock clock) {
|
||||||
this.hashType = hashType;
|
this.hashType = hashType;
|
||||||
this.binaryType = binaryType;
|
this.binaryType = binaryType;
|
||||||
this.counterType = counterType;
|
this.counterType = counterType;
|
||||||
this.secretType = secretType;
|
this.secretType = secretType;
|
||||||
this.random = random;
|
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +271,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
} else {
|
} else {
|
||||||
createTables(txn);
|
createTables(txn);
|
||||||
storeSchemaVersion(txn);
|
storeSchemaVersion(txn);
|
||||||
storeDeviceId(txn);
|
|
||||||
}
|
}
|
||||||
commitTransaction(txn);
|
commitTransaction(txn);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -304,14 +295,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
mergeSettings(txn, s, DB_SETTINGS_NAMESPACE);
|
mergeSettings(txn, s, DB_SETTINGS_NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeDeviceId(Connection txn) throws DbException {
|
|
||||||
byte[] deviceId = new byte[UniqueId.LENGTH];
|
|
||||||
random.nextBytes(deviceId);
|
|
||||||
Settings s = new Settings();
|
|
||||||
s.put(DEVICE_ID_KEY, StringUtils.toHexString(deviceId));
|
|
||||||
mergeSettings(txn, s, DEVICE_SETTINGS_NAMESPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryToClose(ResultSet rs) {
|
private void tryToClose(ResultSet rs) {
|
||||||
try {
|
try {
|
||||||
if (rs != null) rs.close();
|
if (rs != null) rs.close();
|
||||||
@@ -463,12 +446,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if (interrupted) Thread.currentThread().interrupt();
|
if (interrupted) Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DeviceId getDeviceId(Connection txn) throws DbException {
|
|
||||||
Settings s = getSettings(txn, DEVICE_SETTINGS_NAMESPACE);
|
|
||||||
return new DeviceId(StringUtils.fromHexString(s.get(DEVICE_ID_KEY)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
||||||
boolean verified, boolean active) throws DbException {
|
boolean verified, boolean active) throws DbException {
|
||||||
|
|||||||
@@ -1658,7 +1658,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
private Database<Connection> open(boolean resume) throws Exception {
|
private Database<Connection> open(boolean resume) throws Exception {
|
||||||
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
||||||
MAX_SIZE), new SecureRandom(), new SystemClock());
|
MAX_SIZE), new SystemClock());
|
||||||
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
||||||
db.open();
|
db.open();
|
||||||
return db;
|
return db;
|
||||||
|
|||||||
Reference in New Issue
Block a user