Factor out methods for storing and retrieving contact ID.

This commit is contained in:
akwizgran
2020-11-23 17:15:57 +00:00
parent 029ddddd27
commit bab2b4594d
23 changed files with 104 additions and 161 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.bramble.api.client; package org.briarproject.bramble.api.client;
import org.briarproject.bramble.api.FormatException; import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.crypto.PrivateKey; import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey; import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
@@ -119,4 +120,17 @@ public interface ClientHelper {
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap( Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
BdfDictionary properties) throws FormatException; BdfDictionary properties) throws FormatException;
/**
* Retrieves the contact ID from the group metadata of the given contact
* group.
*/
ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException, FormatException;
/**
* Stores the given contact ID in the group metadata of the given contact
* group.
*/
void setContactId(Transaction txn, GroupId contactGroupId, ContactId c)
throws DbException;
} }

View File

@@ -0,0 +1,9 @@
package org.briarproject.bramble.api.client;
public interface ContactGroupConstants {
/**
* Group metadata key for associating a contact ID with a contact group.
*/
String GROUP_KEY_CONTACT_ID = "contactId";
}

View File

@@ -2,11 +2,13 @@ package org.briarproject.bramble.client;
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.ContactId;
import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyParser; import org.briarproject.bramble.api.crypto.KeyParser;
import org.briarproject.bramble.api.crypto.PrivateKey; import org.briarproject.bramble.api.crypto.PrivateKey;
import org.briarproject.bramble.api.crypto.PublicKey; import org.briarproject.bramble.api.crypto.PublicKey;
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.BdfList; import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.BdfReader; import org.briarproject.bramble.api.data.BdfReader;
import org.briarproject.bramble.api.data.BdfReaderFactory; import org.briarproject.bramble.api.data.BdfReaderFactory;
@@ -39,6 +41,7 @@ import java.util.Map.Entry;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION; import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
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.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
@@ -389,4 +392,27 @@ class ClientHelperImpl implements ClientHelper {
return tpMap; return tpMap;
} }
@Override
public ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException {
try {
BdfDictionary meta =
getGroupMetadataAsDictionary(txn, contactGroupId);
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
}
@Override
public void setContactId(Transaction txn, GroupId contactGroupId,
ContactId c) throws DbException {
BdfDictionary meta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, c.getInt()));
try {
mergeGroupMetadata(txn, contactGroupId, meta);
} catch (FormatException e) {
throw new AssertionError(e);
}
}
} }

View File

@@ -5,6 +5,5 @@ interface ClientVersioningConstants {
// Metadata keys // Metadata keys
String MSG_KEY_UPDATE_VERSION = "version"; String MSG_KEY_UPDATE_VERSION = "version";
String MSG_KEY_LOCAL = "local"; String MSG_KEY_LOCAL = "local";
String GROUP_KEY_CONTACT_ID = "contactId";
} }

View File

@@ -50,7 +50,6 @@ import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE; 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.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;
@@ -161,13 +160,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
db.addGroup(txn, g); db.addGroup(txn, g);
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED); db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
// Attach the contact ID to the group // Attach the contact ID to the group
BdfDictionary meta = new BdfDictionary(); clientHelper.setContactId(txn, g.getId(), c.getId());
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
try {
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
} catch (FormatException e) {
throw new AssertionError(e);
}
// Create and store the first local update // Create and store the first local update
List<ClientVersion> versions = new ArrayList<>(clients); List<ClientVersion> versions = new ArrayList<>(clients);
Collections.sort(versions); Collections.sort(versions);
@@ -229,7 +222,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
Map<ClientMajorVersion, Visibility> after = Map<ClientMajorVersion, Visibility> after =
getVisibilities(newLocalStates, newRemoteStates); getVisibilities(newLocalStates, newRemoteStates);
// Call hooks for any visibilities that have changed // Call hooks for any visibilities that have changed
ContactId c = getContactId(txn, m.getGroupId()); ContactId c = clientHelper.getContactId(txn, m.getGroupId());
if (!before.equals(after)) { if (!before.equals(after)) {
Contact contact = db.getContact(txn, c); Contact contact = db.getContact(txn, c);
callVisibilityHooks(txn, contact, before, after); callVisibilityHooks(txn, contact, before, after);
@@ -521,17 +514,6 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
storeUpdate(txn, g, states, 1); storeUpdate(txn, g, states, 1);
} }
private ContactId getContactId(Transaction txn, GroupId g)
throws DbException {
try {
BdfDictionary meta =
clientHelper.getGroupMetadataAsDictionary(txn, g);
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
} catch (FormatException e) {
throw new DbException(e);
}
}
private List<ClientState> updateStatesFromRemoteStates( private List<ClientState> updateStatesFromRemoteStates(
List<ClientState> oldLocalStates, List<ClientState> remoteStates) { List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
Set<ClientMajorVersion> remoteSet = new HashSet<>(); Set<ClientMajorVersion> remoteSet = new HashSet<>();

View File

@@ -38,7 +38,6 @@ 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.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
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;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -60,8 +59,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
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);
private final BdfDictionary groupMeta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
private ClientVersioningManagerImpl createInstance() { private ClientVersioningManagerImpl createInstance() {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -123,8 +120,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
oneOf(db).addGroup(txn, contactGroup); oneOf(db).addGroup(txn, contactGroup);
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroup.getId(), SHARED);
oneOf(clientHelper).mergeGroupMetadata(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
groupMeta); contact.getId());
oneOf(clock).currentTimeMillis(); oneOf(clock).currentTimeMillis();
will(returnValue(now)); will(returnValue(now));
oneOf(clientHelper).createMessage(contactGroup.getId(), now, oneOf(clientHelper).createMessage(contactGroup.getId(), now,
@@ -460,9 +457,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
oneOf(db).deleteMessage(txn, oldRemoteUpdateId); oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId); oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
// Get contact ID // Get contact ID
oneOf(clientHelper).getGroupMetadataAsDictionary(txn, oneOf(clientHelper).getContactId(txn, contactGroup.getId());
contactGroup.getId()); will(returnValue(contact.getId()));
will(returnValue(groupMeta));
// No states or visibilities have changed // No states or visibilities have changed
}}); }});
@@ -492,10 +488,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
// Load the latest local update // Load the latest local update
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId); oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
will(returnValue(oldLocalUpdateBody)); will(returnValue(oldLocalUpdateBody));
// Get client ID // Get contact ID
oneOf(clientHelper).getGroupMetadataAsDictionary(txn, oneOf(clientHelper).getContactId(txn, contactGroup.getId());
contactGroup.getId()); will(returnValue(contact.getId()));
will(returnValue(groupMeta));
// No states or visibilities have changed // No states or visibilities have changed
}}); }});
@@ -546,8 +541,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
BdfDictionary newLocalUpdateMeta = BdfDictionary.of( BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L), new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
new BdfEntry(MSG_KEY_LOCAL, true)); new BdfEntry(MSG_KEY_LOCAL, true));
BdfDictionary groupMeta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).toList(newRemoteUpdate); oneOf(clientHelper).toList(newRemoteUpdate);
@@ -577,9 +570,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate, oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
newLocalUpdateMeta, true, false); newLocalUpdateMeta, true, false);
// The client's visibility has changed // The client's visibility has changed
oneOf(clientHelper).getGroupMetadataAsDictionary(txn, oneOf(clientHelper).getContactId(txn, contactGroup.getId());
contactGroup.getId()); will(returnValue(contact.getId()));
will(returnValue(groupMeta));
oneOf(db).getContact(txn, contact.getId()); oneOf(db).getContact(txn, contact.getId());
will(returnValue(contact)); will(returnValue(contact));
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility); oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
@@ -619,8 +611,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
BdfDictionary newLocalUpdateMeta = BdfDictionary.of( BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L), new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
new BdfEntry(MSG_KEY_LOCAL, true)); new BdfEntry(MSG_KEY_LOCAL, true));
BdfDictionary groupMeta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).toList(newRemoteUpdate); oneOf(clientHelper).toList(newRemoteUpdate);
@@ -650,9 +640,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate, oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
newLocalUpdateMeta, true, false); newLocalUpdateMeta, true, false);
// The client's visibility has changed // The client's visibility has changed
oneOf(clientHelper).getGroupMetadataAsDictionary(txn, oneOf(clientHelper).getContactId(txn, contactGroup.getId());
contactGroup.getId()); will(returnValue(contact.getId()));
will(returnValue(groupMeta));
oneOf(db).getContact(txn, contact.getId()); oneOf(db).getContact(txn, contact.getId());
will(returnValue(contact)); will(returnValue(contact));
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE); oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);

View File

@@ -36,7 +36,6 @@ import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER; import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID; import static org.briarproject.briar.api.introduction.IntroductionManager.CLIENT_ID;
import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION; import static org.briarproject.briar.api.introduction.IntroductionManager.MAJOR_VERSION;
import static org.briarproject.briar.introduction.IntroductionConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.introduction.MessageType.ABORT; import static org.briarproject.briar.introduction.MessageType.ABORT;
import static org.briarproject.briar.introduction.MessageType.ACCEPT; import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE; import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
@@ -237,10 +236,7 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId) boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
throws DbException { throws DbException {
try { try {
BdfDictionary meta = clientHelper ContactId c = clientHelper.getContactId(txn, contactGroupId);
.getGroupMetadataAsDictionary(txn, contactGroupId);
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
ContactId c = new ContactId(contactId);
int minorVersion = clientVersioningManager int minorVersion = clientVersioningManager
.getClientMinorVersion(txn, c, CLIENT_ID, MAJOR_VERSION); .getClientMinorVersion(txn, c, CLIENT_ID, MAJOR_VERSION);
// Auto-delete was added in client version 0.1 // Auto-delete was added in client version 0.1

View File

@@ -2,9 +2,6 @@ package org.briarproject.briar.introduction;
interface IntroductionConstants { interface IntroductionConstants {
// Group metadata keys
String GROUP_KEY_CONTACT_ID = "contactId";
// Message metadata keys // Message metadata keys
String MSG_KEY_MESSAGE_TYPE = "messageType"; String MSG_KEY_MESSAGE_TYPE = "messageType";
String MSG_KEY_SESSION_ID = "sessionId"; String MSG_KEY_SESSION_ID = "sessionId";

View File

@@ -59,7 +59,6 @@ import static org.briarproject.briar.introduction.IntroduceeState.REMOTE_DECLINE
import static org.briarproject.briar.introduction.IntroducerState.A_DECLINED; import static org.briarproject.briar.introduction.IntroducerState.A_DECLINED;
import static org.briarproject.briar.introduction.IntroducerState.B_DECLINED; import static org.briarproject.briar.introduction.IntroducerState.B_DECLINED;
import static org.briarproject.briar.introduction.IntroducerState.START; import static org.briarproject.briar.introduction.IntroducerState.START;
import static org.briarproject.briar.introduction.IntroductionConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.introduction.MessageType.ABORT; import static org.briarproject.briar.introduction.MessageType.ABORT;
import static org.briarproject.briar.introduction.MessageType.ACCEPT; import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE; import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
@@ -136,13 +135,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
c.getId(), CLIENT_ID, MAJOR_VERSION); c.getId(), CLIENT_ID, MAJOR_VERSION);
db.setGroupVisibility(txn, c.getId(), g.getId(), client); db.setGroupVisibility(txn, c.getId(), g.getId(), client);
// Attach the contact ID to the group // Attach the contact ID to the group
BdfDictionary meta = new BdfDictionary(); clientHelper.setContactId(txn, g.getId(), c.getId());
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
try {
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
} catch (FormatException e) {
throw new AssertionError(e);
}
} }
@Override @Override
@@ -183,7 +176,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} }
StoredSession ss = getSession(txn, sessionId); StoredSession ss = getSession(txn, sessionId);
// Handle the message // Handle the message
Session session; Session<?> session;
MessageId storageId; MessageId storageId;
if (ss == null) { if (ss == null) {
if (meta.getMessageType() != REQUEST) throw new FormatException(); if (meta.getMessageType() != REQUEST) throw new FormatException();
@@ -211,7 +204,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
private IntroduceeSession createNewIntroduceeSession(Transaction txn, private IntroduceeSession createNewIntroduceeSession(Transaction txn,
Message m, BdfList body) throws DbException, FormatException { Message m, BdfList body) throws DbException, FormatException {
ContactId introducerId = getContactId(txn, m.getGroupId()); ContactId introducerId = clientHelper.getContactId(txn, m.getGroupId());
Author introducer = db.getContact(txn, introducerId).getAuthor(); Author introducer = db.getContact(txn, introducerId).getAuthor();
Author local = identityManager.getLocalAuthor(txn); Author local = identityManager.getLocalAuthor(txn);
Author remote = messageParser.parseRequestMessage(m, body).getAuthor(); Author remote = messageParser.parseRequestMessage(m, body).getAuthor();
@@ -223,7 +216,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
remote); remote);
} }
private <S extends Session> S handleMessage(Transaction txn, Message m, private <S extends Session<?>> S handleMessage(Transaction txn, Message m,
BdfList body, MessageType type, S session, ProtocolEngine<S> engine) BdfList body, MessageType type, S session, ProtocolEngine<S> engine)
throws DbException, FormatException { throws DbException, FormatException {
if (type == REQUEST) { if (type == REQUEST) {
@@ -263,13 +256,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
results.values().iterator().next()); results.values().iterator().next());
} }
private ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException, FormatException {
BdfDictionary meta =
clientHelper.getGroupMetadataAsDictionary(txn, contactGroupId);
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
}
private MessageId createStorageId(Transaction txn) throws DbException { private MessageId createStorageId(Transaction txn) throws DbException {
Message m = clientHelper Message m = clientHelper
.createMessageForStoringMetadata(localGroup.getId()); .createMessageForStoringMetadata(localGroup.getId());
@@ -278,7 +264,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} }
private void storeSession(Transaction txn, MessageId storageId, private void storeSession(Transaction txn, MessageId storageId,
Session session) throws DbException { Session<?> session) throws DbException {
BdfDictionary d; BdfDictionary d;
if (session.getRole() == INTRODUCER) { if (session.getRole() == INTRODUCER) {
d = sessionEncoder d = sessionEncoder
@@ -666,7 +652,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
try { try {
StoredSession ss = getSession(txn, sessionId); StoredSession ss = getSession(txn, sessionId);
if (ss == null) throw new AssertionError(); if (ss == null) throw new AssertionError();
Session s; Session<?> s;
Role role = sessionParser.getRole(ss.bdfSession); Role role = sessionParser.getRole(ss.bdfSession);
if (role == INTRODUCER) { if (role == INTRODUCER) {
s = sessionParser.parseIntroducerSession(ss.bdfSession); s = sessionParser.parseIntroducerSession(ss.bdfSession);

View File

@@ -2,9 +2,6 @@ package org.briarproject.briar.messaging;
interface MessagingConstants { interface MessagingConstants {
// Metadata keys for groups
String GROUP_KEY_CONTACT_ID = "contactId";
// Metadata keys for messages // Metadata keys for messages
String MSG_KEY_TIMESTAMP = "timestamp"; String MSG_KEY_TIMESTAMP = "timestamp";
String MSG_KEY_LOCAL = "local"; String MSG_KEY_LOCAL = "local";

View File

@@ -68,7 +68,6 @@ import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONL
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ; import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT; import static org.briarproject.briar.messaging.MessageTypes.ATTACHMENT;
import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE; import static org.briarproject.briar.messaging.MessageTypes.PRIVATE_MESSAGE;
import static org.briarproject.briar.messaging.MessagingConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_ATTACHMENT_HEADERS; import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_ATTACHMENT_HEADERS;
import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_AUTO_DELETE_TIMER; import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_AUTO_DELETE_TIMER;
import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_CONTENT_TYPE; import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_CONTENT_TYPE;
@@ -139,13 +138,7 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
c.getId(), CLIENT_ID, MAJOR_VERSION); c.getId(), CLIENT_ID, MAJOR_VERSION);
db.setGroupVisibility(txn, c.getId(), g.getId(), client); db.setGroupVisibility(txn, c.getId(), g.getId(), client);
// Attach the contact ID to the group // Attach the contact ID to the group
BdfDictionary d = new BdfDictionary(); clientHelper.setContactId(txn, g.getId(), c.getId());
d.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
try {
clientHelper.mergeGroupMetadata(txn, g.getId(), d);
} catch (FormatException e) {
throw new AssertionError(e);
}
// Initialize the group count with current time // Initialize the group count with current time
messageTracker.initializeGroupCount(txn, g.getId()); messageTracker.initializeGroupCount(txn, g.getId());
} }

View File

@@ -31,7 +31,6 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER; import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT; import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE; import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN; import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
@@ -76,13 +75,6 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
this.clock = clock; this.clock = clock;
} }
ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException, FormatException {
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn,
contactGroupId);
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
}
boolean isSubscribedPrivateGroup(Transaction txn, GroupId g) boolean isSubscribedPrivateGroup(Transaction txn, GroupId g)
throws DbException { throws DbException {
if (!db.containsGroup(txn, g)) return false; if (!db.containsGroup(txn, g)) return false;
@@ -100,7 +92,8 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
void setPrivateGroupVisibility(Transaction txn, S session, void setPrivateGroupVisibility(Transaction txn, S session,
Visibility preferred) throws DbException, FormatException { Visibility preferred) throws DbException, FormatException {
// Apply min of preferred visibility and client's visibility // Apply min of preferred visibility and client's visibility
ContactId contactId = getContactId(txn, session.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, session.getContactGroupId());
Visibility client = clientVersioningManager.getClientVisibility(txn, Visibility client = clientVersioningManager.getClientVisibility(txn,
contactId, PrivateGroupManager.CLIENT_ID, contactId, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION); PrivateGroupManager.MAJOR_VERSION);
@@ -273,10 +266,7 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId) boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
throws DbException { throws DbException {
try { try {
BdfDictionary meta = clientHelper ContactId c = clientHelper.getContactId(txn, contactGroupId);
.getGroupMetadataAsDictionary(txn, contactGroupId);
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
ContactId c = new ContactId(contactId);
int minorVersion = clientVersioningManager int minorVersion = clientVersioningManager
.getClientMinorVersion(txn, c, .getClientMinorVersion(txn, c,
GroupInvitationManager.CLIENT_ID, GroupInvitationManager.CLIENT_ID,

View File

@@ -191,7 +191,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
// Share the private group with the contact // Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED); setPrivateGroupVisibility(txn, s, SHARED);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent( txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, true), contactId)); createInvitationResponse(m, true), contactId));
// Move to the JOINED state // Move to the JOINED state
@@ -213,7 +214,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent( txn.attach(new GroupInvitationResponseReceivedEvent(
createInvitationResponse(m, false), contactId)); createInvitationResponse(m, false), contactId));
// Move to the START state // Move to the START state

View File

@@ -2,9 +2,6 @@ package org.briarproject.briar.privategroup.invitation;
interface GroupInvitationConstants { interface GroupInvitationConstants {
// Group metadata keys
String GROUP_KEY_CONTACT_ID = "contactId";
// Message metadata keys // Message metadata keys
String MSG_KEY_MESSAGE_TYPE = "messageType"; String MSG_KEY_MESSAGE_TYPE = "messageType";
String MSG_KEY_PRIVATE_GROUP_ID = "privateGroupId"; String MSG_KEY_PRIVATE_GROUP_ID = "privateGroupId";

View File

@@ -53,7 +53,6 @@ import javax.inject.Inject;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.briar.privategroup.invitation.CreatorState.START; import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT; import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE; import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN; import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
@@ -123,13 +122,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
c.getId(), CLIENT_ID, MAJOR_VERSION); c.getId(), CLIENT_ID, MAJOR_VERSION);
db.setGroupVisibility(txn, c.getId(), g.getId(), client); db.setGroupVisibility(txn, c.getId(), g.getId(), client);
// Attach the contact ID to the group // Attach the contact ID to the group
BdfDictionary meta = new BdfDictionary(); clientHelper.setContactId(txn, g.getId(), c.getId());
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
try {
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
} catch (FormatException e) {
throw new AssertionError(e);
}
// If the contact belongs to any private groups, create a peer session // If the contact belongs to any private groups, create a peer session
for (Group pg : db.getGroups(txn, PrivateGroupManager.CLIENT_ID, for (Group pg : db.getGroups(txn, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION)) { PrivateGroupManager.MAJOR_VERSION)) {
@@ -189,7 +182,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
results.values().iterator().next()); results.values().iterator().next());
} }
private Session<?> handleFirstMessage(Transaction txn, Message m, BdfList body, private Session<?> handleFirstMessage(Transaction txn, Message m,
BdfList body,
MessageMetadata meta) throws DbException, FormatException { MessageMetadata meta) throws DbException, FormatException {
GroupId privateGroupId = meta.getPrivateGroupId(); GroupId privateGroupId = meta.getPrivateGroupId();
MessageType type = meta.getMessageType(); MessageType type = meta.getMessageType();

View File

@@ -230,7 +230,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
// The timestamp must be higher than the last invite message, if any // The timestamp must be higher than the last invite message, if any
if (m.getTimestamp() <= s.getInviteTimestamp()) return abort(txn, s); if (m.getTimestamp() <= s.getInviteTimestamp()) return abort(txn, s);
// Check that the contact is the creator // Check that the contact is the creator
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId());
Author contact = db.getContact(txn, contactId).getAuthor(); Author contact = db.getContact(txn, contactId).getAuthor();
if (!contact.getId().equals(m.getCreator().getId())) if (!contact.getId().equals(m.getCreator().getId()))
return abort(txn, s); return abort(txn, s);

View File

@@ -355,7 +355,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
private void relationshipRevealed(Transaction txn, PeerSession s, private void relationshipRevealed(Transaction txn, PeerSession s,
boolean byContact) throws DbException, FormatException { boolean byContact) throws DbException, FormatException {
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId());
Contact contact = db.getContact(txn, contactId); Contact contact = db.getContact(txn, contactId);
privateGroupManager.relationshipRevealed(txn, s.getPrivateGroupId(), privateGroupManager.relationshipRevealed(txn, s.getPrivateGroupId(),
contact.getAuthor().getId(), byContact); contact.getAuthor().getId(), byContact);

View File

@@ -37,7 +37,6 @@ import static org.briarproject.briar.sharing.MessageType.ACCEPT;
import static org.briarproject.briar.sharing.MessageType.DECLINE; import static org.briarproject.briar.sharing.MessageType.DECLINE;
import static org.briarproject.briar.sharing.MessageType.INVITE; import static org.briarproject.briar.sharing.MessageType.INVITE;
import static org.briarproject.briar.sharing.MessageType.LEAVE; import static org.briarproject.briar.sharing.MessageType.LEAVE;
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.sharing.State.LOCAL_INVITED; import static org.briarproject.briar.sharing.State.LOCAL_INVITED;
import static org.briarproject.briar.sharing.State.LOCAL_LEFT; import static org.briarproject.briar.sharing.State.LOCAL_LEFT;
import static org.briarproject.briar.sharing.State.REMOTE_HANGING; import static org.briarproject.briar.sharing.State.REMOTE_HANGING;
@@ -341,7 +340,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId());
txn.attach(getInvitationRequestReceivedEvent(m, contactId, available, txn.attach(getInvitationRequestReceivedEvent(m, contactId, available,
false)); false));
// Move to the next state // Move to the next state
@@ -367,7 +367,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
// Share the shareable with the contact // Share the shareable with the contact
setShareableVisibility(txn, s, SHARED); setShareableVisibility(txn, s, SHARED);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId());
txn.attach( txn.attach(
getInvitationRequestReceivedEvent(m, contactId, false, true)); getInvitationRequestReceivedEvent(m, contactId, false, true));
// Move to the next state // Move to the next state
@@ -411,7 +412,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId());
txn.attach(getInvitationResponseReceivedEvent(m, contactId)); txn.attach(getInvitationResponseReceivedEvent(m, contactId));
// Move to the next state // Move to the next state
return new Session(nextState, s.getContactGroupId(), s.getShareableId(), return new Session(nextState, s.getContactGroupId(), s.getShareableId(),
@@ -469,7 +471,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
throw new DbException(e); // Invalid group metadata throw new DbException(e); // Invalid group metadata
} }
// Broadcast an event // Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId());
txn.attach(getInvitationResponseReceivedEvent(m, contactId)); txn.attach(getInvitationResponseReceivedEvent(m, contactId));
// Move to the next state // Move to the next state
return new Session(START, s.getContactGroupId(), s.getShareableId(), return new Session(START, s.getContactGroupId(), s.getShareableId(),
@@ -529,7 +532,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
if (isInvalidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abortWithMessage(txn, s); return abortWithMessage(txn, s);
// Broadcast event informing that contact left // Broadcast event informing that contact left
ContactId contactId = getContactId(txn, s.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId());
ContactLeftShareableEvent e = new ContactLeftShareableEvent( ContactLeftShareableEvent e = new ContactLeftShareableEvent(
s.getShareableId(), contactId); s.getShareableId(), contactId);
txn.attach(e); txn.attach(e);
@@ -648,20 +652,14 @@ abstract class ProtocolEngineImpl<S extends Shareable>
private void setShareableVisibility(Transaction txn, Session session, private void setShareableVisibility(Transaction txn, Session session,
Visibility preferred) throws DbException, FormatException { Visibility preferred) throws DbException, FormatException {
// Apply min of preferred visibility and client's visibility // Apply min of preferred visibility and client's visibility
ContactId contactId = getContactId(txn, session.getContactGroupId()); ContactId contactId =
clientHelper.getContactId(txn, session.getContactGroupId());
Visibility client = clientVersioningManager.getClientVisibility(txn, Visibility client = clientVersioningManager.getClientVisibility(txn,
contactId, shareableClientId, shareableClientMajorVersion); contactId, shareableClientId, shareableClientMajorVersion);
Visibility min = Visibility.min(preferred, client); Visibility min = Visibility.min(preferred, client);
db.setGroupVisibility(txn, contactId, session.getShareableId(), min); db.setGroupVisibility(txn, contactId, session.getShareableId(), min);
} }
private ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException, FormatException {
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn,
contactGroupId);
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
}
private boolean isInvalidDependency(Session session, private boolean isInvalidDependency(Session session,
@Nullable MessageId dependency) { @Nullable MessageId dependency) {
MessageId expected = session.getLastRemoteMessageId(); MessageId expected = session.getLastRemoteMessageId();
@@ -678,10 +676,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId) boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
throws DbException { throws DbException {
try { try {
BdfDictionary meta = clientHelper ContactId c = clientHelper.getContactId(txn, contactGroupId);
.getGroupMetadataAsDictionary(txn, contactGroupId);
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
ContactId c = new ContactId(contactId);
int minorVersion = clientVersioningManager int minorVersion = clientVersioningManager
.getClientMinorVersion(txn, c, sharingClientId, .getClientMinorVersion(txn, c, sharingClientId,
sharingClientMajorVersion); sharingClientMajorVersion);

View File

@@ -4,9 +4,6 @@ import org.briarproject.briar.client.MessageTrackerConstants;
interface SharingConstants { interface SharingConstants {
// Group metadata keys
String GROUP_KEY_CONTACT_ID = "contactId";
// Message metadata keys // Message metadata keys
String MSG_KEY_MESSAGE_TYPE = "messageType"; String MSG_KEY_MESSAGE_TYPE = "messageType";
String MSG_KEY_SHAREABLE_ID = "shareableId"; String MSG_KEY_SHAREABLE_ID = "shareableId";

View File

@@ -52,7 +52,6 @@ import static org.briarproject.briar.sharing.MessageType.ACCEPT;
import static org.briarproject.briar.sharing.MessageType.DECLINE; import static org.briarproject.briar.sharing.MessageType.DECLINE;
import static org.briarproject.briar.sharing.MessageType.INVITE; import static org.briarproject.briar.sharing.MessageType.INVITE;
import static org.briarproject.briar.sharing.MessageType.LEAVE; import static org.briarproject.briar.sharing.MessageType.LEAVE;
import static org.briarproject.briar.sharing.SharingConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.sharing.State.SHARING; import static org.briarproject.briar.sharing.State.SHARING;
@NotNullByDefault @NotNullByDefault
@@ -114,13 +113,7 @@ abstract class SharingManagerImpl<S extends Shareable>
c.getId(), getClientId(), getMajorVersion()); c.getId(), getClientId(), getMajorVersion());
db.setGroupVisibility(txn, c.getId(), g.getId(), client); db.setGroupVisibility(txn, c.getId(), g.getId(), client);
// Attach the contact ID to the group // Attach the contact ID to the group
BdfDictionary meta = new BdfDictionary(); clientHelper.setContactId(txn, g.getId(), c.getId());
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
try {
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
} catch (FormatException e) {
throw new AssertionError(e);
}
} }
@Override @Override

View File

@@ -37,7 +37,6 @@ import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROUP_SALT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT; import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE; import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN; import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
@@ -81,8 +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;
final BdfDictionary groupMeta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
final InviteMessage inviteMessage = final InviteMessage inviteMessage =
new InviteMessage(new MessageId(getRandomId()), contactGroupId, new InviteMessage(new MessageId(getRandomId()), contactGroupId,
@@ -196,12 +193,9 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
} }
void expectGetContactId() throws Exception { void expectGetContactId() throws Exception {
BdfDictionary groupMeta = BdfDictionary
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper) oneOf(clientHelper).getContactId(txn, contactGroupId);
.getGroupMetadataAsDictionary(txn, contactGroupId); will(returnValue(contactId));
will(returnValue(groupMeta));
}}); }});
} }
@@ -231,9 +225,8 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
void expectCheckWhetherContactSupportsAutoDeletion() throws Exception { void expectCheckWhetherContactSupportsAutoDeletion() throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).getGroupMetadataAsDictionary(txn, oneOf(clientHelper).getContactId(txn, contactGroupId);
contactGroupId); will(returnValue(contactId));
will(returnValue(groupMeta));
oneOf(clientVersioningManager).getClientMinorVersion(txn, contactId, oneOf(clientVersioningManager).getClientMinorVersion(txn, contactId,
GroupInvitationManager.CLIENT_ID, GroupInvitationManager.CLIENT_ID,
GroupInvitationManager.MAJOR_VERSION); GroupInvitationManager.MAJOR_VERSION);

View File

@@ -58,7 +58,6 @@ import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.GROU
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID; import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.MAJOR_VERSION; import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.MAJOR_VERSION;
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT; import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE; import static org.briarproject.briar.privategroup.invitation.MessageType.INVITE;
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN; import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
@@ -178,9 +177,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
} }
private void expectAddingContact(Contact c) throws Exception { private void expectAddingContact(Contact c) throws Exception {
BdfDictionary meta = BdfDictionary
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, c); MAJOR_VERSION, c);
@@ -192,7 +188,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(db).setGroupVisibility(txn, c.getId(), contactGroup.getId(), oneOf(db).setGroupVisibility(txn, c.getId(), contactGroup.getId(),
SHARED); SHARED);
oneOf(clientHelper) oneOf(clientHelper)
.mergeGroupMetadata(txn, contactGroup.getId(), meta); .setContactId(txn, contactGroup.getId(), contactId);
oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID, oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION); PrivateGroupManager.MAJOR_VERSION);
will(returnValue(Collections.singletonList(privateGroup))); will(returnValue(Collections.singletonList(privateGroup)));

View File

@@ -5,7 +5,6 @@ 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.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.MetadataParser; 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.DbException; import org.briarproject.bramble.api.db.DbException;
@@ -41,7 +40,6 @@ 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.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;
public class BlogSharingManagerImplTest extends BrambleMockTestCase { public class BlogSharingManagerImplTest extends BrambleMockTestCase {
@@ -117,8 +115,6 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
} }
private void expectAddingContact(Transaction txn) throws Exception { private void expectAddingContact(Transaction txn) throws Exception {
BdfDictionary meta = BdfDictionary.of(
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
Map<MessageId, BdfDictionary> sessions = Collections.emptyMap(); Map<MessageId, BdfDictionary> sessions = Collections.emptyMap();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -134,7 +130,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
SHARED); SHARED);
// Attach the contact ID to the group // Attach the contact ID to the group
oneOf(clientHelper) oneOf(clientHelper)
.mergeGroupMetadata(txn, contactGroup.getId(), meta); .setContactId(txn, contactGroup.getId(), contactId);
// Get our blog and the contact's blog // Get our blog and the contact's blog
oneOf(identityManager).getLocalAuthor(txn); oneOf(identityManager).getLocalAuthor(txn);
will(returnValue(localAuthor)); will(returnValue(localAuthor));