mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Hook up incoming messages to the auto-delete manager.
This commit is contained in:
@@ -244,6 +244,13 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
return conversationManager.getTimestampForOutgoingMessage(txn, c);
|
||||
}
|
||||
|
||||
void receiveAutoDeleteTimer(Transaction txn, AbstractIntroductionMessage m)
|
||||
throws DbException {
|
||||
ContactId c = getContactId(txn, m.getGroupId());
|
||||
autoDeleteManager.receiveAutoDeleteTimer(txn, c, m.getAutoDeleteTimer(),
|
||||
m.getTimestamp());
|
||||
}
|
||||
|
||||
private ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
|
||||
@@ -259,6 +259,9 @@ class IntroduceeProtocolEngine
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Broadcast IntroductionRequestReceivedEvent
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
|
||||
Contact c = contactManager.getContact(txn, s.getIntroducer().getId(),
|
||||
@@ -334,8 +337,7 @@ class IntroduceeProtocolEngine
|
||||
}
|
||||
|
||||
private IntroduceeSession onRemoteAccept(Transaction txn,
|
||||
IntroduceeSession s, AcceptMessage m)
|
||||
throws DbException {
|
||||
IntroduceeSession s, AcceptMessage m) throws DbException {
|
||||
// The timestamp must be higher than the last request message
|
||||
if (m.getTimestamp() <= s.getRequestTimestamp())
|
||||
return abort(txn, s);
|
||||
@@ -343,6 +345,9 @@ class IntroduceeProtocolEngine
|
||||
if (isInvalidDependency(s, m.getPreviousMessageId()))
|
||||
return abort(txn, s);
|
||||
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Determine next state
|
||||
IntroduceeState state =
|
||||
s.getState() == AWAIT_RESPONSES ? REMOTE_ACCEPTED : AWAIT_AUTH;
|
||||
@@ -372,6 +377,9 @@ class IntroduceeProtocolEngine
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Broadcast IntroductionResponseReceivedEvent
|
||||
broadcastIntroductionResponseReceivedEvent(txn, s,
|
||||
s.getIntroducer().getId(), s.getRemote().author, m, false);
|
||||
|
||||
@@ -262,6 +262,8 @@ class IntroducerProtocolEngine
|
||||
// Track the incoming message
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Forward ACCEPT message
|
||||
Introducee i = getOtherIntroducee(s, m.getGroupId());
|
||||
@@ -323,6 +325,8 @@ class IntroducerProtocolEngine
|
||||
// Track the incoming message
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Forward ACCEPT message
|
||||
Introducee i = getOtherIntroducee(s, m.getGroupId());
|
||||
@@ -376,6 +380,8 @@ class IntroducerProtocolEngine
|
||||
// Track the incoming message
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Forward DECLINE message
|
||||
Introducee i = getOtherIntroducee(s, m.getGroupId());
|
||||
@@ -429,6 +435,8 @@ class IntroducerProtocolEngine
|
||||
// Track the incoming message
|
||||
messageTracker
|
||||
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
|
||||
// Forward DECLINE message
|
||||
Introducee i = getOtherIntroducee(s, m.getGroupId());
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook;
|
||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.attachment.FileTooBigException;
|
||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
|
||||
@@ -87,18 +88,24 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
private final MessageTracker messageTracker;
|
||||
private final ClientVersioningManager clientVersioningManager;
|
||||
private final ContactGroupFactory contactGroupFactory;
|
||||
private final AutoDeleteManager autoDeleteManager;
|
||||
|
||||
@Inject
|
||||
MessagingManagerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
||||
MessagingManagerImpl(
|
||||
DatabaseComponent db,
|
||||
ClientHelper clientHelper,
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
MetadataParser metadataParser, MessageTracker messageTracker,
|
||||
ContactGroupFactory contactGroupFactory) {
|
||||
MetadataParser metadataParser,
|
||||
MessageTracker messageTracker,
|
||||
ContactGroupFactory contactGroupFactory,
|
||||
AutoDeleteManager autoDeleteManager) {
|
||||
this.db = db;
|
||||
this.clientHelper = clientHelper;
|
||||
this.metadataParser = metadataParser;
|
||||
this.messageTracker = messageTracker;
|
||||
this.clientVersioningManager = clientVersioningManager;
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.autoDeleteManager = autoDeleteManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,6 +210,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
new PrivateMessageReceivedEvent(header, contactId);
|
||||
txn.attach(event);
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
autoDeleteManager.receiveAutoDeleteTimer(txn, contactId, timer,
|
||||
timestamp);
|
||||
}
|
||||
|
||||
private List<AttachmentHeader> parseAttachmentHeaders(GroupId g,
|
||||
|
||||
@@ -300,6 +300,13 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
|
||||
return max(s.getLocalTimestamp(), s.getInviteTimestamp());
|
||||
}
|
||||
|
||||
void receiveAutoDeleteTimer(Transaction txn,
|
||||
DeletableGroupInvitationMessage m) throws DbException {
|
||||
ContactId c = getContactId(txn, m.getContactGroupId());
|
||||
autoDeleteManager.receiveAutoDeleteTimer(txn, c, m.getAutoDeleteTimer(),
|
||||
m.getTimestamp());
|
||||
}
|
||||
|
||||
private void sendMessage(Transaction txn, Message m, MessageType type,
|
||||
GroupId privateGroupId, boolean visibleInConversation,
|
||||
long autoDeleteTimer) throws DbException {
|
||||
|
||||
@@ -201,6 +201,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Share the private group with the contact
|
||||
setPrivateGroupVisibility(txn, s, SHARED);
|
||||
// Broadcast an event
|
||||
@@ -226,6 +228,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Broadcast an event
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
|
||||
@@ -251,6 +251,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Broadcast an event
|
||||
PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup(
|
||||
m.getGroupName(), m.getCreator(), m.getSalt());
|
||||
|
||||
@@ -360,6 +360,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Broadcast an event
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, s.getContactGroupId());
|
||||
@@ -385,6 +387,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Share the shareable with the contact
|
||||
setShareableVisibility(txn, s, SHARED);
|
||||
// Broadcast an event
|
||||
@@ -432,6 +436,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Broadcast an event
|
||||
ContactId contactId =
|
||||
clientHelper.getContactId(txn, m.getContactGroupId());
|
||||
@@ -485,6 +491,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
// Track the message
|
||||
messageTracker.trackMessage(txn, m.getContactGroupId(),
|
||||
m.getTimestamp(), false);
|
||||
// Receive the auto-delete timer
|
||||
receiveAutoDeleteTimer(txn, m);
|
||||
// Make the shareable invisible (not actually needed in REMOTE_HANGING)
|
||||
try {
|
||||
setShareableVisibility(txn, s, INVISIBLE);
|
||||
@@ -719,6 +727,13 @@ abstract class ProtocolEngineImpl<S extends Shareable>
|
||||
return max(s.getLocalTimestamp(), s.getInviteTimestamp());
|
||||
}
|
||||
|
||||
private void receiveAutoDeleteTimer(Transaction txn,
|
||||
DeletableSharingMessage m) throws DbException {
|
||||
ContactId c = getContactId(txn, m.getContactGroupId());
|
||||
autoDeleteManager.receiveAutoDeleteTimer(txn, c, m.getAutoDeleteTimer(),
|
||||
m.getTimestamp());
|
||||
}
|
||||
|
||||
private ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
||||
throws DbException {
|
||||
try {
|
||||
|
||||
@@ -28,8 +28,7 @@ import static org.briarproject.briar.autodelete.AutoDeleteConstants.GROUP_KEY_TI
|
||||
import static org.briarproject.briar.autodelete.AutoDeleteConstants.NO_PREVIOUS_TIMER;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
// Thank you, I'm using them for readability
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
@SuppressWarnings("UnnecessaryLocalVariable") // Using them for readability
|
||||
public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.messaging;
|
||||
import org.briarproject.bramble.BrambleCoreIntegrationTestEagerSingletons;
|
||||
import org.briarproject.bramble.BrambleCoreModule;
|
||||
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
|
||||
import org.briarproject.briar.autodelete.AutoDeleteModule;
|
||||
import org.briarproject.briar.avatar.AvatarModule;
|
||||
import org.briarproject.briar.client.BriarClientModule;
|
||||
import org.briarproject.briar.forum.ForumModule;
|
||||
@@ -17,6 +18,7 @@ import dagger.Component;
|
||||
BrambleCoreIntegrationTestModule.class,
|
||||
BrambleCoreModule.class,
|
||||
BriarClientModule.class,
|
||||
AutoDeleteModule.class,
|
||||
AvatarModule.class,
|
||||
ForumModule.class,
|
||||
IdentityModule.class,
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||
import org.briarproject.briar.autodelete.AutoDeleteModule;
|
||||
import org.briarproject.briar.client.BriarClientModule;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -18,6 +19,7 @@ import dagger.Component;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
AutoDeleteModule.class,
|
||||
BrambleCoreIntegrationTestModule.class,
|
||||
BrambleCoreModule.class,
|
||||
BriarClientModule.class,
|
||||
|
||||
@@ -153,7 +153,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
if (visible) expectGetTimestampForVisibleMessage(messageTimestamp);
|
||||
else expectGetTimestampForInvisibleMessage(messageTimestamp);
|
||||
expectCheckWhetherContactSupportsAutoDeletion();
|
||||
if (visible) expectGetAutoDeleteTimer();
|
||||
if (visible) expectGetAutoDeleteTimer(messageTimestamp);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeJoinMessage(m.getContactGroupId(),
|
||||
m.getPrivateGroupId(), m.getTimestamp(),
|
||||
@@ -167,7 +167,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
if (visible) expectGetTimestampForVisibleMessage(messageTimestamp);
|
||||
else expectGetTimestampForInvisibleMessage(messageTimestamp);
|
||||
expectCheckWhetherContactSupportsAutoDeletion();
|
||||
if (visible) expectGetAutoDeleteTimer();
|
||||
if (visible) expectGetAutoDeleteTimer(messageTimestamp);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageEncoder).encodeLeaveMessage(contactGroupId,
|
||||
privateGroupId, messageTimestamp, lastLocalMessageId,
|
||||
@@ -254,11 +254,28 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
|
||||
}});
|
||||
}
|
||||
|
||||
void expectGetAutoDeleteTimer() throws Exception {
|
||||
void expectGetAutoDeleteTimer(long timestamp) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(autoDeleteManager).getAutoDeleteTimer(txn, contactId,
|
||||
localTimestamp);
|
||||
timestamp);
|
||||
will(returnValue(NO_AUTO_DELETE_TIMER));
|
||||
}});
|
||||
}
|
||||
|
||||
void expectTrackUnreadMessage(long timestamp) throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageTracker).trackMessage(txn, contactGroupId, timestamp,
|
||||
false);
|
||||
}});
|
||||
}
|
||||
|
||||
void expectReceiveAutoDeleteTimer(DeletableGroupInvitationMessage m)
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).getContactId(txn, contactGroupId);
|
||||
will(returnValue(contactId));
|
||||
oneOf(autoDeleteManager).receiveAutoDeleteTimer(txn, contactId,
|
||||
m.getAutoDeleteTimer(), m.getTimestamp());
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,11 +308,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
|
||||
expectSendJoinMessage(properJoinMessage, false);
|
||||
expectMarkMessageVisibleInUi(properJoinMessage.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
}});
|
||||
expectTrackUnreadMessage(properJoinMessage.getTimestamp());
|
||||
expectReceiveAutoDeleteTimer(properJoinMessage);
|
||||
expectGetContactId();
|
||||
expectSetPrivateGroupVisibility(SHARED);
|
||||
CreatorSession newSession =
|
||||
@@ -399,11 +396,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
CreatorSession session = getDefaultSession(INVITED);
|
||||
|
||||
expectMarkMessageVisibleInUi(properLeaveMessage.getId());
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageTracker)
|
||||
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
|
||||
false);
|
||||
}});
|
||||
expectTrackUnreadMessage(properLeaveMessage.getTimestamp());
|
||||
expectReceiveAutoDeleteTimer(properLeaveMessage);
|
||||
expectGetContactId();
|
||||
CreatorSession newSession =
|
||||
engine.onLeaveMessage(txn, session, properLeaveMessage);
|
||||
|
||||
@@ -366,9 +366,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
|
||||
}});
|
||||
expectMarkMessageVisibleInUi(properInviteMessage.getId());
|
||||
expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true);
|
||||
expectTrackUnreadMessage(properInviteMessage.getTimestamp());
|
||||
expectReceiveAutoDeleteTimer(properInviteMessage);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(messageTracker).trackMessage(txn, contactGroupId,
|
||||
properInviteMessage.getTimestamp(), false);
|
||||
oneOf(privateGroupFactory)
|
||||
.createPrivateGroup(properInviteMessage.getGroupName(),
|
||||
properInviteMessage.getCreator(),
|
||||
|
||||
Reference in New Issue
Block a user