mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Re-introduce InvitationResponse
This was done, so private responses don't need to include a Nameable already. Retreiving a nameable is tricky and requires a data migration, so we just don't do it now.
This commit is contained in:
@@ -152,8 +152,8 @@ abstract class AbstractProtocolEngine<S extends Session>
|
||||
IntroductionResponse response =
|
||||
new IntroductionResponse(m.getMessageId(), m.getGroupId(),
|
||||
m.getTimestamp(), false, false, false, false,
|
||||
s.getSessionId(), otherAuthor,
|
||||
m instanceof AcceptMessage, s.getRole());
|
||||
s.getSessionId(), m instanceof AcceptMessage,
|
||||
otherAuthor, s.getRole());
|
||||
IntroductionResponseReceivedEvent e =
|
||||
new IntroductionResponseReceivedEvent(response, c.getId());
|
||||
txn.attach(e);
|
||||
|
||||
@@ -495,7 +495,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
} else throw new AssertionError();
|
||||
return new IntroductionResponse(m, contactGroupId, meta.getTimestamp(),
|
||||
meta.isLocal(), status.isSent(), status.isSeen(), meta.isRead(),
|
||||
sessionId, author, accept, role);
|
||||
sessionId, accept, author, role);
|
||||
}
|
||||
|
||||
private void removeSessionWithIntroducer(Transaction txn,
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
|
||||
@@ -193,10 +192,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
setPrivateGroupVisibility(txn, s, SHARED);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
PrivateGroup privateGroup =
|
||||
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, privateGroup, true), contactId));
|
||||
createInvitationResponse(m, true), contactId));
|
||||
// Move to the JOINED state
|
||||
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
sent.getId(), m.getId(), sent.getTimestamp(),
|
||||
@@ -217,10 +214,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
m.getTimestamp(), false);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
PrivateGroup privateGroup =
|
||||
privateGroupManager.getPrivateGroup(txn, m.getPrivateGroupId());
|
||||
txn.attach(new GroupInvitationResponseReceivedEvent(
|
||||
createInvitationResponse(m, privateGroup, false), contactId));
|
||||
createInvitationResponse(m, false), contactId));
|
||||
// Move to the START state
|
||||
return new CreatorSession(s.getContactGroupId(), s.getPrivateGroupId(),
|
||||
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
|
||||
@@ -258,11 +253,10 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
}
|
||||
|
||||
private GroupInvitationResponse createInvitationResponse(
|
||||
GroupInvitationMessage m, PrivateGroup privateGroup,
|
||||
boolean accept) {
|
||||
GroupInvitationMessage m, boolean accept) {
|
||||
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
|
||||
return new GroupInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false, sessionId,
|
||||
privateGroup, accept);
|
||||
accept, m.getPrivateGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,36 +378,21 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
List<PrivateMessageHeader> messages =
|
||||
new ArrayList<>(results.size());
|
||||
// get invite message first and remember private groups
|
||||
Map<SessionId, PrivateGroup> privateGroups = new HashMap<>();
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
messageParser.parseMetadata(e.getValue());
|
||||
MessageType type = meta.getMessageType();
|
||||
if (type != INVITE) continue;
|
||||
MessageStatus status = db.getMessageStatus(txn, c, m);
|
||||
GroupInvitationRequest invite = parseInvitationRequest(txn,
|
||||
contactGroupId, m, meta, status);
|
||||
messages.add(invite);
|
||||
privateGroups.put(invite.getSessionId(), invite.getNameable());
|
||||
}
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
messageParser.parseMetadata(e.getValue());
|
||||
MessageType type = meta.getMessageType();
|
||||
if (type == INVITE) continue;
|
||||
MessageStatus status = db.getMessageStatus(txn, c, m);
|
||||
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
|
||||
PrivateGroup privateGroup = privateGroups.get(sessionId);
|
||||
if (privateGroup == null) throw new AssertionError();
|
||||
if (type == JOIN) {
|
||||
if (type == INVITE) {
|
||||
messages.add(parseInvitationRequest(txn, contactGroupId, m,
|
||||
meta, status));
|
||||
} else if (type == JOIN) {
|
||||
messages.add(parseInvitationResponse(contactGroupId, m,
|
||||
meta, status, sessionId, privateGroup, true));
|
||||
meta, status, true));
|
||||
} else if (type == LEAVE) {
|
||||
messages.add(parseInvitationResponse(contactGroupId, m,
|
||||
meta, status, sessionId, privateGroup, false));
|
||||
meta, status, false));
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
@@ -436,12 +421,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
private GroupInvitationResponse parseInvitationResponse(
|
||||
GroupId contactGroupId, MessageId m, MessageMetadata meta,
|
||||
MessageStatus status, SessionId sessionId,
|
||||
PrivateGroup privateGroup, boolean accept) {
|
||||
MessageStatus status, boolean accept) {
|
||||
SessionId sessionId = getSessionId(meta.getPrivateGroupId());
|
||||
return new GroupInvitationResponse(m, contactGroupId,
|
||||
meta.getTimestamp(), meta.isLocal(), status.isSent(),
|
||||
status.isSeen(), meta.isRead(), sessionId, privateGroup,
|
||||
accept);
|
||||
status.isSeen(), meta.isRead(), sessionId, accept,
|
||||
meta.getPrivateGroupId()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,10 +30,10 @@ public class BlogInvitationFactoryImpl
|
||||
@Override
|
||||
public BlogInvitationResponse createInvitationResponse(MessageId id,
|
||||
GroupId contactGroupId, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read, Blog blog, boolean accept) {
|
||||
SessionId sessionId = new SessionId(blog.getId().getBytes());
|
||||
boolean seen, boolean read, boolean accept, GroupId shareableId) {
|
||||
SessionId sessionId = new SessionId(shareableId.getBytes());
|
||||
return new BlogInvitationResponse(id, contactGroupId, time, local, sent,
|
||||
seen, read, sessionId, blog, accept);
|
||||
seen, read, sessionId, accept, shareableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,21 +58,21 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
|
||||
|
||||
@Override
|
||||
Event getInvitationResponseReceivedEvent(AcceptMessage m,
|
||||
ContactId contactId, Blog shareable) {
|
||||
ContactId contactId) {
|
||||
BlogInvitationResponse response = invitationFactory
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
true, m.getShareableId());
|
||||
return new BlogInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
Event getInvitationResponseReceivedEvent(DeclineMessage m,
|
||||
ContactId contactId, Blog shareable) {
|
||||
ContactId contactId) {
|
||||
BlogInvitationResponse response = invitationFactory
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
true, m.getShareableId());
|
||||
return new BlogInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ public class ForumInvitationFactoryImpl
|
||||
@Override
|
||||
public ForumInvitationResponse createInvitationResponse(MessageId id,
|
||||
GroupId contactGroupId, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read, Forum forum, boolean accept) {
|
||||
SessionId sessionId = new SessionId(forum.getId().getBytes());
|
||||
boolean seen, boolean read, boolean accept, GroupId shareableId) {
|
||||
SessionId sessionId = new SessionId(shareableId.getBytes());
|
||||
return new ForumInvitationResponse(id, contactGroupId, time, local,
|
||||
sent, seen, read, sessionId, forum, accept);
|
||||
sent, seen, read, sessionId, accept, shareableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ import static org.briarproject.briar.api.forum.ForumManager.MAJOR_VERSION;
|
||||
class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
|
||||
|
||||
private final ForumManager forumManager;
|
||||
private final InvitationFactory<Forum, ForumInvitationResponse>
|
||||
invitationFactory;
|
||||
private final InvitationFactory<Forum, ForumInvitationResponse> invitationFactory;
|
||||
|
||||
@Inject
|
||||
ForumProtocolEngineImpl(DatabaseComponent db,
|
||||
@@ -60,21 +59,21 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
|
||||
|
||||
@Override
|
||||
Event getInvitationResponseReceivedEvent(AcceptMessage m,
|
||||
ContactId contactId, Forum shareable) {
|
||||
ContactId contactId) {
|
||||
ForumInvitationResponse response = invitationFactory
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
true, m.getShareableId());
|
||||
return new ForumInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
@Override
|
||||
Event getInvitationResponseReceivedEvent(DeclineMessage m,
|
||||
ContactId contactId, Forum shareable) {
|
||||
ContactId contactId) {
|
||||
ForumInvitationResponse response = invitationFactory
|
||||
.createInvitationResponse(m.getId(), m.getContactGroupId(),
|
||||
m.getTimestamp(), false, false, true, false,
|
||||
shareable, true);
|
||||
true, m.getShareableId());
|
||||
return new ForumInvitationResponseReceivedEvent(response, contactId);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,17 @@ import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
public interface InvitationFactory<S extends Shareable, I extends PrivateResponse<S>> {
|
||||
public interface InvitationFactory<S extends Shareable, R extends InvitationResponse> {
|
||||
|
||||
PrivateRequest<S> createInvitationRequest(boolean local, boolean sent,
|
||||
boolean seen, boolean read, InviteMessage<S> m, ContactId c,
|
||||
boolean available, boolean canBeOpened);
|
||||
|
||||
I createInvitationResponse(MessageId id,
|
||||
GroupId contactGroupId, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read, S shareable, boolean accept);
|
||||
R createInvitationResponse(MessageId id, GroupId contactGroupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read,
|
||||
boolean accept, GroupId shareableId);
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,13 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
|
||||
private Message sendInviteMessage(Transaction txn, Session s,
|
||||
@Nullable String message, long timestamp) throws DbException {
|
||||
BdfList descriptor = getDescriptor(txn, s.getShareableId());
|
||||
Group g = db.getGroup(txn, s.getShareableId());
|
||||
BdfList descriptor;
|
||||
try {
|
||||
descriptor = clientHelper.toList(g.getDescriptor());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e); // Invalid group descriptor
|
||||
}
|
||||
long localTimestamp = Math.max(timestamp, getLocalTimestamp(s));
|
||||
Message m = messageEncoder.encodeInviteMessage(s.getContactGroupId(),
|
||||
localTimestamp, s.getLastLocalMessageId(), descriptor, message);
|
||||
@@ -287,7 +293,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
if (m.getTimestamp() <= s.getInviteTimestamp())
|
||||
return abortWithMessage(txn, s);
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Mark the invite message visible in the UI and (un)available to answer
|
||||
markMessageVisibleInUi(txn, m.getId());
|
||||
@@ -311,7 +317,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
if (m.getTimestamp() <= s.getInviteTimestamp())
|
||||
return abortWithMessage(txn, s);
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Mark the invite message visible in the UI and unavailable to answer
|
||||
markMessageVisibleInUi(txn, m.getId());
|
||||
@@ -358,7 +364,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
if (m.getTimestamp() <= s.getInviteTimestamp())
|
||||
return abortWithMessage(txn, s);
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Mark the response visible in the UI
|
||||
markMessageVisibleInUi(txn, m.getId());
|
||||
@@ -367,8 +373,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
m.getTimestamp(), false);
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
S shareable = getShareable(txn, s.getShareableId());
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId, shareable));
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId));
|
||||
// Move to the next state
|
||||
return new Session(nextState, s.getContactGroupId(), s.getShareableId(),
|
||||
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
|
||||
@@ -386,7 +391,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
}
|
||||
|
||||
abstract Event getInvitationResponseReceivedEvent(AcceptMessage m,
|
||||
ContactId contactId, S shareable);
|
||||
ContactId contactId);
|
||||
|
||||
@Override
|
||||
public Session onDeclineMessage(Transaction txn, Session s,
|
||||
@@ -411,7 +416,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
if (m.getTimestamp() <= s.getInviteTimestamp())
|
||||
return abortWithMessage(txn, s);
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Mark the response visible in the UI
|
||||
markMessageVisibleInUi(txn, m.getId());
|
||||
@@ -426,8 +431,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
}
|
||||
// Broadcast an event
|
||||
ContactId contactId = getContactId(txn, m.getContactGroupId());
|
||||
S shareable = getShareable(txn, s.getShareableId());
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId, shareable));
|
||||
txn.attach(getInvitationResponseReceivedEvent(m, contactId));
|
||||
// Move to the next state
|
||||
return new Session(START, s.getContactGroupId(), s.getShareableId(),
|
||||
s.getLastLocalMessageId(), m.getId(), s.getLocalTimestamp(),
|
||||
@@ -435,7 +439,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
}
|
||||
|
||||
abstract Event getInvitationResponseReceivedEvent(DeclineMessage m,
|
||||
ContactId contactId, S shareable);
|
||||
ContactId contactId);
|
||||
|
||||
@Override
|
||||
public Session onLeaveMessage(Transaction txn, Session s,
|
||||
@@ -459,7 +463,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
private Session onRemoteLeaveWhenInvited(Transaction txn, Session s,
|
||||
LeaveMessage m) throws DbException, FormatException {
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Mark any invite messages in the session unavailable to answer
|
||||
markInvitesUnavailableToAnswer(txn, s);
|
||||
@@ -472,7 +476,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
private Session onRemoteLeaveWhenLocalLeft(Transaction txn, Session s,
|
||||
LeaveMessage m) throws DbException, FormatException {
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Move to the next state
|
||||
return new Session(START, s.getContactGroupId(), s.getShareableId(),
|
||||
@@ -483,7 +487,7 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
private Session onRemoteLeaveWhenSharing(Transaction txn, Session s,
|
||||
LeaveMessage m) throws DbException, FormatException {
|
||||
// The dependency, if any, must be the last remote message
|
||||
if (!isValidDependency(s, m.getPreviousMessageId()))
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abortWithMessage(txn, s);
|
||||
// Broadcast event informing that contact left
|
||||
ContactId contactId = getContactId(txn, s.getContactGroupId());
|
||||
@@ -526,26 +530,6 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
sent.getId(), null, 0, 0);
|
||||
}
|
||||
|
||||
private S getShareable(Transaction txn, GroupId groupId)
|
||||
throws DbException {
|
||||
BdfList descriptor = getDescriptor(txn, groupId);
|
||||
try {
|
||||
return messageParser.createShareable(descriptor);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private BdfList getDescriptor(Transaction txn, GroupId groupId)
|
||||
throws DbException {
|
||||
Group g = db.getGroup(txn, groupId);
|
||||
try {
|
||||
return clientHelper.toList(g.getDescriptor());
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e); // Invalid group descriptor
|
||||
}
|
||||
}
|
||||
|
||||
private void markInvitesUnavailableToAnswer(Transaction txn, Session s)
|
||||
throws DbException, FormatException {
|
||||
GroupId shareableId = s.getShareableId();
|
||||
@@ -639,11 +623,11 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||
}
|
||||
|
||||
private boolean isValidDependency(Session session,
|
||||
private boolean isInvalidDependency(Session session,
|
||||
@Nullable MessageId dependency) {
|
||||
MessageId expected = session.getLastRemoteMessageId();
|
||||
if (dependency == null) return expected == null;
|
||||
return expected != null && dependency.equals(expected);
|
||||
if (dependency == null) return expected != null;
|
||||
return expected == null || !dependency.equals(expected);
|
||||
}
|
||||
|
||||
private long getLocalTimestamp(Session session) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||
import org.briarproject.briar.api.messaging.PrivateResponse;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
import org.briarproject.briar.api.sharing.SharingInvitationItem;
|
||||
import org.briarproject.briar.api.sharing.SharingManager;
|
||||
@@ -329,37 +329,23 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
List<PrivateMessageHeader> messages =
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
new ArrayList<>(results.size());
|
||||
// get invite messages first and remember shareables
|
||||
Map<GroupId, S> shareables = new HashMap<>();
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
messageParser.parseMetadata(e.getValue());
|
||||
MessageType type = meta.getMessageType();
|
||||
if (type != INVITE) continue;
|
||||
MessageStatus status = db.getMessageStatus(txn, c, m);
|
||||
PrivateRequest<S> invite = parseInvitationRequest(txn, c, m,
|
||||
meta, status);
|
||||
messages.add(invite);
|
||||
shareables.put(invite.getNameable().getId(), invite.getNameable());
|
||||
}
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
messageParser.parseMetadata(e.getValue());
|
||||
MessageType type = meta.getMessageType();
|
||||
if (type == INVITE) continue;
|
||||
MessageStatus status = db.getMessageStatus(txn, c, m);
|
||||
S shareable = shareables.get(meta.getShareableId());
|
||||
if (shareable == null) throw new AssertionError();
|
||||
if (type == ACCEPT) {
|
||||
if (type == INVITE) {
|
||||
messages.add(parseInvitationRequest(txn, c, m,
|
||||
meta, status));
|
||||
} else if (type == ACCEPT) {
|
||||
messages.add(parseInvitationResponse(contactGroupId, m,
|
||||
meta, status, shareable, true));
|
||||
meta, status, true));
|
||||
} else if (type == DECLINE) {
|
||||
messages.add(parseInvitationResponse(contactGroupId, m,
|
||||
meta, status, shareable, false));
|
||||
meta, status, false));
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
@@ -382,12 +368,12 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
meta.isAvailableToAnswer(), canBeOpened);
|
||||
}
|
||||
|
||||
private PrivateResponse<S> parseInvitationResponse(GroupId contactGroupId,
|
||||
private InvitationResponse parseInvitationResponse(GroupId contactGroupId,
|
||||
MessageId m, MessageMetadata meta, MessageStatus status,
|
||||
S shareable, boolean accept) {
|
||||
boolean accept) {
|
||||
return invitationFactory.createInvitationResponse(m, contactGroupId,
|
||||
meta.getTimestamp(), meta.isLocal(), status.isSent(),
|
||||
status.isSeen(), meta.isRead(), shareable, accept);
|
||||
status.isSeen(), meta.isRead(), accept, meta.getShareableId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -159,7 +159,7 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response1Received);
|
||||
assertEquals(introducee2.getAuthor().getName(),
|
||||
listener0.getResponse().getNameable().getName());
|
||||
listener0.getResponse().getIntroducedAuthor().getName());
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
|
||||
// sync second ACCEPT message
|
||||
@@ -167,7 +167,7 @@ public class IntroductionIntegrationTest
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response2Received);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener0.getResponse().getNameable().getName());
|
||||
listener0.getResponse().getIntroducedAuthor().getName());
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
|
||||
// sync forwarded ACCEPT messages to introducees
|
||||
@@ -265,7 +265,7 @@ public class IntroductionIntegrationTest
|
||||
|
||||
// assert that the name on the decline event is correct
|
||||
assertEquals(introducee2.getAuthor().getName(),
|
||||
listener0.getResponse().getNameable().getName());
|
||||
listener0.getResponse().getIntroducedAuthor().getName());
|
||||
|
||||
// sync second response
|
||||
sync2To0(1, true);
|
||||
@@ -282,7 +282,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener2.getResponse().getNameable().getName());
|
||||
listener2.getResponse().getIntroducedAuthor().getName());
|
||||
|
||||
// note how the introducer does not forward the second response,
|
||||
// because after the first decline the protocol finished
|
||||
@@ -356,7 +356,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(contact2From0.getAuthor().getName(),
|
||||
listener1.getResponse().getNameable().getName());
|
||||
listener1.getResponse().getIntroducedAuthor().getName());
|
||||
|
||||
assertFalse(contactManager1
|
||||
.contactExists(author2.getId(), author1.getId()));
|
||||
@@ -484,7 +484,7 @@ public class IntroductionIntegrationTest
|
||||
// assert that the name on the decline event is correct
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(introducee1.getAuthor().getName(),
|
||||
listener2.getResponse().getNameable().getName());
|
||||
listener2.getResponse().getIntroducedAuthor().getName());
|
||||
|
||||
// assert that introducee2 is in correct state
|
||||
introduceeSession = getIntroduceeSession(c2);
|
||||
|
||||
@@ -310,8 +310,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroup));
|
||||
}});
|
||||
expectGetContactId();
|
||||
expectSetPrivateGroupVisibility(SHARED);
|
||||
@@ -401,8 +399,6 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
oneOf(privateGroupManager).getPrivateGroup(txn, privateGroupId);
|
||||
will(returnValue(privateGroup));
|
||||
}});
|
||||
expectGetContactId();
|
||||
CreatorSession newSession =
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.privategroup.invitation;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
@@ -127,7 +126,7 @@ public class GroupInvitationIntegrationTest
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getNameable());
|
||||
assertEquals(privateGroup0.getId(), response.getShareableId());
|
||||
assertTrue(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
}
|
||||
@@ -144,7 +143,7 @@ public class GroupInvitationIntegrationTest
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getNameable());
|
||||
assertEquals(privateGroup0.getId(), response.getShareableId());
|
||||
assertFalse(response.isLocal());
|
||||
assertFalse(response.wasAccepted());
|
||||
}
|
||||
@@ -177,7 +176,7 @@ public class GroupInvitationIntegrationTest
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getNameable());
|
||||
assertEquals(privateGroup0.getId(), response.getShareableId());
|
||||
assertTrue(response.wasAccepted());
|
||||
} else {
|
||||
GroupInvitationRequest request = (GroupInvitationRequest) m;
|
||||
@@ -197,7 +196,7 @@ public class GroupInvitationIntegrationTest
|
||||
if (m instanceof GroupInvitationResponse) {
|
||||
foundResponse = true;
|
||||
GroupInvitationResponse response = (GroupInvitationResponse) m;
|
||||
assertEquals(privateGroup0, response.getNameable());
|
||||
assertEquals(privateGroup0.getId(), response.getShareableId());
|
||||
assertTrue(response.wasAccepted());
|
||||
}
|
||||
}
|
||||
@@ -441,38 +440,6 @@ public class GroupInvitationIntegrationTest
|
||||
sync1To0(1, true);
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testDeleteOnlyInvitationFails() throws Exception {
|
||||
// send invitation
|
||||
sendInvitation(clock.currentTimeMillis(), null);
|
||||
sync0To1(1, true);
|
||||
|
||||
// save MessageId of invitation
|
||||
Collection<PrivateMessageHeader> messages =
|
||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(1, messages.size());
|
||||
MessageId inviteId = messages.iterator().next().getId();
|
||||
|
||||
// decline invitation
|
||||
groupInvitationManager1
|
||||
.respondToInvitation(contactId0From1, privateGroup0, false);
|
||||
|
||||
// we should have an invitation and a decline message
|
||||
messages = withinTransactionReturns(db1, txn -> groupInvitationManager1
|
||||
.getMessageHeaders(txn, contactId0From1));
|
||||
assertEquals(2, messages.size());
|
||||
|
||||
// delete only invitation
|
||||
withinTransaction(db1, txn -> {
|
||||
db1.deleteMessage(txn, inviteId);
|
||||
db1.deleteMessageMetadata(txn, inviteId);
|
||||
// This should fail
|
||||
groupInvitationManager1.getMessageHeaders(txn, contactId0From1);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void sendInvitation(long timestamp, @Nullable String msg) throws
|
||||
DbException {
|
||||
byte[] signature = groupInvitationFactory.signInvitation(contact1From0,
|
||||
|
||||
@@ -680,8 +680,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
contactGroup.getId(), query);
|
||||
will(returnValue(results));
|
||||
// first message
|
||||
oneOf(messageParser).parseMetadata(meta2);
|
||||
will(returnValue(messageMetadata2));
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
will(returnValue(messageMetadata1));
|
||||
oneOf(db).getMessageStatus(txn, contactId, message.getId());
|
||||
@@ -695,8 +693,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
// second message
|
||||
oneOf(messageParser).parseMetadata(meta2);
|
||||
will(returnValue(messageMetadata2));
|
||||
oneOf(messageParser).parseMetadata(meta);
|
||||
will(returnValue(messageMetadata1));
|
||||
oneOf(db).getMessageStatus(txn, contactId, messageId2);
|
||||
}});
|
||||
|
||||
@@ -712,7 +708,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
} else if (m.getId().equals(messageId2)) {
|
||||
assertTrue(m instanceof GroupInvitationResponse);
|
||||
assertEquals(time2, m.getTimestamp());
|
||||
assertEquals(pg, ((GroupInvitationResponse) m).getNameable());
|
||||
assertEquals(pg.getId(),
|
||||
((GroupInvitationResponse) m).getShareableId());
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(blog2, response.getNameable());
|
||||
assertEquals(blog2.getId(), response.getShareableId());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -233,7 +233,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals("Hi!", invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(rssBlog, response.getNameable());
|
||||
assertEquals(rssBlog.getId(), response.getShareableId());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -294,7 +294,7 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals(null, invitation.getMessage());
|
||||
} else {
|
||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||
assertEquals(blog2, response.getNameable());
|
||||
assertEquals(blog2.getId(), response.getShareableId());
|
||||
assertFalse(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class ForumSharingIntegrationTest
|
||||
assertTrue(invitation.canBeOpened());
|
||||
} else {
|
||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||
assertEquals(forum0, response.getNameable());
|
||||
assertEquals(forum0.getId(), response.getShareableId());
|
||||
assertTrue(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
@@ -198,7 +198,7 @@ public class ForumSharingIntegrationTest
|
||||
assertFalse(invitation.canBeOpened());
|
||||
} else {
|
||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||
assertEquals(forum0, response.getNameable());
|
||||
assertEquals(forum0.getId(), response.getShareableId());
|
||||
assertFalse(response.wasAccepted());
|
||||
assertTrue(response.isLocal());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user