Include unique device ID in transport updates.

This commit is contained in:
akwizgran
2016-01-27 12:16:09 +00:00
parent 88475bdd54
commit c776d1e893
8 changed files with 79 additions and 18 deletions

View File

@@ -1,5 +1,6 @@
package org.briarproject.db;
import org.briarproject.api.DeviceId;
import org.briarproject.api.TransportId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
@@ -256,6 +257,13 @@ interface Database<T> {
*/
Collection<ContactId> getContacts(T txn, AuthorId a) throws DbException;
/**
* Returns the unique ID for this device.
* <p>
* Locking: read.
*/
DeviceId getDeviceId(T txn) throws DbException;
/**
* 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

View File

@@ -1,5 +1,6 @@
package org.briarproject.db;
import org.briarproject.api.DeviceId;
import org.briarproject.api.TransportId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
@@ -542,6 +543,23 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
}
}
public DeviceId getDeviceId() throws DbException {
lock.readLock().lock();
try {
T txn = db.startTransaction();
try {
DeviceId id = db.getDeviceId(txn);
db.commitTransaction(txn);
return id;
} catch (DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
lock.readLock().unlock();
}
}
public Group getGroup(GroupId g) throws DbException {
lock.readLock().lock();
try {

View File

@@ -1,5 +1,6 @@
package org.briarproject.db;
import org.briarproject.api.DeviceId;
import org.briarproject.api.TransportId;
import org.briarproject.api.UniqueId;
import org.briarproject.api.contact.Contact;
@@ -484,6 +485,11 @@ abstract class JdbcDatabase implements Database<Connection> {
if (interrupted) Thread.currentThread().interrupt();
}
public DeviceId getDeviceId(Connection txn) throws DbException {
Settings s = getSettings(txn, DEVICE_SETTINGS_NAMESPACE);
return new DeviceId(StringUtils.fromHexString(s.get(DEVICE_ID_KEY)));
}
public ContactId addContact(Connection txn, Author remote, AuthorId local)
throws DbException {
PreparedStatement ps = null;