Merge branch '732-reveal-backennd' into 'master'

Add support for revealing contacts to the PrivateGroupManager

This also adds three integration tests and improves some small details here and there in the private group client.

Prerequisite for #732.

See merge request !396
This commit is contained in:
akwizgran
2016-11-10 17:00:31 +00:00
16 changed files with 582 additions and 208 deletions

View File

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

View File

@@ -12,12 +12,12 @@ public class GroupMember {
private final Author author;
private final Status status;
private final boolean shared;
private final Visibility visibility;
public GroupMember(Author author, Status status, boolean shared) {
public GroupMember(Author author, Status status, Visibility visibility) {
this.author = author;
this.status = status;
this.shared = shared;
this.visibility = visibility;
}
public Author getAuthor() {
@@ -28,8 +28,8 @@ public class GroupMember {
return status;
}
public boolean isShared() {
return shared;
public Visibility getVisibility() {
return visibility;
}
}

View File

@@ -1,10 +1,6 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable;
import javax.annotation.concurrent.Immutable;
@@ -12,10 +8,16 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class JoinMessageHeader extends GroupMessageHeader {
public JoinMessageHeader(GroupId groupId, MessageId id,
@Nullable MessageId parentId, long timestamp, Author author,
Author.Status authorStatus, boolean read) {
super(groupId, id, parentId, timestamp, author, authorStatus, read);
private final Visibility visibility;
public JoinMessageHeader(GroupMessageHeader h, Visibility visibility) {
super(h.getGroupId(), h.getId(), h.getParentId(), h.getTimestamp(),
h.getAuthor(), h.getAuthorStatus(), h.isRead());
this.visibility = visibility;
}
public Visibility getVisibility() {
return visibility;
}
}

View File

@@ -12,20 +12,20 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class PrivateGroup extends NamedGroup implements Shareable {
private final Author author;
private final Author creator;
public PrivateGroup(Group group, String name, Author author, byte[] salt) {
public PrivateGroup(Group group, String name, Author creator, byte[] salt) {
super(group, name, salt);
this.author = author;
this.creator = creator;
}
public Author getAuthor() {
return author;
public Author getCreator() {
return creator;
}
@Override
public boolean equals(Object o) {
return o instanceof PrivateGroup && super.equals(o);
return o instanceof PrivateGroup && super.equals(o);
}
}

View File

@@ -1,9 +1,11 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
@@ -23,19 +25,21 @@ public interface PrivateGroupManager extends MessageTracker {
* Adds a new private group and joins it.
*
* @param group The private group to add
* @param joinMsg The new member's join message
* @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.
*
* @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.
@@ -43,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;
@@ -103,6 +107,17 @@ public interface PrivateGroupManager extends MessageTracker {
*/
boolean isMember(Transaction txn, GroupId g, Author a) throws DbException;
/**
* This method needs to be called when a contact relationship
* 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
* the relationship first. Otherwise false.
*/
void relationshipRevealed(Transaction txn, GroupId g, AuthorId a,
boolean byContact) throws FormatException, DbException;
/**
* Registers a hook to be called when members are added
* or groups are removed.

View File

@@ -0,0 +1,27 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.FormatException;
public enum Visibility {
INVISIBLE(0),
VISIBLE(1),
REVEALED_BY_US(2),
REVEALED_BY_CONTACT(3);
int value;
Visibility(int value) {
this.value = value;
}
public static Visibility valueOf(int value) throws FormatException {
for (Visibility v : values()) if (v.value == value) return v;
throw new FormatException();
}
public int getInt() {
return value;
}
}