Add handshake key pairs to DB, remove inactive contacts.

This commit is contained in:
akwizgran
2019-04-18 13:15:25 +01:00
parent dcebd5a81c
commit 0587fdc54c
44 changed files with 407 additions and 532 deletions

View File

@@ -8,6 +8,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.util.StringUtils.toUtf8; import static org.briarproject.bramble.util.StringUtils.toUtf8;
@Immutable @Immutable
@@ -19,21 +20,28 @@ public class Contact {
private final AuthorId localAuthorId; private final AuthorId localAuthorId;
@Nullable @Nullable
private final String alias; private final String alias;
private final boolean verified, active; @Nullable
private final byte[] handshakePublicKey;
private final boolean verified;
public Contact(ContactId id, Author author, AuthorId localAuthorId, public Contact(ContactId id, Author author, AuthorId localAuthorId,
@Nullable String alias, boolean verified, boolean active) { @Nullable String alias, @Nullable byte[] handshakePublicKey,
boolean verified) {
if (alias != null) { if (alias != null) {
int aliasLength = toUtf8(alias).length; int aliasLength = toUtf8(alias).length;
if (aliasLength == 0 || aliasLength > MAX_AUTHOR_NAME_LENGTH) if (aliasLength == 0 || aliasLength > MAX_AUTHOR_NAME_LENGTH)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
if (handshakePublicKey != null && (handshakePublicKey.length == 0 ||
handshakePublicKey.length > MAX_PUBLIC_KEY_LENGTH)) {
throw new IllegalArgumentException();
}
this.id = id; this.id = id;
this.author = author; this.author = author;
this.localAuthorId = localAuthorId; this.localAuthorId = localAuthorId;
this.alias = alias; this.alias = alias;
this.handshakePublicKey = handshakePublicKey;
this.verified = verified; this.verified = verified;
this.active = active;
} }
public ContactId getId() { public ContactId getId() {
@@ -53,12 +61,13 @@ public class Contact {
return alias; return alias;
} }
public boolean isVerified() { @Nullable
return verified; public byte[] getHandshakePublicKey() {
return handshakePublicKey;
} }
public boolean isActive() { public boolean isVerified() {
return active; return verified;
} }
@Override @Override

View File

@@ -39,7 +39,7 @@ public interface ContactManager {
* and returns an ID for the contact. * and returns an ID for the contact.
*/ */
ContactId addContact(Transaction txn, Author remote, AuthorId local, ContactId addContact(Transaction txn, Author remote, AuthorId local,
boolean verified, boolean active) throws DbException; boolean verified) throws DbException;
/** /**
* Stores a contact associated with the given local and remote pseudonyms, * Stores a contact associated with the given local and remote pseudonyms,
@@ -108,7 +108,7 @@ public interface ContactManager {
/** /**
* Returns all active contacts. * Returns all active contacts.
*/ */
Collection<Contact> getActiveContacts() throws DbException; Collection<Contact> getContacts() throws DbException;
/** /**
* Removes a contact and all associated state. * Removes a contact and all associated state.
@@ -120,12 +120,6 @@ public interface ContactManager {
*/ */
void removeContact(Transaction txn, ContactId c) throws DbException; void removeContact(Transaction txn, ContactId c) throws DbException;
/**
* Marks a contact as active or inactive.
*/
void setContactActive(Transaction txn, ContactId c, boolean active)
throws DbException;
/** /**
* Sets an alias name for the contact or unsets it if alias is null. * Sets an alias name for the contact or unsets it if alias is null.
*/ */

View File

@@ -14,18 +14,12 @@ import javax.annotation.concurrent.Immutable;
public class ContactAddedEvent extends Event { public class ContactAddedEvent extends Event {
private final ContactId contactId; private final ContactId contactId;
private final boolean active;
public ContactAddedEvent(ContactId contactId, boolean active) { public ContactAddedEvent(ContactId contactId) {
this.contactId = contactId; this.contactId = contactId;
this.active = active;
} }
public ContactId getContactId() { public ContactId getContactId() {
return contactId; return contactId;
} }
public boolean isActive() {
return active;
}
} }

View File

@@ -1,31 +0,0 @@
package org.briarproject.bramble.api.contact.event;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
/**
* An event that is broadcast when a contact is marked active or inactive.
*/
@Immutable
@NotNullByDefault
public class ContactStatusChangedEvent extends Event {
private final ContactId contactId;
private final boolean active;
public ContactStatusChangedEvent(ContactId contactId, boolean active) {
this.contactId = contactId;
this.active = active;
}
public ContactId getContactId() {
return contactId;
}
public boolean isActive() {
return active;
}
}

View File

@@ -106,7 +106,7 @@ public interface DatabaseComponent {
* and returns an ID for the contact. * and returns an ID for the contact.
*/ */
ContactId addContact(Transaction txn, Author remote, AuthorId local, ContactId addContact(Transaction txn, Author remote, AuthorId local,
boolean verified, boolean active) throws DbException; boolean verified) throws DbException;
/** /**
* Stores a group. * Stores a group.
@@ -590,12 +590,6 @@ public interface DatabaseComponent {
*/ */
void setContactVerified(Transaction txn, ContactId c) throws DbException; void setContactVerified(Transaction txn, ContactId c) throws DbException;
/**
* Marks the given contact as active or inactive.
*/
void setContactActive(Transaction txn, ContactId c, boolean active)
throws DbException;
/** /**
* Sets an alias name for the contact or unsets it if alias is null. * Sets an alias name for the contact or unsets it if alias is null.
*/ */

View File

@@ -2,8 +2,11 @@ package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
/** /**
* A pseudonym for the local user. * A pseudonym for the local user.
*/ */
@@ -12,6 +15,8 @@ import javax.annotation.concurrent.Immutable;
public class LocalAuthor extends Author { public class LocalAuthor extends Author {
private final byte[] privateKey; private final byte[] privateKey;
@Nullable
private final byte[] handshakePublicKey, handshakePrivateKey;
private final long created; private final long created;
public LocalAuthor(AuthorId id, int formatVersion, String name, public LocalAuthor(AuthorId id, int formatVersion, String name,
@@ -19,6 +24,22 @@ public class LocalAuthor extends Author {
super(id, formatVersion, name, publicKey); super(id, formatVersion, name, publicKey);
this.privateKey = privateKey; this.privateKey = privateKey;
this.created = created; this.created = created;
handshakePublicKey = null;
handshakePrivateKey = null;
}
public LocalAuthor(AuthorId id, int formatVersion, String name,
byte[] publicKey, byte[] privateKey, byte[] handshakePublicKey,
byte[] handshakePrivateKey, long created) {
super(id, formatVersion, name, publicKey);
if (handshakePublicKey.length == 0 ||
handshakePublicKey.length > MAX_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException();
}
this.privateKey = privateKey;
this.handshakePublicKey = handshakePublicKey;
this.handshakePrivateKey = handshakePrivateKey;
this.created = created;
} }
/** /**
@@ -28,6 +49,22 @@ public class LocalAuthor extends Author {
return privateKey; return privateKey;
} }
/**
* Returns the public key used for handshaking, or null if no key exists.
*/
@Nullable
public byte[] getHandshakePublicKey() {
return handshakePublicKey;
}
/**
* Returns the private key used for handshaking, or null if no key exists.
*/
@Nullable
public byte[] getHandshakePrivateKey() {
return handshakePrivateKey;
}
/** /**
* Returns the time the pseudonym was created, in milliseconds since the * Returns the time the pseudonym was created, in milliseconds since the
* Unix epoch. * Unix epoch.

View File

@@ -23,9 +23,8 @@ public interface KeyManager {
* <p/> * <p/>
* {@link StreamContext StreamContexts} for the contact can be created * {@link StreamContext StreamContexts} for the contact can be created
* after this method has returned. * after this method has returned.
* @param alice true if the local party is Alice
* *
* @param alice true if the local party is Alice
* @param active whether the derived keys can be used for outgoing streams
*/ */
Map<TransportId, TransportKeySetId> addContact(Transaction txn, ContactId c, Map<TransportId, TransportKeySetId> addContact(Transaction txn, ContactId c,
SecretKey rootKey, long timestamp, boolean alice, boolean active) SecretKey rootKey, long timestamp, boolean alice, boolean active)

View File

@@ -1,6 +1,8 @@
package org.briarproject.bramble.test; package org.briarproject.bramble.test;
import org.briarproject.bramble.api.UniqueId; import org.briarproject.bramble.api.UniqueId;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.PendingContact; import org.briarproject.bramble.api.contact.PendingContact;
import org.briarproject.bramble.api.contact.PendingContactId; import org.briarproject.bramble.api.contact.PendingContactId;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
@@ -44,6 +46,7 @@ public class TestUtils {
new AtomicInteger((int) (Math.random() * 1000 * 1000)); new AtomicInteger((int) (Math.random() * 1000 * 1000));
private static final Random random = new Random(); private static final Random random = new Random();
private static final long timestamp = System.currentTimeMillis(); private static final long timestamp = System.currentTimeMillis();
private static final AtomicInteger nextContactId = new AtomicInteger(1);
public static File getTestDirectory() { public static File getTestDirectory() {
int name = nextTestDir.getAndIncrement(); int name = nextTestDir.getAndIncrement();
@@ -155,6 +158,27 @@ public class TestUtils {
timestamp); timestamp);
} }
public static ContactId getContactId() {
return new ContactId(nextContactId.getAndIncrement());
}
public static Contact getContact() {
return getContact(getAuthor(), new AuthorId(getRandomId()),
random.nextBoolean());
}
public static Contact getContact(Author remote, AuthorId local,
boolean verified) {
return getContact(getContactId(), remote, local, verified);
}
public static Contact getContact(ContactId c, Author remote, AuthorId local,
boolean verified) {
return new Contact(c, remote, local,
getRandomString(MAX_AUTHOR_NAME_LENGTH),
getRandomBytes(MAX_PUBLIC_KEY_LENGTH), verified);
}
public static double getMedian(Collection<? extends Number> samples) { public static double getMedian(Collection<? extends Number> samples) {
int size = samples.size(); int size = samples.size();
if (size == 0) throw new IllegalArgumentException(); if (size == 0) throw new IllegalArgumentException();

View File

@@ -18,7 +18,6 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.transport.KeyManager; import org.briarproject.bramble.api.transport.KeyManager;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -72,7 +71,7 @@ class ContactManagerImpl implements ContactManager {
public ContactId addContact(Transaction txn, Author remote, AuthorId local, public ContactId addContact(Transaction txn, Author remote, AuthorId local,
SecretKey rootKey, long timestamp, boolean alice, boolean verified, SecretKey rootKey, long timestamp, boolean alice, boolean verified,
boolean active) throws DbException { boolean active) throws DbException {
ContactId c = db.addContact(txn, remote, local, verified, active); ContactId c = db.addContact(txn, remote, local, verified);
keyManager.addContact(txn, c, rootKey, timestamp, alice, active); keyManager.addContact(txn, c, rootKey, timestamp, alice, active);
Contact contact = db.getContact(txn, c); Contact contact = db.getContact(txn, c);
for (ContactHook hook : hooks) hook.addingContact(txn, contact); for (ContactHook hook : hooks) hook.addingContact(txn, contact);
@@ -81,8 +80,8 @@ class ContactManagerImpl implements ContactManager {
@Override @Override
public ContactId addContact(Transaction txn, Author remote, AuthorId local, public ContactId addContact(Transaction txn, Author remote, AuthorId local,
boolean verified, boolean active) throws DbException { boolean verified) throws DbException {
ContactId c = db.addContact(txn, remote, local, verified, active); ContactId c = db.addContact(txn, remote, local, verified);
Contact contact = db.getContact(txn, c); Contact contact = db.getContact(txn, c);
for (ContactHook hook : hooks) hook.addingContact(txn, contact); for (ContactHook hook : hooks) hook.addingContact(txn, contact);
return c; return c;
@@ -165,12 +164,8 @@ class ContactManagerImpl implements ContactManager {
} }
@Override @Override
public Collection<Contact> getActiveContacts() throws DbException { public Collection<Contact> getContacts() throws DbException {
Collection<Contact> contacts = return db.transactionWithResult(true, db::getContacts);
db.transactionWithResult(true, db::getContacts);
List<Contact> active = new ArrayList<>(contacts.size());
for (Contact c : contacts) if (c.isActive()) active.add(c);
return active;
} }
@Override @Override
@@ -178,12 +173,6 @@ class ContactManagerImpl implements ContactManager {
db.transaction(false, txn -> removeContact(txn, c)); db.transaction(false, txn -> removeContact(txn, c));
} }
@Override
public void setContactActive(Transaction txn, ContactId c, boolean active)
throws DbException {
db.setContactActive(txn, c, active);
}
@Override @Override
public void setContactAlias(Transaction txn, ContactId c, public void setContactAlias(Transaction txn, ContactId c,
@Nullable String alias) throws DbException { @Nullable String alias) throws DbException {

View File

@@ -90,8 +90,8 @@ interface Database<T> {
* Stores a contact associated with the given local and remote pseudonyms, * Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact. * and returns an ID for the contact.
*/ */
ContactId addContact(T txn, Author remote, AuthorId local, boolean verified, ContactId addContact(T txn, Author remote, AuthorId local, boolean verified)
boolean active) throws DbException; throws DbException;
/** /**
* Stores a group. * Stores a group.
@@ -672,12 +672,6 @@ interface Database<T> {
*/ */
void setContactVerified(T txn, ContactId c) throws DbException; void setContactVerified(T txn, ContactId c) throws DbException;
/**
* Marks the given contact as active or inactive.
*/
void setContactActive(T txn, ContactId c, boolean active)
throws DbException;
/** /**
* Sets an alias name for a contact. * Sets an alias name for a contact.
*/ */

View File

@@ -6,7 +6,6 @@ import org.briarproject.bramble.api.contact.PendingContact;
import org.briarproject.bramble.api.contact.PendingContactId; import org.briarproject.bramble.api.contact.PendingContactId;
import org.briarproject.bramble.api.contact.event.ContactAddedEvent; import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent; import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
import org.briarproject.bramble.api.contact.event.ContactVerifiedEvent; import org.briarproject.bramble.api.contact.event.ContactVerifiedEvent;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.CommitAction; import org.briarproject.bramble.api.db.CommitAction;
@@ -234,7 +233,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
@Override @Override
public ContactId addContact(Transaction transaction, Author remote, public ContactId addContact(Transaction transaction, Author remote,
AuthorId local, boolean verified, boolean active) AuthorId local, boolean verified)
throws DbException { throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException(); if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction); T txn = unbox(transaction);
@@ -244,9 +243,8 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
throw new ContactExistsException(); throw new ContactExistsException();
if (db.containsContact(txn, remote.getId(), local)) if (db.containsContact(txn, remote.getId(), local))
throw new ContactExistsException(); throw new ContactExistsException();
ContactId c = db.addContact(txn, remote, local, verified, active); ContactId c = db.addContact(txn, remote, local, verified);
transaction.attach(new ContactAddedEvent(c, active)); transaction.attach(new ContactAddedEvent(c));
if (active) transaction.attach(new ContactStatusChangedEvent(c, true));
return c; return c;
} }
@@ -969,17 +967,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
transaction.attach(new ContactVerifiedEvent(c)); transaction.attach(new ContactVerifiedEvent(c));
} }
@Override
public void setContactActive(Transaction transaction, ContactId c,
boolean active) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction);
if (!db.containsContact(txn, c))
throw new NoSuchContactException();
db.setContactActive(txn, c, active);
transaction.attach(new ContactStatusChangedEvent(c, active));
}
@Override @Override
public void setContactAlias(Transaction transaction, ContactId c, public void setContactAlias(Transaction transaction, ContactId c,
@Nullable String alias) throws DbException { @Nullable String alias) throws DbException {

View File

@@ -44,7 +44,6 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@@ -64,6 +63,7 @@ import javax.annotation.Nullable;
import static java.sql.Types.BINARY; import static java.sql.Types.BINARY;
import static java.sql.Types.INTEGER; import static java.sql.Types.INTEGER;
import static java.sql.Types.VARCHAR; import static java.sql.Types.VARCHAR;
import static java.util.Arrays.asList;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.api.db.Metadata.REMOVE; import static org.briarproject.bramble.api.db.Metadata.REMOVE;
@@ -113,6 +113,8 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " name _STRING NOT NULL," + " name _STRING NOT NULL,"
+ " publicKey _BINARY NOT NULL," + " publicKey _BINARY NOT NULL,"
+ " privateKey _BINARY NOT NULL," + " privateKey _BINARY NOT NULL,"
+ " handshakePublicKey _BINARY," // Null if not generated
+ " handshakePrivateKey _BINARY," // Null if not generated
+ " created BIGINT NOT NULL," + " created BIGINT NOT NULL,"
+ " PRIMARY KEY (authorId))"; + " PRIMARY KEY (authorId))";
@@ -122,11 +124,11 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " authorId _HASH NOT NULL," + " authorId _HASH NOT NULL,"
+ " formatVersion INT NOT NULL," + " formatVersion INT NOT NULL,"
+ " name _STRING NOT NULL," + " name _STRING NOT NULL,"
+ " alias _STRING," // Null if no alias exists + " alias _STRING," // Null if no alias has been set
+ " publicKey _BINARY NOT NULL," + " publicKey _BINARY NOT NULL,"
+ " handshakePublicKey _BINARY," // Null if key is unknown
+ " localAuthorId _HASH NOT NULL," + " localAuthorId _HASH NOT NULL,"
+ " verified BOOLEAN NOT NULL," + " verified BOOLEAN NOT NULL,"
+ " active BOOLEAN NOT NULL,"
+ " PRIMARY KEY (contactId)," + " PRIMARY KEY (contactId),"
+ " FOREIGN KEY (localAuthorId)" + " FOREIGN KEY (localAuthorId)"
+ " REFERENCES localAuthors (authorId)" + " REFERENCES localAuthors (authorId)"
@@ -479,11 +481,12 @@ abstract class JdbcDatabase implements Database<Connection> {
// Package access for testing // Package access for testing
List<Migration<Connection>> getMigrations() { List<Migration<Connection>> getMigrations() {
return Arrays.asList( return asList(
new Migration38_39(), new Migration38_39(),
new Migration39_40(), new Migration39_40(),
new Migration40_41(dbTypes), new Migration40_41(dbTypes),
new Migration41_42(dbTypes) new Migration41_42(dbTypes),
new Migration42_43(dbTypes)
); );
} }
@@ -660,16 +663,15 @@ abstract class JdbcDatabase implements Database<Connection> {
@Override @Override
public ContactId addContact(Connection txn, Author remote, AuthorId local, public ContactId addContact(Connection txn, Author remote, AuthorId local,
boolean verified, boolean active) throws DbException { boolean verified) throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
// Create a contact row // Create a contact row
String sql = "INSERT INTO contacts" String sql = "INSERT INTO contacts"
+ " (authorId, formatVersion, name, publicKey," + " (authorId, formatVersion, name, publicKey,"
+ " localAuthorId," + " localAuthorId, verified)"
+ " verified, active)" + " VALUES (?, ?, ?, ?, ?, ?)";
+ " VALUES (?, ?, ?, ?, ?, ?, ?)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, remote.getId().getBytes()); ps.setBytes(1, remote.getId().getBytes());
ps.setInt(2, remote.getFormatVersion()); ps.setInt(2, remote.getFormatVersion());
@@ -677,7 +679,6 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setBytes(4, remote.getPublicKey()); ps.setBytes(4, remote.getPublicKey());
ps.setBytes(5, local.getBytes()); ps.setBytes(5, local.getBytes());
ps.setBoolean(6, verified); ps.setBoolean(6, verified);
ps.setBoolean(7, active);
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if (affected != 1) throw new DbStateException(); if (affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -878,16 +879,20 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
String sql = "INSERT INTO localAuthors" String sql = "INSERT INTO localAuthors"
+ " (authorId, formatVersion, name, publicKey," + " (authorId, formatVersion, name, publicKey, privateKey,"
+ " privateKey, created)" + " handshakePublicKey, handshakePrivateKey, created)"
+ " VALUES (?, ?, ?, ?, ?, ?)"; + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, a.getId().getBytes()); ps.setBytes(1, a.getId().getBytes());
ps.setInt(2, a.getFormatVersion()); ps.setInt(2, a.getFormatVersion());
ps.setString(3, a.getName()); ps.setString(3, a.getName());
ps.setBytes(4, a.getPublicKey()); ps.setBytes(4, a.getPublicKey());
ps.setBytes(5, a.getPrivateKey()); ps.setBytes(5, a.getPrivateKey());
ps.setLong(6, a.getTimeCreated()); if (a.getHandshakePublicKey() == null) ps.setNull(6, BINARY);
else ps.setBytes(6, a.getHandshakePublicKey());
if (a.getHandshakePrivateKey() == null) ps.setNull(7, BINARY);
else ps.setBytes(7, a.getHandshakePrivateKey());
ps.setLong(8, a.getTimeCreated());
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if (affected != 1) throw new DbStateException(); if (affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -1427,7 +1432,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT authorId, formatVersion, name, alias," String sql = "SELECT authorId, formatVersion, name, alias,"
+ " publicKey, localAuthorId, verified, active" + " publicKey, handshakePublicKey, localAuthorId, verified"
+ " FROM contacts" + " FROM contacts"
+ " WHERE contactId = ?"; + " WHERE contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -1439,15 +1444,15 @@ abstract class JdbcDatabase implements Database<Connection> {
String name = rs.getString(3); String name = rs.getString(3);
String alias = rs.getString(4); String alias = rs.getString(4);
byte[] publicKey = rs.getBytes(5); byte[] publicKey = rs.getBytes(5);
AuthorId localAuthorId = new AuthorId(rs.getBytes(6)); byte[] handshakePublicKey = rs.getBytes(6);
boolean verified = rs.getBoolean(7); AuthorId localAuthorId = new AuthorId(rs.getBytes(7));
boolean active = rs.getBoolean(8); boolean verified = rs.getBoolean(8);
rs.close(); rs.close();
ps.close(); ps.close();
Author author = Author author =
new Author(authorId, formatVersion, name, publicKey); new Author(authorId, formatVersion, name, publicKey);
return new Contact(c, author, localAuthorId, alias, verified, return new Contact(c, author, localAuthorId, alias,
active); handshakePublicKey, verified);
} catch (SQLException e) { } catch (SQLException e) {
tryToClose(rs, LOG, WARNING); tryToClose(rs, LOG, WARNING);
tryToClose(ps, LOG, WARNING); tryToClose(ps, LOG, WARNING);
@@ -1456,13 +1461,13 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
@Override @Override
public Collection<Contact> getContacts(Connection txn) public Collection<Contact> getContacts(Connection txn) throws DbException {
throws DbException {
Statement s = null; Statement s = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT contactId, authorId, formatVersion, name," String sql = "SELECT contactId, authorId, formatVersion, name,"
+ " alias, publicKey, localAuthorId, verified, active" + " alias, publicKey, handshakePublicKey, localAuthorId,"
+ " verified"
+ " FROM contacts"; + " FROM contacts";
s = txn.createStatement(); s = txn.createStatement();
rs = s.executeQuery(sql); rs = s.executeQuery(sql);
@@ -1474,13 +1479,13 @@ abstract class JdbcDatabase implements Database<Connection> {
String name = rs.getString(4); String name = rs.getString(4);
String alias = rs.getString(5); String alias = rs.getString(5);
byte[] publicKey = rs.getBytes(6); byte[] publicKey = rs.getBytes(6);
byte[] handshakePublicKey = rs.getBytes(7);
AuthorId localAuthorId = new AuthorId(rs.getBytes(8));
boolean verified = rs.getBoolean(9);
Author author = Author author =
new Author(authorId, formatVersion, name, publicKey); new Author(authorId, formatVersion, name, publicKey);
AuthorId localAuthorId = new AuthorId(rs.getBytes(7));
boolean verified = rs.getBoolean(8);
boolean active = rs.getBoolean(9);
contacts.add(new Contact(contactId, author, localAuthorId, contacts.add(new Contact(contactId, author, localAuthorId,
alias, verified, active)); alias, handshakePublicKey, verified));
} }
rs.close(); rs.close();
s.close(); s.close();
@@ -1522,7 +1527,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT contactId, formatVersion, name, alias," String sql = "SELECT contactId, formatVersion, name, alias,"
+ " publicKey, localAuthorId, verified, active" + " publicKey, handshakePublicKey, localAuthorId, verified"
+ " FROM contacts" + " FROM contacts"
+ " WHERE authorId = ?"; + " WHERE authorId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -1530,18 +1535,18 @@ abstract class JdbcDatabase implements Database<Connection> {
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Contact> contacts = new ArrayList<>(); List<Contact> contacts = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
ContactId c = new ContactId(rs.getInt(1)); ContactId contactId = new ContactId(rs.getInt(1));
int formatVersion = rs.getInt(2); int formatVersion = rs.getInt(2);
String name = rs.getString(3); String name = rs.getString(3);
String alias = rs.getString(4); String alias = rs.getString(4);
byte[] publicKey = rs.getBytes(5); byte[] publicKey = rs.getBytes(5);
AuthorId localAuthorId = new AuthorId(rs.getBytes(6)); byte[] handshakePublicKey = rs.getBytes(6);
boolean verified = rs.getBoolean(7); AuthorId localAuthorId = new AuthorId(rs.getBytes(7));
boolean active = rs.getBoolean(8); boolean verified = rs.getBoolean(8);
Author author = Author author =
new Author(remote, formatVersion, name, publicKey); new Author(remote, formatVersion, name, publicKey);
contacts.add(new Contact(c, author, localAuthorId, alias, contacts.add(new Contact(contactId, author, localAuthorId,
verified, active)); alias, handshakePublicKey, verified));
} }
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1661,8 +1666,8 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT formatVersion, name, publicKey," String sql = "SELECT formatVersion, name, publicKey, privateKey,"
+ " privateKey, created" + " handshakePublicKey, handshakePrivateKey, created"
+ " FROM localAuthors" + " FROM localAuthors"
+ " WHERE authorId = ?"; + " WHERE authorId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -1673,9 +1678,12 @@ abstract class JdbcDatabase implements Database<Connection> {
String name = rs.getString(2); String name = rs.getString(2);
byte[] publicKey = rs.getBytes(3); byte[] publicKey = rs.getBytes(3);
byte[] privateKey = rs.getBytes(4); byte[] privateKey = rs.getBytes(4);
byte[] handshakePublicKey = rs.getBytes(5);
byte[] handshakePrivateKey = rs.getBytes(6);
long created = rs.getLong(5); long created = rs.getLong(5);
LocalAuthor localAuthor = new LocalAuthor(a, formatVersion, name, LocalAuthor localAuthor = new LocalAuthor(a, formatVersion, name,
publicKey, privateKey, created); publicKey, privateKey, handshakePublicKey,
handshakePrivateKey, created);
if (rs.next()) throw new DbStateException(); if (rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
@@ -3119,24 +3127,6 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
@Override
public void setContactActive(Connection txn, ContactId c, boolean active)
throws DbException {
PreparedStatement ps = null;
try {
String sql = "UPDATE contacts SET active = ? WHERE contactId = ?";
ps = txn.prepareStatement(sql);
ps.setBoolean(1, active);
ps.setInt(2, c.getInt());
int affected = ps.executeUpdate();
if (affected < 0 || affected > 1) throw new DbStateException();
ps.close();
} catch (SQLException e) {
tryToClose(ps, LOG, WARNING);
throw new DbException(e);
}
}
@Override @Override
public void setContactAlias(Connection txn, ContactId c, public void setContactAlias(Connection txn, ContactId c,
@Nullable String alias) throws DbException { @Nullable String alias) throws DbException {

View File

@@ -0,0 +1,52 @@
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 Migration42_43 implements Migration<Connection> {
private static final Logger LOG = getLogger(Migration42_43.class.getName());
private final DatabaseTypes dbTypes;
Migration42_43(DatabaseTypes dbTypes) {
this.dbTypes = dbTypes;
}
@Override
public int getStartVersion() {
return 42;
}
@Override
public int getEndVersion() {
return 43;
}
@Override
public void migrate(Connection txn) throws DbException {
Statement s = null;
try {
s = txn.createStatement();
s.execute(dbTypes.replaceTypes("ALTER TABLE localAuthors"
+ " ADD COLUMN handshakePublicKey _BINARY"));
s.execute(dbTypes.replaceTypes("ALTER TABLE localAuthors"
+ " ADD COLUMN handshakePrivateKey _BINARY"));
s.execute(dbTypes.replaceTypes("ALTER TABLE contacts"
+ " ADD COLUMN handshakePublicKey _BINARY"));
s.execute(dbTypes.replaceTypes("ALTER TABLE contacts"
+ " DROP COLUMN active"));
} catch (SQLException e) {
tryToClose(s, LOG, WARNING);
throw new DbException(e);
}
}
}

View File

@@ -1,7 +1,7 @@
package org.briarproject.bramble.plugin; package org.briarproject.bramble.plugin;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent; import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventListener; import org.briarproject.bramble.api.event.EventListener;
@@ -80,12 +80,10 @@ class Poller implements EventListener {
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof ContactStatusChangedEvent) { if (e instanceof ContactAddedEvent) {
ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; ContactAddedEvent c = (ContactAddedEvent) e;
if (c.isActive()) { // Connect to the newly activated contact
// Connect to the newly activated contact connectToContact(c.getContactId());
connectToContact(c.getContactId());
}
} else if (e instanceof ConnectionClosedEvent) { } else if (e instanceof ConnectionClosedEvent) {
ConnectionClosedEvent c = (ConnectionClosedEvent) e; ConnectionClosedEvent c = (ConnectionClosedEvent) e;
// Reschedule polling, the polling interval may have decreased // Reschedule polling, the polling interval may have decreased

View File

@@ -199,8 +199,6 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
private TransportProperties getRemoteProperties(Transaction txn, Contact c, private TransportProperties getRemoteProperties(Transaction txn, Contact c,
TransportId t) throws DbException { TransportId t) throws DbException {
// Don't return properties for inactive contacts
if (!c.isActive()) return new TransportProperties();
Group g = getContactGroup(c); Group g = getContactGroup(c);
try { try {
// Find the latest remote update // Find the latest remote update

View File

@@ -1,9 +1,7 @@
package org.briarproject.bramble.transport; package org.briarproject.bramble.transport;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent; import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DatabaseExecutor; import org.briarproject.bramble.api.db.DatabaseExecutor;
@@ -46,7 +44,6 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
private final Executor dbExecutor; private final Executor dbExecutor;
private final PluginConfig pluginConfig; private final PluginConfig pluginConfig;
private final TransportKeyManagerFactory transportKeyManagerFactory; private final TransportKeyManagerFactory transportKeyManagerFactory;
private final Map<ContactId, Boolean> activeContacts;
private final ConcurrentHashMap<TransportId, TransportKeyManager> managers; private final ConcurrentHashMap<TransportId, TransportKeyManager> managers;
private final AtomicBoolean used = new AtomicBoolean(false); private final AtomicBoolean used = new AtomicBoolean(false);
@@ -58,8 +55,6 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
this.dbExecutor = dbExecutor; this.dbExecutor = dbExecutor;
this.pluginConfig = pluginConfig; this.pluginConfig = pluginConfig;
this.transportKeyManagerFactory = transportKeyManagerFactory; this.transportKeyManagerFactory = transportKeyManagerFactory;
// Use a ConcurrentHashMap as a thread-safe set
activeContacts = new ConcurrentHashMap<>();
managers = new ConcurrentHashMap<>(); managers = new ConcurrentHashMap<>();
} }
@@ -73,8 +68,6 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
transports.put(f.getId(), f.getMaxLatency()); transports.put(f.getId(), f.getMaxLatency());
try { try {
db.transaction(false, txn -> { db.transaction(false, txn -> {
for (Contact c : db.getContacts(txn))
if (c.isActive()) activeContacts.put(c.getId(), true);
for (Entry<TransportId, Integer> e : transports.entrySet()) for (Entry<TransportId, Integer> e : transports.entrySet())
db.addTransport(txn, e.getKey(), e.getValue()); db.addTransport(txn, e.getKey(), e.getValue());
for (Entry<TransportId, Integer> e : transports.entrySet()) { for (Entry<TransportId, Integer> e : transports.entrySet()) {
@@ -130,8 +123,6 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
@Override @Override
public StreamContext getStreamContext(ContactId c, TransportId t) public StreamContext getStreamContext(ContactId c, TransportId t)
throws DbException { throws DbException {
// Don't allow outgoing streams to inactive contacts
if (!activeContacts.containsKey(c)) return null;
TransportKeyManager m = managers.get(t); TransportKeyManager m = managers.get(t);
if (m == null) { if (m == null) {
if (LOG.isLoggable(INFO)) LOG.info("No key manager for " + t); if (LOG.isLoggable(INFO)) LOG.info("No key manager for " + t);
@@ -157,15 +148,10 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof ContactRemovedEvent) { if (e instanceof ContactRemovedEvent) {
removeContact(((ContactRemovedEvent) e).getContactId()); removeContact(((ContactRemovedEvent) e).getContactId());
} else if (e instanceof ContactStatusChangedEvent) {
ContactStatusChangedEvent c = (ContactStatusChangedEvent) e;
if (c.isActive()) activeContacts.put(c.getContactId(), true);
else activeContacts.remove(c.getContactId());
} }
} }
private void removeContact(ContactId c) { private void removeContact(ContactId c) {
activeContacts.remove(c);
dbExecutor.execute(() -> { dbExecutor.execute(() -> {
for (TransportKeyManager m : managers.values()) m.removeContact(c); for (TransportKeyManager m : managers.values()) m.removeContact(c);
}); });

View File

@@ -20,9 +20,7 @@ import org.jmock.Expectations;
import org.jmock.Mockery; import org.jmock.Mockery;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Random; import java.util.Random;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
@@ -33,6 +31,7 @@ import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED; 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.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
@@ -49,17 +48,16 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
private final IdentityManager identityManager = private final IdentityManager identityManager =
context.mock(IdentityManager.class); context.mock(IdentityManager.class);
private final ContactManager contactManager; private final ContactManager contactManager;
private final ContactId contactId = new ContactId(42);
private final Author remote = getAuthor(); private final Author remote = getAuthor();
private final AuthorId local = new AuthorId(getRandomId());
private final LocalAuthor localAuthor = getLocalAuthor(); private final LocalAuthor localAuthor = getLocalAuthor();
private final String alias = getRandomString(MAX_AUTHOR_NAME_LENGTH); private final AuthorId local = localAuthor.getId();
private final boolean verified = false, active = true; private final boolean verified = false, active = true;
private final Contact contact = private final Contact contact = getContact(remote, local, verified);
new Contact(contactId, remote, local, alias, verified, active); private final ContactId contactId = contact.getId();
public ContactManagerImplTest() { public ContactManagerImplTest() {
contactManager = new ContactManagerImpl(db, keyManager, identityManager); contactManager =
new ContactManagerImpl(db, keyManager, identityManager);
} }
@Test @Test
@@ -71,7 +69,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(false), withDbCallable(txn)); oneOf(db).transactionWithResult(with(false), withDbCallable(txn));
oneOf(db).addContact(txn, remote, local, verified, active); oneOf(db).addContact(txn, remote, local, verified);
will(returnValue(contactId)); will(returnValue(contactId));
oneOf(keyManager).addContact(txn, contactId, rootKey, timestamp, oneOf(keyManager).addContact(txn, contactId, rootKey, timestamp,
alice, active); alice, active);
@@ -98,7 +96,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetContactByAuthor() throws Exception { public void testGetContactByAuthor() throws Exception {
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact); Collection<Contact> contacts = singletonList(contact);
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn)); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getContactsByAuthorId(txn, remote.getId()); oneOf(db).getContactsByAuthorId(txn, remote.getId());
@@ -123,7 +121,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test(expected = NoSuchContactException.class) @Test(expected = NoSuchContactException.class)
public void testGetContactByUnknownLocalAuthor() throws Exception { public void testGetContactByUnknownLocalAuthor() throws Exception {
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = Collections.singleton(contact); Collection<Contact> contacts = singletonList(contact);
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn)); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getContactsByAuthorId(txn, remote.getId()); oneOf(db).getContactsByAuthorId(txn, remote.getId());
@@ -134,11 +132,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
} }
@Test @Test
public void testGetActiveContacts() throws Exception { public void testGetContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact); Collection<Contact> contacts = singletonList(contact);
Collection<Contact> contacts = new ArrayList<>(activeContacts);
contacts.add(new Contact(new ContactId(3), remote, local, alias, true,
false));
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn)); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
@@ -146,7 +141,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
will(returnValue(contacts)); will(returnValue(contacts));
}}); }});
assertEquals(activeContacts, contactManager.getActiveContacts()); assertEquals(contacts, contactManager.getContacts());
} }
@Test @Test
@@ -162,19 +157,11 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
contactManager.removeContact(contactId); contactManager.removeContact(contactId);
} }
@Test
public void testSetContactActive() throws Exception {
Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{
oneOf(db).setContactActive(txn, contactId, active);
}});
contactManager.setContactActive(txn, contactId, active);
}
@Test @Test
public void testSetContactAlias() throws Exception { public void testSetContactAlias() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
String alias = getRandomString(MAX_AUTHOR_NAME_LENGTH);
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transaction(with(false), withDbRunnable(txn)); oneOf(db).transaction(with(false), withDbRunnable(txn));
oneOf(db).setContactAlias(txn, contactId, alias); oneOf(db).setContactAlias(txn, contactId, alias);
@@ -205,21 +192,18 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetAuthorInfo() throws Exception { public void testGetAuthorInfo() throws Exception {
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
Collection<Contact> contacts = singletonList(
new Contact(new ContactId(1), remote, localAuthor.getId(),
alias, false, true));
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
oneOf(db).transactionWithResult(with(true), withDbCallable(txn)); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(identityManager).getLocalAuthor(txn); oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor)); will(returnValue(localAuthor));
oneOf(db).getContactsByAuthorId(txn, remote.getId()); oneOf(db).getContactsByAuthorId(txn, remote.getId());
will(returnValue(contacts)); will(returnValue(singletonList(contact)));
}}); }});
AuthorInfo authorInfo = AuthorInfo authorInfo =
contactManager.getAuthorInfo(txn, remote.getId()); contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(UNVERIFIED, authorInfo.getStatus()); assertEquals(UNVERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias()); assertEquals(contact.getAlias(), authorInfo.getAlias());
} }
@Test @Test
@@ -239,21 +223,17 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
assertNull(authorInfo.getAlias()); assertNull(authorInfo.getAlias());
// check unverified contact // check unverified contact
Collection<Contact> contacts = singletonList( checkAuthorInfoContext(txn, remote.getId(), singletonList(contact));
new Contact(new ContactId(1), remote, localAuthor.getId(),
alias, false, true));
checkAuthorInfoContext(txn, remote.getId(), contacts);
authorInfo = contactManager.getAuthorInfo(txn, remote.getId()); authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(UNVERIFIED, authorInfo.getStatus()); assertEquals(UNVERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias()); assertEquals(contact.getAlias(), authorInfo.getAlias());
// check verified contact // check verified contact
contacts = singletonList(new Contact(new ContactId(1), remote, Contact verified = getContact(remote, local, true);
localAuthor.getId(), alias, true, true)); checkAuthorInfoContext(txn, remote.getId(), singletonList(verified));
checkAuthorInfoContext(txn, remote.getId(), contacts);
authorInfo = contactManager.getAuthorInfo(txn, remote.getId()); authorInfo = contactManager.getAuthorInfo(txn, remote.getId());
assertEquals(VERIFIED, authorInfo.getStatus()); assertEquals(VERIFIED, authorInfo.getStatus());
assertEquals(alias, contact.getAlias()); assertEquals(verified.getAlias(), authorInfo.getAlias());
// check ourselves // check ourselves
context.checking(new Expectations() {{ context.checking(new Expectations() {{

View File

@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.PendingContactId; import org.briarproject.bramble.api.contact.PendingContactId;
import org.briarproject.bramble.api.contact.event.ContactAddedEvent; import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent; import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.ContactExistsException; import org.briarproject.bramble.api.db.ContactExistsException;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
@@ -76,13 +75,13 @@ import static org.briarproject.bramble.api.transport.TransportConstants.REORDERI
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES; import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@@ -124,7 +123,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
groupId = group.getId(); groupId = group.getId();
author = getAuthor(); author = getAuthor();
localAuthor = getLocalAuthor(); localAuthor = getLocalAuthor();
alias = getRandomString(5);
message = getMessage(groupId); message = getMessage(groupId);
message1 = getMessage(groupId); message1 = getMessage(groupId);
messageId = message.getId(); messageId = message.getId();
@@ -133,9 +131,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
metadata.put("foo", new byte[] {'b', 'a', 'r'}); metadata.put("foo", new byte[] {'b', 'a', 'r'});
transportId = getTransportId(); transportId = getTransportId();
maxLatency = Integer.MAX_VALUE; maxLatency = Integer.MAX_VALUE;
contactId = new ContactId(234); contact = getContact(author, localAuthor.getId(), true);
contact = new Contact(contactId, author, localAuthor.getId(), alias, contactId = contact.getId();
true, true); alias = contact.getAlias();
keySetId = new TransportKeySetId(345); keySetId = new TransportKeySetId(345);
pendingContactId = new PendingContactId(getRandomId()); pendingContactId = new PendingContactId(getRandomId());
} }
@@ -172,12 +170,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
oneOf(database).containsContact(txn, author.getId(), oneOf(database).containsContact(txn, author.getId(),
localAuthor.getId()); localAuthor.getId());
will(returnValue(false)); will(returnValue(false));
oneOf(database).addContact(txn, author, localAuthor.getId(), oneOf(database).addContact(txn, author, localAuthor.getId(), true);
true, true);
will(returnValue(contactId)); will(returnValue(contactId));
oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class))); oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
oneOf(eventBus).broadcast(with(any(
ContactStatusChangedEvent.class)));
// getContacts() // getContacts()
oneOf(database).getContacts(txn); oneOf(database).getContacts(txn);
will(returnValue(singletonList(contact))); will(returnValue(singletonList(contact)));
@@ -223,7 +218,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.transaction(false, transaction -> { db.transaction(false, transaction -> {
db.addLocalAuthor(transaction, localAuthor); db.addLocalAuthor(transaction, localAuthor);
assertEquals(contactId, db.addContact(transaction, author, assertEquals(contactId, db.addContact(transaction, author,
localAuthor.getId(), true, true)); localAuthor.getId(), true));
assertEquals(singletonList(contact), assertEquals(singletonList(contact),
db.getContacts(transaction)); db.getContacts(transaction));
db.addGroup(transaction, group); // First time - listeners called db.addGroup(transaction, group); // First time - listeners called
@@ -284,11 +279,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
// Check whether the contact is in the DB (which it's not) // Check whether the contact is in the DB (which it's not)
exactly(18).of(database).startTransaction(); exactly(17).of(database).startTransaction();
will(returnValue(txn)); will(returnValue(txn));
exactly(18).of(database).containsContact(txn, contactId); exactly(17).of(database).containsContact(txn, contactId);
will(returnValue(false)); will(returnValue(false));
exactly(18).of(database).abortTransaction(txn); exactly(17).of(database).abortTransaction(txn);
}}); }});
DatabaseComponent db = createDatabaseComponent(database, eventBus, DatabaseComponent db = createDatabaseComponent(database, eventBus,
eventExecutor, shutdownManager); eventExecutor, shutdownManager);
@@ -418,14 +413,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
// Expected // Expected
} }
try {
db.transaction(false, transaction ->
db.setContactActive(transaction, contactId, true));
fail();
} catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.setContactAlias(transaction, contactId, alias)); db.setContactAlias(transaction, contactId, alias));
@@ -462,7 +449,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
try { try {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.addContact(transaction, author, localAuthor.getId(), db.addContact(transaction, author, localAuthor.getId(),
true, true)); true));
fail(); fail();
} catch (NoSuchLocalAuthorException expected) { } catch (NoSuchLocalAuthorException expected) {
// Expected // Expected
@@ -1430,7 +1417,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
try { try {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.addContact(transaction, author, localAuthor.getId(), db.addContact(transaction, author, localAuthor.getId(),
true, true)); true));
fail(); fail();
} catch (ContactExistsException expected) { } catch (ContactExistsException expected) {
// Expected // Expected
@@ -1459,7 +1446,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
try { try {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.addContact(transaction, author, localAuthor.getId(), db.addContact(transaction, author, localAuthor.getId(),
true, true)); true));
fail(); fail();
} catch (ContactExistsException expected) { } catch (ContactExistsException expected) {
// Expected // Expected

View File

@@ -49,8 +49,6 @@ import static org.junit.Assert.assertTrue;
public abstract class DatabasePerformanceTest extends BrambleTestCase { public abstract class DatabasePerformanceTest extends BrambleTestCase {
private static final int ONE_MEGABYTE = 1024 * 1024;
/** /**
* How many contacts to simulate. * How many contacts to simulate.
*/ */
@@ -548,7 +546,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
for (int i = 0; i < CONTACTS; i++) { for (int i = 0; i < CONTACTS; i++) {
ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(), ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(),
random.nextBoolean(), true); random.nextBoolean());
contacts.add(db.getContact(txn, c)); contacts.add(db.getContact(txn, c));
contactGroups.put(c, new ArrayList<>()); contactGroups.put(c, new ArrayList<>());
for (int j = 0; j < GROUPS_PER_CONTACT; j++) { for (int j = 0; j < GROUPS_PER_CONTACT; j++) {

View File

@@ -146,8 +146,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
Connection txn = db.startTransaction(); Connection txn = db.startTransaction();
assertFalse(db.containsContact(txn, contactId)); assertFalse(db.containsContact(txn, contactId));
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
assertTrue(db.containsContact(txn, contactId)); assertTrue(db.containsContact(txn, contactId));
assertFalse(db.containsGroup(txn, groupId)); assertFalse(db.containsGroup(txn, groupId));
db.addGroup(txn, group); db.addGroup(txn, group);
@@ -209,8 +209,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -240,8 +240,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared but unvalidated message // Add a contact, a shared group and a shared but unvalidated message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, UNKNOWN, true, null); db.addMessage(txn, message, UNKNOWN, true, null);
@@ -285,8 +285,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, an invisible group and a shared message // Add a contact, an invisible group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -336,8 +336,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and an unshared message // Add a contact, a shared group and an unshared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, false, null); db.addMessage(txn, message, DELIVERED, false, null);
@@ -367,8 +367,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -394,8 +394,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact and a visible group // Add a contact and a visible group
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, false); db.addGroupVisibility(txn, contactId, groupId, false);
@@ -435,8 +435,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -567,8 +567,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact and a shared group // Add a contact and a shared group
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
@@ -587,8 +587,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact // Add a contact
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
// The group is not in the database // The group is not in the database
assertFalse(db.containsVisibleMessage(txn, contactId, messageId)); assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
@@ -605,8 +605,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, an invisible group and a message // Add a contact, an invisible group and a message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -624,8 +624,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact and a group // Add a contact and a group
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
// The group should not be visible to the contact // The group should not be visible to the contact
@@ -676,8 +676,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, the transport and the transport keys // Add the contact, the transport and the transport keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, active)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1)); assertEquals(keySetId1, db.addTransportKeys(txn, contactId, keys1));
@@ -777,8 +777,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, the transport and the handshake keys // Add the contact, the transport and the handshake keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(handshakeKeySetId, assertEquals(handshakeKeySetId,
db.addHandshakeKeys(txn, contactId, keys)); db.addHandshakeKeys(txn, contactId, keys));
@@ -930,8 +930,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, transport and transport keys // Add the contact, transport and transport keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
@@ -974,8 +974,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, transport and handshake keys // Add the contact, transport and handshake keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(handshakeKeySetId, assertEquals(handshakeKeySetId,
db.addHandshakeKeys(txn, contactId, keys)); db.addHandshakeKeys(txn, contactId, keys));
@@ -1021,8 +1021,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, transport and transport keys // Add the contact, transport and transport keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, active)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys)); assertEquals(keySetId, db.addTransportKeys(txn, contactId, keys));
@@ -1068,8 +1068,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the contact, transport and handshake keys // Add the contact, transport and handshake keys
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addTransport(txn, transportId, 123); db.addTransport(txn, transportId, 123);
assertEquals(handshakeKeySetId, assertEquals(handshakeKeySetId,
db.addHandshakeKeys(txn, contactId, keys)); db.addHandshakeKeys(txn, contactId, keys));
@@ -1113,8 +1113,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
// Add a contact associated with the local author // Add a contact associated with the local author
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
// Ensure contact is returned from database by Author ID // Ensure contact is returned from database by Author ID
Collection<Contact> contacts = Collection<Contact> contacts =
@@ -1143,8 +1143,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
assertEquals(emptyList(), contacts); assertEquals(emptyList(), contacts);
// Add a contact associated with the local author // Add a contact associated with the local author
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
contacts = db.getContacts(txn, localAuthor.getId()); contacts = db.getContacts(txn, localAuthor.getId());
assertEquals(singletonList(contactId), contacts); assertEquals(singletonList(contactId), contacts);
@@ -1165,8 +1165,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact - initially there should be no offered messages // Add a contact - initially there should be no offered messages
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
assertEquals(0, db.countOfferedMessages(txn, contactId)); assertEquals(0, db.countOfferedMessages(txn, contactId));
// Add some offered messages and count them // Add some offered messages and count them
@@ -1749,8 +1749,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -1861,9 +1861,9 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add the same contact for each local author // Add the same contact for each local author
ContactId contactId = ContactId contactId =
db.addContact(txn, author, localAuthor.getId(), true, true); db.addContact(txn, author, localAuthor.getId(), true);
ContactId contactId1 = ContactId contactId1 =
db.addContact(txn, author, localAuthor1.getId(), true, true); db.addContact(txn, author, localAuthor1.getId(), true);
// The contacts should be distinct // The contacts should be distinct
assertNotEquals(contactId, contactId1); assertNotEquals(contactId, contactId1);
@@ -1882,8 +1882,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -1929,38 +1929,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
db.close(); db.close();
} }
@Test
public void testSetContactActive() throws Exception {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Add a contact
db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(),
true, true));
// The contact should be active
Contact contact = db.getContact(txn, contactId);
assertTrue(contact.isActive());
// Set the contact inactive
db.setContactActive(txn, contactId, false);
// The contact should be inactive
contact = db.getContact(txn, contactId);
assertFalse(contact.isActive());
// Set the contact active
db.setContactActive(txn, contactId, true);
// The contact should be active
contact = db.getContact(txn, contactId);
assertTrue(contact.isActive());
db.commitTransaction(txn);
db.close();
}
@Test @Test
public void testSetContactAlias() throws Exception { public void testSetContactAlias() throws Exception {
Database<Connection> db = open(false); Database<Connection> db = open(false);
@@ -1968,8 +1936,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact // Add a contact
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
// The contact should have no alias // The contact should have no alias
Contact contact = db.getContact(txn, contactId); Contact contact = db.getContact(txn, contactId);
@@ -2025,8 +1993,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a group and a message // Add a contact, a group and a message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addMessage(txn, message, UNKNOWN, false, null); db.addMessage(txn, message, UNKNOWN, false, null);
@@ -2109,8 +2077,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);
@@ -2154,8 +2122,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
// Add a contact, a shared group and a shared message // Add a contact, a shared group and a shared message
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
assertEquals(contactId, db.addContact(txn, author, localAuthor.getId(), assertEquals(contactId,
true, true)); db.addContact(txn, author, localAuthor.getId(), true));
db.addGroup(txn, group); db.addGroup(txn, group);
db.addGroupVisibility(txn, contactId, groupId, true); db.addGroupVisibility(txn, contactId, groupId, true);
db.addMessage(txn, message, DELIVERED, true, null); db.addMessage(txn, message, DELIVERED, true, null);

View File

@@ -17,6 +17,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -28,8 +29,8 @@ public class ConnectionRegistryImplTest extends BrambleTestCase {
private final TransportId transportId, transportId1; private final TransportId transportId, transportId1;
public ConnectionRegistryImplTest() { public ConnectionRegistryImplTest() {
contactId = new ContactId(1); contactId = getContactId();
contactId1 = new ContactId(2); contactId1 = getContactId();
transportId = getTransportId(); transportId = getTransportId();
transportId1 = getTransportId(); transportId1 = getTransportId();
} }

View File

@@ -1,7 +1,7 @@
package org.briarproject.bramble.plugin; package org.briarproject.bramble.plugin;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent; import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.plugin.ConnectionManager; import org.briarproject.bramble.api.plugin.ConnectionManager;
import org.briarproject.bramble.api.plugin.ConnectionRegistry; import org.briarproject.bramble.api.plugin.ConnectionRegistry;
import org.briarproject.bramble.api.plugin.Plugin; import org.briarproject.bramble.api.plugin.Plugin;
@@ -36,6 +36,7 @@ import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
public class PollerTest extends BrambleMockTestCase { public class PollerTest extends BrambleMockTestCase {
@@ -56,7 +57,7 @@ public class PollerTest extends BrambleMockTestCase {
private final Executor ioExecutor = new ImmediateExecutor(); private final Executor ioExecutor = new ImmediateExecutor();
private final TransportId transportId = getTransportId(); private final TransportId transportId = getTransportId();
private final ContactId contactId = new ContactId(234); private final ContactId contactId = getContactId();
private final TransportProperties properties = new TransportProperties(); private final TransportProperties properties = new TransportProperties();
private final int pollingInterval = 60 * 1000; private final int pollingInterval = 60 * 1000;
private final long now = System.currentTimeMillis(); private final long now = System.currentTimeMillis();
@@ -67,7 +68,7 @@ public class PollerTest extends BrambleMockTestCase {
} }
@Test @Test
public void testConnectOnContactStatusChanged() throws Exception { public void testConnectOnContactAdded() throws Exception {
// Two simplex plugins: one supports polling, the other doesn't // Two simplex plugins: one supports polling, the other doesn't
SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class); SimplexPlugin simplexPlugin = context.mock(SimplexPlugin.class);
SimplexPlugin simplexPlugin1 = SimplexPlugin simplexPlugin1 =
@@ -143,7 +144,7 @@ public class PollerTest extends BrambleMockTestCase {
connectionRegistry, pluginManager, transportPropertyManager, connectionRegistry, pluginManager, transportPropertyManager,
random, clock); random, clock);
p.eventOccurred(new ContactStatusChangedEvent(contactId, true)); p.eventOccurred(new ContactAddedEvent(contactId));
} }
@Test @Test

View File

@@ -11,7 +11,6 @@ import org.briarproject.bramble.api.data.MetadataParser;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.Metadata; import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
@@ -36,12 +35,10 @@ import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID; import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION; import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; 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.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -58,7 +55,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
private final Clock clock = context.mock(Clock.class); private final Clock clock = context.mock(Clock.class);
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final LocalAuthor localAuthor = getLocalAuthor();
private final BdfDictionary fooPropertiesDict = BdfDictionary.of( private final BdfDictionary fooPropertiesDict = BdfDictionary.of(
new BdfEntry("fooKey1", "fooValue1"), new BdfEntry("fooKey1", "fooValue1"),
new BdfEntry("fooKey2", "fooValue2") new BdfEntry("fooKey2", "fooValue2")
@@ -69,8 +65,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
); );
private final TransportProperties fooProperties, barProperties; private final TransportProperties fooProperties, barProperties;
private int nextContactId = 0;
public TransportPropertyManagerImplTest() throws Exception { public TransportPropertyManagerImplTest() throws Exception {
fooProperties = new TransportProperties(); fooProperties = new TransportProperties();
for (String key : fooPropertiesDict.keySet()) for (String key : fooPropertiesDict.keySet())
@@ -94,7 +88,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testCreatesGroupsAtStartup() throws Exception { public void testCreatesGroupsAtStartup() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -141,7 +135,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testCreatesContactGroupWhenAddingContact() throws Exception { public void testCreatesContactGroupWhenAddingContact() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -170,7 +164,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRemovesGroupWhenRemovingContact() throws Exception { public void testRemovesGroupWhenRemovingContact() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -302,7 +296,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testStoresRemotePropertiesWithVersion0() throws Exception { public void testStoresRemotePropertiesWithVersion0() throws Exception {
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Map<TransportId, TransportProperties> properties = Map<TransportId, TransportProperties> properties =
@@ -406,31 +400,30 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
public void testReturnsRemotePropertiesOrEmptyProperties() public void testReturnsRemotePropertiesOrEmptyProperties()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
Contact contact1 = getContact(false); Contact contact1 = getContact();
Contact contact2 = getContact(true); Contact contact2 = getContact();
Contact contact3 = getContact(true); List<Contact> contacts = asList(contact1, contact2);
List<Contact> contacts = asList(contact1, contact2, contact3); Group contactGroup1 = getGroup(CLIENT_ID, MAJOR_VERSION);
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION); Map<MessageId, BdfDictionary> messageMetadata2 =
Map<MessageId, BdfDictionary> messageMetadata3 =
new LinkedHashMap<>(); new LinkedHashMap<>();
// A remote update for another transport should be ignored // A remote update for another transport should be ignored
MessageId barUpdateId = new MessageId(getRandomId()); MessageId barUpdateId = new MessageId(getRandomId());
messageMetadata3.put(barUpdateId, BdfDictionary.of( messageMetadata2.put(barUpdateId, BdfDictionary.of(
new BdfEntry("transportId", "bar"), new BdfEntry("transportId", "bar"),
new BdfEntry("version", 1), new BdfEntry("version", 1),
new BdfEntry("local", false) new BdfEntry("local", false)
)); ));
// A local update for the right transport should be ignored // A local update for the right transport should be ignored
MessageId localUpdateId = new MessageId(getRandomId()); MessageId localUpdateId = new MessageId(getRandomId());
messageMetadata3.put(localUpdateId, BdfDictionary.of( messageMetadata2.put(localUpdateId, BdfDictionary.of(
new BdfEntry("transportId", "foo"), new BdfEntry("transportId", "foo"),
new BdfEntry("version", 1), new BdfEntry("version", 1),
new BdfEntry("local", true) new BdfEntry("local", true)
)); ));
// A remote update for the right transport should be returned // A remote update for the right transport should be returned
MessageId fooUpdateId = new MessageId(getRandomId()); MessageId fooUpdateId = new MessageId(getRandomId());
messageMetadata3.put(fooUpdateId, BdfDictionary.of( messageMetadata2.put(fooUpdateId, BdfDictionary.of(
new BdfEntry("transportId", "foo"), new BdfEntry("transportId", "foo"),
new BdfEntry("version", 1), new BdfEntry("version", 1),
new BdfEntry("local", false) new BdfEntry("local", false)
@@ -441,21 +434,20 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
oneOf(db).transactionWithResult(with(true), withDbCallable(txn)); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
oneOf(db).getContacts(txn); oneOf(db).getContacts(txn);
will(returnValue(contacts)); will(returnValue(contacts));
// First contact: skipped because not active // First contact: no updates
// Second contact: no updates oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact1);
will(returnValue(contactGroup1));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup1.getId());
will(returnValue(Collections.emptyMap()));
// Second contact: returns an update
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact2); MAJOR_VERSION, contact2);
will(returnValue(contactGroup2)); will(returnValue(contactGroup2));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup2.getId()); contactGroup2.getId());
will(returnValue(Collections.emptyMap())); will(returnValue(messageMetadata2));
// Third contact: returns an update
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact3);
will(returnValue(contactGroup3));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup3.getId());
will(returnValue(messageMetadata3));
oneOf(clientHelper).getMessageAsList(txn, fooUpdateId); oneOf(clientHelper).getMessageAsList(txn, fooUpdateId);
will(returnValue(fooUpdate)); will(returnValue(fooUpdate));
oneOf(clientHelper).parseAndValidateTransportProperties( oneOf(clientHelper).parseAndValidateTransportProperties(
@@ -466,10 +458,9 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
TransportPropertyManagerImpl t = createInstance(); TransportPropertyManagerImpl t = createInstance();
Map<ContactId, TransportProperties> properties = Map<ContactId, TransportProperties> properties =
t.getRemoteProperties(new TransportId("foo")); t.getRemoteProperties(new TransportId("foo"));
assertEquals(3, properties.size()); assertEquals(2, properties.size());
assertEquals(0, properties.get(contact1.getId()).size()); assertEquals(0, properties.get(contact1.getId()).size());
assertEquals(0, properties.get(contact2.getId()).size()); assertEquals(fooProperties, properties.get(contact2.getId()));
assertEquals(fooProperties, properties.get(contact3.getId()));
} }
@Test @Test
@@ -506,7 +497,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testMergingNewPropertiesCreatesUpdate() throws Exception { public void testMergingNewPropertiesCreatesUpdate() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
context.checking(new DbExpectations() {{ context.checking(new DbExpectations() {{
@@ -538,7 +529,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testMergingUpdatedPropertiesCreatesUpdate() throws Exception { public void testMergingUpdatedPropertiesCreatesUpdate() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(true); Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary oldMetadata = BdfDictionary.of( BdfDictionary oldMetadata = BdfDictionary.of(
new BdfEntry("transportId", "foo"), new BdfEntry("transportId", "foo"),
@@ -593,12 +584,6 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
t.mergeLocalProperties(new TransportId("foo"), fooProperties); t.mergeLocalProperties(new TransportId("foo"), fooProperties);
} }
private Contact getContact(boolean active) {
ContactId c = new ContactId(nextContactId++);
return new Contact(c, getAuthor(), localAuthor.getId(),
getRandomString(5), true, active);
}
private void expectGetLocalProperties(Transaction txn) throws Exception { private void expectGetLocalProperties(Transaction txn) throws Exception {
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
// The latest update for transport "foo" should be returned // The latest update for transport "foo" should be returned

View File

@@ -19,6 +19,7 @@ import java.util.concurrent.Executor;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS; import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
@@ -33,7 +34,7 @@ public class SimplexOutgoingSessionTest extends BrambleMockTestCase {
context.mock(SyncRecordWriter.class); context.mock(SyncRecordWriter.class);
private final Executor dbExecutor = new ImmediateExecutor(); private final Executor dbExecutor = new ImmediateExecutor();
private final ContactId contactId = new ContactId(234); private final ContactId contactId = getContactId();
private final Message message = getMessage(new GroupId(getRandomId())); private final Message message = getMessage(new GroupId(getRandomId()));
private final MessageId messageId = message.getId(); private final MessageId messageId = message.getId();

View File

@@ -22,7 +22,6 @@ import org.briarproject.bramble.api.transport.StreamReaderFactory;
import org.briarproject.bramble.api.transport.StreamWriter; import org.briarproject.bramble.api.transport.StreamWriter;
import org.briarproject.bramble.api.transport.StreamWriterFactory; import org.briarproject.bramble.api.transport.StreamWriterFactory;
import org.briarproject.bramble.test.BrambleTestCase; import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.bramble.test.TestUtils;
import org.junit.Test; import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -37,6 +36,8 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_GROUP_DESCRIPT
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION; import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH; import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -73,11 +74,11 @@ public class SyncIntegrationTest extends BrambleTestCase {
DaggerSyncIntegrationTestComponent.builder().build(); DaggerSyncIntegrationTestComponent.builder().build();
component.inject(this); component.inject(this);
contactId = new ContactId(234); contactId = getContactId();
transportId = getTransportId(); transportId = getTransportId();
// Create the transport keys // Create the transport keys
tagKey = TestUtils.getSecretKey(); tagKey = getSecretKey();
headerKey = TestUtils.getSecretKey(); headerKey = getSecretKey();
streamNumber = 123; streamNumber = 123;
// Create a group // Create a group
ClientId clientId = getClientId(); ClientId clientId = getClientId();

View File

@@ -37,6 +37,7 @@ import static org.briarproject.bramble.api.sync.validation.MessageState.INVALID;
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING; import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN; import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
@@ -64,7 +65,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
private final Metadata metadata = new Metadata(); private final Metadata metadata = new Metadata();
private final MessageContext validResult = new MessageContext(metadata); private final MessageContext validResult = new MessageContext(metadata);
private final ContactId contactId = new ContactId(234); private final ContactId contactId = getContactId();
private final MessageContext validResultWithDependencies = private final MessageContext validResultWithDependencies =
new MessageContext(metadata, singletonList(messageId1)); new MessageContext(metadata, singletonList(messageId1));

View File

@@ -1,14 +1,10 @@
package org.briarproject.bramble.transport; package org.briarproject.bramble.transport;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent; import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
import org.briarproject.bramble.api.crypto.SecretKey; import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.Transaction; 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.plugin.PluginConfig; import org.briarproject.bramble.api.plugin.PluginConfig;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory; import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
@@ -21,7 +17,6 @@ import org.jmock.lib.concurrent.DeterministicExecutor;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@@ -29,12 +24,10 @@ import java.util.Random;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH; import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@@ -49,14 +42,12 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
private final DeterministicExecutor executor = new DeterministicExecutor(); private final DeterministicExecutor executor = new DeterministicExecutor();
private final Transaction txn = new Transaction(null, false); private final Transaction txn = new Transaction(null, false);
private final ContactId contactId = new ContactId(123); private final ContactId contactId = getContactId();
private final ContactId inactiveContactId = new ContactId(234);
private final TransportKeySetId keySetId = new TransportKeySetId(345); private final TransportKeySetId keySetId = new TransportKeySetId(345);
private final TransportId transportId = getTransportId(); private final TransportId transportId = getTransportId();
private final TransportId unknownTransportId = getTransportId(); private final TransportId unknownTransportId = getTransportId();
private final StreamContext streamContext = private final StreamContext streamContext = new StreamContext(contactId,
new StreamContext(contactId, transportId, getSecretKey(), transportId, getSecretKey(), getSecretKey(), 1);
getSecretKey(), 1);
private final byte[] tag = getRandomBytes(TAG_LENGTH); private final byte[] tag = getRandomBytes(TAG_LENGTH);
private final Random random = new Random(); private final Random random = new Random();
@@ -66,13 +57,6 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
@Before @Before
public void testStartService() throws Exception { public void testStartService() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Author remoteAuthor = getAuthor();
AuthorId localAuthorId = new AuthorId(getRandomId());
Collection<Contact> contacts = new ArrayList<>();
contacts.add(new Contact(contactId, remoteAuthor, localAuthorId,
getRandomString(5), true, true));
contacts.add(new Contact(inactiveContactId, remoteAuthor, localAuthorId,
getRandomString(5), true, false));
SimplexPluginFactory pluginFactory = SimplexPluginFactory pluginFactory =
context.mock(SimplexPluginFactory.class); context.mock(SimplexPluginFactory.class);
Collection<SimplexPluginFactory> factories = Collection<SimplexPluginFactory> factories =
@@ -92,8 +76,6 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
will(returnValue(transportKeyManager)); will(returnValue(transportKeyManager));
oneOf(pluginConfig).getDuplexFactories(); oneOf(pluginConfig).getDuplexFactories();
oneOf(db).transaction(with(false), withDbRunnable(txn)); oneOf(db).transaction(with(false), withDbRunnable(txn));
oneOf(db).getContacts(txn);
will(returnValue(contacts));
oneOf(transportKeyManager).start(txn); oneOf(transportKeyManager).start(txn);
}}); }});
@@ -118,11 +100,6 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
assertEquals(singletonMap(transportId, keySetId), ids); assertEquals(singletonMap(transportId, keySetId), ids);
} }
@Test
public void testGetStreamContextForInactiveContact() throws Exception {
assertNull(keyManager.getStreamContext(inactiveContactId, transportId));
}
@Test @Test
public void testGetStreamContextForUnknownTransport() throws Exception { public void testGetStreamContextForUnknownTransport() throws Exception {
assertNull(keyManager.getStreamContext(contactId, unknownTransportId)); assertNull(keyManager.getStreamContext(contactId, unknownTransportId));
@@ -161,32 +138,14 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
} }
@Test @Test
public void testContactRemovedEvent() throws Exception { public void testContactRemovedEvent() {
ContactRemovedEvent event = new ContactRemovedEvent(contactId); ContactRemovedEvent event = new ContactRemovedEvent(contactId);
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(transportKeyManager).removeContact(contactId); oneOf(transportKeyManager).removeContact(contactId);
}}); }});
keyManager.eventOccurred(event); keyManager.eventOccurred(event);
executor.runUntilIdle(); executor.runUntilIdle();
assertNull(keyManager.getStreamContext(contactId, transportId));
}
@Test
public void testContactStatusChangedEvent() throws Exception {
ContactStatusChangedEvent event =
new ContactStatusChangedEvent(inactiveContactId, true);
context.checking(new DbExpectations() {{
oneOf(db).transactionWithNullableResult(with(false),
withNullableDbCallable(txn));
oneOf(transportKeyManager).getStreamContext(txn, inactiveContactId);
will(returnValue(streamContext));
}});
keyManager.eventOccurred(event);
assertEquals(streamContext,
keyManager.getStreamContext(inactiveContactId, transportId));
} }
} }

View File

@@ -16,7 +16,6 @@ import org.briarproject.bramble.api.transport.TransportKeys;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
import org.briarproject.bramble.test.RunAction; import org.briarproject.bramble.test.RunAction;
import org.briarproject.bramble.test.TestUtils;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.api.Action; import org.jmock.api.Action;
@@ -37,6 +36,8 @@ import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOC
import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION; import static org.briarproject.bramble.api.transport.TransportConstants.PROTOCOL_VERSION;
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE; import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH; import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTransportId; import static org.briarproject.bramble.test.TestUtils.getTransportId;
import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED; import static org.briarproject.bramble.util.ByteUtils.MAX_32_BIT_UNSIGNED;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -58,13 +59,13 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
private final TransportId transportId = getTransportId(); private final TransportId transportId = getTransportId();
private final long maxLatency = 30 * 1000; // 30 seconds private final long maxLatency = 30 * 1000; // 30 seconds
private final long timePeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE; private final long timePeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
private final ContactId contactId = new ContactId(123); private final ContactId contactId = getContactId();
private final ContactId contactId1 = new ContactId(234); private final ContactId contactId1 = getContactId();
private final TransportKeySetId keySetId = new TransportKeySetId(345); private final TransportKeySetId keySetId = new TransportKeySetId(345);
private final TransportKeySetId keySetId1 = new TransportKeySetId(456); private final TransportKeySetId keySetId1 = new TransportKeySetId(456);
private final SecretKey tagKey = TestUtils.getSecretKey(); private final SecretKey tagKey = getSecretKey();
private final SecretKey headerKey = TestUtils.getSecretKey(); private final SecretKey headerKey = getSecretKey();
private final SecretKey rootKey = TestUtils.getSecretKey(); private final SecretKey rootKey = getSecretKey();
private final Random random = new Random(); private final Random random = new Random();
@Test @Test

View File

@@ -3,7 +3,6 @@ package org.briarproject.bramble.versioning;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory; import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfList;
@@ -34,13 +33,11 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.CLIENT_ID; import static org.briarproject.bramble.api.versioning.ClientVersioningManager.CLIENT_ID;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MAJOR_VERSION; import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MAJOR_VERSION;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getClientId; import static org.briarproject.bramble.test.TestUtils.getClientId;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getGroup; 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.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID; import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL; import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION; import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
@@ -59,9 +56,7 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Contact contact = new Contact(new ContactId(123), private final Contact contact = getContact();
getAuthor(), getLocalAuthor().getId(), getRandomString(5), true,
true);
private final ClientId clientId = getClientId(); private final ClientId clientId = getClientId();
private final long now = System.currentTimeMillis(); private final long now = System.currentTimeMillis();
private final Transaction txn = new Transaction(null, false); private final Transaction txn = new Transaction(null, false);

View File

@@ -17,8 +17,8 @@ import android.view.ViewGroup;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent; import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
import org.briarproject.bramble.api.contact.event.ContactStatusChangedEvent;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.NoSuchContactException; import org.briarproject.bramble.api.db.NoSuchContactException;
import org.briarproject.bramble.api.event.Event; import org.briarproject.bramble.api.event.Event;
@@ -194,7 +194,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
try { try {
long start = now(); long start = now();
List<ContactListItem> contacts = new ArrayList<>(); List<ContactListItem> contacts = new ArrayList<>();
for (Contact c : contactManager.getActiveContacts()) { for (Contact c : contactManager.getContacts()) {
try { try {
ContactId id = c.getId(); ContactId id = c.getId();
GroupCount count = GroupCount count =
@@ -229,15 +229,9 @@ public class ContactListFragment extends BaseFragment implements EventListener {
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof ContactStatusChangedEvent) { if (e instanceof ContactAddedEvent) {
ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; LOG.info("Contact added, reloading");
if (c.isActive()) { loadContacts();
LOG.info("Contact activated, reloading");
loadContacts();
} else {
LOG.info("Contact deactivated, removing item");
removeItem(c.getContactId());
}
} else if (e instanceof ContactConnectedEvent) { } else if (e instanceof ContactConnectedEvent) {
setConnected(((ContactConnectedEvent) e).getContactId(), true); setConnected(((ContactConnectedEvent) e).getContactId(), true);
} else if (e instanceof ContactDisconnectedEvent) { } else if (e instanceof ContactDisconnectedEvent) {

View File

@@ -44,7 +44,7 @@ public abstract class ContactSelectorControllerImpl
runOnDbThread(() -> { runOnDbThread(() -> {
try { try {
Collection<SelectableContactItem> contacts = new ArrayList<>(); Collection<SelectableContactItem> contacts = new ArrayList<>();
for (Contact c : contactManager.getActiveContacts()) { for (Contact c : contactManager.getContacts()) {
// was this contact already selected? // was this contact already selected?
boolean selected = selection.contains(c.getId()); boolean selected = selection.contains(c.getId());
// can this contact be selected? // can this contact be selected?

View File

@@ -204,7 +204,7 @@ public class ConversationViewModel extends AndroidViewModel {
imageSupport.postValue(imagesSupported); imageSupport.postValue(imagesSupported);
// check if introductions are supported // check if introductions are supported
Collection<Contact> contacts = contactManager.getActiveContacts(); Collection<Contact> contacts = contactManager.getContacts();
boolean introductionSupported = contacts.size() > 1; boolean introductionSupported = contacts.size() > 1;
showIntroductionAction.postValue(introductionSupported); showIntroductionAction.postValue(introductionSupported);

View File

@@ -119,7 +119,7 @@ public class ContactChooserFragment extends BaseFragment {
listener.runOnDbThread(() -> { listener.runOnDbThread(() -> {
try { try {
List<ContactListItem> contacts = new ArrayList<>(); List<ContactListItem> contacts = new ArrayList<>();
for (Contact c : contactManager.getActiveContacts()) { for (Contact c : contactManager.getContacts()) {
if (c.getId().equals(contactId)) { if (c.getId().equals(contactId)) {
c1 = c; c1 = c;
} else { } else {

View File

@@ -78,7 +78,7 @@ class RevealContactsControllerImpl extends DbControllerImpl
Collection<GroupMember> members = Collection<GroupMember> members =
groupManager.getMembers(g); groupManager.getMembers(g);
Collection<Contact> contacts = Collection<Contact> contacts =
contactManager.getActiveContacts(); contactManager.getContacts();
Collection<RevealableContactItem> items = Collection<RevealableContactItem> items =
new ArrayList<>(members.size()); new ArrayList<>(members.size());
for (GroupMember m : members) { for (GroupMember m : members) {

View File

@@ -434,7 +434,7 @@ class IntroduceeProtocolEngine
try { try {
contactManager contactManager
.addContact(txn, s.getRemote().author, localAuthor.getId(), .addContact(txn, s.getRemote().author, localAuthor.getId(),
false, true); false);
// Only add transport properties and keys when the contact was added // 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 // This will be changed once we have a way to reset state for peers

View File

@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.contact.ContactManager; import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
@@ -37,6 +36,7 @@ import org.junit.Test;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.NONE;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED; import static org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
@@ -90,7 +90,8 @@ public class BlogManagerImplTest extends BriarTestCase {
public BlogManagerImplTest() { public BlogManagerImplTest() {
MetadataParser metadataParser = context.mock(MetadataParser.class); MetadataParser metadataParser = context.mock(MetadataParser.class);
blogManager = new BlogManagerImpl(db, contactManager, identityManager, clientHelper, blogManager = new BlogManagerImpl(db, contactManager, identityManager,
clientHelper,
metadataParser, blogFactory, blogPostFactory); metadataParser, blogFactory, blogPostFactory);
localAuthor1 = getLocalAuthor(); localAuthor1 = getLocalAuthor();
@@ -130,10 +131,8 @@ public class BlogManagerImplTest extends BriarTestCase {
@Test @Test
public void testRemovingContact() throws DbException { public void testRemovingContact() throws DbException {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(blog2.getAuthor(),
ContactId contactId = new ContactId(0); blog1.getAuthor().getId(), true);
Contact contact = new Contact(contactId, blog2.getAuthor(),
blog1.getAuthor().getId(), getRandomString(5), true, true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).createBlog(blog2.getAuthor()); oneOf(blogFactory).createBlog(blog2.getAuthor());
@@ -152,10 +151,8 @@ public class BlogManagerImplTest extends BriarTestCase {
@Test @Test
public void testRemovingContactAfterRemovingBlog() throws DbException { public void testRemovingContactAfterRemovingBlog() throws DbException {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact(blog2.getAuthor(),
ContactId contactId = new ContactId(0); blog1.getAuthor().getId(), true);
Contact contact = new Contact(contactId, blog2.getAuthor(),
blog1.getAuthor().getId(), getRandomString(5), true, true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(blogFactory).createBlog(blog2.getAuthor()); oneOf(blogFactory).createBlog(blog2.getAuthor());

View File

@@ -234,12 +234,12 @@ public class IntroductionIntegrationTest
.contactExists(author1.getId(), author2.getId())); .contactExists(author1.getId(), author2.getId()));
// make sure that introduced contacts are not verified // make sure that introduced contacts are not verified
for (Contact c : contactManager1.getActiveContacts()) { for (Contact c : contactManager1.getContacts()) {
if (c.getAuthor().equals(author2)) { if (c.getAuthor().equals(author2)) {
assertFalse(c.isVerified()); assertFalse(c.isVerified());
} }
} }
for (Contact c : contactManager2.getActiveContacts()) { for (Contact c : contactManager2.getContacts()) {
if (c.getAuthor().equals(author1)) { if (c.getAuthor().equals(author1)) {
assertFalse(c.isVerified()); assertFalse(c.isVerified());
} }

View File

@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.Transaction; import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.IdentityManager; import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.Group.Visibility; import org.briarproject.bramble.api.sync.Group.Visibility;
@@ -27,7 +26,7 @@ import org.jmock.Expectations;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; 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.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -64,10 +63,12 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
final Clock clock = context.mock(Clock.class); final Clock clock = context.mock(Clock.class);
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
final Contact contact = getContact();
final ContactId contactId = contact.getId();
final Author author = contact.getAuthor();
final GroupId contactGroupId = new GroupId(getRandomId()); final GroupId contactGroupId = new GroupId(getRandomId());
final Group privateGroupGroup = getGroup(CLIENT_ID, MAJOR_VERSION); final Group privateGroupGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
final GroupId privateGroupId = privateGroupGroup.getId(); final GroupId privateGroupId = privateGroupGroup.getId();
final Author author = getAuthor();
final PrivateGroup privateGroup = new PrivateGroup(privateGroupGroup, final PrivateGroup privateGroup = new PrivateGroup(privateGroupGroup,
getRandomString(MAX_GROUP_NAME_LENGTH), author, getRandomString(MAX_GROUP_NAME_LENGTH), author,
getRandomBytes(GROUP_SALT_LENGTH)); getRandomBytes(GROUP_SALT_LENGTH));
@@ -79,11 +80,6 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
final long messageTimestamp = message.getTimestamp(); final long messageTimestamp = message.getTimestamp();
final long inviteTimestamp = messageTimestamp - 1; final long inviteTimestamp = messageTimestamp - 1;
final long localTimestamp = inviteTimestamp - 1; final long localTimestamp = inviteTimestamp - 1;
private final BdfDictionary meta =
BdfDictionary.of(new BdfEntry("me", "ta"));
final ContactId contactId = new ContactId(5);
final Contact contact = new Contact(contactId, author,
new AuthorId(getRandomId()), getRandomString(5), true, true);
final InviteMessage inviteMessage = final InviteMessage inviteMessage =
new InviteMessage(new MessageId(getRandomId()), contactGroupId, new InviteMessage(new MessageId(getRandomId()), contactGroupId,
@@ -168,6 +164,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
private void expectSendMessage(MessageType type, boolean visible) private void expectSendMessage(MessageType type, boolean visible)
throws Exception { throws Exception {
BdfDictionary meta = BdfDictionary.of(new BdfEntry("me", "ta"));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder).encodeMetadata(type, privateGroupId, oneOf(messageEncoder).encodeMetadata(type, privateGroupId,
message.getTimestamp(), true, true, visible, false, false); message.getTimestamp(), true, true, visible, false, false);

View File

@@ -36,7 +36,6 @@ import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser; import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@@ -44,9 +43,11 @@ import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static java.util.Arrays.asList;
import static junit.framework.TestCase.fail; import static junit.framework.TestCase.fail;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; 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.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -97,10 +98,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
private final GroupInvitationManagerImpl groupInvitationManager; private final GroupInvitationManagerImpl groupInvitationManager;
private final Transaction txn = new Transaction(null, false); private final Transaction txn = new Transaction(null, false);
private final ContactId contactId = new ContactId(0);
private final Author author = getAuthor(); private final Author author = getAuthor();
private final Contact contact = new Contact(contactId, author, private final Contact contact = getContact(author,
new AuthorId(getRandomId()), getRandomString(5), true, true); new AuthorId(getRandomId()), true);
private final ContactId contactId = contact.getId();
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group privateGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
@@ -844,12 +845,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRemovingGroupEndsSessions() throws Exception { public void testRemovingGroupEndsSessions() throws Exception {
Contact contact2 = new Contact(new ContactId(2), author, Contact contact2 = getContact();
author.getId(), getRandomString(5), true, true); Contact contact3 = getContact();
Contact contact3 = new Contact(new ContactId(3), author, Collection<Contact> contacts = asList(contact, contact2, contact3);
author.getId(), getRandomString(5), true, true);
Collection<Contact> contacts =
Arrays.asList(contact, contact2, contact3);
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION); Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);

View File

@@ -3,7 +3,6 @@ package org.briarproject.briar.privategroup.invitation;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.ProtocolStateException; import org.briarproject.briar.api.client.ProtocolStateException;
@@ -18,6 +17,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE; import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
import static org.briarproject.bramble.test.TestUtils.getAuthor; 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.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
@@ -31,6 +31,7 @@ import static org.briarproject.briar.privategroup.invitation.InviteeState.LEFT;
import static org.briarproject.briar.privategroup.invitation.InviteeState.START; import static org.briarproject.briar.privategroup.invitation.InviteeState.START;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -53,43 +54,43 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
// onInviteAction // onInviteAction
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromStart() throws Exception { public void testOnInviteActionFromStart() {
engine.onInviteAction(txn, getDefaultSession(START), null, engine.onInviteAction(txn, getDefaultSession(START), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromLeft() throws Exception { public void testOnInviteActionFromLeft() {
engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null, engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromInvited() throws Exception { public void testOnInviteActionFromInvited() {
engine.onInviteAction(txn, getDefaultSession(INVITED), null, engine.onInviteAction(txn, getDefaultSession(INVITED), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromDissolved() throws Exception { public void testOnInviteActionFromDissolved() {
engine.onInviteAction(txn, getDefaultSession(DISSOLVED), null, engine.onInviteAction(txn, getDefaultSession(DISSOLVED), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromAccepted() throws Exception { public void testOnInviteActionFromAccepted() {
engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null, engine.onInviteAction(txn, getDefaultSession(ACCEPTED), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromJoined() throws Exception { public void testOnInviteActionFromJoined() {
engine.onInviteAction(txn, getDefaultSession(JOINED), null, engine.onInviteAction(txn, getDefaultSession(JOINED), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testOnInviteActionFromError() throws Exception { public void testOnInviteActionFromError() {
engine.onInviteAction(txn, getDefaultSession(ERROR), null, engine.onInviteAction(txn, getDefaultSession(ERROR), null,
messageTimestamp, signature); messageTimestamp, signature);
} }
@@ -263,43 +264,43 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
// onMemberAddedAction // onMemberAddedAction
@Test @Test
public void testOnMemberAddedFromStart() throws Exception { public void testOnMemberAddedFromStart() {
InviteeSession session = getDefaultSession(START); InviteeSession session = getDefaultSession(START);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromInvited() throws Exception { public void testOnMemberAddedFromInvited() {
InviteeSession session = getDefaultSession(INVITED); InviteeSession session = getDefaultSession(INVITED);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromAccepted() throws Exception { public void testOnMemberAddedFromAccepted() {
InviteeSession session = getDefaultSession(ACCEPTED); InviteeSession session = getDefaultSession(ACCEPTED);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromJoined() throws Exception { public void testOnMemberAddedFromJoined() {
InviteeSession session = getDefaultSession(JOINED); InviteeSession session = getDefaultSession(JOINED);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromLeft() throws Exception { public void testOnMemberAddedFromLeft() {
InviteeSession session = getDefaultSession(LEFT); InviteeSession session = getDefaultSession(LEFT);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromDissolved() throws Exception { public void testOnMemberAddedFromDissolved() {
InviteeSession session = getDefaultSession(DISSOLVED); InviteeSession session = getDefaultSession(DISSOLVED);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@Test @Test
public void testOnMemberAddedFromError() throws Exception { public void testOnMemberAddedFromError() {
InviteeSession session = getDefaultSession(ERROR); InviteeSession session = getDefaultSession(ERROR);
assertEquals(session, engine.onMemberAddedAction(txn, session)); assertEquals(session, engine.onMemberAddedAction(txn, session));
} }
@@ -329,9 +330,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
privateGroup.getSalt(), privateGroup.getSalt(),
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH), getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
signature); signature);
Author notCreator = getAuthor(); Contact notCreatorContact = getContact(contactId, getAuthor(),
Contact notCreatorContact = new Contact(contactId, notCreator, localAuthor.getId(), true);
localAuthor.getId(), getRandomString(5), true, true);
expectGetContactId(); expectGetContactId();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -510,8 +510,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
session.getInviteTimestamp()); session.getInviteTimestamp());
assertNotNull(session.getLastRemoteMessageId()); assertNotNull(session.getLastRemoteMessageId());
assertNotNull(invalidJoinMessage.getPreviousMessageId()); assertNotNull(invalidJoinMessage.getPreviousMessageId());
assertFalse(session.getLastRemoteMessageId() assertNotEquals(session.getLastRemoteMessageId(),
.equals(invalidJoinMessage.getPreviousMessageId())); invalidJoinMessage.getPreviousMessageId());
expectAbortWhenSubscribedToGroup(); expectAbortWhenSubscribedToGroup();
InviteeSession newSession = InviteeSession newSession =
@@ -530,8 +530,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
session.getInviteTimestamp()); session.getInviteTimestamp());
assertNotNull(session.getLastRemoteMessageId()); assertNotNull(session.getLastRemoteMessageId());
assertNotNull(properJoinMessage.getPreviousMessageId()); assertNotNull(properJoinMessage.getPreviousMessageId());
assertTrue(session.getLastRemoteMessageId() assertEquals(session.getLastRemoteMessageId(),
.equals(properJoinMessage.getPreviousMessageId())); properJoinMessage.getPreviousMessageId());
expectSetPrivateGroupVisibility(SHARED); expectSetPrivateGroupVisibility(SHARED);
@@ -646,8 +646,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
session.getInviteTimestamp()); session.getInviteTimestamp());
assertNotNull(session.getLastRemoteMessageId()); assertNotNull(session.getLastRemoteMessageId());
assertNotNull(properLeaveMessage.getPreviousMessageId()); assertNotNull(properLeaveMessage.getPreviousMessageId());
assertTrue(session.getLastRemoteMessageId() assertEquals(session.getLastRemoteMessageId(),
.equals(properLeaveMessage.getPreviousMessageId())); properLeaveMessage.getPreviousMessageId());
expectMarkInvitesUnavailableToAnswer(); expectMarkInvitesUnavailableToAnswer();
InviteeSession newSession = InviteeSession newSession =
@@ -676,8 +676,8 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
session.getInviteTimestamp()); session.getInviteTimestamp());
assertNotNull(session.getLastRemoteMessageId()); assertNotNull(session.getLastRemoteMessageId());
assertNotNull(properLeaveMessage.getPreviousMessageId()); assertNotNull(properLeaveMessage.getPreviousMessageId());
assertTrue(session.getLastRemoteMessageId() assertEquals(session.getLastRemoteMessageId(),
.equals(properLeaveMessage.getPreviousMessageId())); properLeaveMessage.getPreviousMessageId());
expectMarkInvitesUnavailableToAnswer(); expectMarkInvitesUnavailableToAnswer();
InviteeSession newSession = InviteeSession newSession =

View File

@@ -34,11 +34,11 @@ import java.util.Map;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; 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.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor; import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID; import static org.briarproject.briar.api.blog.BlogSharingManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION; import static org.briarproject.briar.api.blog.BlogSharingManager.MAJOR_VERSION;
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID; import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
@@ -61,11 +61,10 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
private final BlogManager blogManager = context.mock(BlogManager.class); private final BlogManager blogManager = context.mock(BlogManager.class);
private final LocalAuthor localAuthor = getLocalAuthor(); private final LocalAuthor localAuthor = getLocalAuthor();
private final ContactId contactId = new ContactId(0);
private final Author author = getAuthor(); private final Author author = getAuthor();
private final Contact contact = private final Contact contact =
new Contact(contactId, author, localAuthor.getId(), getContact(author, localAuthor.getId(), true);
getRandomString(5), true, true); private final ContactId contactId = contact.getId();
private final Collection<Contact> contacts = private final Collection<Contact> contacts =
Collections.singletonList(contact); Collections.singletonList(contact);
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);

View File

@@ -16,7 +16,7 @@ internal class ContactControllerImpl
constructor(private val contactManager: ContactManager) : ContactController { constructor(private val contactManager: ContactManager) : ContactController {
override fun list(ctx: Context): Context { override fun list(ctx: Context): Context {
val contacts = contactManager.activeContacts.map { contact -> val contacts = contactManager.contacts.map { contact ->
contact.output() contact.output()
} }
return ctx.json(contacts) return ctx.json(contacts)

View File

@@ -5,7 +5,6 @@ import io.javalin.Context
import io.javalin.core.util.ContextUtil import io.javalin.core.util.ContextUtil
import io.mockk.mockk import io.mockk.mockk
import org.briarproject.bramble.api.contact.Contact import org.briarproject.bramble.api.contact.Contact
import org.briarproject.bramble.api.contact.ContactId
import org.briarproject.bramble.api.contact.ContactManager import org.briarproject.bramble.api.contact.ContactManager
import org.briarproject.bramble.api.identity.Author import org.briarproject.bramble.api.identity.Author
import org.briarproject.bramble.api.identity.IdentityManager import org.briarproject.bramble.api.identity.IdentityManager
@@ -36,8 +35,7 @@ abstract class ControllerTest {
protected val group: Group = getGroup(getClientId(), 0) protected val group: Group = getGroup(getClientId(), 0)
protected val author: Author = getAuthor() protected val author: Author = getAuthor()
protected val localAuthor: LocalAuthor = getLocalAuthor() protected val localAuthor: LocalAuthor = getLocalAuthor()
protected val contact = protected val contact: Contact = getContact(author, localAuthor.id, true)
Contact(ContactId(1), author, localAuthor.id, getRandomString(5), true, true)
protected val message: Message = getMessage(group.id) protected val message: Message = getMessage(group.id)
protected val text: String = getRandomString(5) protected val text: String = getRandomString(5)
protected val timestamp = 42L protected val timestamp = 42L

View File

@@ -19,14 +19,14 @@ internal class ContactControllerTest : ControllerTest() {
@Test @Test
fun testEmptyContactList() { fun testEmptyContactList() {
every { contactManager.activeContacts } returns emptyList<Contact>() every { contactManager.contacts } returns emptyList<Contact>()
every { ctx.json(emptyList<Any>()) } returns ctx every { ctx.json(emptyList<Any>()) } returns ctx
controller.list(ctx) controller.list(ctx)
} }
@Test @Test
fun testList() { fun testList() {
every { contactManager.activeContacts } returns listOf(contact) every { contactManager.contacts } returns listOf(contact)
every { ctx.json(listOf(contact.output())) } returns ctx every { ctx.json(listOf(contact.output())) } returns ctx
controller.list(ctx) controller.list(ctx)
} }