Added third group visibility state.

This commit is contained in:
akwizgran
2016-11-15 14:08:01 +00:00
parent 007df4288b
commit ec1f4dccdb
19 changed files with 563 additions and 408 deletions

View File

@@ -18,6 +18,7 @@ import org.briarproject.api.privategroup.PrivateGroup;
import org.briarproject.api.privategroup.PrivateGroupFactory;
import org.briarproject.api.privategroup.PrivateGroupManager;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.Group.Visibility;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
@@ -90,11 +91,10 @@ abstract class AbstractProtocolEngine<S extends Session>
return dependency.equals(expected);
}
void syncPrivateGroupWithContact(Transaction txn, S session, boolean sync)
void setPrivateGroupVisibility(Transaction txn, S session, Visibility v)
throws DbException, FormatException {
ContactId contactId = getContactId(txn, session.getContactGroupId());
db.setVisibleToContact(txn, contactId, session.getPrivateGroupId(),
sync);
db.setGroupVisibility(txn, contactId, session.getPrivateGroupId(), v);
}
Message sendInviteMessage(Transaction txn, S session,

View File

@@ -22,6 +22,8 @@ import org.briarproject.api.system.Clock;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.api.sync.Group.Visibility.SHARED;
import static org.briarproject.privategroup.invitation.CreatorState.DISSOLVED;
import static org.briarproject.privategroup.invitation.CreatorState.ERROR;
import static org.briarproject.privategroup.invitation.CreatorState.INVITED;
@@ -158,8 +160,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
private CreatorSession onLocalLeave(Transaction txn, CreatorSession s)
throws DbException {
try {
// Stop syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, false);
// Make the private group invisible to the contact
setPrivateGroupVisibility(txn, s, INVISIBLE);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -183,8 +185,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
// Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false);
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
// Broadcast an event
ContactId contactId = getContactId(txn, m.getContactGroupId());
txn.attach(new GroupInvitationResponseReceivedEvent(contactId,
@@ -224,8 +226,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
// The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId()))
return abort(txn, s);
// Stop syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, false);
// Make the private group invisible to the contact
setPrivateGroupVisibility(txn, s, INVISIBLE);
// Move to the INVITEE_LEFT state
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
@@ -236,9 +238,9 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
throws DbException, FormatException {
// If the session has already been aborted, do nothing
if (s.getState() == ERROR) return s;
// If we subscribe, stop syncing the private group with the contact
// If we subscribe, make the private group invisible to the contact
if (isSubscribedPrivateGroup(txn, s.getPrivateGroupId()))
syncPrivateGroupWithContact(txn, s, false);
setPrivateGroupVisibility(txn, s, INVISIBLE);
// Send an ABORT message
Message sent = sendAbortMessage(txn, s);
// Move to the ERROR state

View File

@@ -45,6 +45,7 @@ import java.util.Map.Entry;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import static org.briarproject.api.sync.Group.Visibility.SHARED;
import static org.briarproject.privategroup.invitation.CreatorState.START;
import static org.briarproject.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
import static org.briarproject.privategroup.invitation.MessageType.ABORT;
@@ -110,7 +111,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
if (db.containsGroup(txn, g.getId())) return;
// Store the group and share it with the contact
db.addGroup(txn, g);
db.setVisibleToContact(txn, c.getId(), g.getId(), true);
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());

View File

@@ -25,6 +25,8 @@ import org.briarproject.api.system.Clock;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.api.sync.Group.Visibility.SHARED;
import static org.briarproject.privategroup.invitation.InviteeState.DISSOLVED;
import static org.briarproject.privategroup.invitation.InviteeState.ERROR;
import static org.briarproject.privategroup.invitation.InviteeState.INVITED;
@@ -157,8 +159,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
try {
// Subscribe to the private group
subscribeToPrivateGroup(txn, inviteId);
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -228,8 +230,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
if (!isValidDependency(s, m.getPreviousMessageId()))
return abort(txn, s);
try {
// Stop syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, false);
// Make the private group invisible to the contact
setPrivateGroupVisibility(txn, s, INVISIBLE);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -247,9 +249,9 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
if (s.getState() == ERROR) return s;
// Mark any invite messages in the session unavailable to answer
markInvitesUnavailableToAnswer(txn, s);
// Stop syncing the private group with the contact, if we subscribe
// If we subscribe, make the private group invisible to the contact
if (isSubscribedPrivateGroup(txn, s.getPrivateGroupId()))
syncPrivateGroupWithContact(txn, s, false);
setPrivateGroupVisibility(txn, s, INVISIBLE);
// Send an ABORT message
Message sent = sendAbortMessage(txn, s);
// Move to the ERROR state

View File

@@ -20,6 +20,8 @@ import org.briarproject.api.system.Clock;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.api.sync.Group.Visibility.SHARED;
import static org.briarproject.privategroup.invitation.PeerState.AWAIT_MEMBER;
import static org.briarproject.privategroup.invitation.PeerState.BOTH_JOINED;
import static org.briarproject.privategroup.invitation.PeerState.ERROR;
@@ -178,8 +180,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
// Send a JOIN message
Message sent = sendJoinMessage(txn, s, false);
try {
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -195,8 +197,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
// Send a LEAVE message
Message sent = sendLeaveMessage(txn, s, false);
try {
// Stop syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, false);
// Make the private group invisible to the contact
setPrivateGroupVisibility(txn, s, INVISIBLE);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -228,8 +230,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
// Send a JOIN message
Message sent = sendJoinMessage(txn, s, false);
try {
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
} catch (FormatException e) {
throw new DbException(e); // Invalid group metadata
}
@@ -263,8 +265,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
return abort(txn, s);
// Send a JOIN message
Message sent = sendJoinMessage(txn, s, false);
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
// Mark the relationship visible to the group, revealed by contact
relationshipRevealed(txn, s, true);
// Move to the BOTH_JOINED state
@@ -277,8 +279,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
// The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId()))
return abort(txn, s);
// Start syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, true);
// Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED);
// Mark the relationship visible to the group, revealed by us
relationshipRevealed(txn, s, false);
// Move to the BOTH_JOINED state
@@ -314,8 +316,8 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
// The dependency, if any, must be the last remote message
if (!isValidDependency(s, m.getPreviousMessageId()))
return abort(txn, s);
// Stop syncing the private group with the contact
syncPrivateGroupWithContact(txn, s, false);
// Make the private group invisible to the contact
setPrivateGroupVisibility(txn, s, INVISIBLE);
// Move to the LOCAL_JOINED state
return new PeerSession(s.getContactGroupId(), s.getPrivateGroupId(),
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
@@ -326,9 +328,9 @@ class PeerProtocolEngine extends AbstractProtocolEngine<PeerSession> {
throws DbException, FormatException {
// If the session has already been aborted, do nothing
if (s.getState() == ERROR) return s;
// Stop syncing the private group with the contact, if we subscribe
// If we subscribe, make the private group invisible to the contact
if (isSubscribedPrivateGroup(txn, s.getPrivateGroupId()))
syncPrivateGroupWithContact(txn, s, false);
setPrivateGroupVisibility(txn, s, INVISIBLE);
// Send an ABORT message
Message sent = sendAbortMessage(txn, s);
// Move to the ERROR state