mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Factor out methods for storing and retrieving contact ID.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.bramble.api.client;
|
||||
|
||||
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.PublicKey;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
@@ -119,4 +120,17 @@ public interface ClientHelper {
|
||||
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
@@ -2,11 +2,13 @@ package org.briarproject.bramble.client;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
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.KeyParser;
|
||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||
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.BdfReader;
|
||||
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
||||
@@ -39,6 +41,7 @@ import java.util.Map.Entry;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
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.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
@@ -389,4 +392,27 @@ class ClientHelperImpl implements ClientHelper {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,5 @@ interface ClientVersioningConstants {
|
||||
// Metadata keys
|
||||
String MSG_KEY_UPDATE_VERSION = "version";
|
||||
String MSG_KEY_LOCAL = "local";
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
}
|
||||
|
||||
|
||||
@@ -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.SHARED;
|
||||
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_UPDATE_VERSION;
|
||||
|
||||
@@ -161,13 +160,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
db.addGroup(txn, g);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
// Create and store the first local update
|
||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||
Collections.sort(versions);
|
||||
@@ -229,7 +222,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
Map<ClientMajorVersion, Visibility> after =
|
||||
getVisibilities(newLocalStates, newRemoteStates);
|
||||
// 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)) {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
callVisibilityHooks(txn, contact, before, after);
|
||||
@@ -521,17 +514,6 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
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(
|
||||
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
||||
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
||||
|
||||
@@ -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.getMessage;
|
||||
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_UPDATE_VERSION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -60,8 +59,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
private final ClientId clientId = getClientId();
|
||||
private final long now = System.currentTimeMillis();
|
||||
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() {
|
||||
context.checking(new Expectations() {{
|
||||
@@ -123,8 +120,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
contactGroup.getId(), SHARED);
|
||||
oneOf(clientHelper).mergeGroupMetadata(txn, contactGroup.getId(),
|
||||
groupMeta);
|
||||
oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
|
||||
contact.getId());
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
||||
@@ -460,9 +457,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
||||
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
||||
// Get contact ID
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
// No states or visibilities have changed
|
||||
}});
|
||||
|
||||
@@ -492,10 +488,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
// Load the latest local update
|
||||
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
||||
will(returnValue(oldLocalUpdateBody));
|
||||
// Get client ID
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
// Get contact ID
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
// No states or visibilities have changed
|
||||
}});
|
||||
|
||||
@@ -546,8 +541,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||
BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||
@@ -577,9 +570,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||
newLocalUpdateMeta, true, false);
|
||||
// The client's visibility has changed
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
||||
@@ -619,8 +611,6 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||
BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||
@@ -650,9 +640,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||
newLocalUpdateMeta, true, false);
|
||||
// The client's visibility has changed
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||
will(returnValue(contact.getId()));
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
||||
|
||||
@@ -37,7 +37,6 @@ import javax.annotation.concurrent.Immutable;
|
||||
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.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.ACCEPT;
|
||||
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
|
||||
@@ -241,10 +240,7 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta = clientHelper
|
||||
.getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
|
||||
ContactId c = new ContactId(contactId);
|
||||
ContactId c = clientHelper.getContactId(txn, contactGroupId);
|
||||
int minorVersion = clientVersioningManager
|
||||
.getClientMinorVersion(txn, c, CLIENT_ID, MAJOR_VERSION);
|
||||
// Auto-delete was added in client version 0.1
|
||||
|
||||
@@ -2,9 +2,6 @@ package org.briarproject.briar.introduction;
|
||||
|
||||
interface IntroductionConstants {
|
||||
|
||||
// Group metadata keys
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
|
||||
// Message metadata keys
|
||||
String MSG_KEY_MESSAGE_TYPE = "messageType";
|
||||
String MSG_KEY_SESSION_ID = "sessionId";
|
||||
|
||||
@@ -60,7 +60,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.B_DECLINED;
|
||||
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.ACCEPT;
|
||||
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
|
||||
@@ -140,13 +139,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,7 +180,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
// Handle the message
|
||||
Session session;
|
||||
Session<?> session;
|
||||
MessageId storageId;
|
||||
if (ss == null) {
|
||||
if (meta.getMessageType() != REQUEST) throw new FormatException();
|
||||
@@ -215,7 +208,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
|
||||
private IntroduceeSession createNewIntroduceeSession(Transaction txn,
|
||||
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 local = identityManager.getLocalAuthor(txn);
|
||||
Author remote = messageParser.parseRequestMessage(m, body).getAuthor();
|
||||
@@ -227,7 +220,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
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)
|
||||
throws DbException, FormatException {
|
||||
if (type == REQUEST) {
|
||||
@@ -267,13 +260,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
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 {
|
||||
Message m = clientHelper
|
||||
.createMessageForStoringMetadata(localGroup.getId());
|
||||
@@ -282,7 +268,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
private void storeSession(Transaction txn, MessageId storageId,
|
||||
Session session) throws DbException {
|
||||
Session<?> session) throws DbException {
|
||||
BdfDictionary d;
|
||||
if (session.getRole() == INTRODUCER) {
|
||||
d = sessionEncoder
|
||||
@@ -670,7 +656,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
try {
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
if (ss == null) throw new AssertionError();
|
||||
Session s;
|
||||
Session<?> s;
|
||||
Role role = sessionParser.getRole(ss.bdfSession);
|
||||
if (role == INTRODUCER) {
|
||||
s = sessionParser.parseIntroducerSession(ss.bdfSession);
|
||||
|
||||
@@ -2,9 +2,6 @@ package org.briarproject.briar.messaging;
|
||||
|
||||
interface MessagingConstants {
|
||||
|
||||
// Metadata keys for groups
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
|
||||
// Metadata keys for messages
|
||||
String MSG_KEY_TIMESTAMP = "timestamp";
|
||||
String MSG_KEY_LOCAL = "local";
|
||||
|
||||
@@ -56,6 +56,7 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
||||
@@ -67,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.messaging.MessageTypes.ATTACHMENT;
|
||||
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_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.briar.messaging.MessagingConstants.MSG_KEY_HAS_TEXT;
|
||||
@@ -136,13 +136,7 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary d = new BdfDictionary();
|
||||
d.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), d);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
// Initialize the group count with current time
|
||||
messageTracker.initializeGroupCount(txn, g.getId());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
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.INVITE;
|
||||
import static org.briarproject.briar.privategroup.invitation.MessageType.JOIN;
|
||||
@@ -76,13 +75,6 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
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)
|
||||
throws DbException {
|
||||
if (!db.containsGroup(txn, g)) return false;
|
||||
@@ -100,7 +92,8 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
void setPrivateGroupVisibility(Transaction txn, S session,
|
||||
Visibility preferred) throws DbException, FormatException {
|
||||
// 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,
|
||||
contactId, PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
@@ -273,10 +266,7 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta = clientHelper
|
||||
.getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
|
||||
ContactId c = new ContactId(contactId);
|
||||
ContactId c = clientHelper.getContactId(txn, contactGroupId);
|
||||
int minorVersion = clientVersioningManager
|
||||
.getClientMinorVersion(txn, c,
|
||||
GroupInvitationManager.CLIENT_ID,
|
||||
|
||||
@@ -191,7 +191,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
// Share the private group with the contact
|
||||
setPrivateGroupVisibility(txn, s, SHARED);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, true), contactId));
|
||||
// Move to the JOINED state
|
||||
@@ -213,7 +214,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, false), contactId));
|
||||
// Move to the START state
|
||||
|
||||
@@ -2,9 +2,6 @@ package org.briarproject.briar.privategroup.invitation;
|
||||
|
||||
interface GroupInvitationConstants {
|
||||
|
||||
// Group metadata keys
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
|
||||
// Message metadata keys
|
||||
String MSG_KEY_MESSAGE_TYPE = "messageType";
|
||||
String MSG_KEY_PRIVATE_GROUP_ID = "privateGroupId";
|
||||
|
||||
@@ -53,7 +53,6 @@ import javax.inject.Inject;
|
||||
|
||||
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.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
|
||||
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.JOIN;
|
||||
@@ -123,13 +122,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
// If the contact belongs to any private groups, create a peer session
|
||||
for (Group pg : db.getGroups(txn, PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION)) {
|
||||
@@ -189,7 +182,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
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 {
|
||||
GroupId privateGroupId = meta.getPrivateGroupId();
|
||||
MessageType type = meta.getMessageType();
|
||||
|
||||
@@ -230,7 +230,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
// The timestamp must be higher than the last invite message, if any
|
||||
if (m.getTimestamp() <= s.getInviteTimestamp()) return abort(txn, s);
|
||||
// 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();
|
||||
if (!contact.getId().equals(m.getCreator().getId()))
|
||||
return abort(txn, s);
|
||||
|
||||
@@ -355,7 +355,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
|
||||
|
||||
private void relationshipRevealed(Transaction txn, PeerSession s,
|
||||
boolean byContact) throws DbException, FormatException {
|
||||
ContactId contactId = getContactId(txn, s.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, s.getContactGroupId());
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
privateGroupManager.relationshipRevealed(txn, s.getPrivateGroupId(),
|
||||
contact.getAuthor().getId(), byContact);
|
||||
|
||||
@@ -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.INVITE;
|
||||
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_LEFT;
|
||||
import static org.briarproject.briar.sharing.State.REMOTE_HANGING;
|
||||
@@ -341,7 +340,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, s.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, s.getContactGroupId());
|
||||
txn.attach(getInvitationRequestReceivedEvent(m, contactId, available,
|
||||
false));
|
||||
// Move to the next state
|
||||
@@ -367,7 +367,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
// Share the shareable with the contact
|
||||
setShareableVisibility(txn, s, SHARED);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, s.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, s.getContactGroupId());
|
||||
txn.attach(
|
||||
getInvitationRequestReceivedEvent(m, contactId, false, true));
|
||||
// Move to the next state
|
||||
@@ -411,7 +412,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId));
|
||||
// Move to the next state
|
||||
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
|
||||
}
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId));
|
||||
// Move to the next state
|
||||
return new Session(START, s.getContactGroupId(), s.getShareableId(),
|
||||
@@ -529,7 +532,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Broadcast event informing that contact left
|
||||
ContactId contactId = getContactId(txn, s.getContactGroupId());
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, s.getContactGroupId());
|
||||
ContactLeftShareableEvent e = new ContactLeftShareableEvent(
|
||||
s.getShareableId(), contactId);
|
||||
txn.attach(e);
|
||||
@@ -648,20 +652,14 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
private void setShareableVisibility(Transaction txn, Session session,
|
||||
Visibility preferred) throws DbException, FormatException {
|
||||
// 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,
|
||||
contactId, shareableClientId, shareableClientMajorVersion);
|
||||
Visibility min = Visibility.min(preferred, client);
|
||||
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,
|
||||
@Nullable MessageId dependency) {
|
||||
MessageId expected = session.getLastRemoteMessageId();
|
||||
@@ -678,10 +676,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
boolean contactSupportsAutoDeletion(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta = clientHelper
|
||||
.getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||
int contactId = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
|
||||
ContactId c = new ContactId(contactId);
|
||||
ContactId c = clientHelper.getContactId(txn, contactGroupId);
|
||||
int minorVersion = clientVersioningManager
|
||||
.getClientMinorVersion(txn, c, sharingClientId,
|
||||
sharingClientMajorVersion);
|
||||
|
||||
@@ -4,9 +4,6 @@ import org.briarproject.briar.client.MessageTrackerConstants;
|
||||
|
||||
interface SharingConstants {
|
||||
|
||||
// Group metadata keys
|
||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||
|
||||
// Message metadata keys
|
||||
String MSG_KEY_MESSAGE_TYPE = "messageType";
|
||||
String MSG_KEY_SHAREABLE_ID = "shareableId";
|
||||
|
||||
@@ -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.INVITE;
|
||||
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;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -114,13 +113,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
c.getId(), getClientId(), getMajorVersion());
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.MAX_GROUP_INVITATION_TEXT_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.INVITE;
|
||||
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 inviteTimestamp = messageTimestamp - 1;
|
||||
final long localTimestamp = inviteTimestamp - 1;
|
||||
final BdfDictionary groupMeta = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
|
||||
final InviteMessage inviteMessage =
|
||||
new InviteMessage(new MessageId(getRandomId()), contactGroupId,
|
||||
@@ -196,12 +193,9 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
void expectGetContactId() throws Exception {
|
||||
BdfDictionary groupMeta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, contactId.getInt()));
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper)
|
||||
.getGroupMetadataAsDictionary(txn, contactGroupId);
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(clientHelper).getContactId(txn, contactGroupId);
|
||||
will(returnValue(contactId));
|
||||
}});
|
||||
}
|
||||
|
||||
@@ -231,9 +225,8 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
|
||||
void expectCheckWhetherContactSupportsAutoDeletion() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||
contactGroupId);
|
||||
will(returnValue(groupMeta));
|
||||
oneOf(clientHelper).getContactId(txn, contactGroupId);
|
||||
will(returnValue(contactId));
|
||||
oneOf(clientVersioningManager).getClientMinorVersion(txn, contactId,
|
||||
GroupInvitationManager.CLIENT_ID,
|
||||
GroupInvitationManager.MAJOR_VERSION);
|
||||
|
||||
@@ -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.invitation.GroupInvitationManager.CLIENT_ID;
|
||||
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.INVITE;
|
||||
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 {
|
||||
BdfDictionary meta = BdfDictionary
|
||||
.of(new BdfEntry(GROUP_KEY_CONTACT_ID, c.getId().getInt()));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, c);
|
||||
@@ -192,7 +188,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).setGroupVisibility(txn, c.getId(), contactGroup.getId(),
|
||||
SHARED);
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, contactGroup.getId(), meta);
|
||||
.setContactId(txn, contactGroup.getId(), contactId);
|
||||
oneOf(db).getGroups(txn, PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
will(returnValue(Collections.singletonList(privateGroup)));
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.MetadataParser;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
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.briar.api.blog.BlogSharingManager.CLIENT_ID;
|
||||
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 {
|
||||
|
||||
@@ -117,8 +115,6 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -134,7 +130,7 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
SHARED);
|
||||
// Attach the contact ID to the group
|
||||
oneOf(clientHelper)
|
||||
.mergeGroupMetadata(txn, contactGroup.getId(), meta);
|
||||
.setContactId(txn, contactGroup.getId(), contactId);
|
||||
// Get our blog and the contact's blog
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
|
||||
Reference in New Issue
Block a user