mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Rename account to identity.
This commit is contained in:
@@ -5,9 +5,9 @@ import org.briarproject.bramble.api.contact.ContactId;
|
|||||||
import org.briarproject.bramble.api.contact.PendingContact;
|
import org.briarproject.bramble.api.contact.PendingContact;
|
||||||
import org.briarproject.bramble.api.contact.PendingContactId;
|
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
@@ -101,11 +101,6 @@ public interface DatabaseComponent {
|
|||||||
<R, E extends Exception> R transactionWithNullableResult(boolean readOnly,
|
<R, E extends Exception> R transactionWithNullableResult(boolean readOnly,
|
||||||
NullableDbCallable<R, E> task) throws DbException, E;
|
NullableDbCallable<R, E> task) throws DbException, E;
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores an account.
|
|
||||||
*/
|
|
||||||
void addAccount(Transaction txn, Account a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a contact associated with the given local and remote pseudonyms,
|
* Stores a contact associated with the given local and remote pseudonyms,
|
||||||
* and returns an ID for the contact.
|
* and returns an ID for the contact.
|
||||||
@@ -132,6 +127,11 @@ public interface DatabaseComponent {
|
|||||||
HandshakeKeySetId addHandshakeKeys(Transaction txn, PendingContactId p,
|
HandshakeKeySetId addHandshakeKeys(Transaction txn, PendingContactId p,
|
||||||
HandshakeKeys k) throws DbException;
|
HandshakeKeys k) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores an identity.
|
||||||
|
*/
|
||||||
|
void addIdentity(Transaction txn, Identity i) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a local message.
|
* Stores a local message.
|
||||||
*/
|
*/
|
||||||
@@ -157,13 +157,6 @@ public interface DatabaseComponent {
|
|||||||
TransportKeySetId addTransportKeys(Transaction txn, ContactId c,
|
TransportKeySetId addTransportKeys(Transaction txn, ContactId c,
|
||||||
TransportKeys k) throws DbException;
|
TransportKeys k) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the database contains an account for the given pseudonym.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
boolean containsAccount(Transaction txn, AuthorId local) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database contains the given contact for the given
|
* Returns true if the database contains the given contact for the given
|
||||||
* local pseudonym.
|
* local pseudonym.
|
||||||
@@ -180,6 +173,14 @@ public interface DatabaseComponent {
|
|||||||
*/
|
*/
|
||||||
boolean containsGroup(Transaction txn, GroupId g) throws DbException;
|
boolean containsGroup(Transaction txn, GroupId g) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the database contains an identity for the given
|
||||||
|
* pseudonym.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
boolean containsIdentity(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database contains the given pending contact.
|
* Returns true if the database contains the given pending contact.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -246,20 +247,6 @@ public interface DatabaseComponent {
|
|||||||
Collection<Message> generateRequestedBatch(Transaction txn, ContactId c,
|
Collection<Message> generateRequestedBatch(Transaction txn, ContactId c,
|
||||||
int maxLength, int maxLatency) throws DbException;
|
int maxLength, int maxLatency) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the account for the local pseudonym with the given ID.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
Account getAccount(Transaction txn, AuthorId a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the accounts for all local pseudonyms.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
Collection<Account> getAccounts(Transaction txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the contact with the given ID.
|
* Returns the contact with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -329,6 +316,20 @@ public interface DatabaseComponent {
|
|||||||
Collection<HandshakeKeySet> getHandshakeKeys(Transaction txn, TransportId t)
|
Collection<HandshakeKeySet> getHandshakeKeys(Transaction txn, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identity for the local pseudonym with the given ID.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Identity getIdentity(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identities for all local pseudonyms.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Collection<Identity> getIdentities(Transaction txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message with the given ID.
|
* Returns the message with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -541,11 +542,6 @@ public interface DatabaseComponent {
|
|||||||
void receiveRequest(Transaction txn, ContactId c, Request r)
|
void receiveRequest(Transaction txn, ContactId c, Request r)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an account (and all associated state) from the database.
|
|
||||||
*/
|
|
||||||
void removeAccount(Transaction txn, AuthorId a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a contact (and all associated state) from the database.
|
* Removes a contact (and all associated state) from the database.
|
||||||
*/
|
*/
|
||||||
@@ -562,6 +558,11 @@ public interface DatabaseComponent {
|
|||||||
void removeHandshakeKeys(Transaction txn, TransportId t,
|
void removeHandshakeKeys(Transaction txn, TransportId t,
|
||||||
HandshakeKeySetId k) throws DbException;
|
HandshakeKeySetId k) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an identity (and all associated state) from the database.
|
||||||
|
*/
|
||||||
|
void removeIdentity(Transaction txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a message (and all associated state) from the database.
|
* Removes a message (and all associated state) from the database.
|
||||||
*/
|
*/
|
||||||
@@ -619,7 +620,7 @@ public interface DatabaseComponent {
|
|||||||
Collection<MessageId> dependencies) throws DbException;
|
Collection<MessageId> dependencies) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the handshake key pair for the account with the given ID.
|
* Sets the handshake key pair for the identity with the given ID.
|
||||||
*/
|
*/
|
||||||
void setHandshakeKeyPair(Transaction txn, AuthorId local, byte[] publicKey,
|
void setHandshakeKeyPair(Transaction txn, AuthorId local, byte[] publicKey,
|
||||||
byte[] privateKey) throws DbException;
|
byte[] privateKey) throws DbException;
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_
|
|||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class Account {
|
public class Identity {
|
||||||
|
|
||||||
private final LocalAuthor localAuthor;
|
private final LocalAuthor localAuthor;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final byte[] handshakePublicKey, handshakePrivateKey;
|
private final byte[] handshakePublicKey, handshakePrivateKey;
|
||||||
private final long created;
|
private final long created;
|
||||||
|
|
||||||
public Account(LocalAuthor localAuthor,
|
public Identity(LocalAuthor localAuthor,
|
||||||
@Nullable byte[] handshakePublicKey,
|
@Nullable byte[] handshakePublicKey,
|
||||||
@Nullable byte[] handshakePrivateKey, long created) {
|
@Nullable byte[] handshakePrivateKey, long created) {
|
||||||
if (handshakePublicKey != null) {
|
if (handshakePublicKey != null) {
|
||||||
@@ -47,7 +47,7 @@ public class Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the account has a handshake key pair.
|
* Returns true if the identity has a handshake key pair.
|
||||||
*/
|
*/
|
||||||
public boolean hasHandshakeKeyPair() {
|
public boolean hasHandshakeKeyPair() {
|
||||||
return handshakePublicKey != null && handshakePrivateKey != null;
|
return handshakePublicKey != null && handshakePrivateKey != null;
|
||||||
@@ -70,7 +70,7 @@ public class Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the time the account was created, in milliseconds since the
|
* Returns the time the identity was created, in milliseconds since the
|
||||||
* Unix epoch.
|
* Unix epoch.
|
||||||
*/
|
*/
|
||||||
public long getTimeCreated() {
|
public long getTimeCreated() {
|
||||||
@@ -84,12 +84,12 @@ public class Account {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Account) {
|
if (o instanceof Identity) {
|
||||||
Account a = (Account) o;
|
Identity i = (Identity) o;
|
||||||
return created == a.created &&
|
return created == i.created &&
|
||||||
localAuthor.equals(a.localAuthor) &&
|
localAuthor.equals(i.localAuthor) &&
|
||||||
Arrays.equals(handshakePublicKey, a.handshakePublicKey) &&
|
Arrays.equals(handshakePublicKey, i.handshakePublicKey) &&
|
||||||
Arrays.equals(handshakePrivateKey, a.handshakePrivateKey);
|
Arrays.equals(handshakePrivateKey, i.handshakePrivateKey);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -11,19 +11,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
public interface IdentityManager {
|
public interface IdentityManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an account with the given name. The account includes a handshake
|
* Creates an identity with the given name. The identity includes a
|
||||||
* key pair.
|
* handshake key pair.
|
||||||
*/
|
*/
|
||||||
@CryptoExecutor
|
@CryptoExecutor
|
||||||
Account createAccount(String name);
|
Identity createIdentity(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the given account with the manager. This method should be
|
* Registers the given identity with the manager. This method should be
|
||||||
* called before {@link LifecycleManager#startServices(SecretKey)}. The
|
* called before {@link LifecycleManager#startServices(SecretKey)}. The
|
||||||
* account is stored when {@link LifecycleManager#startServices(SecretKey)}
|
* identity is stored when {@link LifecycleManager#startServices(SecretKey)}
|
||||||
* is called. The account must include a handshake key pair.
|
* is called. The identity must include a handshake key pair.
|
||||||
*/
|
*/
|
||||||
void registerAccount(Account a);
|
void registerIdentity(Identity i);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cached local identity or loads it from the database.
|
* Returns the cached local identity or loads it from the database.
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import org.briarproject.bramble.api.contact.ContactId;
|
|||||||
import org.briarproject.bramble.api.contact.PendingContact;
|
import org.briarproject.bramble.api.contact.PendingContact;
|
||||||
import org.briarproject.bramble.api.contact.PendingContactId;
|
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
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.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
@@ -101,11 +101,12 @@ public class TestUtils {
|
|||||||
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
return new SecretKey(getRandomBytes(SecretKey.LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account getAccount() {
|
public static Identity getIdentity() {
|
||||||
LocalAuthor localAuthor = getLocalAuthor();
|
LocalAuthor localAuthor = getLocalAuthor();
|
||||||
byte[] handshakePub = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
byte[] handshakePub = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
||||||
byte[] handshakePriv = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
byte[] handshakePriv = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
||||||
return new Account(localAuthor, handshakePub, handshakePriv, timestamp);
|
return new Identity(localAuthor, handshakePub, handshakePriv,
|
||||||
|
timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalAuthor getLocalAuthor() {
|
public static LocalAuthor getLocalAuthor() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import org.briarproject.bramble.api.account.AccountManager;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
@@ -161,8 +161,8 @@ class AccountManagerImpl implements AccountManager {
|
|||||||
synchronized (stateChangeLock) {
|
synchronized (stateChangeLock) {
|
||||||
if (hasDatabaseKey())
|
if (hasDatabaseKey())
|
||||||
throw new AssertionError("Already have a database key");
|
throw new AssertionError("Already have a database key");
|
||||||
Account account = identityManager.createAccount(name);
|
Identity identity = identityManager.createIdentity(name);
|
||||||
identityManager.registerAccount(account);
|
identityManager.registerIdentity(identity);
|
||||||
SecretKey key = crypto.generateSecretKey();
|
SecretKey key = crypto.generateSecretKey();
|
||||||
if (!encryptAndStoreDatabaseKey(key, password)) return false;
|
if (!encryptAndStoreDatabaseKey(key, password)) return false;
|
||||||
databaseKey = key;
|
databaseKey = key;
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import org.briarproject.bramble.api.db.DbException;
|
|||||||
import org.briarproject.bramble.api.db.MessageDeletedException;
|
import org.briarproject.bramble.api.db.MessageDeletedException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.db.MigrationListener;
|
import org.briarproject.bramble.api.db.MigrationListener;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
@@ -86,11 +86,6 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
void commitTransaction(T txn) throws DbException;
|
void commitTransaction(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores an account.
|
|
||||||
*/
|
|
||||||
void addAccount(T txn, Account a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a contact associated with the given local and remote pseudonyms,
|
* Stores a contact associated with the given local and remote pseudonyms,
|
||||||
* and returns an ID for the contact.
|
* and returns an ID for the contact.
|
||||||
@@ -124,6 +119,11 @@ interface Database<T> {
|
|||||||
HandshakeKeySetId addHandshakeKeys(T txn, PendingContactId p,
|
HandshakeKeySetId addHandshakeKeys(T txn, PendingContactId p,
|
||||||
HandshakeKeys k) throws DbException;
|
HandshakeKeys k) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores an identity.
|
||||||
|
*/
|
||||||
|
void addIdentity(T txn, Identity i) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a message.
|
* Stores a message.
|
||||||
*
|
*
|
||||||
@@ -163,13 +163,6 @@ interface Database<T> {
|
|||||||
TransportKeySetId addTransportKeys(T txn, ContactId c, TransportKeys k)
|
TransportKeySetId addTransportKeys(T txn, ContactId c, TransportKeys k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the database contains an account for the given pseudonym.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
boolean containsAccount(T txn, AuthorId a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database contains the given contact for the given
|
* Returns true if the database contains the given contact for the given
|
||||||
* local pseudonym.
|
* local pseudonym.
|
||||||
@@ -193,6 +186,14 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
boolean containsGroup(T txn, GroupId g) throws DbException;
|
boolean containsGroup(T txn, GroupId g) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the database contains an identity for the given
|
||||||
|
* pseudonym.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
boolean containsIdentity(T txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database contains the given message.
|
* Returns true if the database contains the given message.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -245,20 +246,6 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
void deleteMessageMetadata(T txn, MessageId m) throws DbException;
|
void deleteMessageMetadata(T txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the account for local pseudonym with the given ID.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
Account getAccount(T txn, AuthorId a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the accounts for all local pseudonyms.
|
|
||||||
* <p/>
|
|
||||||
* Read-only.
|
|
||||||
*/
|
|
||||||
Collection<Account> getAccounts(T txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the contact with the given ID.
|
* Returns the contact with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -336,6 +323,20 @@ interface Database<T> {
|
|||||||
Collection<HandshakeKeySet> getHandshakeKeys(T txn, TransportId t)
|
Collection<HandshakeKeySet> getHandshakeKeys(T txn, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identity for local pseudonym with the given ID.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Identity getIdentity(T txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the identities for all local pseudonyms.
|
||||||
|
* <p/>
|
||||||
|
* Read-only.
|
||||||
|
*/
|
||||||
|
Collection<Identity> getIdentities(T txn) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message with the given ID.
|
* Returns the message with the given ID.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -605,11 +606,6 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
void raiseSeenFlag(T txn, ContactId c, MessageId m) throws DbException;
|
void raiseSeenFlag(T txn, ContactId c, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an account (and all associated state) from the database.
|
|
||||||
*/
|
|
||||||
void removeAccount(T txn, AuthorId a) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a contact from the database.
|
* Removes a contact from the database.
|
||||||
*/
|
*/
|
||||||
@@ -633,6 +629,11 @@ interface Database<T> {
|
|||||||
void removeHandshakeKeys(T txn, TransportId t, HandshakeKeySetId k)
|
void removeHandshakeKeys(T txn, TransportId t, HandshakeKeySetId k)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an identity (and all associated state) from the database.
|
||||||
|
*/
|
||||||
|
void removeIdentity(T txn, AuthorId a) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a message (and all associated state) from the database.
|
* Removes a message (and all associated state) from the database.
|
||||||
*/
|
*/
|
||||||
@@ -686,7 +687,7 @@ interface Database<T> {
|
|||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the handshake key pair for the account with the given ID.
|
* Sets the handshake key pair for the identity with the given ID.
|
||||||
*/
|
*/
|
||||||
void setHandshakeKeyPair(T txn, AuthorId local, byte[] publicKey,
|
void setHandshakeKeyPair(T txn, AuthorId local, byte[] publicKey,
|
||||||
byte[] privateKey) throws DbException;
|
byte[] privateKey) throws DbException;
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ import org.briarproject.bramble.api.db.TaskAction;
|
|||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.event.EventExecutor;
|
import org.briarproject.bramble.api.event.EventExecutor;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent;
|
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent;
|
||||||
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent;
|
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent;
|
||||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||||
@@ -231,26 +231,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return txnClass.cast(transaction.unbox());
|
return txnClass.cast(transaction.unbox());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAccount(Transaction transaction, Account a)
|
|
||||||
throws DbException {
|
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
if (!db.containsAccount(txn, a.getId())) {
|
|
||||||
db.addAccount(txn, a);
|
|
||||||
transaction.attach(new LocalAuthorAddedEvent(a.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContactId addContact(Transaction transaction, Author remote,
|
public ContactId addContact(Transaction transaction, Author remote,
|
||||||
AuthorId local, boolean verified)
|
AuthorId local, boolean verified)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsAccount(txn, local))
|
if (!db.containsIdentity(txn, local))
|
||||||
throw new NoSuchLocalAuthorException();
|
throw new NoSuchLocalAuthorException();
|
||||||
if (db.containsAccount(txn, remote.getId()))
|
if (db.containsIdentity(txn, remote.getId()))
|
||||||
throw new ContactExistsException();
|
throw new ContactExistsException();
|
||||||
if (db.containsContact(txn, remote.getId(), local))
|
if (db.containsContact(txn, remote.getId(), local))
|
||||||
throw new ContactExistsException();
|
throw new ContactExistsException();
|
||||||
@@ -293,6 +282,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.addHandshakeKeys(txn, p, k);
|
return db.addHandshakeKeys(txn, p, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addIdentity(Transaction transaction, Identity i)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsIdentity(txn, i.getId())) {
|
||||||
|
db.addIdentity(txn, i);
|
||||||
|
transaction.attach(new LocalAuthorAddedEvent(i.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLocalMessage(Transaction transaction, Message m,
|
public void addLocalMessage(Transaction transaction, Message m,
|
||||||
Metadata meta, boolean shared) throws DbException {
|
Metadata meta, boolean shared) throws DbException {
|
||||||
@@ -341,18 +341,11 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.addTransportKeys(txn, c, k);
|
return db.addTransportKeys(txn, c, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsAccount(Transaction transaction, AuthorId local)
|
|
||||||
throws DbException {
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
return db.containsAccount(txn, local);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsContact(Transaction transaction, AuthorId remote,
|
public boolean containsContact(Transaction transaction, AuthorId remote,
|
||||||
AuthorId local) throws DbException {
|
AuthorId local) throws DbException {
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsAccount(txn, local))
|
if (!db.containsIdentity(txn, local))
|
||||||
throw new NoSuchLocalAuthorException();
|
throw new NoSuchLocalAuthorException();
|
||||||
return db.containsContact(txn, remote, local);
|
return db.containsContact(txn, remote, local);
|
||||||
}
|
}
|
||||||
@@ -364,6 +357,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.containsGroup(txn, g);
|
return db.containsGroup(txn, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsIdentity(Transaction transaction, AuthorId a)
|
||||||
|
throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
return db.containsIdentity(txn, a);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsPendingContact(Transaction transaction,
|
public boolean containsPendingContact(Transaction transaction,
|
||||||
PendingContactId p) throws DbException {
|
PendingContactId p) throws DbException {
|
||||||
@@ -478,22 +478,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Account getAccount(Transaction transaction, AuthorId a)
|
|
||||||
throws DbException {
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
if (!db.containsAccount(txn, a))
|
|
||||||
throw new NoSuchLocalAuthorException();
|
|
||||||
return db.getAccount(txn, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Account> getAccounts(Transaction transaction)
|
|
||||||
throws DbException {
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
return db.getAccounts(txn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contact getContact(Transaction transaction, ContactId c)
|
public Contact getContact(Transaction transaction, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -521,7 +505,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
public Collection<ContactId> getContacts(Transaction transaction,
|
public Collection<ContactId> getContacts(Transaction transaction,
|
||||||
AuthorId a) throws DbException {
|
AuthorId a) throws DbException {
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsAccount(txn, a))
|
if (!db.containsIdentity(txn, a))
|
||||||
throw new NoSuchLocalAuthorException();
|
throw new NoSuchLocalAuthorException();
|
||||||
return db.getContacts(txn, a);
|
return db.getContacts(txn, a);
|
||||||
}
|
}
|
||||||
@@ -569,6 +553,22 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
return db.getHandshakeKeys(txn, t);
|
return db.getHandshakeKeys(txn, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identity getIdentity(Transaction transaction, AuthorId a)
|
||||||
|
throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsIdentity(txn, a))
|
||||||
|
throw new NoSuchLocalAuthorException();
|
||||||
|
return db.getIdentity(txn, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Identity> getIdentities(Transaction transaction)
|
||||||
|
throws DbException {
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
return db.getIdentities(txn);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message getMessage(Transaction transaction, MessageId m)
|
public Message getMessage(Transaction transaction, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -868,17 +868,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
if (requested) transaction.attach(new MessageRequestedEvent(c));
|
if (requested) transaction.attach(new MessageRequestedEvent(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAccount(Transaction transaction, AuthorId a)
|
|
||||||
throws DbException {
|
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
|
||||||
T txn = unbox(transaction);
|
|
||||||
if (!db.containsAccount(txn, a))
|
|
||||||
throw new NoSuchLocalAuthorException();
|
|
||||||
db.removeAccount(txn, a);
|
|
||||||
transaction.attach(new LocalAuthorRemovedEvent(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeContact(Transaction transaction, ContactId c)
|
public void removeContact(Transaction transaction, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -915,6 +904,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.removeHandshakeKeys(txn, t, k);
|
db.removeHandshakeKeys(txn, t, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeIdentity(Transaction transaction, AuthorId a)
|
||||||
|
throws DbException {
|
||||||
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
|
T txn = unbox(transaction);
|
||||||
|
if (!db.containsIdentity(txn, a))
|
||||||
|
throw new NoSuchLocalAuthorException();
|
||||||
|
db.removeIdentity(txn, a);
|
||||||
|
transaction.attach(new LocalAuthorRemovedEvent(a));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMessage(Transaction transaction, MessageId m)
|
public void removeMessage(Transaction transaction, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -1040,7 +1040,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
byte[] publicKey, byte[] privateKey) throws DbException {
|
byte[] publicKey, byte[] privateKey) throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsAccount(txn, local))
|
if (!db.containsIdentity(txn, local))
|
||||||
throw new NoSuchLocalAuthorException();
|
throw new NoSuchLocalAuthorException();
|
||||||
db.setHandshakeKeyPair(txn, local, publicKey, privateKey);
|
db.setHandshakeKeyPair(txn, local, publicKey, privateKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import org.briarproject.bramble.api.db.DbException;
|
|||||||
import org.briarproject.bramble.api.db.MessageDeletedException;
|
import org.briarproject.bramble.api.db.MessageDeletedException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.db.MigrationListener;
|
import org.briarproject.bramble.api.db.MigrationListener;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
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.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
@@ -662,35 +662,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if (interrupted) Thread.currentThread().interrupt();
|
if (interrupted) Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAccount(Connection txn, Account a) throws DbException {
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
try {
|
|
||||||
String sql = "INSERT INTO localAuthors"
|
|
||||||
+ " (authorId, formatVersion, name, publicKey, privateKey,"
|
|
||||||
+ " handshakePublicKey, handshakePrivateKey, created)"
|
|
||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
LocalAuthor local = a.getLocalAuthor();
|
|
||||||
ps.setBytes(1, local.getId().getBytes());
|
|
||||||
ps.setInt(2, local.getFormatVersion());
|
|
||||||
ps.setString(3, local.getName());
|
|
||||||
ps.setBytes(4, local.getPublicKey());
|
|
||||||
ps.setBytes(5, local.getPrivateKey());
|
|
||||||
if (a.getHandshakePublicKey() == null) ps.setNull(6, BINARY);
|
|
||||||
else ps.setBytes(6, a.getHandshakePublicKey());
|
|
||||||
if (a.getHandshakePrivateKey() == null) ps.setNull(7, BINARY);
|
|
||||||
else ps.setBytes(7, a.getHandshakePrivateKey());
|
|
||||||
ps.setLong(8, a.getTimeCreated());
|
|
||||||
int affected = ps.executeUpdate();
|
|
||||||
if (affected != 1) throw new DbStateException();
|
|
||||||
ps.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
tryToClose(ps, LOG, WARNING);
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
||||||
boolean verified) throws DbException {
|
boolean verified) throws DbException {
|
||||||
@@ -903,6 +874,35 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addIdentity(Connection txn, Identity i) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
try {
|
||||||
|
String sql = "INSERT INTO localAuthors"
|
||||||
|
+ " (authorId, formatVersion, name, publicKey, privateKey,"
|
||||||
|
+ " handshakePublicKey, handshakePrivateKey, created)"
|
||||||
|
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
LocalAuthor local = i.getLocalAuthor();
|
||||||
|
ps.setBytes(1, local.getId().getBytes());
|
||||||
|
ps.setInt(2, local.getFormatVersion());
|
||||||
|
ps.setString(3, local.getName());
|
||||||
|
ps.setBytes(4, local.getPublicKey());
|
||||||
|
ps.setBytes(5, local.getPrivateKey());
|
||||||
|
if (i.getHandshakePublicKey() == null) ps.setNull(6, BINARY);
|
||||||
|
else ps.setBytes(6, i.getHandshakePublicKey());
|
||||||
|
if (i.getHandshakePrivateKey() == null) ps.setNull(7, BINARY);
|
||||||
|
else ps.setBytes(7, i.getHandshakePrivateKey());
|
||||||
|
ps.setLong(8, i.getTimeCreated());
|
||||||
|
int affected = ps.executeUpdate();
|
||||||
|
if (affected != 1) throw new DbStateException();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMessage(Connection txn, Message m, MessageState state,
|
public void addMessage(Connection txn, Message m, MessageState state,
|
||||||
boolean messageShared, @Nullable ContactId sender)
|
boolean messageShared, @Nullable ContactId sender)
|
||||||
@@ -1180,28 +1180,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsAccount(Connection txn, AuthorId a)
|
|
||||||
throws DbException {
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
String sql = "SELECT NULL FROM localAuthors WHERE authorId = ?";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
ps.setBytes(1, a.getBytes());
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
boolean found = rs.next();
|
|
||||||
if (rs.next()) throw new DbStateException();
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
return found;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
tryToClose(rs, LOG, WARNING);
|
|
||||||
tryToClose(ps, LOG, WARNING);
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsContact(Connection txn, AuthorId remote,
|
public boolean containsContact(Connection txn, AuthorId remote,
|
||||||
AuthorId local) throws DbException {
|
AuthorId local) throws DbException {
|
||||||
@@ -1270,6 +1248,28 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsIdentity(Connection txn, AuthorId a)
|
||||||
|
throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT NULL FROM localAuthors WHERE authorId = ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setBytes(1, a.getBytes());
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
boolean found = rs.next();
|
||||||
|
if (rs.next()) throw new DbStateException();
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return found;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsMessage(Connection txn, MessageId m)
|
public boolean containsMessage(Connection txn, MessageId m)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -1427,76 +1427,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Account getAccount(Connection txn, AuthorId a) throws DbException {
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
String sql = "SELECT formatVersion, name, publicKey, privateKey,"
|
|
||||||
+ " handshakePublicKey, handshakePrivateKey, created"
|
|
||||||
+ " FROM localAuthors"
|
|
||||||
+ " WHERE authorId = ?";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
ps.setBytes(1, a.getBytes());
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
if (!rs.next()) throw new DbStateException();
|
|
||||||
int formatVersion = rs.getInt(1);
|
|
||||||
String name = rs.getString(2);
|
|
||||||
byte[] publicKey = rs.getBytes(3);
|
|
||||||
byte[] privateKey = rs.getBytes(4);
|
|
||||||
byte[] handshakePublicKey = rs.getBytes(5);
|
|
||||||
byte[] handshakePrivateKey = rs.getBytes(6);
|
|
||||||
long created = rs.getLong(7);
|
|
||||||
if (rs.next()) throw new DbStateException();
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
LocalAuthor local = new LocalAuthor(a, formatVersion, name,
|
|
||||||
publicKey, privateKey);
|
|
||||||
return new Account(local, handshakePublicKey, handshakePrivateKey,
|
|
||||||
created);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
tryToClose(rs, LOG, WARNING);
|
|
||||||
tryToClose(ps, LOG, WARNING);
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<Account> getAccounts(Connection txn) throws DbException {
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
String sql = "SELECT authorId, formatVersion, name, publicKey,"
|
|
||||||
+ " privateKey, handshakePublicKey, handshakePrivateKey,"
|
|
||||||
+ " created"
|
|
||||||
+ " FROM localAuthors";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
rs = ps.executeQuery();
|
|
||||||
List<Account> accounts = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
AuthorId authorId = new AuthorId(rs.getBytes(1));
|
|
||||||
int formatVersion = rs.getInt(2);
|
|
||||||
String name = rs.getString(3);
|
|
||||||
byte[] publicKey = rs.getBytes(4);
|
|
||||||
byte[] privateKey = rs.getBytes(5);
|
|
||||||
byte[] handshakePublicKey = rs.getBytes(6);
|
|
||||||
byte[] handshakePrivateKey = rs.getBytes(7);
|
|
||||||
long created = rs.getLong(8);
|
|
||||||
LocalAuthor local = new LocalAuthor(authorId, formatVersion,
|
|
||||||
name, publicKey, privateKey);
|
|
||||||
accounts.add(new Account(local, handshakePublicKey,
|
|
||||||
handshakePrivateKey, created));
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
ps.close();
|
|
||||||
return accounts;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
tryToClose(rs, LOG, WARNING);
|
|
||||||
tryToClose(ps, LOG, WARNING);
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Contact getContact(Connection txn, ContactId c) throws DbException {
|
public Contact getContact(Connection txn, ContactId c) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
@@ -1811,6 +1741,77 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identity getIdentity(Connection txn, AuthorId a) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT formatVersion, name, publicKey, privateKey,"
|
||||||
|
+ " handshakePublicKey, handshakePrivateKey, created"
|
||||||
|
+ " FROM localAuthors"
|
||||||
|
+ " WHERE authorId = ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setBytes(1, a.getBytes());
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
if (!rs.next()) throw new DbStateException();
|
||||||
|
int formatVersion = rs.getInt(1);
|
||||||
|
String name = rs.getString(2);
|
||||||
|
byte[] publicKey = rs.getBytes(3);
|
||||||
|
byte[] privateKey = rs.getBytes(4);
|
||||||
|
byte[] handshakePublicKey = rs.getBytes(5);
|
||||||
|
byte[] handshakePrivateKey = rs.getBytes(6);
|
||||||
|
long created = rs.getLong(7);
|
||||||
|
if (rs.next()) throw new DbStateException();
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
LocalAuthor local = new LocalAuthor(a, formatVersion, name,
|
||||||
|
publicKey, privateKey);
|
||||||
|
return new Identity(local, handshakePublicKey, handshakePrivateKey,
|
||||||
|
created);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Identity> getIdentities(Connection txn)
|
||||||
|
throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT authorId, formatVersion, name, publicKey,"
|
||||||
|
+ " privateKey, handshakePublicKey, handshakePrivateKey,"
|
||||||
|
+ " created"
|
||||||
|
+ " FROM localAuthors";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
List<Identity> identities = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
AuthorId authorId = new AuthorId(rs.getBytes(1));
|
||||||
|
int formatVersion = rs.getInt(2);
|
||||||
|
String name = rs.getString(3);
|
||||||
|
byte[] publicKey = rs.getBytes(4);
|
||||||
|
byte[] privateKey = rs.getBytes(5);
|
||||||
|
byte[] handshakePublicKey = rs.getBytes(6);
|
||||||
|
byte[] handshakePrivateKey = rs.getBytes(7);
|
||||||
|
long created = rs.getLong(8);
|
||||||
|
LocalAuthor local = new LocalAuthor(authorId, formatVersion,
|
||||||
|
name, publicKey, privateKey);
|
||||||
|
identities.add(new Identity(local, handshakePublicKey,
|
||||||
|
handshakePrivateKey, created));
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
return identities;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(rs, LOG, WARNING);
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message getMessage(Connection txn, MessageId m) throws DbException {
|
public Message getMessage(Connection txn, MessageId m) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
@@ -2879,22 +2880,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAccount(Connection txn, AuthorId a) throws DbException {
|
|
||||||
PreparedStatement ps = null;
|
|
||||||
try {
|
|
||||||
String sql = "DELETE FROM localAuthors WHERE authorId = ?";
|
|
||||||
ps = txn.prepareStatement(sql);
|
|
||||||
ps.setBytes(1, a.getBytes());
|
|
||||||
int affected = ps.executeUpdate();
|
|
||||||
if (affected != 1) throw new DbStateException();
|
|
||||||
ps.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
tryToClose(ps, LOG, WARNING);
|
|
||||||
throw new DbException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeContact(Connection txn, ContactId c)
|
public void removeContact(Connection txn, ContactId c)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
@@ -2977,6 +2962,22 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeIdentity(Connection txn, AuthorId a) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM localAuthors WHERE authorId = ?";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setBytes(1, a.getBytes());
|
||||||
|
int affected = ps.executeUpdate();
|
||||||
|
if (affected != 1) throw new DbStateException();
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
tryToClose(ps, LOG, WARNING);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMessage(Connection txn, MessageId m) throws DbException {
|
public void removeMessage(Connection txn, MessageId m) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import org.briarproject.bramble.api.crypto.KeyPair;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
|
||||||
@@ -38,23 +38,23 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user's account, or null if no account has been registered or loaded.
|
* The user's identity, or null if no identity has been registered or
|
||||||
* If non-null, this account always has handshake keys.
|
* loaded. If non-null, this identity always has handshake keys.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile Account cachedAccount = null;
|
private volatile Identity cachedIdentity = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if {@code cachedAccount} was registered via
|
* True if {@code cachedIdentity} was registered via
|
||||||
* {@link #registerAccount(Account)} and should be stored when
|
* {@link #registerIdentity(Identity)} and should be stored when
|
||||||
* {@link #onDatabaseOpened(Transaction)} is called.
|
* {@link #onDatabaseOpened(Transaction)} is called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private volatile boolean shouldStoreAccount = false;
|
private volatile boolean shouldStoreIdentity = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the handshake keys in {@code cachedAccount} were generated when
|
* True if the handshake keys in {@code cachedIdentity} were generated
|
||||||
* the account was loaded and should be stored when
|
* when the identity was loaded and should be stored when
|
||||||
* {@link #onDatabaseOpened(Transaction)} is called.
|
* {@link #onDatabaseOpened(Transaction)} is called.
|
||||||
*/
|
*/
|
||||||
private volatile boolean shouldStoreKeys = false;
|
private volatile boolean shouldStoreKeys = false;
|
||||||
@@ -69,31 +69,31 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Account createAccount(String name) {
|
public Identity createIdentity(String name) {
|
||||||
long start = now();
|
long start = now();
|
||||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name);
|
LocalAuthor localAuthor = authorFactory.createLocalAuthor(name);
|
||||||
KeyPair handshakeKeyPair = crypto.generateAgreementKeyPair();
|
KeyPair handshakeKeyPair = crypto.generateAgreementKeyPair();
|
||||||
byte[] handshakePub = handshakeKeyPair.getPublic().getEncoded();
|
byte[] handshakePub = handshakeKeyPair.getPublic().getEncoded();
|
||||||
byte[] handshakePriv = handshakeKeyPair.getPrivate().getEncoded();
|
byte[] handshakePriv = handshakeKeyPair.getPrivate().getEncoded();
|
||||||
logDuration(LOG, "Creating account", start);
|
logDuration(LOG, "Creating identity", start);
|
||||||
return new Account(localAuthor, handshakePub, handshakePriv,
|
return new Identity(localAuthor, handshakePub, handshakePriv,
|
||||||
clock.currentTimeMillis());
|
clock.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerAccount(Account a) {
|
public void registerIdentity(Identity i) {
|
||||||
if (!a.hasHandshakeKeyPair()) throw new IllegalArgumentException();
|
if (!i.hasHandshakeKeyPair()) throw new IllegalArgumentException();
|
||||||
cachedAccount = a;
|
cachedIdentity = i;
|
||||||
shouldStoreAccount = true;
|
shouldStoreIdentity = true;
|
||||||
LOG.info("Account registered");
|
LOG.info("Identity registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatabaseOpened(Transaction txn) throws DbException {
|
public void onDatabaseOpened(Transaction txn) throws DbException {
|
||||||
Account cached = getCachedAccount(txn);
|
Identity cached = getCachedIdentity(txn);
|
||||||
if (shouldStoreAccount) {
|
if (shouldStoreIdentity) {
|
||||||
db.addAccount(txn, cached);
|
db.addIdentity(txn, cached);
|
||||||
LOG.info("Account stored");
|
LOG.info("Identity stored");
|
||||||
} else if (shouldStoreKeys) {
|
} else if (shouldStoreKeys) {
|
||||||
byte[] publicKey = requireNonNull(cached.getHandshakePublicKey());
|
byte[] publicKey = requireNonNull(cached.getHandshakePublicKey());
|
||||||
byte[] privateKey = requireNonNull(cached.getHandshakePrivateKey());
|
byte[] privateKey = requireNonNull(cached.getHandshakePrivateKey());
|
||||||
@@ -104,49 +104,50 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor getLocalAuthor() throws DbException {
|
public LocalAuthor getLocalAuthor() throws DbException {
|
||||||
Account cached = cachedAccount;
|
Identity cached = cachedIdentity;
|
||||||
if (cached == null)
|
if (cached == null)
|
||||||
cached = db.transactionWithResult(true, this::getCachedAccount);
|
cached = db.transactionWithResult(true, this::getCachedIdentity);
|
||||||
return cached.getLocalAuthor();
|
return cached.getLocalAuthor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
||||||
return getCachedAccount(txn).getLocalAuthor();
|
return getCachedIdentity(txn).getLocalAuthor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[][] getHandshakeKeys(Transaction txn) throws DbException {
|
public byte[][] getHandshakeKeys(Transaction txn) throws DbException {
|
||||||
Account cached = getCachedAccount(txn);
|
Identity cached = getCachedIdentity(txn);
|
||||||
return new byte[][] {
|
return new byte[][] {
|
||||||
cached.getHandshakePublicKey(),
|
cached.getHandshakePublicKey(),
|
||||||
cached.getHandshakePrivateKey()
|
cached.getHandshakePrivateKey()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account getCachedAccount(Transaction txn) throws DbException {
|
private Identity getCachedIdentity(Transaction txn) throws DbException {
|
||||||
Account cached = cachedAccount;
|
Identity cached = cachedIdentity;
|
||||||
if (cached == null)
|
if (cached == null)
|
||||||
cachedAccount = cached = loadAccountWithKeyPair(txn);
|
cachedIdentity = cached = loadIdentityWithKeyPair(txn);
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account loadAccountWithKeyPair(Transaction txn) throws DbException {
|
private Identity loadIdentityWithKeyPair(Transaction txn)
|
||||||
Account a = loadAccount(txn);
|
throws DbException {
|
||||||
LOG.info("Account loaded");
|
Identity i = loadIdentity(txn);
|
||||||
if (a.hasHandshakeKeyPair()) return a;
|
LOG.info("Identity loaded");
|
||||||
|
if (i.hasHandshakeKeyPair()) return i;
|
||||||
KeyPair keyPair = crypto.generateAgreementKeyPair();
|
KeyPair keyPair = crypto.generateAgreementKeyPair();
|
||||||
byte[] publicKey = keyPair.getPublic().getEncoded();
|
byte[] publicKey = keyPair.getPublic().getEncoded();
|
||||||
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
byte[] privateKey = keyPair.getPrivate().getEncoded();
|
||||||
LOG.info("Handshake key pair generated");
|
LOG.info("Handshake key pair generated");
|
||||||
shouldStoreKeys = true;
|
shouldStoreKeys = true;
|
||||||
return new Account(a.getLocalAuthor(), publicKey, privateKey,
|
return new Identity(i.getLocalAuthor(), publicKey, privateKey,
|
||||||
a.getTimeCreated());
|
i.getTimeCreated());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account loadAccount(Transaction txn) throws DbException {
|
private Identity loadIdentity(Transaction txn) throws DbException {
|
||||||
Collection<Account> accounts = db.getAccounts(txn);
|
Collection<Identity> identities = db.getIdentities(txn);
|
||||||
if (accounts.size() != 1) throw new DbException();
|
if (identities.size() != 1) throw new DbException();
|
||||||
return accounts.iterator().next();
|
return identities.iterator().next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.briarproject.bramble.account;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
@@ -25,7 +25,7 @@ import static junit.framework.Assert.assertFalse;
|
|||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
||||||
@@ -48,8 +48,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final String encryptedKeyHex = toHexString(encryptedKey);
|
private final String encryptedKeyHex = toHexString(encryptedKey);
|
||||||
private final byte[] newEncryptedKey = getRandomBytes(123);
|
private final byte[] newEncryptedKey = getRandomBytes(123);
|
||||||
private final String newEncryptedKeyHex = toHexString(newEncryptedKey);
|
private final String newEncryptedKeyHex = toHexString(newEncryptedKey);
|
||||||
private final Account account = getAccount();
|
private final Identity identity = getIdentity();
|
||||||
private final LocalAuthor localAuthor = account.getLocalAuthor();
|
private final LocalAuthor localAuthor = identity.getLocalAuthor();
|
||||||
private final String authorName = localAuthor.getName();
|
private final String authorName = localAuthor.getName();
|
||||||
private final String password = getRandomString(10);
|
private final String password = getRandomString(10);
|
||||||
private final String newPassword = getRandomString(10);
|
private final String newPassword = getRandomString(10);
|
||||||
@@ -253,9 +253,9 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testCreateAccountStoresDbKey() throws Exception {
|
public void testCreateAccountStoresDbKey() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(identityManager).createAccount(authorName);
|
oneOf(identityManager).createIdentity(authorName);
|
||||||
will(returnValue(account));
|
will(returnValue(identity));
|
||||||
oneOf(identityManager).registerAccount(account);
|
oneOf(identityManager).registerIdentity(identity);
|
||||||
oneOf(crypto).generateSecretKey();
|
oneOf(crypto).generateSecretKey();
|
||||||
will(returnValue(key));
|
will(returnValue(key));
|
||||||
oneOf(crypto).encryptWithPassword(key.getBytes(), password);
|
oneOf(crypto).encryptWithPassword(key.getBytes(), password);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import org.briarproject.bramble.api.db.NoSuchPendingContactException;
|
|||||||
import org.briarproject.bramble.api.db.NoSuchTransportException;
|
import org.briarproject.bramble.api.db.NoSuchTransportException;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent;
|
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent;
|
||||||
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent;
|
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent;
|
||||||
@@ -75,11 +75,11 @@ import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERE
|
|||||||
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
|
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
|
||||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
@@ -107,7 +107,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Author author;
|
private final Author author;
|
||||||
private final Account account;
|
private final Identity identity;
|
||||||
private final LocalAuthor localAuthor;
|
private final LocalAuthor localAuthor;
|
||||||
private final String alias;
|
private final String alias;
|
||||||
private final Message message, message1;
|
private final Message message, message1;
|
||||||
@@ -126,8 +126,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
group = getGroup(clientId, majorVersion);
|
group = getGroup(clientId, majorVersion);
|
||||||
groupId = group.getId();
|
groupId = group.getId();
|
||||||
author = getAuthor();
|
author = getAuthor();
|
||||||
account = getAccount();
|
identity = getIdentity();
|
||||||
localAuthor = account.getLocalAuthor();
|
localAuthor = identity.getLocalAuthor();
|
||||||
message = getMessage(groupId);
|
message = getMessage(groupId);
|
||||||
message1 = getMessage(groupId);
|
message1 = getMessage(groupId);
|
||||||
messageId = message.getId();
|
messageId = message.getId();
|
||||||
@@ -162,15 +162,15 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
// startTransaction()
|
// startTransaction()
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
// addAccount()
|
// addIdentity()
|
||||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).addAccount(txn, account);
|
oneOf(database).addIdentity(txn, identity);
|
||||||
oneOf(eventBus).broadcast(with(any(LocalAuthorAddedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(LocalAuthorAddedEvent.class)));
|
||||||
// addContact()
|
// addContact()
|
||||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).containsAccount(txn, author.getId());
|
oneOf(database).containsIdentity(txn, author.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).containsContact(txn, author.getId(),
|
oneOf(database).containsContact(txn, author.getId(),
|
||||||
localAuthor.getId());
|
localAuthor.getId());
|
||||||
@@ -206,10 +206,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).removeContact(txn, contactId);
|
oneOf(database).removeContact(txn, contactId);
|
||||||
oneOf(eventBus).broadcast(with(any(ContactRemovedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(ContactRemovedEvent.class)));
|
||||||
// removeAccount()
|
// removeIdentity()
|
||||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).removeAccount(txn, localAuthor.getId());
|
oneOf(database).removeIdentity(txn, localAuthor.getId());
|
||||||
oneOf(eventBus).broadcast(with(any(LocalAuthorRemovedEvent.class)));
|
oneOf(eventBus).broadcast(with(any(LocalAuthorRemovedEvent.class)));
|
||||||
// endTransaction()
|
// endTransaction()
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
@@ -221,7 +221,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
assertFalse(db.open(key, null));
|
assertFalse(db.open(key, null));
|
||||||
db.transaction(false, transaction -> {
|
db.transaction(false, transaction -> {
|
||||||
db.addAccount(transaction, account);
|
db.addIdentity(transaction, identity);
|
||||||
assertEquals(contactId, db.addContact(transaction, author,
|
assertEquals(contactId, db.addContact(transaction, author,
|
||||||
localAuthor.getId(), true));
|
localAuthor.getId(), true));
|
||||||
assertEquals(singletonList(contact),
|
assertEquals(singletonList(contact),
|
||||||
@@ -232,7 +232,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
db.getGroups(transaction, clientId, majorVersion));
|
db.getGroups(transaction, clientId, majorVersion));
|
||||||
db.removeGroup(transaction, group);
|
db.removeGroup(transaction, group);
|
||||||
db.removeContact(transaction, contactId);
|
db.removeContact(transaction, contactId);
|
||||||
db.removeAccount(transaction, localAuthor.getId());
|
db.removeIdentity(transaction, localAuthor.getId());
|
||||||
});
|
});
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
@@ -437,13 +437,13 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariousMethodsThrowExceptionIfAccountIsMissing()
|
public void testVariousMethodsThrowExceptionIfIdentityIsMissing()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether the account is in the DB (which it's not)
|
// Check whether the identity is in the DB (which it's not)
|
||||||
exactly(4).of(database).startTransaction();
|
exactly(4).of(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
exactly(4).of(database).containsAccount(txn, localAuthor.getId());
|
exactly(4).of(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
exactly(4).of(database).abortTransaction(txn);
|
exactly(4).of(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -461,7 +461,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.getAccount(transaction, localAuthor.getId()));
|
db.getIdentity(transaction, localAuthor.getId()));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchLocalAuthorException expected) {
|
} catch (NoSuchLocalAuthorException expected) {
|
||||||
// Expected
|
// Expected
|
||||||
@@ -469,7 +469,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
db.transaction(false, transaction ->
|
db.transaction(false, transaction ->
|
||||||
db.removeAccount(transaction, localAuthor.getId()));
|
db.removeIdentity(transaction, localAuthor.getId()));
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchLocalAuthorException expected) {
|
} catch (NoSuchLocalAuthorException expected) {
|
||||||
// Expected
|
// Expected
|
||||||
@@ -1418,10 +1418,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
// Contact is a local identity
|
// Contact is a local identity
|
||||||
oneOf(database).containsAccount(txn, author.getId());
|
oneOf(database).containsIdentity(txn, author.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).abortTransaction(txn);
|
oneOf(database).abortTransaction(txn);
|
||||||
}});
|
}});
|
||||||
@@ -1444,9 +1444,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).containsAccount(txn, author.getId());
|
oneOf(database).containsIdentity(txn, author.getId());
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
// Contact already exists for this local identity
|
// Contact already exists for this local identity
|
||||||
oneOf(database).containsContact(txn, author.getId(),
|
oneOf(database).containsContact(txn, author.getId(),
|
||||||
@@ -1469,7 +1469,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testMessageDependencies() throws Exception {
|
public void testMessageDependencies() throws Exception {
|
||||||
int shutdownHandle = 12345;
|
int shutdownHandle = 12345;
|
||||||
MessageId messageId2 = new MessageId(getRandomId());
|
MessageId messageId2 = new MessageId(getRandomId());
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import org.briarproject.bramble.api.contact.Contact;
|
|||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.AuthorId;
|
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.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
@@ -36,9 +36,9 @@ import static java.util.logging.Level.OFF;
|
|||||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
@@ -162,11 +162,11 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsAccount() throws Exception {
|
public void testContainsIdentity() throws Exception {
|
||||||
String name = "containsAccount(T, AuthorId)";
|
String name = "containsIdentity(T, AuthorId)";
|
||||||
benchmark(name, db -> {
|
benchmark(name, db -> {
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
db.containsAccount(txn, localAuthor.getId());
|
db.containsIdentity(txn, localAuthor.getId());
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -296,21 +296,21 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccount() throws Exception {
|
public void testGetIdentity() throws Exception {
|
||||||
String name = "getAccount(T, AuthorId)";
|
String name = "getIdentity(T, AuthorId)";
|
||||||
benchmark(name, db -> {
|
benchmark(name, db -> {
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
db.getAccount(txn, localAuthor.getId());
|
db.getIdentity(txn, localAuthor.getId());
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAccounts() throws Exception {
|
public void testGetIdentities() throws Exception {
|
||||||
String name = "getAccounts(T)";
|
String name = "getIdentities(T)";
|
||||||
benchmark(name, db -> {
|
benchmark(name, db -> {
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
db.getAccounts(txn);
|
db.getIdentities(txn);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -532,8 +532,8 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void populateDatabase(Database<Connection> db) throws DbException {
|
void populateDatabase(Database<Connection> db) throws DbException {
|
||||||
Account account = getAccount();
|
Identity identity = getIdentity();
|
||||||
localAuthor = account.getLocalAuthor();
|
localAuthor = identity.getLocalAuthor();
|
||||||
clientIds = new ArrayList<>();
|
clientIds = new ArrayList<>();
|
||||||
contacts = new ArrayList<>();
|
contacts = new ArrayList<>();
|
||||||
groups = new ArrayList<>();
|
groups = new ArrayList<>();
|
||||||
@@ -545,7 +545,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
|||||||
for (int i = 0; i < CLIENTS; i++) clientIds.add(getClientId());
|
for (int i = 0; i < CLIENTS; i++) clientIds.add(getClientId());
|
||||||
|
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
for (int i = 0; i < CONTACTS; i++) {
|
for (int i = 0; i < CONTACTS; i++) {
|
||||||
ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(),
|
ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(),
|
||||||
random.nextBoolean());
|
random.nextBoolean());
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import org.briarproject.bramble.api.db.DatabaseConfig;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.MessageDeletedException;
|
import org.briarproject.bramble.api.db.MessageDeletedException;
|
||||||
import org.briarproject.bramble.api.db.Metadata;
|
import org.briarproject.bramble.api.db.Metadata;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
@@ -72,10 +72,10 @@ import static org.briarproject.bramble.db.DatabaseConstants.DB_SETTINGS_NAMESPAC
|
|||||||
import static org.briarproject.bramble.db.DatabaseConstants.LAST_COMPACTED_KEY;
|
import static org.briarproject.bramble.db.DatabaseConstants.LAST_COMPACTED_KEY;
|
||||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_COMPACTION_INTERVAL_MS;
|
import static org.briarproject.bramble.db.DatabaseConstants.MAX_COMPACTION_INTERVAL_MS;
|
||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getPendingContact;
|
import static org.briarproject.bramble.test.TestUtils.getPendingContact;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||||
@@ -106,7 +106,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
private final int majorVersion;
|
private final int majorVersion;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final Author author;
|
private final Author author;
|
||||||
private final Account account;
|
private final Identity identity;
|
||||||
private final LocalAuthor localAuthor;
|
private final LocalAuthor localAuthor;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
private final MessageId messageId;
|
private final MessageId messageId;
|
||||||
@@ -123,8 +123,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
group = getGroup(clientId, majorVersion);
|
group = getGroup(clientId, majorVersion);
|
||||||
groupId = group.getId();
|
groupId = group.getId();
|
||||||
author = getAuthor();
|
author = getAuthor();
|
||||||
account = getAccount();
|
identity = getIdentity();
|
||||||
localAuthor = account.getLocalAuthor();
|
localAuthor = identity.getLocalAuthor();
|
||||||
message = getMessage(groupId);
|
message = getMessage(groupId);
|
||||||
messageId = message.getId();
|
messageId = message.getId();
|
||||||
transportId = getTransportId();
|
transportId = getTransportId();
|
||||||
@@ -150,7 +150,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
assertFalse(db.containsContact(txn, contactId));
|
assertFalse(db.containsContact(txn, contactId));
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
assertTrue(db.containsContact(txn, contactId));
|
assertTrue(db.containsContact(txn, contactId));
|
||||||
@@ -213,7 +213,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -244,7 +244,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared but unvalidated message
|
// Add a contact, a shared group and a shared but unvalidated message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -289,7 +289,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, an invisible group and a shared message
|
// Add a contact, an invisible group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -340,7 +340,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and an unshared message
|
// Add a contact, a shared group and an unshared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -371,7 +371,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -398,7 +398,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and a visible group
|
// Add a contact and a visible group
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -439,7 +439,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -571,7 +571,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and a shared group
|
// Add a contact and a shared group
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -591,7 +591,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact
|
// Add a contact
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
|
|
||||||
@@ -609,7 +609,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, an invisible group and a message
|
// Add a contact, an invisible group and a message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -628,7 +628,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact and a group
|
// Add a contact and a group
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -680,7 +680,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
assertEquals(emptyList(), db.getTransportKeys(txn, transportId));
|
assertEquals(emptyList(), db.getTransportKeys(txn, transportId));
|
||||||
|
|
||||||
// Add the contact, the transport and the transport keys
|
// Add the contact, the transport and the transport keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -781,7 +781,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
assertEquals(emptyList(), db.getHandshakeKeys(txn, transportId));
|
assertEquals(emptyList(), db.getHandshakeKeys(txn, transportId));
|
||||||
|
|
||||||
// Add the contact, the transport and the handshake keys
|
// Add the contact, the transport and the handshake keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -934,7 +934,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, transport and transport keys
|
// Add the contact, transport and transport keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -978,7 +978,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, transport and handshake keys
|
// Add the contact, transport and handshake keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -1025,7 +1025,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, transport and transport keys
|
// Add the contact, transport and transport keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -1072,7 +1072,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add the contact, transport and handshake keys
|
// Add the contact, transport and handshake keys
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addTransport(txn, transportId, 123);
|
db.addTransport(txn, transportId, 123);
|
||||||
@@ -1114,14 +1114,15 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add an account for a local author - no contacts should be associated
|
// Add an identity for a local author - no contacts should be
|
||||||
db.addAccount(txn, account);
|
// associated
|
||||||
|
db.addIdentity(txn, identity);
|
||||||
|
|
||||||
// Add a contact associated with the local author
|
// Add a contact associated with the local author
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
|
|
||||||
// Ensure contact is returned from database by Author ID
|
// Ensure contact is returned from database by author ID
|
||||||
Collection<Contact> contacts =
|
Collection<Contact> contacts =
|
||||||
db.getContactsByAuthorId(txn, author.getId());
|
db.getContactsByAuthorId(txn, author.getId());
|
||||||
assertEquals(1, contacts.size());
|
assertEquals(1, contacts.size());
|
||||||
@@ -1141,8 +1142,9 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add an account for a local author - no contacts should be associated
|
// Add an identity for a local author - no contacts should be
|
||||||
db.addAccount(txn, account);
|
// associated
|
||||||
|
db.addIdentity(txn, identity);
|
||||||
Collection<ContactId> contacts =
|
Collection<ContactId> contacts =
|
||||||
db.getContacts(txn, localAuthor.getId());
|
db.getContacts(txn, localAuthor.getId());
|
||||||
assertEquals(emptyList(), contacts);
|
assertEquals(emptyList(), contacts);
|
||||||
@@ -1153,8 +1155,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
contacts = db.getContacts(txn, localAuthor.getId());
|
contacts = db.getContacts(txn, localAuthor.getId());
|
||||||
assertEquals(singletonList(contactId), contacts);
|
assertEquals(singletonList(contactId), contacts);
|
||||||
|
|
||||||
// Remove the account - the contact should be removed
|
// Remove the identity - the contact should be removed
|
||||||
db.removeAccount(txn, localAuthor.getId());
|
db.removeIdentity(txn, localAuthor.getId());
|
||||||
contacts = db.getContacts(txn, localAuthor.getId());
|
contacts = db.getContacts(txn, localAuthor.getId());
|
||||||
assertEquals(emptyList(), contacts);
|
assertEquals(emptyList(), contacts);
|
||||||
assertFalse(db.containsContact(txn, contactId));
|
assertFalse(db.containsContact(txn, contactId));
|
||||||
@@ -1169,7 +1171,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact - initially there should be no offered messages
|
// Add a contact - initially there should be no offered messages
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
||||||
@@ -1753,7 +1755,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -1855,15 +1857,15 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testDifferentLocalAuthorsCanHaveTheSameContact()
|
public void testDifferentLocalAuthorsCanHaveTheSameContact()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Account account1 = getAccount();
|
Identity identity1 = getIdentity();
|
||||||
LocalAuthor localAuthor1 = account1.getLocalAuthor();
|
LocalAuthor localAuthor1 = identity1.getLocalAuthor();
|
||||||
|
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add accounts for two local authors
|
// Add identities for two local authors
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
db.addAccount(txn, account1);
|
db.addIdentity(txn, identity1);
|
||||||
|
|
||||||
// Add the same contact for each local author
|
// Add the same contact for each local author
|
||||||
ContactId contactId =
|
ContactId contactId =
|
||||||
@@ -1887,7 +1889,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -1941,7 +1943,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact
|
// Add a contact
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
|
|
||||||
@@ -1998,7 +2000,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a group and a message
|
// Add a contact, a group and a message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -2082,7 +2084,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -2127,7 +2129,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact, a shared group and a shared message
|
// Add a contact, a shared group and a shared message
|
||||||
db.addAccount(txn, account);
|
db.addIdentity(txn, identity);
|
||||||
assertEquals(contactId,
|
assertEquals(contactId,
|
||||||
db.addContact(txn, author, localAuthor.getId(), true));
|
db.addContact(txn, author, localAuthor.getId(), true));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
@@ -2245,8 +2247,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetHandshakeKeyPair() throws Exception {
|
public void testSetHandshakeKeyPair() throws Exception {
|
||||||
Account withoutKeys =
|
Identity withoutKeys =
|
||||||
new Account(localAuthor, null, null, account.getTimeCreated());
|
new Identity(localAuthor, null, null, identity.getTimeCreated());
|
||||||
assertFalse(withoutKeys.hasHandshakeKeyPair());
|
assertFalse(withoutKeys.hasHandshakeKeyPair());
|
||||||
byte[] publicKey = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
byte[] publicKey = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
||||||
byte[] privateKey = getRandomBytes(123);
|
byte[] privateKey = getRandomBytes(123);
|
||||||
@@ -2254,11 +2256,11 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
db.addAccount(txn, withoutKeys);
|
db.addIdentity(txn, withoutKeys);
|
||||||
Account retrieved = db.getAccount(txn, localAuthor.getId());
|
Identity retrieved = db.getIdentity(txn, localAuthor.getId());
|
||||||
assertFalse(retrieved.hasHandshakeKeyPair());
|
assertFalse(retrieved.hasHandshakeKeyPair());
|
||||||
db.setHandshakeKeyPair(txn, localAuthor.getId(), publicKey, privateKey);
|
db.setHandshakeKeyPair(txn, localAuthor.getId(), publicKey, privateKey);
|
||||||
retrieved = db.getAccount(txn, localAuthor.getId());
|
retrieved = db.getIdentity(txn, localAuthor.getId());
|
||||||
assertTrue(retrieved.hasHandshakeKeyPair());
|
assertTrue(retrieved.hasHandshakeKeyPair());
|
||||||
assertArrayEquals(publicKey, retrieved.getHandshakePublicKey());
|
assertArrayEquals(publicKey, retrieved.getHandshakePublicKey());
|
||||||
assertArrayEquals(privateKey, retrieved.getHandshakePrivateKey());
|
assertArrayEquals(privateKey, retrieved.getHandshakePrivateKey());
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import org.briarproject.bramble.api.crypto.PublicKey;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
@@ -18,7 +18,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class IdentityManagerImplTest extends BrambleMockTestCase {
|
public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||||
@@ -33,16 +33,16 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
context.mock(PrivateKey.class);
|
context.mock(PrivateKey.class);
|
||||||
|
|
||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
private final Account accountWithKeys = getAccount();
|
private final Identity identityWithKeys = getIdentity();
|
||||||
private final LocalAuthor localAuthor = accountWithKeys.getLocalAuthor();
|
private final LocalAuthor localAuthor = identityWithKeys.getLocalAuthor();
|
||||||
private final Account accountWithoutKeys = new Account(localAuthor,
|
private final Identity identityWithoutKeys = new Identity(localAuthor,
|
||||||
null, null, accountWithKeys.getTimeCreated());
|
null, null, identityWithKeys.getTimeCreated());
|
||||||
private final KeyPair handshakeKeyPair =
|
private final KeyPair handshakeKeyPair =
|
||||||
new KeyPair(handshakePublicKey, handshakePrivateKey);
|
new KeyPair(handshakePublicKey, handshakePrivateKey);
|
||||||
private final byte[] handshakePublicKeyBytes =
|
private final byte[] handshakePublicKeyBytes =
|
||||||
accountWithKeys.getHandshakePublicKey();
|
identityWithKeys.getHandshakePublicKey();
|
||||||
private final byte[] handshakePrivateKeyBytes =
|
private final byte[] handshakePrivateKeyBytes =
|
||||||
accountWithKeys.getHandshakePrivateKey();
|
identityWithKeys.getHandshakePrivateKey();
|
||||||
|
|
||||||
private IdentityManagerImpl identityManager;
|
private IdentityManagerImpl identityManager;
|
||||||
|
|
||||||
@@ -53,20 +53,20 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenDatabaseAccountRegistered() throws Exception {
|
public void testOpenDatabaseIdentityRegistered() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).addAccount(txn, accountWithKeys);
|
oneOf(db).addIdentity(txn, identityWithKeys);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
identityManager.registerAccount(accountWithKeys);
|
identityManager.registerIdentity(identityWithKeys);
|
||||||
identityManager.onDatabaseOpened(txn);
|
identityManager.onDatabaseOpened(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOpenDatabaseHandshakeKeysGenerated() throws Exception {
|
public void testOpenDatabaseHandshakeKeysGenerated() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getAccounts(txn);
|
oneOf(db).getIdentities(txn);
|
||||||
will(returnValue(singletonList(accountWithoutKeys)));
|
will(returnValue(singletonList(identityWithoutKeys)));
|
||||||
oneOf(crypto).generateAgreementKeyPair();
|
oneOf(crypto).generateAgreementKeyPair();
|
||||||
will(returnValue(handshakeKeyPair));
|
will(returnValue(handshakeKeyPair));
|
||||||
oneOf(handshakePublicKey).getEncoded();
|
oneOf(handshakePublicKey).getEncoded();
|
||||||
@@ -83,16 +83,16 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testOpenDatabaseNoHandshakeKeysGenerated() throws Exception {
|
public void testOpenDatabaseNoHandshakeKeysGenerated() throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getAccounts(txn);
|
oneOf(db).getIdentities(txn);
|
||||||
will(returnValue(singletonList(accountWithKeys)));
|
will(returnValue(singletonList(identityWithKeys)));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
identityManager.onDatabaseOpened(txn);
|
identityManager.onDatabaseOpened(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLocalAuthorAccountRegistered() throws DbException {
|
public void testGetLocalAuthorIdentityRegistered() throws DbException {
|
||||||
identityManager.registerAccount(accountWithKeys);
|
identityManager.registerIdentity(identityWithKeys);
|
||||||
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +100,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
public void testGetLocalAuthorHandshakeKeysGenerated() throws Exception {
|
public void testGetLocalAuthorHandshakeKeysGenerated() throws Exception {
|
||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
oneOf(db).getAccounts(txn);
|
oneOf(db).getIdentities(txn);
|
||||||
will(returnValue(singletonList(accountWithoutKeys)));
|
will(returnValue(singletonList(identityWithoutKeys)));
|
||||||
oneOf(crypto).generateAgreementKeyPair();
|
oneOf(crypto).generateAgreementKeyPair();
|
||||||
will(returnValue(handshakeKeyPair));
|
will(returnValue(handshakeKeyPair));
|
||||||
oneOf(handshakePublicKey).getEncoded();
|
oneOf(handshakePublicKey).getEncoded();
|
||||||
@@ -117,8 +117,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
|||||||
public void testGetLocalAuthorNoHandshakeKeysGenerated() throws Exception {
|
public void testGetLocalAuthorNoHandshakeKeysGenerated() throws Exception {
|
||||||
context.checking(new DbExpectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||||
oneOf(db).getAccounts(txn);
|
oneOf(db).getIdentities(txn);
|
||||||
will(returnValue(singletonList(accountWithKeys)));
|
will(returnValue(singletonList(identityWithKeys)));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.briarproject.briar.feed;
|
package org.briarproject.briar.feed;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.contact.ContactModule;
|
import org.briarproject.bramble.contact.ContactModule;
|
||||||
@@ -51,8 +51,8 @@ public class FeedManagerIntegrationTest extends BriarTestCase {
|
|||||||
injectEagerSingletons(component);
|
injectEagerSingletons(component);
|
||||||
|
|
||||||
IdentityManager identityManager = component.getIdentityManager();
|
IdentityManager identityManager = component.getIdentityManager();
|
||||||
Account account = identityManager.createAccount("feedTest");
|
Identity identity = identityManager.createIdentity("feedTest");
|
||||||
identityManager.registerAccount(account);
|
identityManager.registerIdentity(identity);
|
||||||
|
|
||||||
lifecycleManager = component.getLifecycleManager();
|
lifecycleManager = component.getLifecycleManager();
|
||||||
lifecycleManager.startServices(getSecretKey());
|
lifecycleManager.startServices(getSecretKey());
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
|||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -75,14 +75,14 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testWriteAndRead() throws Exception {
|
public void testWriteAndRead() throws Exception {
|
||||||
// Create the identities
|
// Create the identities
|
||||||
Account aliceAccount =
|
Identity aliceIdentity =
|
||||||
alice.getIdentityManager().createAccount("Alice");
|
alice.getIdentityManager().createIdentity("Alice");
|
||||||
Account bobAccount = bob.getIdentityManager().createAccount("Bob");
|
Identity bobIdentity = bob.getIdentityManager().createIdentity("Bob");
|
||||||
// Set up the devices and get the contact IDs
|
// Set up the devices and get the contact IDs
|
||||||
ContactId bobId = setUp(alice, aliceAccount,
|
ContactId bobId = setUp(alice, aliceIdentity,
|
||||||
bobAccount.getLocalAuthor(), true);
|
bobIdentity.getLocalAuthor(), true);
|
||||||
ContactId aliceId = setUp(bob, bobAccount,
|
ContactId aliceId = setUp(bob, bobIdentity,
|
||||||
aliceAccount.getLocalAuthor(), false);
|
aliceIdentity.getLocalAuthor(), false);
|
||||||
// Add a private message listener
|
// Add a private message listener
|
||||||
PrivateMessageListener listener = new PrivateMessageListener();
|
PrivateMessageListener listener = new PrivateMessageListener();
|
||||||
bob.getEventBus().addListener(listener);
|
bob.getEventBus().addListener(listener);
|
||||||
@@ -101,10 +101,10 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ContactId setUp(SimplexMessagingIntegrationTestComponent device,
|
private ContactId setUp(SimplexMessagingIntegrationTestComponent device,
|
||||||
Account local, Author remote, boolean alice) throws Exception {
|
Identity local, Author remote, boolean alice) throws Exception {
|
||||||
// Add an identity for the user
|
// Add an identity for the user
|
||||||
IdentityManager identityManager = device.getIdentityManager();
|
IdentityManager identityManager = device.getIdentityManager();
|
||||||
identityManager.registerAccount(local);
|
identityManager.registerIdentity(local);
|
||||||
// Start the lifecycle manager
|
// Start the lifecycle manager
|
||||||
LifecycleManager lifecycleManager = device.getLifecycleManager();
|
LifecycleManager lifecycleManager = device.getLifecycleManager();
|
||||||
lifecycleManager.startServices(getSecretKey());
|
lifecycleManager.startServices(getSecretKey());
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.identity.Account;
|
import org.briarproject.bramble.api.identity.Identity;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
@@ -275,15 +275,15 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createAndRegisterIdentities() {
|
private void createAndRegisterIdentities() {
|
||||||
Account account0 = identityManager0.createAccount(AUTHOR0);
|
Identity identity0 = identityManager0.createIdentity(AUTHOR0);
|
||||||
identityManager0.registerAccount(account0);
|
identityManager0.registerIdentity(identity0);
|
||||||
author0 = account0.getLocalAuthor();
|
author0 = identity0.getLocalAuthor();
|
||||||
Account account1 = identityManager0.createAccount(AUTHOR1);
|
Identity identity1 = identityManager0.createIdentity(AUTHOR1);
|
||||||
identityManager1.registerAccount(account1);
|
identityManager1.registerIdentity(identity1);
|
||||||
author1 = account1.getLocalAuthor();
|
author1 = identity1.getLocalAuthor();
|
||||||
Account account2 = identityManager0.createAccount(AUTHOR2);
|
Identity identity2 = identityManager0.createIdentity(AUTHOR2);
|
||||||
identityManager2.registerAccount(account2);
|
identityManager2.registerIdentity(identity2);
|
||||||
author2 = account2.getLocalAuthor();
|
author2 = identity2.getLocalAuthor();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addDefaultContacts() throws Exception {
|
protected void addDefaultContacts() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user