mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Add ContactRelationshipRevealedEvent and address review comments
This commit is contained in:
@@ -63,7 +63,7 @@ import static org.briarproject.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.api.identity.Author.Status.VERIFIED;
|
||||
import static org.briarproject.api.privategroup.Visibility.INVISIBLE;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_CONTACT;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_YOU;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_US;
|
||||
import static org.briarproject.api.privategroup.Visibility.VISIBLE;
|
||||
import static org.briarproject.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
|
||||
@@ -344,7 +344,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0,
|
||||
joinTime, getRandomBytes(12));
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true);
|
||||
assertEquals(joinMsg0.getMessage().getId(),
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
@@ -367,7 +367,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1);
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
||||
assertEquals(joinMsg1.getMessage().getId(),
|
||||
groupManager1.getPreviousMsgId(groupId0));
|
||||
|
||||
@@ -411,7 +411,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0,
|
||||
inviteTime, creatorSignature);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true);
|
||||
assertEquals(joinMsg0.getMessage().getId(),
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
@@ -434,7 +434,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1);
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
||||
assertEquals(joinMsg1.getMessage().getId(),
|
||||
groupManager1.getPreviousMsgId(groupId0));
|
||||
|
||||
@@ -475,7 +475,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
|
||||
Collection<GroupMember> members1 = groupManager1.getMembers(groupId0);
|
||||
assertEquals(2, members1.size());
|
||||
for (GroupMember m : members0) {
|
||||
for (GroupMember m : members1) {
|
||||
if (m.getAuthor().equals(author1)) {
|
||||
assertEquals(VISIBLE, m.getVisibility());
|
||||
} else {
|
||||
@@ -538,7 +538,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
||||
inviteTime, creatorSignature);
|
||||
Transaction txn2 = db2.startTransaction(false);
|
||||
groupManager2.addPrivateGroup(txn2, privateGroup0, joinMsg2);
|
||||
groupManager2.addPrivateGroup(txn2, privateGroup0, joinMsg2, false);
|
||||
|
||||
// make group visible to 0
|
||||
db2.setVisibleToContact(txn2, contactId01, privateGroup0.getId(), true);
|
||||
@@ -589,7 +589,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
members1 = groupManager1.getMembers(groupId0);
|
||||
for (GroupMember m : members1) {
|
||||
if (m.getAuthor().equals(author2)) {
|
||||
assertEquals(REVEALED_BY_YOU, m.getVisibility());
|
||||
assertEquals(REVEALED_BY_US, m.getVisibility());
|
||||
}
|
||||
}
|
||||
members2 = groupManager2.getMembers(groupId0);
|
||||
@@ -607,7 +607,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
JoinMessageHeader j = (JoinMessageHeader) h;
|
||||
if (h.getAuthor().equals(author2))
|
||||
// 1 revealed the relationship to 2
|
||||
assertEquals(REVEALED_BY_YOU, j.getVisibility());
|
||||
assertEquals(REVEALED_BY_US, j.getVisibility());
|
||||
else
|
||||
// 1's other relationship (to 1 and creator) are visible
|
||||
assertEquals(VISIBLE, j.getVisibility());
|
||||
@@ -633,16 +633,16 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
defaultInit();
|
||||
|
||||
// group is not dissolved initially
|
||||
assertFalse(groupManager0.isDissolved(groupId0));
|
||||
assertFalse(groupManager1.isDissolved(groupId0));
|
||||
|
||||
// creator dissolves group
|
||||
Transaction txn0 = db0.startTransaction(false);
|
||||
groupManager0.markGroupDissolved(txn0, groupId0);
|
||||
db0.commitTransaction(txn0);
|
||||
db0.endTransaction(txn0);
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
groupManager1.markGroupDissolved(txn1, groupId0);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
|
||||
// group is dissolved now
|
||||
assertTrue(groupManager0.isDissolved(groupId0));
|
||||
assertTrue(groupManager1.isDissolved(groupId0));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -737,7 +737,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
long joinTime = clock.currentTimeMillis();
|
||||
GroupMessage joinMsg0 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0);
|
||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0, true);
|
||||
assertEquals(joinMsg0.getMessage().getId(),
|
||||
groupManager0.getPreviousMsgId(groupId0));
|
||||
|
||||
@@ -760,10 +760,10 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
||||
GroupMessage joinMsg1 = groupMessageFactory
|
||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||
inviteTime, creatorSignature);
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
groupManager1.addPrivateGroup(txn1, privateGroup0, joinMsg1);
|
||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
||||
|
||||
// make group visible to 0
|
||||
Transaction txn1 = db1.startTransaction(false);
|
||||
db1.setVisibleToContact(txn1, contactId01, privateGroup0.getId(), true);
|
||||
db1.commitTransaction(txn1);
|
||||
db1.endTransaction(txn1);
|
||||
|
||||
@@ -117,7 +117,7 @@ public class CreateGroupControllerImpl extends DbControllerImpl
|
||||
public void run() {
|
||||
LOG.info("Adding group to database...");
|
||||
try {
|
||||
groupManager.addPrivateGroup(group, joinMsg);
|
||||
groupManager.addPrivateGroup(group, joinMsg, true);
|
||||
handler.onResult(group.getId());
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ContactRelationshipRevealedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final Visibility visibility;
|
||||
|
||||
public ContactRelationshipRevealedEvent(GroupId groupId,
|
||||
Visibility visibility) {
|
||||
this.groupId = groupId;
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,9 +25,7 @@ public class PrivateGroup extends NamedGroup implements Shareable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrivateGroup &&
|
||||
creator.equals(((PrivateGroup) o).getCreator()) &&
|
||||
super.equals(o);
|
||||
return o instanceof PrivateGroup && super.equals(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,22 +22,24 @@ public interface PrivateGroupManager extends MessageTracker {
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.privategroup");
|
||||
|
||||
/**
|
||||
* Adds a new private group and joins it as the creator.
|
||||
* Adds a new private group and joins it.
|
||||
*
|
||||
* @param group The private group to add
|
||||
* @param joinMsg The creators's join message
|
||||
* @param creator True if the group is added by its creator
|
||||
*/
|
||||
void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg)
|
||||
throws DbException;
|
||||
void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg,
|
||||
boolean creator) throws DbException;
|
||||
|
||||
/**
|
||||
* Adds a new private group and joins it as a member.
|
||||
* Adds a new private group and joins it.
|
||||
*
|
||||
* @param group The private group to add
|
||||
* @param joinMsg The new member's join message
|
||||
* @param creator True if the group is added by its creator
|
||||
*/
|
||||
void addPrivateGroup(Transaction txn, PrivateGroup group,
|
||||
GroupMessage joinMsg) throws DbException;
|
||||
GroupMessage joinMsg, boolean creator) throws DbException;
|
||||
|
||||
/**
|
||||
* Removes a dissolved private group.
|
||||
@@ -45,7 +47,7 @@ public interface PrivateGroupManager extends MessageTracker {
|
||||
void removePrivateGroup(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Gets the MessageId of your previous message sent to the group
|
||||
* Gets the MessageId of the user's previous message sent to the group
|
||||
*/
|
||||
MessageId getPreviousMsgId(GroupId g) throws DbException;
|
||||
|
||||
@@ -107,7 +109,7 @@ public interface PrivateGroupManager extends MessageTracker {
|
||||
|
||||
/**
|
||||
* This method needs to be called when a contact relationship
|
||||
* has been revealed between you and the Author with AuthorId a
|
||||
* has been revealed between the user and the Author with AuthorId a
|
||||
* in the Group identified by the GroupId g.
|
||||
*
|
||||
* @param byContact true if the remote contact has revealed
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
|
||||
public enum Visibility {
|
||||
|
||||
INVISIBLE(0),
|
||||
VISIBLE(1),
|
||||
REVEALED_BY_YOU(2),
|
||||
REVEALED_BY_US(2),
|
||||
REVEALED_BY_CONTACT(3);
|
||||
|
||||
int value;
|
||||
@@ -13,9 +15,9 @@ public enum Visibility {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Visibility valueOf(int value) {
|
||||
public static Visibility valueOf(int value) throws FormatException {
|
||||
for (Visibility v : values()) if (v.value == value) return v;
|
||||
throw new IllegalArgumentException();
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.privategroup;
|
||||
|
||||
import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
|
||||
|
||||
interface Constants {
|
||||
interface GroupConstants {
|
||||
|
||||
// Database keys
|
||||
String KEY_TYPE = "type";
|
||||
|
||||
@@ -29,14 +29,14 @@ import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH
|
||||
import static org.briarproject.api.privategroup.MessageType.JOIN;
|
||||
import static org.briarproject.api.privategroup.MessageType.POST;
|
||||
import static org.briarproject.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_NAME;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_PUBLIC_KEY;
|
||||
import static org.briarproject.privategroup.Constants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_PREVIOUS_MSG_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_READ;
|
||||
import static org.briarproject.privategroup.Constants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.privategroup.Constants.KEY_TYPE;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_NAME;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_READ;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TYPE;
|
||||
|
||||
class GroupMessageValidator extends BdfMessageValidator {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.privategroup.ContactRelationshipRevealedEvent;
|
||||
import org.briarproject.api.privategroup.GroupMember;
|
||||
import org.briarproject.api.privategroup.GroupMessage;
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
@@ -52,21 +53,21 @@ import static org.briarproject.api.privategroup.MessageType.JOIN;
|
||||
import static org.briarproject.api.privategroup.MessageType.POST;
|
||||
import static org.briarproject.api.privategroup.Visibility.INVISIBLE;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_CONTACT;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_YOU;
|
||||
import static org.briarproject.api.privategroup.Visibility.REVEALED_BY_US;
|
||||
import static org.briarproject.api.privategroup.Visibility.VISIBLE;
|
||||
import static org.briarproject.privategroup.Constants.GROUP_KEY_CREATOR_ID;
|
||||
import static org.briarproject.privategroup.Constants.GROUP_KEY_DISSOLVED;
|
||||
import static org.briarproject.privategroup.Constants.GROUP_KEY_MEMBERS;
|
||||
import static org.briarproject.privategroup.Constants.GROUP_KEY_OUR_GROUP;
|
||||
import static org.briarproject.privategroup.Constants.GROUP_KEY_VISIBILITY;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_NAME;
|
||||
import static org.briarproject.privategroup.Constants.KEY_MEMBER_PUBLIC_KEY;
|
||||
import static org.briarproject.privategroup.Constants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_PREVIOUS_MSG_ID;
|
||||
import static org.briarproject.privategroup.Constants.KEY_READ;
|
||||
import static org.briarproject.privategroup.Constants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.privategroup.Constants.KEY_TYPE;
|
||||
import static org.briarproject.privategroup.GroupConstants.GROUP_KEY_CREATOR_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.GROUP_KEY_DISSOLVED;
|
||||
import static org.briarproject.privategroup.GroupConstants.GROUP_KEY_MEMBERS;
|
||||
import static org.briarproject.privategroup.GroupConstants.GROUP_KEY_OUR_GROUP;
|
||||
import static org.briarproject.privategroup.GroupConstants.GROUP_KEY_VISIBILITY;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_NAME;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_READ;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.privategroup.GroupConstants.KEY_TYPE;
|
||||
|
||||
@NotNullByDefault
|
||||
public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
@@ -89,11 +90,11 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg)
|
||||
throws DbException {
|
||||
public void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg,
|
||||
boolean creator) throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
addPrivateGroup(txn, group, joinMsg, true);
|
||||
addPrivateGroup(txn, group, joinMsg, creator);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
@@ -102,11 +103,6 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
|
||||
@Override
|
||||
public void addPrivateGroup(Transaction txn, PrivateGroup group,
|
||||
GroupMessage joinMsg) throws DbException {
|
||||
addPrivateGroup(txn, group, joinMsg, false);
|
||||
}
|
||||
|
||||
private void addPrivateGroup(Transaction txn, PrivateGroup group,
|
||||
GroupMessage joinMsg, boolean creator) throws DbException {
|
||||
try {
|
||||
db.addGroup(txn, group.getGroup());
|
||||
@@ -420,8 +416,8 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
BdfList list = meta.getList(GROUP_KEY_MEMBERS);
|
||||
Map<Author, Visibility> members =
|
||||
new HashMap<Author, Visibility>(list.size());
|
||||
for (Object o : list) {
|
||||
BdfDictionary d = (BdfDictionary) o;
|
||||
for (int i = 0 ; i < list.size(); i++) {
|
||||
BdfDictionary d = list.getDictionary(i);
|
||||
Author member = getAuthor(d);
|
||||
Visibility v = getVisibility(d);
|
||||
members.put(member, v);
|
||||
@@ -446,21 +442,22 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
boolean byContact) throws FormatException, DbException {
|
||||
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
BdfList members = meta.getList(GROUP_KEY_MEMBERS);
|
||||
Visibility v = INVISIBLE;
|
||||
boolean foundMember = false;
|
||||
for (Object o : members) {
|
||||
BdfDictionary d = (BdfDictionary) o;
|
||||
for (int i = 0 ; i < members.size(); i++) {
|
||||
BdfDictionary d = members.getDictionary(i);
|
||||
AuthorId memberId = new AuthorId(d.getRaw(KEY_MEMBER_ID));
|
||||
if (a.equals(memberId)) {
|
||||
foundMember = true;
|
||||
Visibility vOld = getVisibility(d);
|
||||
if (vOld != INVISIBLE) throw new ProtocolStateException();
|
||||
Visibility vNew =
|
||||
byContact ? REVEALED_BY_CONTACT : REVEALED_BY_YOU;
|
||||
d.put(GROUP_KEY_VISIBILITY, vNew.getInt());
|
||||
v = byContact ? REVEALED_BY_CONTACT : REVEALED_BY_US;
|
||||
d.put(GROUP_KEY_VISIBILITY, v.getInt());
|
||||
}
|
||||
}
|
||||
if (!foundMember) throw new ProtocolStateException();
|
||||
clientHelper.mergeGroupMetadata(txn, g, meta);
|
||||
txn.attach(new ContactRelationshipRevealedEvent(g, v));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -183,7 +183,8 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
GroupMessage joinMessage = groupMessageFactory.createJoinMessage(
|
||||
privateGroup.getId(), timestamp, member, invite.getTimestamp(),
|
||||
invite.getSignature());
|
||||
privateGroupManager.addPrivateGroup(txn, privateGroup, joinMessage);
|
||||
privateGroupManager
|
||||
.addPrivateGroup(txn, privateGroup, joinMessage, false);
|
||||
}
|
||||
|
||||
long getLocalTimestamp(S session) {
|
||||
|
||||
Reference in New Issue
Block a user