mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Compare commits
1 Commits
remove-dep
...
contact-re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c290a320e |
@@ -18,11 +18,10 @@ public interface ContactGroupFactory {
|
||||
* Creates a group for the given client to share with the given contact.
|
||||
*/
|
||||
Group createContactGroup(ClientId clientId, int majorVersion,
|
||||
Contact contact);
|
||||
Contact contact, AuthorId local);
|
||||
|
||||
/**
|
||||
* Creates a group for the given client to share between the given authors
|
||||
* identified by their AuthorIds.
|
||||
* Creates a group for the given client to share between the given authors.
|
||||
*/
|
||||
Group createContactGroup(ClientId clientId, int majorVersion,
|
||||
AuthorId authorId1, AuthorId authorId2);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.bramble.api.contact;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -17,16 +16,14 @@ public class Contact {
|
||||
|
||||
private final ContactId id;
|
||||
private final Author author;
|
||||
private final AuthorId localAuthorId;
|
||||
@Nullable
|
||||
private final String alias;
|
||||
@Nullable
|
||||
private final byte[] handshakePublicKey;
|
||||
private final boolean verified;
|
||||
|
||||
public Contact(ContactId id, Author author, AuthorId localAuthorId,
|
||||
@Nullable String alias, @Nullable byte[] handshakePublicKey,
|
||||
boolean verified) {
|
||||
public Contact(ContactId id, Author author, @Nullable String alias,
|
||||
@Nullable byte[] handshakePublicKey, boolean verified) {
|
||||
if (alias != null) {
|
||||
int aliasLength = toUtf8(alias).length;
|
||||
if (aliasLength == 0 || aliasLength > MAX_AUTHOR_NAME_LENGTH)
|
||||
@@ -38,7 +35,6 @@ public class Contact {
|
||||
}
|
||||
this.id = id;
|
||||
this.author = author;
|
||||
this.localAuthorId = localAuthorId;
|
||||
this.alias = alias;
|
||||
this.handshakePublicKey = handshakePublicKey;
|
||||
this.verified = verified;
|
||||
@@ -52,10 +48,6 @@ public class Contact {
|
||||
return author;
|
||||
}
|
||||
|
||||
public AuthorId getLocalAuthorId() {
|
||||
return localAuthorId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
|
||||
@@ -24,34 +24,31 @@ public interface ContactManager {
|
||||
void registerContactHook(ContactHook hook);
|
||||
|
||||
/**
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* derives and stores transport keys for each transport, and returns an ID
|
||||
* for the contact.
|
||||
* Stores a contact with the given pseudonym, derives and stores transport
|
||||
* keys for each transport, and returns an ID for the contact.
|
||||
*
|
||||
* @param alice true if the local party is Alice
|
||||
*/
|
||||
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
SecretKey rootKey, long timestamp, boolean alice, boolean verified,
|
||||
boolean active) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a contact associated with the given local and remote pseudonyms
|
||||
* and returns an ID for the contact.
|
||||
*/
|
||||
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
boolean verified) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* derives and stores transport keys for each transport, and returns an ID
|
||||
* for the contact.
|
||||
*
|
||||
* @param alice true if the local party is Alice
|
||||
*/
|
||||
ContactId addContact(Author remote, AuthorId local, SecretKey rootKey,
|
||||
ContactId addContact(Transaction txn, Author a, SecretKey rootKey,
|
||||
long timestamp, boolean alice, boolean verified, boolean active)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a contact with the given pseudonym and returns an ID for the
|
||||
* contact.
|
||||
*/
|
||||
ContactId addContact(Transaction txn, Author a, boolean verified)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a contact with the given pseudonym, derives and stores transport
|
||||
* keys for each transport, and returns an ID for the contact.
|
||||
*
|
||||
* @param alice true if the local party is Alice
|
||||
*/
|
||||
ContactId addContact(Author a, SecretKey rootKey, long timestamp,
|
||||
boolean alice, boolean verified, boolean active) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the static link that needs to be sent to the contact to be added.
|
||||
*/
|
||||
@@ -88,22 +85,14 @@ public interface ContactManager {
|
||||
Contact getContact(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the contact with the given remoteAuthorId
|
||||
* that was added by the LocalAuthor with the given localAuthorId
|
||||
*
|
||||
* @throws org.briarproject.bramble.api.db.NoSuchContactException
|
||||
* Returns the contact with the given ID.
|
||||
*/
|
||||
Contact getContact(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||
throws DbException;
|
||||
Contact getContact(AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the contact with the given remoteAuthorId
|
||||
* that was added by the LocalAuthor with the given localAuthorId
|
||||
*
|
||||
* @throws org.briarproject.bramble.api.db.NoSuchContactException
|
||||
* Returns the contact with the given ID.
|
||||
*/
|
||||
Contact getContact(Transaction txn, AuthorId remoteAuthorId,
|
||||
AuthorId localAuthorId) throws DbException;
|
||||
Contact getContact(Transaction txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all active contacts.
|
||||
@@ -133,16 +122,14 @@ public interface ContactManager {
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Return true if a contact with this name and public key already exists
|
||||
* Returns true if a contact with this pseudonym already exists.
|
||||
*/
|
||||
boolean contactExists(Transaction txn, AuthorId remoteAuthorId,
|
||||
AuthorId localAuthorId) throws DbException;
|
||||
boolean contactExists(Transaction txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Return true if a contact with this name and public key already exists
|
||||
* Returns true if a contact with this pseudonym already exists.
|
||||
*/
|
||||
boolean contactExists(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||
throws DbException;
|
||||
boolean contactExists(AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the {@link AuthorInfo} for the given author.
|
||||
|
||||
@@ -102,11 +102,11 @@ public interface DatabaseComponent {
|
||||
NullableDbCallable<R, E> task) throws DbException, E;
|
||||
|
||||
/**
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* and returns an ID for the contact.
|
||||
* Stores a contact with the given pseudonym and returns an ID for the
|
||||
* contact.
|
||||
*/
|
||||
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
boolean verified) throws DbException;
|
||||
ContactId addContact(Transaction txn, Author a, boolean verified)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a group.
|
||||
@@ -158,13 +158,11 @@ public interface DatabaseComponent {
|
||||
TransportKeys k) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact for the given
|
||||
* local pseudonym.
|
||||
* Returns true if the database contains the given contact.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
boolean containsContact(Transaction txn, AuthorId remote, AuthorId local)
|
||||
throws DbException;
|
||||
boolean containsContact(Transaction txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given group.
|
||||
@@ -254,6 +252,13 @@ public interface DatabaseComponent {
|
||||
*/
|
||||
Contact getContact(Transaction txn, ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the contact with the given author ID.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Contact getContact(Transaction txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all contacts.
|
||||
* <p/>
|
||||
@@ -261,22 +266,6 @@ public interface DatabaseComponent {
|
||||
*/
|
||||
Collection<Contact> getContacts(Transaction txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a possibly empty collection of contacts with the given author ID.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<Contact> getContactsByAuthorId(Transaction txn, AuthorId remote)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all contacts associated with the given local pseudonym.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<ContactId> getContacts(Transaction txn, AuthorId a)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the group with the given ID.
|
||||
* <p/>
|
||||
|
||||
@@ -163,19 +163,15 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
public static Contact getContact() {
|
||||
return getContact(getAuthor(), new AuthorId(getRandomId()),
|
||||
random.nextBoolean());
|
||||
return getContact(getAuthor(), random.nextBoolean());
|
||||
}
|
||||
|
||||
public static Contact getContact(Author remote, AuthorId local,
|
||||
boolean verified) {
|
||||
return getContact(getContactId(), remote, local, verified);
|
||||
public static Contact getContact(Author a, boolean verified) {
|
||||
return getContact(getContactId(), a, verified);
|
||||
}
|
||||
|
||||
public static Contact getContact(ContactId c, Author remote, AuthorId local,
|
||||
boolean verified) {
|
||||
return new Contact(c, remote, local,
|
||||
getRandomString(MAX_AUTHOR_NAME_LENGTH),
|
||||
public static Contact getContact(ContactId c, Author a, boolean verified) {
|
||||
return new Contact(c, a, getRandomString(MAX_AUTHOR_NAME_LENGTH),
|
||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH), verified);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ class ContactGroupFactoryImpl implements ContactGroupFactory {
|
||||
|
||||
@Override
|
||||
public Group createContactGroup(ClientId clientId, int majorVersion,
|
||||
Contact contact) {
|
||||
AuthorId local = contact.getLocalAuthorId();
|
||||
Contact contact, AuthorId local) {
|
||||
AuthorId remote = contact.getAuthor().getId();
|
||||
byte[] descriptor = createGroupDescriptor(local, remote);
|
||||
return groupFactory.createGroup(clientId, majorVersion, descriptor);
|
||||
|
||||
@@ -293,8 +293,7 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
||||
throws DbException {
|
||||
return db.transactionWithResult(false, txn -> {
|
||||
ContactId contactId = contactManager.addContact(txn, remoteAuthor,
|
||||
localAuthor.getId(), masterKey, timestamp, alice,
|
||||
true, true);
|
||||
masterKey, timestamp, alice, true, true);
|
||||
transportPropertyManager.addRemoteProperties(txn, contactId,
|
||||
remoteProperties);
|
||||
return contactId;
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.contact.PendingContactId;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
@@ -68,10 +67,10 @@ class ContactManagerImpl implements ContactManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
SecretKey rootKey, long timestamp, boolean alice, boolean verified,
|
||||
boolean active) throws DbException {
|
||||
ContactId c = db.addContact(txn, remote, local, verified);
|
||||
public ContactId addContact(Transaction txn, Author a, SecretKey rootKey,
|
||||
long timestamp, boolean alice, boolean verified, boolean active)
|
||||
throws DbException {
|
||||
ContactId c = db.addContact(txn, a, verified);
|
||||
keyManager.addContact(txn, c, rootKey, timestamp, alice, active);
|
||||
Contact contact = db.getContact(txn, c);
|
||||
for (ContactHook hook : hooks) hook.addingContact(txn, contact);
|
||||
@@ -79,20 +78,20 @@ class ContactManagerImpl implements ContactManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
boolean verified) throws DbException {
|
||||
ContactId c = db.addContact(txn, remote, local, verified);
|
||||
public ContactId addContact(Transaction txn, Author a, boolean verified)
|
||||
throws DbException {
|
||||
ContactId c = db.addContact(txn, a, verified);
|
||||
Contact contact = db.getContact(txn, c);
|
||||
for (ContactHook hook : hooks) hook.addingContact(txn, contact);
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Author remote, AuthorId local,
|
||||
SecretKey rootKey, long timestamp, boolean alice, boolean verified,
|
||||
boolean active) throws DbException {
|
||||
public ContactId addContact(Author a, SecretKey rootKey, long timestamp,
|
||||
boolean alice, boolean verified, boolean active)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(false, txn ->
|
||||
addContact(txn, remote, local, rootKey, timestamp, alice,
|
||||
addContact(txn, a, rootKey, timestamp, alice,
|
||||
verified, active));
|
||||
}
|
||||
|
||||
@@ -144,23 +143,13 @@ class ContactManagerImpl implements ContactManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact getContact(AuthorId remoteAuthorId, AuthorId localAuthorId)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(true, txn ->
|
||||
getContact(txn, remoteAuthorId, localAuthorId));
|
||||
public Contact getContact(AuthorId a) throws DbException {
|
||||
return db.transactionWithResult(true, txn -> getContact(txn, a));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact getContact(Transaction txn, AuthorId remoteAuthorId,
|
||||
AuthorId localAuthorId) throws DbException {
|
||||
Collection<Contact> contacts =
|
||||
db.getContactsByAuthorId(txn, remoteAuthorId);
|
||||
for (Contact c : contacts) {
|
||||
if (c.getLocalAuthorId().equals(localAuthorId)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
throw new NoSuchContactException();
|
||||
public Contact getContact(Transaction txn, AuthorId a) throws DbException {
|
||||
return db.getContact(txn, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,16 +180,14 @@ class ContactManagerImpl implements ContactManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contactExists(Transaction txn, AuthorId remoteAuthorId,
|
||||
AuthorId localAuthorId) throws DbException {
|
||||
return db.containsContact(txn, remoteAuthorId, localAuthorId);
|
||||
public boolean contactExists(Transaction txn, AuthorId a)
|
||||
throws DbException {
|
||||
return db.containsContact(txn, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contactExists(AuthorId remoteAuthorId,
|
||||
AuthorId localAuthorId) throws DbException {
|
||||
return db.transactionWithResult(true, txn ->
|
||||
contactExists(txn, remoteAuthorId, localAuthorId));
|
||||
public boolean contactExists(AuthorId a) throws DbException {
|
||||
return db.transactionWithResult(true, txn -> contactExists(txn, a));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,12 +209,12 @@ class ContactManagerImpl implements ContactManager {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
if (localAuthor.getId().equals(authorId))
|
||||
return new AuthorInfo(OURSELVES);
|
||||
Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId);
|
||||
if (contacts.isEmpty()) return new AuthorInfo(UNKNOWN);
|
||||
if (contacts.size() > 1) throw new AssertionError();
|
||||
Contact c = contacts.iterator().next();
|
||||
if (c.isVerified()) return new AuthorInfo(VERIFIED, c.getAlias());
|
||||
else return new AuthorInfo(UNVERIFIED, c.getAlias());
|
||||
if (db.containsContact(txn, authorId)) {
|
||||
Contact c = db.getContact(txn, authorId);
|
||||
if (c.isVerified()) return new AuthorInfo(VERIFIED, c.getAlias());
|
||||
else return new AuthorInfo(UNVERIFIED, c.getAlias());
|
||||
}
|
||||
return new AuthorInfo(UNKNOWN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,11 +87,10 @@ interface Database<T> {
|
||||
void commitTransaction(T txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* and returns an ID for the contact.
|
||||
* Stores a contact with the given pseudonym and returns an ID for the
|
||||
* contact.
|
||||
*/
|
||||
ContactId addContact(T txn, Author remote, AuthorId local, boolean verified)
|
||||
throws DbException;
|
||||
ContactId addContact(T txn, Author a, boolean verified) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a group.
|
||||
@@ -164,13 +163,11 @@ interface Database<T> {
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact for the given
|
||||
* local pseudonym.
|
||||
* Returns true if the database contains the given contact.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
boolean containsContact(T txn, AuthorId remote, AuthorId local)
|
||||
throws DbException;
|
||||
boolean containsContact(T txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact.
|
||||
@@ -252,6 +249,13 @@ interface Database<T> {
|
||||
*/
|
||||
Contact getContact(T txn, ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the contact with the given author ID.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Contact getContact(T txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all contacts.
|
||||
* <p/>
|
||||
@@ -259,21 +263,6 @@ interface Database<T> {
|
||||
*/
|
||||
Collection<Contact> getContacts(T txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a possibly empty collection of contacts with the given author ID.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<Contact> getContactsByAuthorId(T txn, AuthorId remote)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all contacts associated with the given local pseudonym.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<ContactId> getContacts(T txn, AuthorId a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the group with the given ID.
|
||||
* <p/>
|
||||
|
||||
@@ -232,18 +232,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Transaction transaction, Author remote,
|
||||
AuthorId local, boolean verified)
|
||||
throws DbException {
|
||||
public ContactId addContact(Transaction transaction, Author a,
|
||||
boolean verified) throws DbException {
|
||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, local))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
if (db.containsLocalAuthor(txn, remote.getId()))
|
||||
if (db.containsLocalAuthor(txn, a.getId()))
|
||||
throw new ContactExistsException();
|
||||
if (db.containsContact(txn, remote.getId(), local))
|
||||
if (db.containsContact(txn, a.getId()))
|
||||
throw new ContactExistsException();
|
||||
ContactId c = db.addContact(txn, remote, local, verified);
|
||||
ContactId c = db.addContact(txn, a, verified);
|
||||
transaction.attach(new ContactAddedEvent(c));
|
||||
return c;
|
||||
}
|
||||
@@ -342,12 +339,10 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsContact(Transaction transaction, AuthorId remote,
|
||||
AuthorId local) throws DbException {
|
||||
public boolean containsContact(Transaction transaction, AuthorId a)
|
||||
throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, local))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
return db.containsContact(txn, remote, local);
|
||||
return db.containsContact(txn, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -487,6 +482,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return db.getContact(txn, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact getContact(Transaction transaction, AuthorId a)
|
||||
throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsContact(txn, a))
|
||||
throw new NoSuchContactException();
|
||||
return db.getContact(txn, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getContacts(Transaction transaction)
|
||||
throws DbException {
|
||||
@@ -494,22 +498,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return db.getContacts(txn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getContactsByAuthorId(Transaction transaction,
|
||||
AuthorId remote) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
return db.getContactsByAuthorId(txn, remote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ContactId> getContacts(Transaction transaction,
|
||||
AuthorId a) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, a))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
return db.getContacts(txn, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(Transaction transaction, GroupId g)
|
||||
throws DbException {
|
||||
|
||||
@@ -92,7 +92,7 @@ import static org.briarproject.bramble.util.LogUtils.now;
|
||||
abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
// Package access for testing
|
||||
static final int CODE_SCHEMA_VERSION = 43;
|
||||
static final int CODE_SCHEMA_VERSION = 44;
|
||||
|
||||
// Time period offsets for incoming transport keys
|
||||
private static final int OFFSET_PREV = -1;
|
||||
@@ -127,12 +127,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " alias _STRING," // Null if no alias has been set
|
||||
+ " publicKey _BINARY NOT NULL,"
|
||||
+ " handshakePublicKey _BINARY," // Null if key is unknown
|
||||
+ " localAuthorId _HASH NOT NULL,"
|
||||
+ " verified BOOLEAN NOT NULL,"
|
||||
+ " PRIMARY KEY (contactId),"
|
||||
+ " FOREIGN KEY (localAuthorId)"
|
||||
+ " REFERENCES localAuthors (authorId)"
|
||||
+ " ON DELETE CASCADE)";
|
||||
+ " PRIMARY KEY (contactId))";
|
||||
|
||||
private static final String CREATE_GROUPS =
|
||||
"CREATE TABLE groups"
|
||||
@@ -486,7 +482,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
new Migration39_40(),
|
||||
new Migration40_41(dbTypes),
|
||||
new Migration41_42(dbTypes),
|
||||
new Migration42_43(dbTypes)
|
||||
new Migration42_43(dbTypes),
|
||||
new Migration43_44()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -662,23 +659,21 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
||||
boolean verified) throws DbException {
|
||||
public ContactId addContact(Connection txn, Author a, boolean verified)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
// Create a contact row
|
||||
String sql = "INSERT INTO contacts"
|
||||
+ " (authorId, formatVersion, name, publicKey,"
|
||||
+ " localAuthorId, verified)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?)";
|
||||
+ " (authorId, formatVersion, name, publicKey, verified)"
|
||||
+ " VALUES (?, ?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, remote.getId().getBytes());
|
||||
ps.setInt(2, remote.getFormatVersion());
|
||||
ps.setString(3, remote.getName());
|
||||
ps.setBytes(4, remote.getPublicKey());
|
||||
ps.setBytes(5, local.getBytes());
|
||||
ps.setBoolean(6, verified);
|
||||
ps.setBytes(1, a.getId().getBytes());
|
||||
ps.setInt(2, a.getFormatVersion());
|
||||
ps.setString(3, a.getName());
|
||||
ps.setBytes(4, a.getPublicKey());
|
||||
ps.setBoolean(5, verified);
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected != 1) throw new DbStateException();
|
||||
ps.close();
|
||||
@@ -1180,16 +1175,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsContact(Connection txn, AuthorId remote,
|
||||
AuthorId local) throws DbException {
|
||||
public boolean containsContact(Connection txn, AuthorId a)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT NULL FROM contacts"
|
||||
+ " WHERE authorId = ? AND localAuthorId = ?";
|
||||
String sql = "SELECT NULL FROM contacts WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, remote.getBytes());
|
||||
ps.setBytes(2, local.getBytes());
|
||||
ps.setBytes(1, a.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
boolean found = rs.next();
|
||||
if (rs.next()) throw new DbStateException();
|
||||
@@ -1432,7 +1425,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT authorId, formatVersion, name, alias,"
|
||||
+ " publicKey, handshakePublicKey, localAuthorId, verified"
|
||||
+ " publicKey, handshakePublicKey, verified"
|
||||
+ " FROM contacts"
|
||||
+ " WHERE contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
@@ -1445,14 +1438,44 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String alias = rs.getString(4);
|
||||
byte[] publicKey = rs.getBytes(5);
|
||||
byte[] handshakePublicKey = rs.getBytes(6);
|
||||
AuthorId localAuthorId = new AuthorId(rs.getBytes(7));
|
||||
boolean verified = rs.getBoolean(8);
|
||||
boolean verified = rs.getBoolean(7);
|
||||
rs.close();
|
||||
ps.close();
|
||||
Author author =
|
||||
new Author(authorId, formatVersion, name, publicKey);
|
||||
return new Contact(c, author, localAuthorId, alias,
|
||||
handshakePublicKey, verified);
|
||||
return new Contact(c, author, alias, handshakePublicKey, verified);
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact getContact(Connection txn, AuthorId a) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT contactId, formatVersion, name, alias,"
|
||||
+ " publicKey, handshakePublicKey, verified"
|
||||
+ " FROM contacts"
|
||||
+ " WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, a.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next()) throw new DbStateException();
|
||||
ContactId contactId = new ContactId(rs.getInt(1));
|
||||
int formatVersion = rs.getInt(2);
|
||||
String name = rs.getString(3);
|
||||
String alias = rs.getString(4);
|
||||
byte[] publicKey = rs.getBytes(5);
|
||||
byte[] handshakePublicKey = rs.getBytes(6);
|
||||
boolean verified = rs.getBoolean(7);
|
||||
rs.close();
|
||||
ps.close();
|
||||
Author author = new Author(a, formatVersion, name, publicKey);
|
||||
return new Contact(contactId, author, alias, handshakePublicKey,
|
||||
verified);
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
@@ -1466,8 +1489,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT contactId, authorId, formatVersion, name,"
|
||||
+ " alias, publicKey, handshakePublicKey, localAuthorId,"
|
||||
+ " verified"
|
||||
+ " alias, publicKey, handshakePublicKey, verified"
|
||||
+ " FROM contacts";
|
||||
s = txn.createStatement();
|
||||
rs = s.executeQuery(sql);
|
||||
@@ -1480,12 +1502,11 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String alias = rs.getString(5);
|
||||
byte[] publicKey = rs.getBytes(6);
|
||||
byte[] handshakePublicKey = rs.getBytes(7);
|
||||
AuthorId localAuthorId = new AuthorId(rs.getBytes(8));
|
||||
boolean verified = rs.getBoolean(9);
|
||||
boolean verified = rs.getBoolean(8);
|
||||
Author author =
|
||||
new Author(authorId, formatVersion, name, publicKey);
|
||||
contacts.add(new Contact(contactId, author, localAuthorId,
|
||||
alias, handshakePublicKey, verified));
|
||||
contacts.add(new Contact(contactId, author, alias,
|
||||
handshakePublicKey, verified));
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
@@ -1497,67 +1518,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ContactId> getContacts(Connection txn, AuthorId local)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT contactId FROM contacts"
|
||||
+ " WHERE localAuthorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, local.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<ContactId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new ContactId(rs.getInt(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
return ids;
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getContactsByAuthorId(Connection txn,
|
||||
AuthorId remote) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT contactId, formatVersion, name, alias,"
|
||||
+ " publicKey, handshakePublicKey, localAuthorId, verified"
|
||||
+ " FROM contacts"
|
||||
+ " WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, remote.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<Contact> contacts = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
ContactId contactId = new ContactId(rs.getInt(1));
|
||||
int formatVersion = rs.getInt(2);
|
||||
String name = rs.getString(3);
|
||||
String alias = rs.getString(4);
|
||||
byte[] publicKey = rs.getBytes(5);
|
||||
byte[] handshakePublicKey = rs.getBytes(6);
|
||||
AuthorId localAuthorId = new AuthorId(rs.getBytes(7));
|
||||
boolean verified = rs.getBoolean(8);
|
||||
Author author =
|
||||
new Author(remote, formatVersion, name, publicKey);
|
||||
contacts.add(new Contact(contactId, author, localAuthorId,
|
||||
alias, handshakePublicKey, verified));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
return contacts;
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getGroup(Connection txn, GroupId g) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.briarproject.bramble.db;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.db.JdbcUtils.tryToClose;
|
||||
|
||||
class Migration43_44 implements Migration<Connection> {
|
||||
|
||||
private static final Logger LOG = getLogger(Migration43_44.class.getName());
|
||||
|
||||
@Override
|
||||
public int getStartVersion() {
|
||||
return 43;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEndVersion() {
|
||||
return 44;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(Connection txn) throws DbException {
|
||||
Statement s = null;
|
||||
try {
|
||||
s = txn.createStatement();
|
||||
s.execute("ALTER TABLE contacts"
|
||||
+ " DROP COLUMN localAuthorId");
|
||||
} catch (SQLException e) {
|
||||
tryToClose(s, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
@@ -44,6 +46,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final ClientHelper clientHelper;
|
||||
private final IdentityManager identityManager;
|
||||
private final ClientVersioningManager clientVersioningManager;
|
||||
private final MetadataParser metadataParser;
|
||||
private final ContactGroupFactory contactGroupFactory;
|
||||
@@ -53,11 +56,13 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
@Inject
|
||||
TransportPropertyManagerImpl(DatabaseComponent db,
|
||||
ClientHelper clientHelper,
|
||||
IdentityManager identityManager,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser,
|
||||
ContactGroupFactory contactGroupFactory, Clock clock) {
|
||||
this.db = db;
|
||||
this.clientHelper = clientHelper;
|
||||
this.identityManager = identityManager;
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.metadataParser = metadataParser;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
@@ -77,7 +82,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
@@ -93,14 +98,14 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -132,7 +137,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
@Override
|
||||
public void addRemoteProperties(Transaction txn, ContactId c,
|
||||
Map<TransportId, TransportProperties> props) throws DbException {
|
||||
Group g = getContactGroup(db.getContact(txn, c));
|
||||
Group g = getContactGroup(db.getContact(txn, c), getLocalAuthorId(txn));
|
||||
for (Entry<TransportId, TransportProperties> e : props.entrySet()) {
|
||||
storeMessage(txn, g.getId(), e.getKey(), e.getValue(), 0,
|
||||
false, false);
|
||||
@@ -191,15 +196,16 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
TransportId t) throws DbException {
|
||||
return db.transactionWithResult(true, txn -> {
|
||||
Map<ContactId, TransportProperties> remote = new HashMap<>();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn))
|
||||
remote.put(c.getId(), getRemoteProperties(txn, c, t));
|
||||
remote.put(c.getId(), getRemoteProperties(txn, c, local, t));
|
||||
return remote;
|
||||
});
|
||||
}
|
||||
|
||||
private TransportProperties getRemoteProperties(Transaction txn, Contact c,
|
||||
TransportId t) throws DbException {
|
||||
Group g = getContactGroup(c);
|
||||
AuthorId local, TransportId t) throws DbException {
|
||||
Group g = getContactGroup(c, local);
|
||||
try {
|
||||
// Find the latest remote update
|
||||
LatestUpdate latest = findLatest(txn, g.getId(), t, false);
|
||||
@@ -216,8 +222,11 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
@Override
|
||||
public TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(true, txn ->
|
||||
getRemoteProperties(txn, db.getContact(txn, c), t));
|
||||
return db.transactionWithResult(true, txn -> {
|
||||
Contact contact = db.getContact(txn ,c);
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
return getRemoteProperties(txn, contact, local, t);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,8 +259,9 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
if (latest != null)
|
||||
db.removeMessage(txn, latest.messageId);
|
||||
// Store the merged properties in each contact's group
|
||||
AuthorId localAuthorId = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, localAuthorId);
|
||||
latest = findLatest(txn, g.getId(), t, true);
|
||||
version = latest == null ? 1 : latest.version + 1;
|
||||
storeMessage(txn, g.getId(), t, merged, version,
|
||||
@@ -267,9 +277,13 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
}
|
||||
}
|
||||
|
||||
private Group getContactGroup(Contact c) {
|
||||
private AuthorId getLocalAuthorId(Transaction txn) throws DbException {
|
||||
return identityManager.getLocalAuthor(txn).getId();
|
||||
}
|
||||
|
||||
private Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
private void storeMessage(Transaction txn, GroupId g, TransportId t,
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
@@ -58,6 +60,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final ClientHelper clientHelper;
|
||||
private final IdentityManager identityManager;
|
||||
private final ContactGroupFactory contactGroupFactory;
|
||||
private final Clock clock;
|
||||
private final Group localGroup;
|
||||
@@ -68,9 +71,11 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
@Inject
|
||||
ClientVersioningManagerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory, Clock clock) {
|
||||
this.db = db;
|
||||
this.clientHelper = clientHelper;
|
||||
this.identityManager = identityManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.clock = clock;
|
||||
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID,
|
||||
@@ -154,7 +159,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group and share it with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
||||
// Attach the contact ID to the group
|
||||
@@ -173,7 +178,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,7 +313,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
List<ClientVersion> versions) throws DbException {
|
||||
try {
|
||||
// Find the latest local and remote updates
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
LatestUpdates latest = findLatestUpdates(txn, g.getId());
|
||||
// Load and parse the latest local update
|
||||
if (latest.local == null) throw new DbException();
|
||||
@@ -344,16 +349,20 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
}
|
||||
}
|
||||
|
||||
private Group getContactGroup(Contact c) {
|
||||
private AuthorId getLocalAuthorId(Transaction txn) throws DbException {
|
||||
return identityManager.getLocalAuthor(txn).getId();
|
||||
}
|
||||
|
||||
private Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LatestUpdates findLatestUpdates(Transaction txn, ContactId c)
|
||||
throws DbException, FormatException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
Group g = getContactGroup(contact);
|
||||
Group g = getContactGroup(contact, getLocalAuthorId(txn));
|
||||
// Contact may be in the process of being added or removed, so
|
||||
// contact group may not exist
|
||||
if (!db.containsGroup(txn, g.getId())) return null;
|
||||
|
||||
@@ -5,25 +5,20 @@ import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.transport.KeyManager;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.DbExpectations;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
||||
@@ -33,7 +28,6 @@ import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -48,11 +42,10 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ContactManager contactManager;
|
||||
private final Author remote = getAuthor();
|
||||
private final Author author = getAuthor();
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final AuthorId local = localAuthor.getId();
|
||||
private final boolean verified = false, active = true;
|
||||
private final Contact contact = getContact(remote, local, verified);
|
||||
private final Contact contact = getContact(author, verified);
|
||||
private final ContactId contactId = contact.getId();
|
||||
|
||||
public ContactManagerImplTest() {
|
||||
@@ -69,7 +62,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(false), withDbCallable(txn));
|
||||
oneOf(db).addContact(txn, remote, local, verified);
|
||||
oneOf(db).addContact(txn, author, verified);
|
||||
will(returnValue(contactId));
|
||||
oneOf(keyManager).addContact(txn, contactId, rootKey, timestamp,
|
||||
alice, active);
|
||||
@@ -77,12 +70,12 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(contact));
|
||||
}});
|
||||
|
||||
assertEquals(contactId, contactManager.addContact(remote, local,
|
||||
rootKey, timestamp, alice, verified, active));
|
||||
assertEquals(contactId, contactManager.addContact(author, rootKey,
|
||||
timestamp, alice, verified, active));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContact() throws Exception {
|
||||
public void testGetContactByContactId() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
@@ -94,41 +87,15 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactByAuthor() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Collection<Contact> contacts = singletonList(contact);
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||
will(returnValue(contacts));
|
||||
}});
|
||||
|
||||
assertEquals(contact, contactManager.getContact(remote.getId(), local));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchContactException.class)
|
||||
public void testGetContactByUnknownAuthor() throws Exception {
|
||||
public void testGetContactByAuthorId() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||
will(returnValue(emptyList()));
|
||||
oneOf(db).getContact(txn, author.getId());
|
||||
will(returnValue(contact));
|
||||
}});
|
||||
|
||||
contactManager.getContact(remote.getId(), local);
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchContactException.class)
|
||||
public void testGetContactByUnknownLocalAuthor() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Collection<Contact> contacts = singletonList(contact);
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||
will(returnValue(contacts));
|
||||
}});
|
||||
|
||||
contactManager.getContact(remote.getId(), new AuthorId(getRandomId()));
|
||||
assertEquals(contact, contactManager.getContact(author.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -182,78 +149,82 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).containsContact(txn, remote.getId(), local);
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
}});
|
||||
|
||||
assertTrue(contactManager.contactExists(remote.getId(), local));
|
||||
assertTrue(contactManager.contactExists(author.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorInfo() throws Exception {
|
||||
public void testGetAuthorInfoOurselves() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||
will(returnValue(singletonList(contact)));
|
||||
}});
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, remote.getId());
|
||||
assertEquals(UNVERIFIED, authorInfo.getStatus());
|
||||
assertEquals(contact.getAlias(), authorInfo.getAlias());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorInfoTransaction() throws DbException {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
// check unknown author
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContactsByAuthorId(txn, remote.getId());
|
||||
will(returnValue(emptyList()));
|
||||
}});
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, remote.getId());
|
||||
assertEquals(UNKNOWN, authorInfo.getStatus());
|
||||
assertNull(authorInfo.getAlias());
|
||||
|
||||
// check unverified contact
|
||||
checkAuthorInfoContext(txn, remote.getId(), singletonList(contact));
|
||||
authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
|
||||
assertEquals(UNVERIFIED, authorInfo.getStatus());
|
||||
assertEquals(contact.getAlias(), authorInfo.getAlias());
|
||||
|
||||
// check verified contact
|
||||
Contact verified = getContact(remote, local, true);
|
||||
checkAuthorInfoContext(txn, remote.getId(), singletonList(verified));
|
||||
authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
|
||||
assertEquals(VERIFIED, authorInfo.getStatus());
|
||||
assertEquals(verified.getAlias(), authorInfo.getAlias());
|
||||
|
||||
// check ourselves
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
never(db).getContactsByAuthorId(txn, remote.getId());
|
||||
}});
|
||||
authorInfo = contactManager.getAuthorInfo(txn, localAuthor.getId());
|
||||
contactManager.getAuthorInfo(txn, localAuthor.getId());
|
||||
assertEquals(OURSELVES, authorInfo.getStatus());
|
||||
assertNull(authorInfo.getAlias());
|
||||
}
|
||||
|
||||
private void checkAuthorInfoContext(Transaction txn, AuthorId authorId,
|
||||
Collection<Contact> contacts) throws DbException {
|
||||
context.checking(new Expectations() {{
|
||||
@Test
|
||||
public void testGetAuthorInfoVerified() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Contact verified = getContact(author, true);
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContactsByAuthorId(txn, authorId);
|
||||
will(returnValue(contacts));
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).getContact(txn, author.getId());
|
||||
will(returnValue(verified));
|
||||
}});
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, author.getId());
|
||||
assertEquals(VERIFIED, authorInfo.getStatus());
|
||||
assertEquals(verified.getAlias(), authorInfo.getAlias());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorInfoUnverified() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
Contact unverified = getContact(author, false);
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).getContact(txn, author.getId());
|
||||
will(returnValue(unverified));
|
||||
}});
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, author.getId());
|
||||
assertEquals(UNVERIFIED, authorInfo.getStatus());
|
||||
assertEquals(unverified.getAlias(), authorInfo.getAlias());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthorInfoUnknown() throws Exception {
|
||||
Transaction txn = new Transaction(null, true);
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
}});
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, author.getId());
|
||||
assertEquals(UNKNOWN, authorInfo.getStatus());
|
||||
assertNull(authorInfo.getAlias());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
metadata.put("foo", new byte[] {'b', 'a', 'r'});
|
||||
transportId = getTransportId();
|
||||
maxLatency = Integer.MAX_VALUE;
|
||||
contact = getContact(author, localAuthor.getId(), true);
|
||||
contact = getContact(author, true);
|
||||
contactId = contact.getId();
|
||||
alias = contact.getAlias();
|
||||
keySetId = new TransportKeySetId(345);
|
||||
@@ -163,14 +163,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
oneOf(database).addLocalAuthor(txn, localAuthor);
|
||||
oneOf(eventBus).broadcast(with(any(LocalAuthorAddedEvent.class)));
|
||||
// addContact()
|
||||
oneOf(database).containsLocalAuthor(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsLocalAuthor(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(database).containsContact(txn, author.getId(),
|
||||
localAuthor.getId());
|
||||
oneOf(database).containsContact(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(database).addContact(txn, author, localAuthor.getId(), true);
|
||||
oneOf(database).addContact(txn, author, true);
|
||||
will(returnValue(contactId));
|
||||
oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
|
||||
// getContacts()
|
||||
@@ -217,8 +214,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
assertFalse(db.open(key, null));
|
||||
db.transaction(false, transaction -> {
|
||||
db.addLocalAuthor(transaction, localAuthor);
|
||||
assertEquals(contactId, db.addContact(transaction, author,
|
||||
localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(transaction, author, true));
|
||||
assertEquals(singletonList(contact),
|
||||
db.getContacts(transaction));
|
||||
db.addGroup(transaction, group); // First time - listeners called
|
||||
@@ -279,11 +275,13 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the contact is in the DB (which it's not)
|
||||
exactly(17).of(database).startTransaction();
|
||||
exactly(18).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(17).of(database).containsContact(txn, contactId);
|
||||
will(returnValue(false));
|
||||
exactly(17).of(database).abortTransaction(txn);
|
||||
oneOf(database).containsContact(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
exactly(18).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
eventExecutor, shutdownManager);
|
||||
@@ -346,6 +344,14 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.getContact(transaction, author.getId()));
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.getMessageStatus(transaction, contactId, groupId));
|
||||
@@ -436,25 +442,16 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the pseudonym is in the DB (which it's not)
|
||||
exactly(3).of(database).startTransaction();
|
||||
exactly(2).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(3).of(database).containsLocalAuthor(txn,
|
||||
exactly(2).of(database).containsLocalAuthor(txn,
|
||||
localAuthor.getId());
|
||||
will(returnValue(false));
|
||||
exactly(3).of(database).abortTransaction(txn);
|
||||
exactly(2).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
eventExecutor, shutdownManager);
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.addContact(transaction, author, localAuthor.getId(),
|
||||
true));
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.getLocalAuthor(transaction, localAuthor.getId()));
|
||||
@@ -1403,8 +1400,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsLocalAuthor(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
// Contact is a local identity
|
||||
oneOf(database).containsLocalAuthor(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
@@ -1416,8 +1411,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.addContact(transaction, author, localAuthor.getId(),
|
||||
true));
|
||||
db.addContact(transaction, author, true));
|
||||
fail();
|
||||
} catch (ContactExistsException expected) {
|
||||
// Expected
|
||||
@@ -1429,13 +1423,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsLocalAuthor(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsLocalAuthor(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
// Contact already exists for this local identity
|
||||
oneOf(database).containsContact(txn, author.getId(),
|
||||
localAuthor.getId());
|
||||
// Contact already exists
|
||||
oneOf(database).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).abortTransaction(txn);
|
||||
}});
|
||||
@@ -1445,8 +1436,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.addContact(transaction, author, localAuthor.getId(),
|
||||
true));
|
||||
db.addContact(transaction, author, true));
|
||||
fail();
|
||||
} catch (ContactExistsException expected) {
|
||||
// Expected
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -131,11 +130,10 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testContainsContactByAuthorId() throws Exception {
|
||||
String name = "containsContact(T, AuthorId, AuthorId)";
|
||||
String name = "containsContact(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
AuthorId remote = pickRandom(contacts).getAuthor().getId();
|
||||
db.containsContact(txn, remote, localAuthor.getId());
|
||||
db.containsContact(txn, pickRandom(contacts).getAuthor().getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
@@ -202,7 +200,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContact() throws Exception {
|
||||
public void testGetContactByContactId() throws Exception {
|
||||
String name = "getContact(T, ContactId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
@@ -211,6 +209,16 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactByAuthorId() throws Exception {
|
||||
String name = "getContact(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.getContact(txn, pickRandom(contacts).getAuthor().getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContacts() throws Exception {
|
||||
String name = "getContacts(T)";
|
||||
@@ -221,27 +229,6 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByRemoteAuthorId() throws Exception {
|
||||
String name = "getContactsByAuthorId(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
AuthorId remote = pickRandom(contacts).getAuthor().getId();
|
||||
db.getContactsByAuthorId(txn, remote);
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByLocalAuthorId() throws Exception {
|
||||
String name = "getContacts(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.getContacts(txn, localAuthor.getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroup() throws Exception {
|
||||
String name = "getGroup(T, GroupId)";
|
||||
@@ -545,8 +532,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
for (int i = 0; i < CONTACTS; i++) {
|
||||
ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(),
|
||||
random.nextBoolean());
|
||||
ContactId c = db.addContact(txn, getAuthor(), random.nextBoolean());
|
||||
contacts.add(db.getContact(txn, c));
|
||||
contactGroups.put(c, new ArrayList<>());
|
||||
for (int j = 0; j < GROUPS_PER_CONTACT; j++) {
|
||||
|
||||
@@ -84,7 +84,6 @@ import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -146,8 +145,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsGroup(txn, groupId));
|
||||
db.addGroup(txn, group);
|
||||
@@ -208,9 +206,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
@@ -239,9 +235,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared but unvalidated message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, UNKNOWN, true, null);
|
||||
@@ -284,9 +278,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, an invisible group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
|
||||
@@ -335,9 +327,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and an unshared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, false, null);
|
||||
@@ -366,17 +356,14 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
|
||||
// The message is sendable, but too large to send
|
||||
Collection<MessageId> ids =
|
||||
db.getMessagesToSend(txn, contactId, message.getRawLength() - 1,
|
||||
MAX_LATENCY);
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||
message.getRawLength() - 1, MAX_LATENCY);
|
||||
assertTrue(ids.isEmpty());
|
||||
// The message is just the right size to send
|
||||
ids = db.getMessagesToSend(txn, contactId, message.getRawLength(),
|
||||
@@ -393,9 +380,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a visible group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, false);
|
||||
|
||||
@@ -434,9 +419,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
@@ -566,9 +549,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a shared group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
|
||||
@@ -586,9 +567,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
|
||||
// The group is not in the database
|
||||
assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
|
||||
@@ -604,9 +583,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, an invisible group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
|
||||
@@ -623,9 +600,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
|
||||
// The group should not be visible to the contact
|
||||
@@ -675,9 +650,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertEquals(emptyList(), db.getTransportKeys(txn, transportId));
|
||||
|
||||
// Add the contact, the transport and the transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
|
||||
assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1));
|
||||
@@ -776,9 +749,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertEquals(emptyList(), db.getHandshakeKeys(txn, transportId));
|
||||
|
||||
// Add the contact, the transport and the handshake keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(handshakeKeySetId,
|
||||
db.addHandshakeKeys(txn, contactId, keys));
|
||||
@@ -929,9 +900,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
|
||||
|
||||
@@ -973,9 +942,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and handshake keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(handshakeKeySetId,
|
||||
db.addHandshakeKeys(txn, contactId, keys));
|
||||
@@ -1020,9 +987,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
|
||||
|
||||
@@ -1067,9 +1032,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and handshake keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author,true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
assertEquals(handshakeKeySetId,
|
||||
db.addHandshakeKeys(txn, contactId, keys));
|
||||
@@ -1105,54 +1068,42 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByAuthorId() throws Exception {
|
||||
public void testGetContactByContactId() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a local author - no contacts should be associated
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
|
||||
// Add a contact associated with the local author
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
|
||||
// Ensure contact is returned from database by Author ID
|
||||
Collection<Contact> contacts =
|
||||
db.getContactsByAuthorId(txn, author.getId());
|
||||
assertEquals(1, contacts.size());
|
||||
assertEquals(contactId, contacts.iterator().next().getId());
|
||||
|
||||
// Ensure no contacts are returned after contact was deleted
|
||||
db.removeContact(txn, contactId);
|
||||
contacts = db.getContactsByAuthorId(txn, author.getId());
|
||||
assertEquals(0, contacts.size());
|
||||
// Check the contact is returned
|
||||
Contact c = db.getContact(txn, contactId);
|
||||
assertEquals(contactId, c.getId());
|
||||
assertEquals(author.getId(), c.getAuthor().getId());
|
||||
assertEquals(author.getFormatVersion(),
|
||||
c.getAuthor().getFormatVersion());
|
||||
assertEquals(author.getName(), c.getAuthor().getName());
|
||||
assertArrayEquals(author.getPublicKey(), c.getAuthor().getPublicKey());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContactsByLocalAuthorId() throws Exception {
|
||||
public void testGetContactByAuthorId() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a local author - no contacts should be associated
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
Collection<ContactId> contacts =
|
||||
db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(emptyList(), contacts);
|
||||
// Add a contact
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
|
||||
// Add a contact associated with the local author
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
contacts = db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(singletonList(contactId), contacts);
|
||||
|
||||
// Remove the local author - the contact should be removed
|
||||
db.removeLocalAuthor(txn, localAuthor.getId());
|
||||
contacts = db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(emptyList(), contacts);
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
// Check the contact is returned
|
||||
Contact c = db.getContact(txn, author.getId());
|
||||
assertEquals(contactId, c.getId());
|
||||
assertEquals(author.getId(), c.getAuthor().getId());
|
||||
assertEquals(author.getFormatVersion(),
|
||||
c.getAuthor().getFormatVersion());
|
||||
assertEquals(author.getName(), c.getAuthor().getName());
|
||||
assertArrayEquals(author.getPublicKey(), c.getAuthor().getPublicKey());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
@@ -1164,9 +1115,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact - initially there should be no offered messages
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
||||
|
||||
// Add some offered messages and count them
|
||||
@@ -1748,9 +1697,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
@@ -1847,43 +1794,13 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentLocalAuthorsCanHaveTheSameContact()
|
||||
throws Exception {
|
||||
LocalAuthor localAuthor1 = getLocalAuthor();
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add two local authors
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
db.addLocalAuthor(txn, localAuthor1);
|
||||
|
||||
// Add the same contact for each local author
|
||||
ContactId contactId =
|
||||
db.addContact(txn, author, localAuthor.getId(), true);
|
||||
ContactId contactId1 =
|
||||
db.addContact(txn, author, localAuthor1.getId(), true);
|
||||
|
||||
// The contacts should be distinct
|
||||
assertNotEquals(contactId, contactId1);
|
||||
assertEquals(2, db.getContacts(txn).size());
|
||||
assertEquals(1, db.getContacts(txn, localAuthor.getId()).size());
|
||||
assertEquals(1, db.getContacts(txn, localAuthor1.getId()).size());
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMessage() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
@@ -1935,9 +1852,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
|
||||
// The contact should have no alias
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
@@ -1992,9 +1907,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addMessage(txn, message, UNKNOWN, false, null);
|
||||
|
||||
@@ -2076,9 +1989,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
@@ -2121,9 +2032,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(contactId, db.addContact(txn, author, true));
|
||||
db.addGroup(txn, group);
|
||||
db.addGroupVisibility(txn, contactId, groupId, true);
|
||||
db.addMessage(txn, message, DELIVERED, true, null);
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -37,6 +39,7 @@ import static org.briarproject.bramble.api.properties.TransportPropertyManager.M
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -46,6 +49,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ClientVersioningManager clientVersioningManager =
|
||||
context.mock(ClientVersioningManager.class);
|
||||
private final MetadataParser metadataParser =
|
||||
@@ -55,6 +60,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final BdfDictionary fooPropertiesDict = BdfDictionary.of(
|
||||
new BdfEntry("fooKey1", "fooValue1"),
|
||||
new BdfEntry("fooKey2", "fooValue2")
|
||||
@@ -81,8 +87,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(localGroup));
|
||||
}});
|
||||
return new TransportPropertyManagerImpl(db, clientHelper,
|
||||
clientVersioningManager, metadataParser, contactGroupFactory,
|
||||
clock);
|
||||
identityManager, clientVersioningManager, metadataParser,
|
||||
contactGroupFactory, clock);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,10 +101,12 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).containsGroup(txn, localGroup.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(db).addGroup(txn, localGroup);
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn,
|
||||
@@ -140,8 +148,10 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the group and share it with the contact
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn,
|
||||
@@ -168,8 +178,10 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).removeGroup(txn, contactGroup);
|
||||
}});
|
||||
@@ -307,8 +319,10 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectStoreMessage(txn, contactGroup.getId(), "foo", fooPropertiesDict,
|
||||
@@ -432,18 +446,20 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
// First contact: no updates
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact1);
|
||||
MAJOR_VERSION, contact1, localAuthor.getId());
|
||||
will(returnValue(contactGroup1));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup1.getId());
|
||||
will(returnValue(Collections.emptyMap()));
|
||||
// Second contact: returns an update
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact2);
|
||||
MAJOR_VERSION, contact2, localAuthor.getId());
|
||||
will(returnValue(contactGroup2));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup2.getId());
|
||||
@@ -510,10 +526,12 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
expectStoreMessage(txn, localGroup.getId(), "foo",
|
||||
fooPropertiesDict, 1, true, false);
|
||||
// Store the new properties in each contact's group, version 1
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
@@ -566,10 +584,12 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
// Delete the previous update
|
||||
oneOf(db).removeMessage(txn, localGroupUpdateId);
|
||||
// Store the merged properties in each contact's group, version 2
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.Group.Visibility;
|
||||
@@ -36,6 +38,7 @@ import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MA
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
||||
@@ -48,12 +51,15 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ContactGroupFactory contactGroupFactory =
|
||||
context.mock(ContactGroupFactory.class);
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
private final ClientVersioningHook hook =
|
||||
context.mock(ClientVersioningHook.class);
|
||||
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Contact contact = getContact();
|
||||
@@ -68,7 +74,7 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(localGroup));
|
||||
}});
|
||||
return new ClientVersioningManagerImpl(db, clientHelper,
|
||||
contactGroupFactory, clock);
|
||||
identityManager, contactGroupFactory, clock);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +123,10 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
@@ -138,8 +146,10 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testRemovesGroupWhenRemovingContact() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).removeGroup(txn, contactGroup);
|
||||
}});
|
||||
@@ -174,10 +184,12 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).addLocalMessage(txn, localVersions, new Metadata(),
|
||||
false);
|
||||
// Inform contacts that client versions have changed
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
// Find the latest local and remote updates (no remote update)
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
@@ -261,10 +273,12 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).addLocalMessage(txn, newLocalVersions, new Metadata(),
|
||||
false);
|
||||
// Inform contacts that client versions have changed
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
// Find the latest local and remote updates (no remote update)
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
@@ -357,10 +371,12 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).addLocalMessage(txn, newLocalVersions, new Metadata(),
|
||||
false);
|
||||
// Inform contacts that client versions have changed
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
// Find the latest local and remote updates
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
@@ -970,8 +986,10 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).containsGroup(txn, contactGroup.getId());
|
||||
will(returnValue(exists));
|
||||
|
||||
@@ -153,8 +153,8 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
List<InvitationContext> contexts = new ArrayList<>();
|
||||
for (Contact c : contacts) {
|
||||
byte[] signature = groupInvitationFactory.signInvitation(c, g,
|
||||
timestamp, localAuthor.getPrivateKey());
|
||||
byte[] signature = groupInvitationFactory.signInvitation(
|
||||
localAuthor, c, g, timestamp);
|
||||
contexts.add(new InvitationContext(c.getId(), timestamp,
|
||||
signature));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -39,7 +40,7 @@ public interface ConversationManager {
|
||||
@NotNullByDefault
|
||||
interface ConversationClient {
|
||||
|
||||
Group getContactGroup(Contact c);
|
||||
Group getContactGroup(Contact c, AuthorId local);
|
||||
|
||||
Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId contactId) throws DbException;
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
@@ -20,8 +21,8 @@ public interface GroupInvitationFactory {
|
||||
* included in the member's join message.
|
||||
*/
|
||||
@CryptoExecutor
|
||||
byte[] signInvitation(Contact c, GroupId privateGroupId, long timestamp,
|
||||
byte[] privateKey);
|
||||
byte[] signInvitation(LocalAuthor creator, Contact member,
|
||||
GroupId privateGroupId, long timestamp);
|
||||
|
||||
/**
|
||||
* Returns a token to be signed by the creator when inviting a member to
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.briar.api.test;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
@@ -24,9 +23,4 @@ public interface TestDataCreator {
|
||||
|
||||
@IoExecutor
|
||||
Contact addContact(String name) throws DbException;
|
||||
|
||||
@IoExecutor
|
||||
void addPrivateMessage(Contact contact, String text, long time,
|
||||
boolean local) throws DbException, FormatException;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
@@ -23,12 +25,14 @@ public abstract class ConversationClientImpl extends BdfIncomingMessageHook
|
||||
implements ConversationClient {
|
||||
|
||||
protected final MessageTracker messageTracker;
|
||||
protected final IdentityManager identityManager;
|
||||
|
||||
protected ConversationClientImpl(DatabaseComponent db,
|
||||
ClientHelper clientHelper, MetadataParser metadataParser,
|
||||
MessageTracker messageTracker) {
|
||||
MessageTracker messageTracker, IdentityManager identityManager) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
this.messageTracker = messageTracker;
|
||||
this.identityManager = identityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,11 +44,16 @@ public abstract class ConversationClientImpl extends BdfIncomingMessageHook
|
||||
messageTracker.initializeGroupCount(txn, g);
|
||||
}
|
||||
|
||||
protected AuthorId getLocalAuthorId(Transaction txn) throws DbException {
|
||||
return identityManager.getLocalAuthor(txn).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCount getGroupCount(Transaction txn, ContactId contactId)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
GroupId groupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId groupId = getContactGroup(contact, local).getId();
|
||||
return messageTracker.getGroupCount(txn, groupId);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,7 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
|
||||
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m,
|
||||
boolean canSucceed) throws DbException {
|
||||
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
|
||||
Contact c = contactManager.getContact(txn, sender, localAuthorId);
|
||||
Contact c = contactManager.getContact(txn, sender);
|
||||
AuthorInfo otherAuthorInfo =
|
||||
contactManager.getAuthorInfo(txn, otherAuthor.getId());
|
||||
IntroductionResponse response =
|
||||
|
||||
@@ -249,9 +249,7 @@ class IntroduceeProtocolEngine
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
|
||||
// Broadcast IntroductionRequestReceivedEvent
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
Contact c = contactManager.getContact(txn, s.getIntroducer().getId(),
|
||||
localAuthor.getId());
|
||||
Contact c = contactManager.getContact(txn, s.getIntroducer().getId());
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, m.getAuthor().getId());
|
||||
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
|
||||
@@ -432,14 +430,13 @@ class IntroduceeProtocolEngine
|
||||
|
||||
Map<TransportId, TransportKeySetId> keys = null;
|
||||
try {
|
||||
contactManager.addContact(txn, s.getRemote().author,
|
||||
localAuthor.getId(), false);
|
||||
contactManager.addContact(txn, s.getRemote().author, false);
|
||||
|
||||
// Only add transport properties and keys when the contact was added
|
||||
// This will be changed once we have a way to reset state for peers
|
||||
// that were contacts already at some point in the past.
|
||||
Contact c = contactManager.getContact(txn,
|
||||
s.getRemote().author.getId(), localAuthor.getId());
|
||||
s.getRemote().author.getId());
|
||||
|
||||
// add the keys to the new contact
|
||||
//noinspection ConstantConditions
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -79,7 +78,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
private final IntroducerProtocolEngine introducerEngine;
|
||||
private final IntroduceeProtocolEngine introduceeEngine;
|
||||
private final IntroductionCrypto crypto;
|
||||
private final IdentityManager identityManager;
|
||||
|
||||
private final Group localGroup;
|
||||
|
||||
@@ -90,6 +88,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser,
|
||||
MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
ContactManager contactManager,
|
||||
MessageParser messageParser,
|
||||
@@ -97,9 +96,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
SessionParser sessionParser,
|
||||
IntroducerProtocolEngine introducerEngine,
|
||||
IntroduceeProtocolEngine introduceeEngine,
|
||||
IntroductionCrypto crypto,
|
||||
IdentityManager identityManager) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
IntroductionCrypto crypto) {
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.contactManager = contactManager;
|
||||
@@ -109,7 +108,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
this.introducerEngine = introducerEngine;
|
||||
this.introduceeEngine = introduceeEngine;
|
||||
this.crypto = crypto;
|
||||
this.identityManager = identityManager;
|
||||
this.localGroup =
|
||||
contactGroupFactory.createLocalGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
}
|
||||
@@ -126,7 +124,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
@@ -148,21 +146,21 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
abortOrRemoveSessionWithIntroducee(txn, c);
|
||||
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory
|
||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, c);
|
||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -328,17 +326,18 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session, if there is one
|
||||
Author introducer = identityManager.getLocalAuthor(txn);
|
||||
SessionId sessionId =
|
||||
crypto.getSessionId(introducer, c1.getAuthor(),
|
||||
c2.getAuthor());
|
||||
SessionId sessionId = crypto.getSessionId(introducer,
|
||||
c1.getAuthor(), c2.getAuthor());
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
// Create or parse the session
|
||||
IntroducerSession session;
|
||||
MessageId storageId;
|
||||
if (ss == null) {
|
||||
// This is the first request - create a new session
|
||||
GroupId groupId1 = getContactGroup(c1).getId();
|
||||
GroupId groupId2 = getContactGroup(c2).getId();
|
||||
GroupId groupId1 =
|
||||
getContactGroup(c1, introducer.getId()).getId();
|
||||
GroupId groupId2 =
|
||||
getContactGroup(c2, introducer.getId()).getId();
|
||||
boolean alice = crypto.isAlice(c1.getAuthor().getId(),
|
||||
c2.getAuthor().getId());
|
||||
// use fixed deterministic roles for the introducees
|
||||
@@ -382,7 +381,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Parse the session
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
IntroduceeSession session = sessionParser
|
||||
.parseIntroduceeSession(contactGroupId, ss.bdfSession);
|
||||
// Handle the join or leave action
|
||||
@@ -408,7 +408,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -521,13 +522,11 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
BdfDictionary query = sessionEncoder.getIntroducerSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> sessions;
|
||||
try {
|
||||
sessions = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, localGroup.getId(),
|
||||
query);
|
||||
sessions = clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
localGroup.getId(), query);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException();
|
||||
}
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
for (Entry<MessageId, BdfDictionary> session : sessions.entrySet()) {
|
||||
IntroducerSession s;
|
||||
try {
|
||||
@@ -537,18 +536,18 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
if (s.getIntroduceeA().author.equals(c.getAuthor())) {
|
||||
abortOrRemoveSessionWithIntroducee(txn, s, session.getKey(),
|
||||
s.getIntroduceeB(), localAuthor);
|
||||
s.getIntroduceeB());
|
||||
} else if (s.getIntroduceeB().author.equals(c.getAuthor())) {
|
||||
abortOrRemoveSessionWithIntroducee(txn, s, session.getKey(),
|
||||
s.getIntroduceeA(), localAuthor);
|
||||
s.getIntroduceeA());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void abortOrRemoveSessionWithIntroducee(Transaction txn,
|
||||
IntroducerSession s, MessageId storageId, Introducee i,
|
||||
LocalAuthor localAuthor) throws DbException {
|
||||
if (db.containsContact(txn, i.author.getId(), localAuthor.getId())) {
|
||||
IntroducerSession s, MessageId storageId, Introducee i)
|
||||
throws DbException {
|
||||
if (db.containsContact(txn, i.author.getId())) {
|
||||
IntroducerSession session =
|
||||
introducerEngine.onIntroduceeRemoved(txn, i, s);
|
||||
storeSession(txn, storageId, session);
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -59,8 +61,10 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
MessagingManagerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
}
|
||||
@@ -79,7 +83,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
@@ -98,21 +102,21 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -188,15 +192,14 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public GroupId getConversationId(ContactId c) throws DbException {
|
||||
Contact contact;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
contact = db.getContact(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return getContactGroup(contact).getId();
|
||||
return db.transactionWithResult(true, txn -> getConversationId(txn, c));
|
||||
}
|
||||
|
||||
private GroupId getConversationId(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
return getContactGroup(contact, local).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,7 +209,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
Collection<MessageStatus> statuses;
|
||||
GroupId g;
|
||||
try {
|
||||
g = getContactGroup(db.getContact(txn, c)).getId();
|
||||
g = getConversationId(txn, c);
|
||||
metadata = clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
statuses = db.getMessageStatus(txn, c, g);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -17,8 +17,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo.Status;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -83,7 +81,6 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
|
||||
private final PrivateGroupFactory privateGroupFactory;
|
||||
private final ContactManager contactManager;
|
||||
private final IdentityManager identityManager;
|
||||
private final MessageTracker messageTracker;
|
||||
private final List<PrivateGroupHook> hooks;
|
||||
|
||||
@@ -91,12 +88,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
PrivateGroupManagerImpl(ClientHelper clientHelper,
|
||||
MetadataParser metadataParser, DatabaseComponent db,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
ContactManager contactManager, IdentityManager identityManager,
|
||||
MessageTracker messageTracker) {
|
||||
ContactManager contactManager, MessageTracker messageTracker) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
this.contactManager = contactManager;
|
||||
this.identityManager = identityManager;
|
||||
this.messageTracker = messageTracker;
|
||||
hooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
@@ -398,18 +393,17 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
try {
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMembers(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
for (Entry<Author, Visibility> m : authors.entrySet()) {
|
||||
Author a = m.getKey();
|
||||
AuthorInfo authorInfo = contactManager.getAuthorInfo(txn, a.getId());
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, a.getId());
|
||||
Status status = authorInfo.getStatus();
|
||||
Visibility v = m.getValue();
|
||||
ContactId c = null;
|
||||
if (v != INVISIBLE &&
|
||||
(status == VERIFIED || status == UNVERIFIED)) {
|
||||
c = contactManager.getContact(txn, a.getId(), la.getId())
|
||||
.getId();
|
||||
c = contactManager.getContact(txn, a.getId()).getId();
|
||||
}
|
||||
boolean isCreator = privateGroup.getCreator().equals(a);
|
||||
members.add(new GroupMember(a, authorInfo, isCreator, c, v));
|
||||
@@ -483,8 +477,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
if (!foundMember) throw new ProtocolStateException();
|
||||
if (changed) {
|
||||
clientHelper.mergeGroupMetadata(txn, g, meta);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
ContactId c = contactManager.getContact(txn, a, la.getId()).getId();
|
||||
ContactId c = contactManager.getContact(txn, a).getId();
|
||||
Event e = new ContactRelationshipRevealedEvent(g, a, c, v);
|
||||
txn.attach(e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -34,14 +35,15 @@ class GroupInvitationFactoryImpl implements GroupInvitationFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] signInvitation(Contact c, GroupId privateGroupId,
|
||||
long timestamp, byte[] privateKey) {
|
||||
AuthorId creatorId = c.getLocalAuthorId();
|
||||
AuthorId memberId = c.getAuthor().getId();
|
||||
public byte[] signInvitation(LocalAuthor creator, Contact member,
|
||||
GroupId privateGroupId, long timestamp) {
|
||||
AuthorId creatorId = creator.getId();
|
||||
AuthorId memberId = member.getAuthor().getId();
|
||||
BdfList token = createInviteToken(creatorId, memberId, privateGroupId,
|
||||
timestamp);
|
||||
try {
|
||||
return clientHelper.sign(SIGNING_LABEL_INVITE, token, privateKey);
|
||||
return clientHelper.sign(SIGNING_LABEL_INVITE, token,
|
||||
creator.getPrivateKey());
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -81,13 +83,15 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
ClientHelper clientHelper,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
PrivateGroupManager privateGroupManager,
|
||||
MessageParser messageParser, SessionParser sessionParser,
|
||||
SessionEncoder sessionEncoder,
|
||||
ProtocolEngineFactory engineFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
@@ -114,7 +118,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
@@ -138,13 +142,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,7 +271,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session, if there is one
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
CreatorSession session;
|
||||
@@ -308,7 +313,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -333,7 +339,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, getSessionId(g));
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -368,11 +375,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -436,8 +444,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// Look up the available invite messages for each contact
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Map<MessageId, BdfDictionary> results =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
contactGroupId, query);
|
||||
@@ -456,10 +465,11 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public boolean isInvitationAllowed(Contact c, GroupId privateGroupId)
|
||||
throws DbException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
@@ -492,15 +502,17 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
public void addingMember(Transaction txn, GroupId privateGroupId, Author a)
|
||||
throws DbException {
|
||||
// If the member is a contact, handle the add member action
|
||||
for (Contact c : db.getContactsByAuthorId(txn, a.getId()))
|
||||
addingMember(txn, privateGroupId, c);
|
||||
if (db.containsContact(txn, a.getId())) {
|
||||
addingMember(txn, privateGroupId, db.getContact(txn, a.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private void addingMember(Transaction txn, GroupId privateGroupId,
|
||||
Contact c) throws DbException {
|
||||
try {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
@@ -533,9 +545,10 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
// If we have any sessions in progress, tell the contacts we're leaving
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) continue; // No session for this contact
|
||||
// Handle the action
|
||||
@@ -574,7 +587,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -603,7 +616,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
private Map<GroupId, Visibility> getPreferredVisibilities(Transaction txn,
|
||||
Contact c) throws DbException, FormatException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
BdfDictionary query = sessionParser.getAllSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.inject.Inject;
|
||||
class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
implements BlogSharingManager, RemoveBlogHook {
|
||||
|
||||
private final IdentityManager identityManager;
|
||||
private final BlogManager blogManager;
|
||||
|
||||
@Inject
|
||||
@@ -43,8 +42,8 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
IdentityManager identityManager, BlogManager blogManager) {
|
||||
super(db, clientHelper, clientVersioningManager, metadataParser,
|
||||
messageParser, sessionEncoder, sessionParser, messageTracker,
|
||||
contactGroupFactory, engine, invitationFactory);
|
||||
this.identityManager = identityManager;
|
||||
identityManager, contactGroupFactory, engine,
|
||||
invitationFactory);
|
||||
this.blogManager = blogManager;
|
||||
}
|
||||
|
||||
@@ -80,8 +79,8 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
|
||||
// Pre-share both blogs, if they have not been shared already
|
||||
try {
|
||||
preShareGroup(txn, c, ourBlog.getGroup());
|
||||
preShareGroup(txn, c, theirBlog.getGroup());
|
||||
preShareGroup(txn, c, ourBlog.getGroup(), localAuthor.getId());
|
||||
preShareGroup(txn, c, theirBlog.getGroup(), localAuthor.getId());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||
@@ -27,13 +28,14 @@ class ForumSharingManagerImpl extends SharingManagerImpl<Forum>
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageParser<Forum> messageParser,
|
||||
SessionEncoder sessionEncoder, SessionParser sessionParser,
|
||||
MessageTracker messageTracker,
|
||||
MessageTracker messageTracker, IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
ProtocolEngine<Forum> engine,
|
||||
InvitationFactory<Forum, ForumInvitationResponse> invitationFactory) {
|
||||
super(db, clientHelper, clientVersioningManager, metadataParser,
|
||||
messageParser, sessionEncoder, sessionParser, messageTracker,
|
||||
contactGroupFactory, engine, invitationFactory);
|
||||
identityManager, contactGroupFactory, engine,
|
||||
invitationFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
@@ -70,10 +72,11 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageParser<S> messageParser,
|
||||
SessionEncoder sessionEncoder, SessionParser sessionParser,
|
||||
MessageTracker messageTracker,
|
||||
MessageTracker messageTracker, IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory, ProtocolEngine<S> engine,
|
||||
InvitationFactory<S, ?> invitationFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.messageParser = messageParser;
|
||||
this.sessionEncoder = sessionEncoder;
|
||||
@@ -105,7 +108,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getClientId(), getMajorVersion());
|
||||
@@ -123,13 +126,13 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(getClientId(),
|
||||
getMajorVersion(), c);
|
||||
getMajorVersion(), c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,10 +163,10 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
* and the Contact c in state SHARING.
|
||||
* If a session already exists, this does nothing.
|
||||
*/
|
||||
void preShareGroup(Transaction txn, Contact c, Group g)
|
||||
void preShareGroup(Transaction txn, Contact c, Group g, AuthorId local)
|
||||
throws DbException, FormatException {
|
||||
// Return if a session already exists with the contact
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession existingSession = getSession(txn, contactGroupId,
|
||||
getSessionId(g.getId()));
|
||||
if (existingSession != null) return;
|
||||
@@ -257,11 +260,13 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
if (!canBeShared(txn, shareableId, contact))
|
||||
if (!canBeShared(txn, shareableId, contact)) {
|
||||
// we might have received an invitation in the meantime
|
||||
return;
|
||||
}
|
||||
// Look up the session, if there is one
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
Session session;
|
||||
@@ -301,7 +306,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, id);
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -325,7 +331,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -385,8 +392,9 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// get invitations from each contact
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Map<MessageId, BdfDictionary> results =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
contactGroupId, query);
|
||||
@@ -456,7 +464,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
||||
if (client != SHARED) return false;
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
SessionId sessionId = getSessionId(g);
|
||||
try {
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
@@ -475,9 +484,10 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
SessionId sessionId = getSessionId(shareable.getId());
|
||||
// If we have any sessions in progress, tell the contacts we're leaving
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) continue; // No session for this contact
|
||||
// Let the engine perform a LEAVE action
|
||||
@@ -496,7 +506,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -525,7 +535,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
private Map<GroupId, Visibility> getPreferredVisibilities(Transaction txn,
|
||||
Contact c) throws DbException, FormatException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
BdfDictionary query = sessionParser.getAllSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
@@ -148,17 +147,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private List<Contact> createContacts(int numContacts) throws DbException {
|
||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < numContacts; i++) {
|
||||
LocalAuthor author = getRandomAuthor();
|
||||
Contact contact = addContact(localAuthor.getId(), author);
|
||||
Contact contact = addContact(author);
|
||||
contacts.add(contact);
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor author)
|
||||
throws DbException {
|
||||
private Contact addContact(LocalAuthor author) throws DbException {
|
||||
|
||||
// prepare to add contact
|
||||
SecretKey secretKey = getSecretKey();
|
||||
@@ -172,9 +169,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
Contact contact;
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
ContactId contactId = contactManager
|
||||
.addContact(txn, author, localAuthorId, secretKey,
|
||||
timestamp, true, verified, true);
|
||||
ContactId contactId = contactManager.addContact(txn, author,
|
||||
secretKey, timestamp, true, verified, true);
|
||||
if (random.nextBoolean()) {
|
||||
contactManager
|
||||
.setContactAlias(txn, contactId, getRandomAuthorName());
|
||||
@@ -196,8 +192,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
@Override
|
||||
public Contact addContact(String name) throws DbException {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
return addContact(localAuthor.getId(), getAuthor(name));
|
||||
return addContact(getAuthor(name));
|
||||
}
|
||||
|
||||
private LocalAuthor getAuthor(String name) {
|
||||
@@ -301,8 +296,10 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private void createPrivateMessages(List<Contact> contacts,
|
||||
int numPrivateMsgs) throws DbException {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (Contact contact : contacts) {
|
||||
Group group = messagingManager.getContactGroup(contact);
|
||||
Group group = messagingManager.getContactGroup(contact,
|
||||
localAuthor.getId());
|
||||
for (int i = 0; i < numPrivateMsgs; i++) {
|
||||
try {
|
||||
createRandomPrivateMessage(group.getId(), i);
|
||||
@@ -345,13 +342,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPrivateMessage(Contact contact, String text, long time,
|
||||
boolean local) throws DbException, FormatException {
|
||||
Group group = messagingManager.getContactGroup(contact);
|
||||
createPrivateMessage(group.getId(), text, time, local);
|
||||
}
|
||||
|
||||
private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
|
||||
throws DbException {
|
||||
for (int i = 0; i < numBlogPosts; i++) {
|
||||
|
||||
@@ -130,8 +130,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContact() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
Contact contact = getContact(blog2.getAuthor(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
@@ -150,8 +149,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContactAfterRemovingBlog() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
Contact contact = getContact(blog2.getAuthor(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
@@ -134,8 +135,10 @@ public class IntroductionIntegrationTest
|
||||
.makeIntroduction(introducee1, introducee2, "Hi!", time);
|
||||
|
||||
// check that messages are tracked properly
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 1, 0);
|
||||
assertGroupCount(messageTracker0, g2.getId(), 1, 0);
|
||||
|
||||
@@ -228,10 +231,8 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(listener1.succeeded);
|
||||
assertTrue(listener2.succeeded);
|
||||
|
||||
assertTrue(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertTrue(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertTrue(contactManager1.contactExists(author2.getId()));
|
||||
assertTrue(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
// make sure that introduced contacts are not verified
|
||||
for (Contact c : contactManager1.getContacts()) {
|
||||
@@ -318,13 +319,13 @@ public class IntroductionIntegrationTest
|
||||
assertFalse(listener1.succeeded);
|
||||
assertFalse(listener2.succeeded);
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertFalse(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertFalse(contactManager1.contactExists(author2.getId()));
|
||||
assertFalse(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
Collection<ConversationMessageHeader> messages =
|
||||
db0.transactionWithResult(true, txn -> introductionManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
@@ -387,10 +388,8 @@ public class IntroductionIntegrationTest
|
||||
listener1.getResponse().getIntroducedAuthor().getName());
|
||||
assertFalse(listener1.getResponse().canSucceed());
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertFalse(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertFalse(contactManager1.contactExists(author2.getId()));
|
||||
assertFalse(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
Collection<ConversationMessageHeader> messages =
|
||||
db0.transactionWithResult(true, txn -> introductionManager0
|
||||
@@ -499,10 +498,8 @@ public class IntroductionIntegrationTest
|
||||
sync1To0(2, true);
|
||||
sync0To2(2, true);
|
||||
|
||||
assertTrue(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertTrue(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertTrue(contactManager1.contactExists(author2.getId()));
|
||||
assertTrue(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
assertDefaultUiMessages();
|
||||
assertFalse(listener0.aborted);
|
||||
@@ -593,8 +590,10 @@ public class IntroductionIntegrationTest
|
||||
introduceeSession = getIntroduceeSession(c1);
|
||||
assertEquals(IntroduceeState.START, introduceeSession.getState());
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||
introductionManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
@@ -787,8 +786,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save ACCEPT from introducee1
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, ACCEPT);
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), ACCEPT);
|
||||
|
||||
// sync ACCEPT back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -824,8 +823,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save ACCEPT from introducee1
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, ACCEPT);
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), ACCEPT);
|
||||
|
||||
// sync ACCEPT back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -859,8 +858,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save DECLINE from introducee1
|
||||
DeclineMessage m = (DeclineMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, DECLINE);
|
||||
DeclineMessage m = (DeclineMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), DECLINE);
|
||||
|
||||
// sync DECLINE back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -903,8 +902,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To2(1, true);
|
||||
|
||||
// save AUTH from introducee1
|
||||
AuthMessage m = (AuthMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, AUTH);
|
||||
AuthMessage m = (AuthMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), AUTH);
|
||||
|
||||
// sync first AUTH message
|
||||
sync1To0(1, true);
|
||||
@@ -1006,13 +1005,11 @@ public class IntroductionIntegrationTest
|
||||
// 0 and 1 remove and re-add each other
|
||||
contactManager0.removeContact(contactId1From0);
|
||||
contactManager1.removeContact(contactId0From1);
|
||||
contactId1From0 = contactManager0
|
||||
.addContact(author1, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From0 = contactManager0.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1
|
||||
.addContact(author0, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From1 = contactManager1.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
|
||||
// Sync initial client versioning updates and transport properties
|
||||
@@ -1060,9 +1057,9 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
|
||||
// get response to be forwarded
|
||||
AcceptMessage message =
|
||||
(AcceptMessage) getMessageFor(c0.getClientHelper(),
|
||||
contact2From0, ACCEPT);
|
||||
AcceptMessage message = (AcceptMessage) getMessageFor(
|
||||
introductionManager0, c0.getClientHelper(), contact2From0,
|
||||
author0.getId(), ACCEPT);
|
||||
|
||||
// allow visitor to modify response
|
||||
AcceptMessage m = visitor.visit(message);
|
||||
@@ -1345,10 +1342,10 @@ public class IntroductionIntegrationTest
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractIntroductionMessage getMessageFor(ClientHelper ch,
|
||||
Contact contact, MessageType type)
|
||||
private AbstractIntroductionMessage getMessageFor(IntroductionManager im,
|
||||
ClientHelper ch, Contact contact, AuthorId local, MessageType type)
|
||||
throws FormatException, DbException {
|
||||
Group g = introductionManager0.getContactGroup(contact);
|
||||
Group g = im.getContactGroup(contact, local);
|
||||
BdfDictionary query = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, type.getValue())
|
||||
);
|
||||
@@ -1400,8 +1397,8 @@ public class IntroductionIntegrationTest
|
||||
.getMessageMetadataAsDictionary(getLocalGroup().getId());
|
||||
assertEquals(1, dicts.size());
|
||||
BdfDictionary d = dicts.values().iterator().next();
|
||||
Group introducerGroup =
|
||||
introductionManager2.getContactGroup(contact0From2);
|
||||
Group introducerGroup = introductionManager2
|
||||
.getContactGroup(contact0From2, author2.getId());
|
||||
return c.getSessionParser()
|
||||
.parseIntroduceeSession(introducerGroup.getId(), d);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
lifecycleManager.waitForStartup();
|
||||
// Add the other user as a contact
|
||||
ContactManager contactManager = device.getContactManager();
|
||||
return contactManager.addContact(remote, local.getId(), rootKey,
|
||||
timestamp, alice, true, true);
|
||||
return contactManager.addContact(remote, rootKey, timestamp, alice,
|
||||
true, true);
|
||||
}
|
||||
|
||||
private void sendMessage(SimplexMessagingIntegrationTestComponent device,
|
||||
|
||||
@@ -29,6 +29,7 @@ import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -164,7 +165,7 @@ public class PrivateGroupIntegrationTest
|
||||
getGroupMember(groupManager2, author1.getId()).getVisibility());
|
||||
|
||||
// 1 reveals the contact relationship to 2
|
||||
assertTrue(contactId2From1 != null);
|
||||
assertNotNull(contactId2From1);
|
||||
groupInvitationManager1.revealRelationship(contactId2From1, groupId0);
|
||||
sync1To2(1, true);
|
||||
sync2To1(1, true);
|
||||
@@ -213,8 +214,7 @@ public class PrivateGroupIntegrationTest
|
||||
@Nullable String text) throws DbException {
|
||||
Contact contact = contactManager0.getContact(c);
|
||||
byte[] signature = groupInvitationFactory
|
||||
.signInvitation(contact, groupId0, timestamp,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, contact, groupId0, timestamp);
|
||||
groupInvitationManager0
|
||||
.sendInvitation(groupId0, c, text, timestamp, signature);
|
||||
}
|
||||
|
||||
@@ -253,8 +253,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -306,8 +305,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
// signature uses joiner's key, not creator's key
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author1.getPrivateKey());
|
||||
.signInvitation(author1, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -400,8 +398,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c2 = contactManager0.getContact(contactId2From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c2, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c2, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg2 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -522,8 +519,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
|
||||
@@ -176,9 +176,9 @@ public class GroupInvitationIntegrationTest
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup0, true);
|
||||
|
||||
messages = db1.transactionWithResult(true,
|
||||
txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
messages = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager1.getMessageHeaders(txn,
|
||||
contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
boolean foundResponse = false;
|
||||
for (ConversationMessageHeader m : messages) {
|
||||
@@ -199,9 +199,9 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
sync1To0(1, true);
|
||||
|
||||
messages = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
messages = db0.transactionWithResult(true, txn ->
|
||||
groupInvitationManager0.getMessageHeaders(txn,
|
||||
contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
foundResponse = false;
|
||||
for (ConversationMessageHeader m : messages) {
|
||||
@@ -228,13 +228,15 @@ public class GroupInvitationIntegrationTest
|
||||
sendInvitation(timestamp, null);
|
||||
|
||||
// 0 has one read outgoing message
|
||||
Group g1 = groupInvitationManager0.getContactGroup(contact1From0);
|
||||
Group g1 = groupInvitationManager0.getContactGroup(contact1From0,
|
||||
author0.getId());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 1, 0, timestamp);
|
||||
|
||||
sync0To1(1, true);
|
||||
|
||||
// 1 has one unread message
|
||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1);
|
||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1,
|
||||
author1.getId());
|
||||
assertGroupCount(messageTracker1, g0.getId(), 1, 1, timestamp);
|
||||
ConversationMessageHeader m = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager1.getMessageHeaders(txn, contactId0From1)
|
||||
@@ -460,8 +462,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
private void sendInvitation(long timestamp, @Nullable String text) throws
|
||||
DbException {
|
||||
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
|
||||
privateGroup0.getId(), timestamp, author0.getPrivateKey());
|
||||
byte[] signature = groupInvitationFactory.signInvitation(author0,
|
||||
contact1From0, privateGroup0.getId(), timestamp);
|
||||
groupInvitationManager0
|
||||
.sendInvitation(privateGroup0.getId(), contactId1From0, text,
|
||||
timestamp, signature);
|
||||
|
||||
@@ -14,7 +14,8 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
@@ -49,6 +50,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -70,6 +72,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ClientVersioningManager clientVersioningManager =
|
||||
context.mock(ClientVersioningManager.class);
|
||||
private final ContactGroupFactory contactGroupFactory =
|
||||
@@ -99,8 +103,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact = getContact(author,
|
||||
new AuthorId(getRandomId()), true);
|
||||
private final Contact contact = getContact(author, true);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
@@ -143,9 +147,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
MessageTracker messageTracker = context.mock(MessageTracker.class);
|
||||
groupInvitationManager = new GroupInvitationManagerImpl(db,
|
||||
clientHelper, clientVersioningManager, metadataParser,
|
||||
messageTracker, contactGroupFactory, privateGroupFactory,
|
||||
privateGroupManager, messageParser, sessionParser,
|
||||
sessionEncoder, engineFactory);
|
||||
messageTracker, identityManager, contactGroupFactory,
|
||||
privateGroupFactory, privateGroupManager, messageParser,
|
||||
sessionParser, sessionEncoder, engineFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +185,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
|
||||
@@ -204,8 +210,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectGetSession(noResults, new SessionId(g.getBytes()),
|
||||
@@ -260,8 +268,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testRemovingContact() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).removeGroup(txn, contactGroup);
|
||||
}});
|
||||
@@ -475,8 +485,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectCreateStorageId();
|
||||
@@ -507,8 +519,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
||||
@@ -536,8 +550,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -588,8 +604,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parseInviteeSession(contactGroup.getId(), bdfSession);
|
||||
@@ -610,8 +628,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parsePeerSession(contactGroup.getId(), bdfSession);
|
||||
@@ -635,8 +655,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -672,8 +694,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(messageParser).getMessagesVisibleInUiQuery();
|
||||
will(returnValue(query));
|
||||
@@ -744,10 +768,12 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(query));
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId(), query);
|
||||
@@ -814,8 +840,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -837,8 +865,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
public void testAddingMember() throws Exception {
|
||||
expectAddingMember(privateGroup.getId(), contact);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContactsByAuthorId(txn, author.getId());
|
||||
will(returnValue(Collections.singletonList(contact)));
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).getContact(txn, author.getId());
|
||||
will(returnValue(contact));
|
||||
}});
|
||||
groupInvitationManager.addingMember(txn, privateGroup.getId(), author);
|
||||
}
|
||||
@@ -866,16 +896,18 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
sessionId, contactGroup3.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact2);
|
||||
MAJOR_VERSION, contact2, localAuthor.getId());
|
||||
will(returnValue(contactGroup2));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact3);
|
||||
MAJOR_VERSION, contact3, localAuthor.getId());
|
||||
will(returnValue(contactGroup3));
|
||||
// session 1
|
||||
oneOf(sessionParser).getRole(bdfSession);
|
||||
|
||||
@@ -330,8 +330,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
privateGroup.getSalt(),
|
||||
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
|
||||
signature);
|
||||
Contact notCreatorContact = getContact(contactId, getAuthor(),
|
||||
localAuthor.getId(), true);
|
||||
Contact notCreatorContact = getContact(contactId, getAuthor(), true);
|
||||
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// get sharing group and assert group message count
|
||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact1From0).getId();
|
||||
MAJOR_VERSION, contact1From0, author0.getId()).getId();
|
||||
assertGroupCount(messageTracker0, g, 1, 0);
|
||||
|
||||
// check that request message state is correct
|
||||
@@ -217,7 +217,7 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// get sharing group and assert group message count
|
||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact1From0).getId();
|
||||
MAJOR_VERSION, contact1From0, author0.getId()).getId();
|
||||
assertGroupCount(messageTracker0, g, 1, 0);
|
||||
|
||||
// sync first request message
|
||||
|
||||
@@ -62,8 +62,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact =
|
||||
getContact(author, localAuthor.getId(), true);
|
||||
private final Contact contact = getContact(author, true);
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Collection<Contact> contacts =
|
||||
Collections.singletonList(contact);
|
||||
@@ -123,8 +122,10 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the contact group and share it with the contact
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
|
||||
@@ -202,7 +203,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
Message message = getMessage(contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||
@@ -237,10 +238,12 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
@@ -416,7 +417,7 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// response and invitation got tracked
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact0From1);
|
||||
MAJOR_VERSION, contact0From1, author1.getId());
|
||||
assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId())
|
||||
.getMsgCount());
|
||||
|
||||
@@ -448,7 +449,7 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// assert that the invitation arrived
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact0From1);
|
||||
MAJOR_VERSION, contact0From1, author1.getId());
|
||||
assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId())
|
||||
.getMsgCount());
|
||||
|
||||
@@ -777,8 +778,9 @@ public class ForumSharingIntegrationTest
|
||||
.contains(contact0From1));
|
||||
|
||||
// send an accept message for the same forum
|
||||
Message m = messageEncoder.encodeAcceptMessage(
|
||||
forumSharingManager0.getContactGroup(contact1From0).getId(),
|
||||
GroupId contactGroupId = forumSharingManager0.getContactGroup(
|
||||
contact1From0, author0.getId()).getId();
|
||||
Message m = messageEncoder.encodeAcceptMessage(contactGroupId,
|
||||
forum0.getId(), clock.currentTimeMillis(), invitationId);
|
||||
c0.getClientHelper().addLocalMessage(m, new BdfDictionary(), true);
|
||||
|
||||
|
||||
@@ -283,21 +283,17 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
}
|
||||
|
||||
protected void addDefaultContacts() throws Exception {
|
||||
contactId1From0 = contactManager0
|
||||
.addContact(author1, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From0 = contactManager0.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1
|
||||
.addContact(author0, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From1 = contactManager1.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
contactId2From0 = contactManager0
|
||||
.addContact(author2, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId2From0 = contactManager0.addContact(author2, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact2From0 = contactManager0.getContact(contactId2From0);
|
||||
contactId0From2 = contactManager2
|
||||
.addContact(author0, author2.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From2 = contactManager2.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From2 = contactManager2.getContact(contactId0From2);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
@@ -315,12 +311,10 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
|
||||
protected void addContacts1And2(boolean haveTransportProperties)
|
||||
throws Exception {
|
||||
contactId2From1 = contactManager1
|
||||
.addContact(author2, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From2 = contactManager2
|
||||
.addContact(author1, author2.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId2From1 = contactManager1.addContact(author2, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From2 = contactManager2.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
sync1To2(1, true);
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.db.DatabaseExecutor
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException
|
||||
import org.briarproject.bramble.api.event.Event
|
||||
import org.briarproject.bramble.api.event.EventListener
|
||||
import org.briarproject.bramble.api.identity.IdentityManager
|
||||
import org.briarproject.bramble.api.system.Clock
|
||||
import org.briarproject.bramble.util.StringUtils.utf8IsTooLong
|
||||
import org.briarproject.briar.api.blog.BlogInvitationRequest
|
||||
@@ -46,6 +47,7 @@ internal class MessagingControllerImpl
|
||||
@Inject
|
||||
constructor(
|
||||
private val messagingManager: MessagingManager,
|
||||
private val identityManager: IdentityManager,
|
||||
private val conversationManager: ConversationManager,
|
||||
private val privateMessageFactory: PrivateMessageFactory,
|
||||
private val contactManager: ContactManager,
|
||||
@@ -71,7 +73,7 @@ constructor(
|
||||
if (utf8IsTooLong(message, MAX_PRIVATE_MESSAGE_TEXT_LENGTH))
|
||||
throw BadRequestResponse("Message text is too long")
|
||||
|
||||
val group = messagingManager.getContactGroup(contact)
|
||||
val group = messagingManager.getContactGroup(contact, identityManager.localAuthor.id)
|
||||
val now = clock.currentTimeMillis()
|
||||
val m = privateMessageFactory.createPrivateMessage(group.id, now, message, emptyList())
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ abstract class ControllerTest {
|
||||
protected val group: Group = getGroup(getClientId(), 0)
|
||||
protected val author: Author = getAuthor()
|
||||
protected val localAuthor: LocalAuthor = getLocalAuthor()
|
||||
protected val contact: Contact = getContact(author, localAuthor.id, true)
|
||||
protected val contact: Contact = getContact(author, true)
|
||||
protected val message: Message = getMessage(group.id)
|
||||
protected val text: String = getRandomString(5)
|
||||
protected val timestamp = 42L
|
||||
|
||||
@@ -40,6 +40,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
|
||||
private val controller = MessagingControllerImpl(
|
||||
messagingManager,
|
||||
identityManager,
|
||||
conversationManager,
|
||||
privateMessageFactory,
|
||||
contactManager,
|
||||
@@ -114,7 +115,8 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
|
||||
expectGetContact()
|
||||
every { ctx.body() } returns """{"text": "$text"}"""
|
||||
every { messagingManager.getContactGroup(contact) } returns group
|
||||
every { identityManager.localAuthor } returns localAuthor
|
||||
every { messagingManager.getContactGroup(contact, localAuthor.id) } returns group
|
||||
every { clock.currentTimeMillis() } returns timestamp
|
||||
every {
|
||||
privateMessageFactory.createPrivateMessage(
|
||||
|
||||
Reference in New Issue
Block a user