mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Remove local author from contacts.
This commit is contained in:
@@ -8,6 +8,8 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
@@ -23,12 +25,14 @@ public abstract class ConversationClientImpl extends BdfIncomingMessageHook
|
||||
implements ConversationClient {
|
||||
|
||||
protected final MessageTracker messageTracker;
|
||||
protected final IdentityManager identityManager;
|
||||
|
||||
protected ConversationClientImpl(DatabaseComponent db,
|
||||
ClientHelper clientHelper, MetadataParser metadataParser,
|
||||
MessageTracker messageTracker) {
|
||||
MessageTracker messageTracker, IdentityManager identityManager) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
this.messageTracker = messageTracker;
|
||||
this.identityManager = identityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,11 +44,16 @@ public abstract class ConversationClientImpl extends BdfIncomingMessageHook
|
||||
messageTracker.initializeGroupCount(txn, g);
|
||||
}
|
||||
|
||||
protected AuthorId getLocalAuthorId(Transaction txn) throws DbException {
|
||||
return identityManager.getLocalAuthor(txn).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCount getGroupCount(Transaction txn, ContactId contactId)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
GroupId groupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId groupId = getContactGroup(contact, local).getId();
|
||||
return messageTracker.getGroupCount(txn, groupId);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,7 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
|
||||
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m,
|
||||
boolean canSucceed) throws DbException {
|
||||
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
|
||||
Contact c = contactManager.getContact(txn, sender, localAuthorId);
|
||||
Contact c = contactManager.getContact(txn, sender);
|
||||
AuthorInfo otherAuthorInfo =
|
||||
contactManager.getAuthorInfo(txn, otherAuthor.getId());
|
||||
IntroductionResponse response =
|
||||
|
||||
@@ -249,9 +249,7 @@ class IntroduceeProtocolEngine
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
|
||||
// Broadcast IntroductionRequestReceivedEvent
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
Contact c = contactManager.getContact(txn, s.getIntroducer().getId(),
|
||||
localAuthor.getId());
|
||||
Contact c = contactManager.getContact(txn, s.getIntroducer().getId());
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, m.getAuthor().getId());
|
||||
IntroductionRequest request = new IntroductionRequest(m.getMessageId(),
|
||||
@@ -432,14 +430,13 @@ class IntroduceeProtocolEngine
|
||||
|
||||
Map<TransportId, TransportKeySetId> keys = null;
|
||||
try {
|
||||
contactManager.addContact(txn, s.getRemote().author,
|
||||
localAuthor.getId(), false);
|
||||
contactManager.addContact(txn, s.getRemote().author, false);
|
||||
|
||||
// Only add transport properties and keys when the contact was added
|
||||
// This will be changed once we have a way to reset state for peers
|
||||
// that were contacts already at some point in the past.
|
||||
Contact c = contactManager.getContact(txn,
|
||||
s.getRemote().author.getId(), localAuthor.getId());
|
||||
s.getRemote().author.getId());
|
||||
|
||||
// add the keys to the new contact
|
||||
//noinspection ConstantConditions
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -79,7 +78,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
private final IntroducerProtocolEngine introducerEngine;
|
||||
private final IntroduceeProtocolEngine introduceeEngine;
|
||||
private final IntroductionCrypto crypto;
|
||||
private final IdentityManager identityManager;
|
||||
|
||||
private final Group localGroup;
|
||||
|
||||
@@ -90,6 +88,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser,
|
||||
MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
ContactManager contactManager,
|
||||
MessageParser messageParser,
|
||||
@@ -97,9 +96,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
SessionParser sessionParser,
|
||||
IntroducerProtocolEngine introducerEngine,
|
||||
IntroduceeProtocolEngine introduceeEngine,
|
||||
IntroductionCrypto crypto,
|
||||
IdentityManager identityManager) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
IntroductionCrypto crypto) {
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.contactManager = contactManager;
|
||||
@@ -109,7 +108,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
this.introducerEngine = introducerEngine;
|
||||
this.introduceeEngine = introduceeEngine;
|
||||
this.crypto = crypto;
|
||||
this.identityManager = identityManager;
|
||||
this.localGroup =
|
||||
contactGroupFactory.createLocalGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
}
|
||||
@@ -126,7 +124,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
@@ -148,21 +146,21 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
abortOrRemoveSessionWithIntroducee(txn, c);
|
||||
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory
|
||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, c);
|
||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -328,17 +326,18 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session, if there is one
|
||||
Author introducer = identityManager.getLocalAuthor(txn);
|
||||
SessionId sessionId =
|
||||
crypto.getSessionId(introducer, c1.getAuthor(),
|
||||
c2.getAuthor());
|
||||
SessionId sessionId = crypto.getSessionId(introducer,
|
||||
c1.getAuthor(), c2.getAuthor());
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
// Create or parse the session
|
||||
IntroducerSession session;
|
||||
MessageId storageId;
|
||||
if (ss == null) {
|
||||
// This is the first request - create a new session
|
||||
GroupId groupId1 = getContactGroup(c1).getId();
|
||||
GroupId groupId2 = getContactGroup(c2).getId();
|
||||
GroupId groupId1 =
|
||||
getContactGroup(c1, introducer.getId()).getId();
|
||||
GroupId groupId2 =
|
||||
getContactGroup(c2, introducer.getId()).getId();
|
||||
boolean alice = crypto.isAlice(c1.getAuthor().getId(),
|
||||
c2.getAuthor().getId());
|
||||
// use fixed deterministic roles for the introducees
|
||||
@@ -382,7 +381,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Parse the session
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
IntroduceeSession session = sessionParser
|
||||
.parseIntroduceeSession(contactGroupId, ss.bdfSession);
|
||||
// Handle the join or leave action
|
||||
@@ -408,7 +408,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -521,13 +522,11 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
BdfDictionary query = sessionEncoder.getIntroducerSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> sessions;
|
||||
try {
|
||||
sessions = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, localGroup.getId(),
|
||||
query);
|
||||
sessions = clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
localGroup.getId(), query);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException();
|
||||
}
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
for (Entry<MessageId, BdfDictionary> session : sessions.entrySet()) {
|
||||
IntroducerSession s;
|
||||
try {
|
||||
@@ -537,18 +536,18 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
if (s.getIntroduceeA().author.equals(c.getAuthor())) {
|
||||
abortOrRemoveSessionWithIntroducee(txn, s, session.getKey(),
|
||||
s.getIntroduceeB(), localAuthor);
|
||||
s.getIntroduceeB());
|
||||
} else if (s.getIntroduceeB().author.equals(c.getAuthor())) {
|
||||
abortOrRemoveSessionWithIntroducee(txn, s, session.getKey(),
|
||||
s.getIntroduceeA(), localAuthor);
|
||||
s.getIntroduceeA());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void abortOrRemoveSessionWithIntroducee(Transaction txn,
|
||||
IntroducerSession s, MessageId storageId, Introducee i,
|
||||
LocalAuthor localAuthor) throws DbException {
|
||||
if (db.containsContact(txn, i.author.getId(), localAuthor.getId())) {
|
||||
IntroducerSession s, MessageId storageId, Introducee i)
|
||||
throws DbException {
|
||||
if (db.containsContact(txn, i.author.getId())) {
|
||||
IntroducerSession session =
|
||||
introducerEngine.onIntroduceeRemoved(txn, i, s);
|
||||
storeSession(txn, storageId, session);
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -59,8 +61,10 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
MessagingManagerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
}
|
||||
@@ -79,7 +83,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
@@ -98,21 +102,21 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -188,15 +192,14 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public GroupId getConversationId(ContactId c) throws DbException {
|
||||
Contact contact;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
contact = db.getContact(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return getContactGroup(contact).getId();
|
||||
return db.transactionWithResult(true, txn -> getConversationId(txn, c));
|
||||
}
|
||||
|
||||
private GroupId getConversationId(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
return getContactGroup(contact, local).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,7 +209,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
Collection<MessageStatus> statuses;
|
||||
GroupId g;
|
||||
try {
|
||||
g = getContactGroup(db.getContact(txn, c)).getId();
|
||||
g = getConversationId(txn, c);
|
||||
metadata = clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
statuses = db.getMessageStatus(txn, c, g);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -17,8 +17,6 @@ import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||
import org.briarproject.bramble.api.identity.AuthorInfo.Status;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -83,7 +81,6 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
|
||||
private final PrivateGroupFactory privateGroupFactory;
|
||||
private final ContactManager contactManager;
|
||||
private final IdentityManager identityManager;
|
||||
private final MessageTracker messageTracker;
|
||||
private final List<PrivateGroupHook> hooks;
|
||||
|
||||
@@ -91,12 +88,10 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
PrivateGroupManagerImpl(ClientHelper clientHelper,
|
||||
MetadataParser metadataParser, DatabaseComponent db,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
ContactManager contactManager, IdentityManager identityManager,
|
||||
MessageTracker messageTracker) {
|
||||
ContactManager contactManager, MessageTracker messageTracker) {
|
||||
super(db, clientHelper, metadataParser);
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
this.contactManager = contactManager;
|
||||
this.identityManager = identityManager;
|
||||
this.messageTracker = messageTracker;
|
||||
hooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
@@ -398,18 +393,17 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
try {
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMembers(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
for (Entry<Author, Visibility> m : authors.entrySet()) {
|
||||
Author a = m.getKey();
|
||||
AuthorInfo authorInfo = contactManager.getAuthorInfo(txn, a.getId());
|
||||
AuthorInfo authorInfo =
|
||||
contactManager.getAuthorInfo(txn, a.getId());
|
||||
Status status = authorInfo.getStatus();
|
||||
Visibility v = m.getValue();
|
||||
ContactId c = null;
|
||||
if (v != INVISIBLE &&
|
||||
(status == VERIFIED || status == UNVERIFIED)) {
|
||||
c = contactManager.getContact(txn, a.getId(), la.getId())
|
||||
.getId();
|
||||
c = contactManager.getContact(txn, a.getId()).getId();
|
||||
}
|
||||
boolean isCreator = privateGroup.getCreator().equals(a);
|
||||
members.add(new GroupMember(a, authorInfo, isCreator, c, v));
|
||||
@@ -483,8 +477,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
if (!foundMember) throw new ProtocolStateException();
|
||||
if (changed) {
|
||||
clientHelper.mergeGroupMetadata(txn, g, meta);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
ContactId c = contactManager.getContact(txn, a, la.getId()).getId();
|
||||
ContactId c = contactManager.getContact(txn, a).getId();
|
||||
Event e = new ContactRelationshipRevealedEvent(g, a, c, v);
|
||||
txn.attach(e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
@@ -34,14 +35,15 @@ class GroupInvitationFactoryImpl implements GroupInvitationFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] signInvitation(Contact c, GroupId privateGroupId,
|
||||
long timestamp, byte[] privateKey) {
|
||||
AuthorId creatorId = c.getLocalAuthorId();
|
||||
AuthorId memberId = c.getAuthor().getId();
|
||||
public byte[] signInvitation(LocalAuthor creator, Contact member,
|
||||
GroupId privateGroupId, long timestamp) {
|
||||
AuthorId creatorId = creator.getId();
|
||||
AuthorId memberId = member.getAuthor().getId();
|
||||
BdfList token = createInviteToken(creatorId, memberId, privateGroupId,
|
||||
timestamp);
|
||||
try {
|
||||
return clientHelper.sign(SIGNING_LABEL_INVITE, token, privateKey);
|
||||
return clientHelper.sign(SIGNING_LABEL_INVITE, token,
|
||||
creator.getPrivateKey());
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (FormatException e) {
|
||||
|
||||
@@ -14,6 +14,8 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -81,13 +83,15 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
ClientHelper clientHelper,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageTracker messageTracker,
|
||||
IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
PrivateGroupFactory privateGroupFactory,
|
||||
PrivateGroupManager privateGroupManager,
|
||||
MessageParser messageParser, SessionParser sessionParser,
|
||||
SessionEncoder sessionEncoder,
|
||||
ProtocolEngineFactory engineFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.privateGroupFactory = privateGroupFactory;
|
||||
@@ -114,7 +118,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
@@ -138,13 +142,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,7 +271,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session, if there is one
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
CreatorSession session;
|
||||
@@ -308,7 +313,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -333,7 +339,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, getSessionId(g));
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -368,11 +375,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(Transaction txn,
|
||||
ContactId c) throws DbException {
|
||||
public Collection<ConversationMessageHeader> getMessageHeaders(
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -436,8 +444,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// Look up the available invite messages for each contact
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Map<MessageId, BdfDictionary> results =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
contactGroupId, query);
|
||||
@@ -456,10 +465,11 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
@Override
|
||||
public boolean isInvitationAllowed(Contact c, GroupId privateGroupId)
|
||||
throws DbException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
@@ -492,15 +502,17 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
public void addingMember(Transaction txn, GroupId privateGroupId, Author a)
|
||||
throws DbException {
|
||||
// If the member is a contact, handle the add member action
|
||||
for (Contact c : db.getContactsByAuthorId(txn, a.getId()))
|
||||
addingMember(txn, privateGroupId, c);
|
||||
if (db.containsContact(txn, a.getId())) {
|
||||
addingMember(txn, privateGroupId, db.getContact(txn, a.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
private void addingMember(Transaction txn, GroupId privateGroupId,
|
||||
Contact c) throws DbException {
|
||||
try {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
@@ -533,9 +545,10 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
// If we have any sessions in progress, tell the contacts we're leaving
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) continue; // No session for this contact
|
||||
// Handle the action
|
||||
@@ -574,7 +587,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -603,7 +616,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
private Map<GroupId, Visibility> getPreferredVisibilities(Transaction txn,
|
||||
Contact c) throws DbException, FormatException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
BdfDictionary query = sessionParser.getAllSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.inject.Inject;
|
||||
class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
implements BlogSharingManager, RemoveBlogHook {
|
||||
|
||||
private final IdentityManager identityManager;
|
||||
private final BlogManager blogManager;
|
||||
|
||||
@Inject
|
||||
@@ -43,8 +42,8 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
IdentityManager identityManager, BlogManager blogManager) {
|
||||
super(db, clientHelper, clientVersioningManager, metadataParser,
|
||||
messageParser, sessionEncoder, sessionParser, messageTracker,
|
||||
contactGroupFactory, engine, invitationFactory);
|
||||
this.identityManager = identityManager;
|
||||
identityManager, contactGroupFactory, engine,
|
||||
invitationFactory);
|
||||
this.blogManager = blogManager;
|
||||
}
|
||||
|
||||
@@ -80,8 +79,8 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
|
||||
// Pre-share both blogs, if they have not been shared already
|
||||
try {
|
||||
preShareGroup(txn, c, ourBlog.getGroup());
|
||||
preShareGroup(txn, c, theirBlog.getGroup());
|
||||
preShareGroup(txn, c, ourBlog.getGroup(), localAuthor.getId());
|
||||
preShareGroup(txn, c, theirBlog.getGroup(), localAuthor.getId());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||
@@ -27,13 +28,14 @@ class ForumSharingManagerImpl extends SharingManagerImpl<Forum>
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageParser<Forum> messageParser,
|
||||
SessionEncoder sessionEncoder, SessionParser sessionParser,
|
||||
MessageTracker messageTracker,
|
||||
MessageTracker messageTracker, IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
ProtocolEngine<Forum> engine,
|
||||
InvitationFactory<Forum, ForumInvitationResponse> invitationFactory) {
|
||||
super(db, clientHelper, clientVersioningManager, metadataParser,
|
||||
messageParser, sessionEncoder, sessionParser, messageTracker,
|
||||
contactGroupFactory, engine, invitationFactory);
|
||||
identityManager, contactGroupFactory, engine,
|
||||
invitationFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,8 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Client;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
@@ -70,10 +72,11 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageParser<S> messageParser,
|
||||
SessionEncoder sessionEncoder, SessionParser sessionParser,
|
||||
MessageTracker messageTracker,
|
||||
MessageTracker messageTracker, IdentityManager identityManager,
|
||||
ContactGroupFactory contactGroupFactory, ProtocolEngine<S> engine,
|
||||
InvitationFactory<S, ?> invitationFactory) {
|
||||
super(db, clientHelper, metadataParser, messageTracker);
|
||||
super(db, clientHelper, metadataParser, messageTracker,
|
||||
identityManager);
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.messageParser = messageParser;
|
||||
this.sessionEncoder = sessionEncoder;
|
||||
@@ -105,7 +108,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public void addingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Create a group to share with the contact
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.addGroup(txn, g);
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getClientId(), getMajorVersion());
|
||||
@@ -123,13 +126,13 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
db.removeGroup(txn, getContactGroup(c, getLocalAuthorId(txn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
public Group getContactGroup(Contact c, AuthorId local) {
|
||||
return contactGroupFactory.createContactGroup(getClientId(),
|
||||
getMajorVersion(), c);
|
||||
getMajorVersion(), c, local);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,10 +163,10 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
* and the Contact c in state SHARING.
|
||||
* If a session already exists, this does nothing.
|
||||
*/
|
||||
void preShareGroup(Transaction txn, Contact c, Group g)
|
||||
void preShareGroup(Transaction txn, Contact c, Group g, AuthorId local)
|
||||
throws DbException, FormatException {
|
||||
// Return if a session already exists with the contact
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession existingSession = getSession(txn, contactGroupId,
|
||||
getSessionId(g.getId()));
|
||||
if (existingSession != null) return;
|
||||
@@ -257,11 +260,13 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
if (!canBeShared(txn, shareableId, contact))
|
||||
if (!canBeShared(txn, shareableId, contact)) {
|
||||
// we might have received an invitation in the meantime
|
||||
return;
|
||||
}
|
||||
// Look up the session, if there is one
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
// Create or parse the session
|
||||
Session session;
|
||||
@@ -301,7 +306,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
try {
|
||||
// Look up the session
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, id);
|
||||
if (ss == null) throw new IllegalArgumentException();
|
||||
// Parse the session
|
||||
@@ -325,7 +331,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn, ContactId c) throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
GroupId contactGroupId = getContactGroup(contact).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(contact, local).getId();
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
@@ -385,8 +392,9 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// get invitations from each contact
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
Map<MessageId, BdfDictionary> results =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn,
|
||||
contactGroupId, query);
|
||||
@@ -456,7 +464,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
||||
if (client != SHARED) return false;
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
SessionId sessionId = getSessionId(g);
|
||||
try {
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
@@ -475,9 +484,10 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
SessionId sessionId = getSessionId(shareable.getId());
|
||||
// If we have any sessions in progress, tell the contacts we're leaving
|
||||
try {
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
// Look up the session for the contact, if there is one
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
if (ss == null) continue; // No session for this contact
|
||||
// Let the engine perform a LEAVE action
|
||||
@@ -496,7 +506,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
public void onClientVisibilityChanging(Transaction txn, Contact c,
|
||||
Visibility v) throws DbException {
|
||||
// Apply the client's visibility to the contact group
|
||||
Group g = getContactGroup(c);
|
||||
Group g = getContactGroup(c, getLocalAuthorId(txn));
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), v);
|
||||
}
|
||||
|
||||
@@ -525,7 +535,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
private Map<GroupId, Visibility> getPreferredVisibilities(Transaction txn,
|
||||
Contact c) throws DbException, FormatException {
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
AuthorId local = getLocalAuthorId(txn);
|
||||
GroupId contactGroupId = getContactGroup(c, local).getId();
|
||||
BdfDictionary query = sessionParser.getAllSessionsQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
@@ -148,17 +147,15 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private List<Contact> createContacts(int numContacts) throws DbException {
|
||||
List<Contact> contacts = new ArrayList<>(numContacts);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < numContacts; i++) {
|
||||
LocalAuthor author = getRandomAuthor();
|
||||
Contact contact = addContact(localAuthor.getId(), author);
|
||||
Contact contact = addContact(author);
|
||||
contacts.add(contact);
|
||||
}
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private Contact addContact(AuthorId localAuthorId, LocalAuthor author)
|
||||
throws DbException {
|
||||
private Contact addContact(LocalAuthor author) throws DbException {
|
||||
|
||||
// prepare to add contact
|
||||
SecretKey secretKey = getSecretKey();
|
||||
@@ -172,9 +169,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
Contact contact;
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
ContactId contactId = contactManager
|
||||
.addContact(txn, author, localAuthorId, secretKey,
|
||||
timestamp, true, verified, true);
|
||||
ContactId contactId = contactManager.addContact(txn, author,
|
||||
secretKey, timestamp, true, verified, true);
|
||||
if (random.nextBoolean()) {
|
||||
contactManager
|
||||
.setContactAlias(txn, contactId, getRandomAuthorName());
|
||||
@@ -196,8 +192,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
@Override
|
||||
public Contact addContact(String name) throws DbException {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
return addContact(localAuthor.getId(), getAuthor(name));
|
||||
return addContact(getAuthor(name));
|
||||
}
|
||||
|
||||
private LocalAuthor getAuthor(String name) {
|
||||
@@ -301,8 +296,10 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private void createPrivateMessages(List<Contact> contacts,
|
||||
int numPrivateMsgs) throws DbException {
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (Contact contact : contacts) {
|
||||
Group group = messagingManager.getContactGroup(contact);
|
||||
Group group = messagingManager.getContactGroup(contact,
|
||||
localAuthor.getId());
|
||||
for (int i = 0; i < numPrivateMsgs; i++) {
|
||||
try {
|
||||
createRandomPrivateMessage(group.getId(), i);
|
||||
@@ -345,13 +342,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPrivateMessage(Contact contact, String text, long time,
|
||||
boolean local) throws DbException, FormatException {
|
||||
Group group = messagingManager.getContactGroup(contact);
|
||||
createPrivateMessage(group.getId(), text, time, local);
|
||||
}
|
||||
|
||||
private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
|
||||
throws DbException {
|
||||
for (int i = 0; i < numBlogPosts; i++) {
|
||||
|
||||
@@ -130,8 +130,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContact() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
Contact contact = getContact(blog2.getAuthor(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
@@ -150,8 +149,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testRemovingContactAfterRemovingBlog() throws DbException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(blog2.getAuthor(),
|
||||
blog1.getAuthor().getId(), true);
|
||||
Contact contact = getContact(blog2.getAuthor(), true);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(blog2.getAuthor());
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
@@ -134,8 +135,10 @@ public class IntroductionIntegrationTest
|
||||
.makeIntroduction(introducee1, introducee2, "Hi!", time);
|
||||
|
||||
// check that messages are tracked properly
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 1, 0);
|
||||
assertGroupCount(messageTracker0, g2.getId(), 1, 0);
|
||||
|
||||
@@ -228,10 +231,8 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(listener1.succeeded);
|
||||
assertTrue(listener2.succeeded);
|
||||
|
||||
assertTrue(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertTrue(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertTrue(contactManager1.contactExists(author2.getId()));
|
||||
assertTrue(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
// make sure that introduced contacts are not verified
|
||||
for (Contact c : contactManager1.getContacts()) {
|
||||
@@ -318,13 +319,13 @@ public class IntroductionIntegrationTest
|
||||
assertFalse(listener1.succeeded);
|
||||
assertFalse(listener2.succeeded);
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertFalse(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertFalse(contactManager1.contactExists(author2.getId()));
|
||||
assertFalse(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
Collection<ConversationMessageHeader> messages =
|
||||
db0.transactionWithResult(true, txn -> introductionManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
@@ -387,10 +388,8 @@ public class IntroductionIntegrationTest
|
||||
listener1.getResponse().getIntroducedAuthor().getName());
|
||||
assertFalse(listener1.getResponse().canSucceed());
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertFalse(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertFalse(contactManager1.contactExists(author2.getId()));
|
||||
assertFalse(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
Collection<ConversationMessageHeader> messages =
|
||||
db0.transactionWithResult(true, txn -> introductionManager0
|
||||
@@ -499,10 +498,8 @@ public class IntroductionIntegrationTest
|
||||
sync1To0(2, true);
|
||||
sync0To2(2, true);
|
||||
|
||||
assertTrue(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
assertTrue(contactManager2
|
||||
.contactExists(author1.getId(), author2.getId()));
|
||||
assertTrue(contactManager1.contactExists(author2.getId()));
|
||||
assertTrue(contactManager2.contactExists(author1.getId()));
|
||||
|
||||
assertDefaultUiMessages();
|
||||
assertFalse(listener0.aborted);
|
||||
@@ -593,8 +590,10 @@ public class IntroductionIntegrationTest
|
||||
introduceeSession = getIntroduceeSession(c1);
|
||||
assertEquals(IntroduceeState.START, introduceeSession.getState());
|
||||
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||
Group g1 = introductionManager0.getContactGroup(introducee1,
|
||||
author0.getId());
|
||||
Group g2 = introductionManager0.getContactGroup(introducee2,
|
||||
author0.getId());
|
||||
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||
introductionManager0.getMessageHeaders(txn, contactId1From0))
|
||||
.size());
|
||||
@@ -787,8 +786,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save ACCEPT from introducee1
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, ACCEPT);
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), ACCEPT);
|
||||
|
||||
// sync ACCEPT back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -824,8 +823,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save ACCEPT from introducee1
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, ACCEPT);
|
||||
AcceptMessage m = (AcceptMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), ACCEPT);
|
||||
|
||||
// sync ACCEPT back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -859,8 +858,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To1(1, true);
|
||||
|
||||
// save DECLINE from introducee1
|
||||
DeclineMessage m = (DeclineMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, DECLINE);
|
||||
DeclineMessage m = (DeclineMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), DECLINE);
|
||||
|
||||
// sync DECLINE back to introducer
|
||||
sync1To0(1, true);
|
||||
@@ -903,8 +902,8 @@ public class IntroductionIntegrationTest
|
||||
sync0To2(1, true);
|
||||
|
||||
// save AUTH from introducee1
|
||||
AuthMessage m = (AuthMessage) getMessageFor(c1.getClientHelper(),
|
||||
contact0From1, AUTH);
|
||||
AuthMessage m = (AuthMessage) getMessageFor(introductionManager1,
|
||||
c1.getClientHelper(), contact0From1, author1.getId(), AUTH);
|
||||
|
||||
// sync first AUTH message
|
||||
sync1To0(1, true);
|
||||
@@ -1006,13 +1005,11 @@ public class IntroductionIntegrationTest
|
||||
// 0 and 1 remove and re-add each other
|
||||
contactManager0.removeContact(contactId1From0);
|
||||
contactManager1.removeContact(contactId0From1);
|
||||
contactId1From0 = contactManager0
|
||||
.addContact(author1, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From0 = contactManager0.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1
|
||||
.addContact(author0, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From1 = contactManager1.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
|
||||
// Sync initial client versioning updates and transport properties
|
||||
@@ -1060,9 +1057,9 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
|
||||
// get response to be forwarded
|
||||
AcceptMessage message =
|
||||
(AcceptMessage) getMessageFor(c0.getClientHelper(),
|
||||
contact2From0, ACCEPT);
|
||||
AcceptMessage message = (AcceptMessage) getMessageFor(
|
||||
introductionManager0, c0.getClientHelper(), contact2From0,
|
||||
author0.getId(), ACCEPT);
|
||||
|
||||
// allow visitor to modify response
|
||||
AcceptMessage m = visitor.visit(message);
|
||||
@@ -1345,10 +1342,10 @@ public class IntroductionIntegrationTest
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractIntroductionMessage getMessageFor(ClientHelper ch,
|
||||
Contact contact, MessageType type)
|
||||
private AbstractIntroductionMessage getMessageFor(IntroductionManager im,
|
||||
ClientHelper ch, Contact contact, AuthorId local, MessageType type)
|
||||
throws FormatException, DbException {
|
||||
Group g = introductionManager0.getContactGroup(contact);
|
||||
Group g = im.getContactGroup(contact, local);
|
||||
BdfDictionary query = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, type.getValue())
|
||||
);
|
||||
@@ -1400,8 +1397,8 @@ public class IntroductionIntegrationTest
|
||||
.getMessageMetadataAsDictionary(getLocalGroup().getId());
|
||||
assertEquals(1, dicts.size());
|
||||
BdfDictionary d = dicts.values().iterator().next();
|
||||
Group introducerGroup =
|
||||
introductionManager2.getContactGroup(contact0From2);
|
||||
Group introducerGroup = introductionManager2
|
||||
.getContactGroup(contact0From2, author2.getId());
|
||||
return c.getSessionParser()
|
||||
.parseIntroduceeSession(introducerGroup.getId(), d);
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
lifecycleManager.waitForStartup();
|
||||
// Add the other user as a contact
|
||||
ContactManager contactManager = device.getContactManager();
|
||||
return contactManager.addContact(remote, local.getId(), rootKey,
|
||||
timestamp, alice, true, true);
|
||||
return contactManager.addContact(remote, rootKey, timestamp, alice,
|
||||
true, true);
|
||||
}
|
||||
|
||||
private void sendMessage(SimplexMessagingIntegrationTestComponent device,
|
||||
|
||||
@@ -29,6 +29,7 @@ import static org.briarproject.briar.api.privategroup.Visibility.INVISIBLE;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_CONTACT;
|
||||
import static org.briarproject.briar.api.privategroup.Visibility.REVEALED_BY_US;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -164,7 +165,7 @@ public class PrivateGroupIntegrationTest
|
||||
getGroupMember(groupManager2, author1.getId()).getVisibility());
|
||||
|
||||
// 1 reveals the contact relationship to 2
|
||||
assertTrue(contactId2From1 != null);
|
||||
assertNotNull(contactId2From1);
|
||||
groupInvitationManager1.revealRelationship(contactId2From1, groupId0);
|
||||
sync1To2(1, true);
|
||||
sync2To1(1, true);
|
||||
@@ -213,8 +214,7 @@ public class PrivateGroupIntegrationTest
|
||||
@Nullable String text) throws DbException {
|
||||
Contact contact = contactManager0.getContact(c);
|
||||
byte[] signature = groupInvitationFactory
|
||||
.signInvitation(contact, groupId0, timestamp,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, contact, groupId0, timestamp);
|
||||
groupInvitationManager0
|
||||
.sendInvitation(groupId0, c, text, timestamp, signature);
|
||||
}
|
||||
|
||||
@@ -253,8 +253,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -306,8 +305,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
// signature uses joiner's key, not creator's key
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author1.getPrivateKey());
|
||||
.signInvitation(author1, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -400,8 +398,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c2 = contactManager0.getContact(contactId2From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c2, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c2, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg2 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
||||
inviteTime, creatorSignature);
|
||||
@@ -522,8 +519,7 @@ public class PrivateGroupManagerIntegrationTest
|
||||
long inviteTime = joinTime - 1;
|
||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||
byte[] creatorSignature = groupInvitationFactory
|
||||
.signInvitation(c1, privateGroup0.getId(), inviteTime,
|
||||
author0.getPrivateKey());
|
||||
.signInvitation(author0, c1, privateGroup0.getId(), inviteTime);
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
|
||||
@@ -176,9 +176,9 @@ public class GroupInvitationIntegrationTest
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup0, true);
|
||||
|
||||
messages = db1.transactionWithResult(true,
|
||||
txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
messages = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager1.getMessageHeaders(txn,
|
||||
contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
boolean foundResponse = false;
|
||||
for (ConversationMessageHeader m : messages) {
|
||||
@@ -199,9 +199,9 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
sync1To0(1, true);
|
||||
|
||||
messages = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager0
|
||||
.getMessageHeaders(txn, contactId1From0));
|
||||
messages = db0.transactionWithResult(true, txn ->
|
||||
groupInvitationManager0.getMessageHeaders(txn,
|
||||
contactId1From0));
|
||||
assertEquals(2, messages.size());
|
||||
foundResponse = false;
|
||||
for (ConversationMessageHeader m : messages) {
|
||||
@@ -228,13 +228,15 @@ public class GroupInvitationIntegrationTest
|
||||
sendInvitation(timestamp, null);
|
||||
|
||||
// 0 has one read outgoing message
|
||||
Group g1 = groupInvitationManager0.getContactGroup(contact1From0);
|
||||
Group g1 = groupInvitationManager0.getContactGroup(contact1From0,
|
||||
author0.getId());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 1, 0, timestamp);
|
||||
|
||||
sync0To1(1, true);
|
||||
|
||||
// 1 has one unread message
|
||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1);
|
||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1,
|
||||
author1.getId());
|
||||
assertGroupCount(messageTracker1, g0.getId(), 1, 1, timestamp);
|
||||
ConversationMessageHeader m = db1.transactionWithResult(true, txn ->
|
||||
groupInvitationManager1.getMessageHeaders(txn, contactId0From1)
|
||||
@@ -460,8 +462,8 @@ public class GroupInvitationIntegrationTest
|
||||
|
||||
private void sendInvitation(long timestamp, @Nullable String text) throws
|
||||
DbException {
|
||||
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
|
||||
privateGroup0.getId(), timestamp, author0.getPrivateKey());
|
||||
byte[] signature = groupInvitationFactory.signInvitation(author0,
|
||||
contact1From0, privateGroup0.getId(), timestamp);
|
||||
groupInvitationManager0
|
||||
.sendInvitation(privateGroup0.getId(), contactId1From0, text,
|
||||
timestamp, signature);
|
||||
|
||||
@@ -14,7 +14,8 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
@@ -49,6 +50,7 @@ import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -70,6 +72,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final ClientHelper clientHelper = context.mock(ClientHelper.class);
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final ClientVersioningManager clientVersioningManager =
|
||||
context.mock(ClientVersioningManager.class);
|
||||
private final ContactGroupFactory contactGroupFactory =
|
||||
@@ -99,8 +103,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact = getContact(author,
|
||||
new AuthorId(getRandomId()), true);
|
||||
private final Contact contact = getContact(author, true);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
@@ -143,9 +147,9 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
MessageTracker messageTracker = context.mock(MessageTracker.class);
|
||||
groupInvitationManager = new GroupInvitationManagerImpl(db,
|
||||
clientHelper, clientVersioningManager, metadataParser,
|
||||
messageTracker, contactGroupFactory, privateGroupFactory,
|
||||
privateGroupManager, messageParser, sessionParser,
|
||||
sessionEncoder, engineFactory);
|
||||
messageTracker, identityManager, contactGroupFactory,
|
||||
privateGroupFactory, privateGroupManager, messageParser,
|
||||
sessionParser, sessionEncoder, engineFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +185,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
|
||||
@@ -204,8 +210,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private void expectAddingMember(GroupId g, Contact c) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
MAJOR_VERSION, c, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectGetSession(noResults, new SessionId(g.getBytes()),
|
||||
@@ -260,8 +268,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testRemovingContact() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).removeGroup(txn, contactGroup);
|
||||
}});
|
||||
@@ -475,8 +485,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectCreateStorageId();
|
||||
@@ -507,8 +519,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
||||
@@ -536,8 +550,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -588,8 +604,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parseInviteeSession(contactGroup.getId(), bdfSession);
|
||||
@@ -610,8 +628,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.parsePeerSession(contactGroup.getId(), bdfSession);
|
||||
@@ -635,8 +655,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
@@ -672,8 +694,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContact(txn, contactId);
|
||||
will(returnValue(contact));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(messageParser).getMessagesVisibleInUiQuery();
|
||||
will(returnValue(query));
|
||||
@@ -744,10 +768,12 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(query));
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(Collections.singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId(), query);
|
||||
@@ -814,8 +840,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
throws Exception {
|
||||
expectGetSession(oneResult, sessionId, contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
@@ -837,8 +865,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
public void testAddingMember() throws Exception {
|
||||
expectAddingMember(privateGroup.getId(), contact);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getContactsByAuthorId(txn, author.getId());
|
||||
will(returnValue(Collections.singletonList(contact)));
|
||||
oneOf(db).containsContact(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).getContact(txn, author.getId());
|
||||
will(returnValue(contact));
|
||||
}});
|
||||
groupInvitationManager.addingMember(txn, privateGroup.getId(), author);
|
||||
}
|
||||
@@ -866,16 +896,18 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
sessionId, contactGroup3.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact2);
|
||||
MAJOR_VERSION, contact2, localAuthor.getId());
|
||||
will(returnValue(contactGroup2));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact3);
|
||||
MAJOR_VERSION, contact3, localAuthor.getId());
|
||||
will(returnValue(contactGroup3));
|
||||
// session 1
|
||||
oneOf(sessionParser).getRole(bdfSession);
|
||||
|
||||
@@ -330,8 +330,7 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
privateGroup.getSalt(),
|
||||
getRandomString(MAX_GROUP_INVITATION_TEXT_LENGTH),
|
||||
signature);
|
||||
Contact notCreatorContact = getContact(contactId, getAuthor(),
|
||||
localAuthor.getId(), true);
|
||||
Contact notCreatorContact = getContact(contactId, getAuthor(), true);
|
||||
|
||||
expectGetContactId();
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -126,7 +126,7 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// get sharing group and assert group message count
|
||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact1From0).getId();
|
||||
MAJOR_VERSION, contact1From0, author0.getId()).getId();
|
||||
assertGroupCount(messageTracker0, g, 1, 0);
|
||||
|
||||
// check that request message state is correct
|
||||
@@ -217,7 +217,7 @@ public class BlogSharingIntegrationTest
|
||||
|
||||
// get sharing group and assert group message count
|
||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact1From0).getId();
|
||||
MAJOR_VERSION, contact1From0, author0.getId()).getId();
|
||||
assertGroupCount(messageTracker0, g, 1, 0);
|
||||
|
||||
// sync first request message
|
||||
|
||||
@@ -62,8 +62,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final Author author = getAuthor();
|
||||
private final Contact contact =
|
||||
getContact(author, localAuthor.getId(), true);
|
||||
private final Contact contact = getContact(author, true);
|
||||
private final ContactId contactId = contact.getId();
|
||||
private final Collection<Contact> contacts =
|
||||
Collections.singletonList(contact);
|
||||
@@ -123,8 +122,10 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the contact group and share it with the contact
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
|
||||
@@ -202,7 +203,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
Message message = getMessage(contactGroup.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||
@@ -237,10 +238,12 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
Session session = new Session(contactGroup.getId(), blog.getId());
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
MAJOR_VERSION, contact, localAuthor.getId());
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(sessionParser)
|
||||
.getSessionQuery(new SessionId(blog.getId().getBytes()));
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
@@ -416,7 +417,7 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// response and invitation got tracked
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact0From1);
|
||||
MAJOR_VERSION, contact0From1, author1.getId());
|
||||
assertEquals(2, c1.getMessageTracker().getGroupCount(group.getId())
|
||||
.getMsgCount());
|
||||
|
||||
@@ -448,7 +449,7 @@ public class ForumSharingIntegrationTest
|
||||
|
||||
// assert that the invitation arrived
|
||||
Group group = contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact0From1);
|
||||
MAJOR_VERSION, contact0From1, author1.getId());
|
||||
assertEquals(1, c1.getMessageTracker().getGroupCount(group.getId())
|
||||
.getMsgCount());
|
||||
|
||||
@@ -777,8 +778,9 @@ public class ForumSharingIntegrationTest
|
||||
.contains(contact0From1));
|
||||
|
||||
// send an accept message for the same forum
|
||||
Message m = messageEncoder.encodeAcceptMessage(
|
||||
forumSharingManager0.getContactGroup(contact1From0).getId(),
|
||||
GroupId contactGroupId = forumSharingManager0.getContactGroup(
|
||||
contact1From0, author0.getId()).getId();
|
||||
Message m = messageEncoder.encodeAcceptMessage(contactGroupId,
|
||||
forum0.getId(), clock.currentTimeMillis(), invitationId);
|
||||
c0.getClientHelper().addLocalMessage(m, new BdfDictionary(), true);
|
||||
|
||||
|
||||
@@ -283,21 +283,17 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
}
|
||||
|
||||
protected void addDefaultContacts() throws Exception {
|
||||
contactId1From0 = contactManager0
|
||||
.addContact(author1, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From0 = contactManager0.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact1From0 = contactManager0.getContact(contactId1From0);
|
||||
contactId0From1 = contactManager1
|
||||
.addContact(author0, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From1 = contactManager1.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From1 = contactManager1.getContact(contactId0From1);
|
||||
contactId2From0 = contactManager0
|
||||
.addContact(author2, author0.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId2From0 = contactManager0.addContact(author2, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact2From0 = contactManager0.getContact(contactId2From0);
|
||||
contactId0From2 = contactManager2
|
||||
.addContact(author0, author2.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId0From2 = contactManager2.addContact(author0, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contact0From2 = contactManager2.getContact(contactId0From2);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
@@ -315,12 +311,10 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
||||
|
||||
protected void addContacts1And2(boolean haveTransportProperties)
|
||||
throws Exception {
|
||||
contactId2From1 = contactManager1
|
||||
.addContact(author2, author1.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From2 = contactManager2
|
||||
.addContact(author1, author2.getId(), getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId2From1 = contactManager1.addContact(author2, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
contactId1From2 = contactManager2.addContact(author1, getSecretKey(),
|
||||
clock.currentTimeMillis(), true, true, true);
|
||||
|
||||
// Sync initial client versioning updates
|
||||
sync1To2(1, true);
|
||||
|
||||
Reference in New Issue
Block a user