Merge branch '804-self-destructing-messages-refactoring' into '804-self-destructing-messages'

Factor out some duplicated client code

See merge request briar/briar!1304
This commit is contained in:
akwizgran
2020-11-24 11:03:24 +00:00
28 changed files with 156 additions and 214 deletions

View File

@@ -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;
}

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

@@ -7,6 +7,10 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
@NotNullByDefault
public class ValidationUtils {
@@ -69,4 +73,11 @@ public class ValidationUtils {
throws FormatException {
if (l != null && (l < min || l > max)) throw new FormatException();
}
public static long validateAutoDeleteTimer(@Nullable Long timer)
throws FormatException {
if (timer == null) return NO_AUTO_DELETE_TIMER;
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS, MAX_AUTO_DELETE_TIMER_MS);
return timer;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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";
}

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.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<>();

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.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);

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.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;
@@ -237,10 +236,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

View File

@@ -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";

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.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;
@@ -136,13 +135,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
@@ -183,7 +176,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();
@@ -211,7 +204,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();
@@ -223,7 +216,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) {
@@ -263,13 +256,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());
@@ -278,7 +264,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
@@ -666,7 +652,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);

View File

@@ -15,19 +15,16 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.briar.api.client.SessionId;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAC_BYTES;
import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_SIGNATURE_BYTES;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkRange;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.bramble.util.ValidationUtils.validateAutoDeleteTimer;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.ACTIVATE;
@@ -88,7 +85,9 @@ class IntroductionValidator extends BdfMessageValidator {
checkLength(text, 1, MAX_INTRODUCTION_TEXT_LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 5) timer = validateTimer(body.getOptionalLong(4));
if (body.size() == 5) {
timer = validateAutoDeleteTimer(body.getOptionalLong(4));
}
BdfDictionary meta =
messageEncoder.encodeRequestMetadata(m.getTimestamp(), timer);
@@ -128,7 +127,9 @@ class IntroductionValidator extends BdfMessageValidator {
.parseAndValidateTransportPropertiesMap(transportProperties);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 7) timer = validateTimer(body.getOptionalLong(6));
if (body.size() == 7) {
timer = validateAutoDeleteTimer(body.getOptionalLong(6));
}
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder.encodeMetadata(ACCEPT, sessionId,
@@ -156,7 +157,9 @@ class IntroductionValidator extends BdfMessageValidator {
checkLength(previousMessageId, UniqueId.LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 4) timer = validateTimer(body.getOptionalLong(3));
if (body.size() == 4) {
timer = validateAutoDeleteTimer(body.getOptionalLong(3));
}
SessionId sessionId = new SessionId(sessionIdBytes);
BdfDictionary meta = messageEncoder.encodeMetadata(type, sessionId,
@@ -236,10 +239,4 @@ class IntroductionValidator extends BdfMessageValidator {
return new BdfMessageContext(meta, singletonList(dependency));
}
}
private long validateTimer(@Nullable Long timer) throws FormatException {
if (timer == null) return NO_AUTO_DELETE_TIMER;
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS, MAX_AUTO_DELETE_TIMER_MS);
return timer;
}
}

View File

@@ -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";

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.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_CONTENT_TYPE;
@@ -139,13 +138,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());
}

View File

@@ -23,13 +23,12 @@ import java.io.InputStream;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkRange;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.bramble.util.ValidationUtils.validateAutoDeleteTimer;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_BYTES;
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
@@ -136,11 +135,9 @@ class PrivateMessageValidator implements MessageValidator {
String contentType = header.getString(1);
checkLength(contentType, 1, MAX_CONTENT_TYPE_BYTES);
}
Long timer = null;
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 4) {
timer = body.getOptionalLong(3);
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS,
MAX_AUTO_DELETE_TIMER_MS);
timer = validateAutoDeleteTimer(body.getOptionalLong(3));
}
// Return the metadata
BdfDictionary meta = new BdfDictionary();
@@ -150,7 +147,9 @@ class PrivateMessageValidator implements MessageValidator {
meta.put(MSG_KEY_MSG_TYPE, PRIVATE_MESSAGE);
meta.put(MSG_KEY_HAS_TEXT, text != null);
meta.put(MSG_KEY_ATTACHMENT_HEADERS, headers);
if (timer != null) meta.put(MSG_KEY_AUTO_DELETE_TIMER, timer);
if (timer != NO_AUTO_DELETE_TIMER) {
meta.put(MSG_KEY_AUTO_DELETE_TIMER, timer);
}
return new BdfMessageContext(meta);
}

View File

@@ -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,

View File

@@ -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

View File

@@ -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";

View File

@@ -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,8 +182,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
results.values().iterator().next());
}
private Session<?> handleFirstMessage(Transaction txn, Message m, BdfList body,
MessageMetadata meta) throws DbException, FormatException {
private Session<?> handleFirstMessage(Transaction txn, Message m,
BdfList body, MessageMetadata meta)
throws DbException, FormatException {
GroupId privateGroupId = meta.getPrivateGroupId();
MessageType type = meta.getMessageType();
if (type == INVITE) {

View File

@@ -21,16 +21,13 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
import java.security.GeneralSecurityException;
import java.util.Collections;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkRange;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.bramble.util.ValidationUtils.validateAutoDeleteTimer;
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;
@@ -91,7 +88,9 @@ class GroupInvitationValidator extends BdfMessageValidator {
byte[] signature = body.getRaw(5);
checkLength(signature, 1, MAX_SIGNATURE_LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 7) timer = validateTimer(body.getOptionalLong(6));
if (body.size() == 7) {
timer = validateAutoDeleteTimer(body.getOptionalLong(6));
}
// Validate the creator and create the private group
Author creator = clientHelper.parseAndValidateAuthor(creatorList);
@@ -128,7 +127,9 @@ class GroupInvitationValidator extends BdfMessageValidator {
byte[] previousMessageId = body.getOptionalRaw(2);
checkLength(previousMessageId, UniqueId.LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 4) timer = validateTimer(body.getOptionalLong(3));
if (body.size() == 4) {
timer = validateAutoDeleteTimer(body.getOptionalLong(3));
}
BdfDictionary meta = messageEncoder.encodeMetadata(JOIN,
new GroupId(privateGroupId), m.getTimestamp(), false, false,
@@ -154,7 +155,9 @@ class GroupInvitationValidator extends BdfMessageValidator {
byte[] previousMessageId = body.getOptionalRaw(2);
checkLength(previousMessageId, UniqueId.LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 4) timer = validateTimer(body.getOptionalLong(3));
if (body.size() == 4) {
timer = validateAutoDeleteTimer(body.getOptionalLong(3));
}
BdfDictionary meta = messageEncoder.encodeMetadata(LEAVE,
new GroupId(privateGroupId), m.getTimestamp(), false, false,
@@ -178,10 +181,4 @@ class GroupInvitationValidator extends BdfMessageValidator {
false, false, false, NO_AUTO_DELETE_TIMER);
return new BdfMessageContext(meta);
}
private long validateTimer(@Nullable Long timer) throws FormatException {
if (timer == null) return NO_AUTO_DELETE_TIMER;
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS, MAX_AUTO_DELETE_TIMER_MS);
return timer;
}
}

View File

@@ -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);

View File

@@ -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);

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.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);

View File

@@ -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";

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.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

View File

@@ -15,16 +15,13 @@ import org.briarproject.bramble.api.sync.Message;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.api.system.Clock;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkRange;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.bramble.util.ValidationUtils.validateAutoDeleteTimer;
import static org.briarproject.briar.api.sharing.SharingConstants.MAX_INVITATION_TEXT_LENGTH;
import static org.briarproject.briar.sharing.MessageType.INVITE;
@@ -49,10 +46,10 @@ abstract class SharingValidator extends BdfMessageValidator {
return validateInviteMessage(m, body);
case ACCEPT:
case DECLINE:
return validateNonInviteMessageWithOptionalTimer(type, m, body);
return validateAcceptOrDeclineMessage(type, m, body);
case LEAVE:
case ABORT:
return validateNonInviteMessageWithoutTimer(type, m, body);
return validateLeaveOrAbortMessage(type, m, body);
default:
throw new FormatException();
}
@@ -72,7 +69,9 @@ abstract class SharingValidator extends BdfMessageValidator {
String text = body.getOptionalString(3);
checkLength(text, 1, MAX_INVITATION_TEXT_LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 5) timer = validateTimer(body.getOptionalLong(4));
if (body.size() == 5) {
timer = validateAutoDeleteTimer(body.getOptionalLong(4));
}
BdfDictionary meta = messageEncoder.encodeMetadata(INVITE, shareableId,
m.getTimestamp(), false, false, false, false, false, timer);
@@ -87,8 +86,8 @@ abstract class SharingValidator extends BdfMessageValidator {
protected abstract GroupId validateDescriptor(BdfList descriptor)
throws FormatException;
private BdfMessageContext validateNonInviteMessageWithoutTimer(
MessageType type, Message m, BdfList body) throws FormatException {
private BdfMessageContext validateLeaveOrAbortMessage(MessageType type,
Message m, BdfList body) throws FormatException {
checkSize(body, 3);
byte[] shareableId = body.getRaw(1);
checkLength(shareableId, UniqueId.LENGTH);
@@ -106,8 +105,8 @@ abstract class SharingValidator extends BdfMessageValidator {
}
}
private BdfMessageContext validateNonInviteMessageWithOptionalTimer(
MessageType type, Message m, BdfList body) throws FormatException {
private BdfMessageContext validateAcceptOrDeclineMessage(MessageType type,
Message m, BdfList body) throws FormatException {
// Client version 0.0: Message type, shareable ID, optional previous
// message ID.
// Client version 0.1: Message type, shareable ID, optional previous
@@ -118,7 +117,9 @@ abstract class SharingValidator extends BdfMessageValidator {
byte[] previousMessageId = body.getOptionalRaw(2);
checkLength(previousMessageId, UniqueId.LENGTH);
long timer = NO_AUTO_DELETE_TIMER;
if (body.size() == 4) timer = validateTimer(body.getOptionalLong(3));
if (body.size() == 4) {
timer = validateAutoDeleteTimer(body.getOptionalLong(3));
}
BdfDictionary meta = messageEncoder.encodeMetadata(type,
new GroupId(shareableId), m.getTimestamp(), false, false,
@@ -130,10 +131,4 @@ abstract class SharingValidator extends BdfMessageValidator {
return new BdfMessageContext(meta, singletonList(dependency));
}
}
private long validateTimer(@Nullable Long timer) throws FormatException {
if (timer == null) return NO_AUTO_DELETE_TIMER;
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS, MAX_AUTO_DELETE_TIMER_MS);
return timer;
}
}

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.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);

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.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)));

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.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));