Hook up incoming messages to the auto-delete manager.

This commit is contained in:
akwizgran
2020-12-03 12:44:28 +00:00
committed by Torsten Grote
parent 27dbe23914
commit 49080cb64c
14 changed files with 97 additions and 23 deletions

View File

@@ -244,6 +244,13 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
return conversationManager.getTimestampForOutgoingMessage(txn, c); 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) private ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException { throws DbException {
try { try {

View File

@@ -259,6 +259,9 @@ class IntroduceeProtocolEngine
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast IntroductionRequestReceivedEvent // Broadcast IntroductionRequestReceivedEvent
LocalAuthor localAuthor = identityManager.getLocalAuthor(txn); LocalAuthor localAuthor = identityManager.getLocalAuthor(txn);
Contact c = contactManager.getContact(txn, s.getIntroducer().getId(), Contact c = contactManager.getContact(txn, s.getIntroducer().getId(),
@@ -334,8 +337,7 @@ class IntroduceeProtocolEngine
} }
private IntroduceeSession onRemoteAccept(Transaction txn, private IntroduceeSession onRemoteAccept(Transaction txn,
IntroduceeSession s, AcceptMessage m) IntroduceeSession s, AcceptMessage m) throws DbException {
throws DbException {
// The timestamp must be higher than the last request message // The timestamp must be higher than the last request message
if (m.getTimestamp() <= s.getRequestTimestamp()) if (m.getTimestamp() <= s.getRequestTimestamp())
return abort(txn, s); return abort(txn, s);
@@ -343,6 +345,9 @@ class IntroduceeProtocolEngine
if (isInvalidDependency(s, m.getPreviousMessageId())) if (isInvalidDependency(s, m.getPreviousMessageId()))
return abort(txn, s); return abort(txn, s);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Determine next state // Determine next state
IntroduceeState state = IntroduceeState state =
s.getState() == AWAIT_RESPONSES ? REMOTE_ACCEPTED : AWAIT_AUTH; s.getState() == AWAIT_RESPONSES ? REMOTE_ACCEPTED : AWAIT_AUTH;
@@ -372,6 +377,9 @@ class IntroduceeProtocolEngine
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast IntroductionResponseReceivedEvent // Broadcast IntroductionResponseReceivedEvent
broadcastIntroductionResponseReceivedEvent(txn, s, broadcastIntroductionResponseReceivedEvent(txn, s,
s.getIntroducer().getId(), s.getRemote().author, m, false); s.getIntroducer().getId(), s.getRemote().author, m, false);

View File

@@ -262,6 +262,8 @@ class IntroducerProtocolEngine
// Track the incoming message // Track the incoming message
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Forward ACCEPT message // Forward ACCEPT message
Introducee i = getOtherIntroducee(s, m.getGroupId()); Introducee i = getOtherIntroducee(s, m.getGroupId());
@@ -323,6 +325,8 @@ class IntroducerProtocolEngine
// Track the incoming message // Track the incoming message
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Forward ACCEPT message // Forward ACCEPT message
Introducee i = getOtherIntroducee(s, m.getGroupId()); Introducee i = getOtherIntroducee(s, m.getGroupId());
@@ -376,6 +380,8 @@ class IntroducerProtocolEngine
// Track the incoming message // Track the incoming message
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Forward DECLINE message // Forward DECLINE message
Introducee i = getOtherIntroducee(s, m.getGroupId()); Introducee i = getOtherIntroducee(s, m.getGroupId());
@@ -429,6 +435,8 @@ class IntroducerProtocolEngine
// Track the incoming message // Track the incoming message
messageTracker messageTracker
.trackMessage(txn, m.getGroupId(), m.getTimestamp(), false); .trackMessage(txn, m.getGroupId(), m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Forward DECLINE message // Forward DECLINE message
Introducee i = getOtherIntroducee(s, m.getGroupId()); Introducee i = getOtherIntroducee(s, m.getGroupId());

View File

@@ -29,6 +29,7 @@ import org.briarproject.bramble.api.versioning.ClientVersioningManager;
import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook; import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook;
import org.briarproject.briar.api.attachment.AttachmentHeader; import org.briarproject.briar.api.attachment.AttachmentHeader;
import org.briarproject.briar.api.attachment.FileTooBigException; 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;
import org.briarproject.briar.api.client.MessageTracker.GroupCount; import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient; import org.briarproject.briar.api.conversation.ConversationManager.ConversationClient;
@@ -87,18 +88,24 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
private final MessageTracker messageTracker; private final MessageTracker messageTracker;
private final ClientVersioningManager clientVersioningManager; private final ClientVersioningManager clientVersioningManager;
private final ContactGroupFactory contactGroupFactory; private final ContactGroupFactory contactGroupFactory;
private final AutoDeleteManager autoDeleteManager;
@Inject @Inject
MessagingManagerImpl(DatabaseComponent db, ClientHelper clientHelper, MessagingManagerImpl(
DatabaseComponent db,
ClientHelper clientHelper,
ClientVersioningManager clientVersioningManager, ClientVersioningManager clientVersioningManager,
MetadataParser metadataParser, MessageTracker messageTracker, MetadataParser metadataParser,
ContactGroupFactory contactGroupFactory) { MessageTracker messageTracker,
ContactGroupFactory contactGroupFactory,
AutoDeleteManager autoDeleteManager) {
this.db = db; this.db = db;
this.clientHelper = clientHelper; this.clientHelper = clientHelper;
this.metadataParser = metadataParser; this.metadataParser = metadataParser;
this.messageTracker = messageTracker; this.messageTracker = messageTracker;
this.clientVersioningManager = clientVersioningManager; this.clientVersioningManager = clientVersioningManager;
this.contactGroupFactory = contactGroupFactory; this.contactGroupFactory = contactGroupFactory;
this.autoDeleteManager = autoDeleteManager;
} }
@Override @Override
@@ -203,6 +210,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
new PrivateMessageReceivedEvent(header, contactId); new PrivateMessageReceivedEvent(header, contactId);
txn.attach(event); txn.attach(event);
messageTracker.trackIncomingMessage(txn, m); messageTracker.trackIncomingMessage(txn, m);
autoDeleteManager.receiveAutoDeleteTimer(txn, contactId, timer,
timestamp);
} }
private List<AttachmentHeader> parseAttachmentHeaders(GroupId g, private List<AttachmentHeader> parseAttachmentHeaders(GroupId g,

View File

@@ -300,6 +300,13 @@ abstract class AbstractProtocolEngine<S extends Session<?>>
return max(s.getLocalTimestamp(), s.getInviteTimestamp()); 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, private void sendMessage(Transaction txn, Message m, MessageType type,
GroupId privateGroupId, boolean visibleInConversation, GroupId privateGroupId, boolean visibleInConversation,
long autoDeleteTimer) throws DbException { long autoDeleteTimer) throws DbException {

View File

@@ -201,6 +201,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Share the private group with the contact // Share the private group with the contact
setPrivateGroupVisibility(txn, s, SHARED); setPrivateGroupVisibility(txn, s, SHARED);
// Broadcast an event // Broadcast an event
@@ -226,6 +228,8 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast an event // Broadcast an event
ContactId contactId = ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId()); clientHelper.getContactId(txn, m.getContactGroupId());

View File

@@ -251,6 +251,8 @@ class InviteeProtocolEngine extends AbstractProtocolEngine<InviteeSession> {
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast an event // Broadcast an event
PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup( PrivateGroup privateGroup = privateGroupFactory.createPrivateGroup(
m.getGroupName(), m.getCreator(), m.getSalt()); m.getGroupName(), m.getCreator(), m.getSalt());

View File

@@ -360,6 +360,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast an event // Broadcast an event
ContactId contactId = ContactId contactId =
clientHelper.getContactId(txn, s.getContactGroupId()); clientHelper.getContactId(txn, s.getContactGroupId());
@@ -385,6 +387,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Share the shareable with the contact // Share the shareable with the contact
setShareableVisibility(txn, s, SHARED); setShareableVisibility(txn, s, SHARED);
// Broadcast an event // Broadcast an event
@@ -432,6 +436,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Broadcast an event // Broadcast an event
ContactId contactId = ContactId contactId =
clientHelper.getContactId(txn, m.getContactGroupId()); clientHelper.getContactId(txn, m.getContactGroupId());
@@ -485,6 +491,8 @@ abstract class ProtocolEngineImpl<S extends Shareable>
// Track the message // Track the message
messageTracker.trackMessage(txn, m.getContactGroupId(), messageTracker.trackMessage(txn, m.getContactGroupId(),
m.getTimestamp(), false); m.getTimestamp(), false);
// Receive the auto-delete timer
receiveAutoDeleteTimer(txn, m);
// Make the shareable invisible (not actually needed in REMOTE_HANGING) // Make the shareable invisible (not actually needed in REMOTE_HANGING)
try { try {
setShareableVisibility(txn, s, INVISIBLE); setShareableVisibility(txn, s, INVISIBLE);
@@ -719,6 +727,13 @@ abstract class ProtocolEngineImpl<S extends Shareable>
return max(s.getLocalTimestamp(), s.getInviteTimestamp()); 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) private ContactId getContactId(Transaction txn, GroupId contactGroupId)
throws DbException { throws DbException {
try { try {

View File

@@ -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.briarproject.briar.autodelete.AutoDeleteConstants.NO_PREVIOUS_TIMER;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
// Thank you, I'm using them for readability @SuppressWarnings("UnnecessaryLocalVariable") // Using them for readability
@SuppressWarnings("UnnecessaryLocalVariable")
public class AutoDeleteManagerImplTest extends BrambleMockTestCase { public class AutoDeleteManagerImplTest extends BrambleMockTestCase {
private final DatabaseComponent db = context.mock(DatabaseComponent.class); private final DatabaseComponent db = context.mock(DatabaseComponent.class);

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.messaging;
import org.briarproject.bramble.BrambleCoreIntegrationTestEagerSingletons; import org.briarproject.bramble.BrambleCoreIntegrationTestEagerSingletons;
import org.briarproject.bramble.BrambleCoreModule; import org.briarproject.bramble.BrambleCoreModule;
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule; import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
import org.briarproject.briar.autodelete.AutoDeleteModule;
import org.briarproject.briar.avatar.AvatarModule; import org.briarproject.briar.avatar.AvatarModule;
import org.briarproject.briar.client.BriarClientModule; import org.briarproject.briar.client.BriarClientModule;
import org.briarproject.briar.forum.ForumModule; import org.briarproject.briar.forum.ForumModule;
@@ -17,6 +18,7 @@ import dagger.Component;
BrambleCoreIntegrationTestModule.class, BrambleCoreIntegrationTestModule.class,
BrambleCoreModule.class, BrambleCoreModule.class,
BriarClientModule.class, BriarClientModule.class,
AutoDeleteModule.class,
AvatarModule.class, AvatarModule.class,
ForumModule.class, ForumModule.class,
IdentityModule.class, IdentityModule.class,

View File

@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule; import org.briarproject.bramble.test.BrambleCoreIntegrationTestModule;
import org.briarproject.briar.api.messaging.MessagingManager; import org.briarproject.briar.api.messaging.MessagingManager;
import org.briarproject.briar.api.messaging.PrivateMessageFactory; import org.briarproject.briar.api.messaging.PrivateMessageFactory;
import org.briarproject.briar.autodelete.AutoDeleteModule;
import org.briarproject.briar.client.BriarClientModule; import org.briarproject.briar.client.BriarClientModule;
import javax.inject.Singleton; import javax.inject.Singleton;
@@ -18,6 +19,7 @@ import dagger.Component;
@Singleton @Singleton
@Component(modules = { @Component(modules = {
AutoDeleteModule.class,
BrambleCoreIntegrationTestModule.class, BrambleCoreIntegrationTestModule.class,
BrambleCoreModule.class, BrambleCoreModule.class,
BriarClientModule.class, BriarClientModule.class,

View File

@@ -153,7 +153,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
if (visible) expectGetTimestampForVisibleMessage(messageTimestamp); if (visible) expectGetTimestampForVisibleMessage(messageTimestamp);
else expectGetTimestampForInvisibleMessage(messageTimestamp); else expectGetTimestampForInvisibleMessage(messageTimestamp);
expectCheckWhetherContactSupportsAutoDeletion(); expectCheckWhetherContactSupportsAutoDeletion();
if (visible) expectGetAutoDeleteTimer(); if (visible) expectGetAutoDeleteTimer(messageTimestamp);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder).encodeJoinMessage(m.getContactGroupId(), oneOf(messageEncoder).encodeJoinMessage(m.getContactGroupId(),
m.getPrivateGroupId(), m.getTimestamp(), m.getPrivateGroupId(), m.getTimestamp(),
@@ -167,7 +167,7 @@ abstract class AbstractProtocolEngineTest extends BrambleMockTestCase {
if (visible) expectGetTimestampForVisibleMessage(messageTimestamp); if (visible) expectGetTimestampForVisibleMessage(messageTimestamp);
else expectGetTimestampForInvisibleMessage(messageTimestamp); else expectGetTimestampForInvisibleMessage(messageTimestamp);
expectCheckWhetherContactSupportsAutoDeletion(); expectCheckWhetherContactSupportsAutoDeletion();
if (visible) expectGetAutoDeleteTimer(); if (visible) expectGetAutoDeleteTimer(messageTimestamp);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageEncoder).encodeLeaveMessage(contactGroupId, oneOf(messageEncoder).encodeLeaveMessage(contactGroupId,
privateGroupId, messageTimestamp, lastLocalMessageId, 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() {{ context.checking(new Expectations() {{
oneOf(autoDeleteManager).getAutoDeleteTimer(txn, contactId, oneOf(autoDeleteManager).getAutoDeleteTimer(txn, contactId,
localTimestamp); timestamp);
will(returnValue(NO_AUTO_DELETE_TIMER)); 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());
}});
}
} }

View File

@@ -308,11 +308,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
expectSendJoinMessage(properJoinMessage, false); expectSendJoinMessage(properJoinMessage, false);
expectMarkMessageVisibleInUi(properJoinMessage.getId()); expectMarkMessageVisibleInUi(properJoinMessage.getId());
context.checking(new Expectations() {{ expectTrackUnreadMessage(properJoinMessage.getTimestamp());
oneOf(messageTracker) expectReceiveAutoDeleteTimer(properJoinMessage);
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false);
}});
expectGetContactId(); expectGetContactId();
expectSetPrivateGroupVisibility(SHARED); expectSetPrivateGroupVisibility(SHARED);
CreatorSession newSession = CreatorSession newSession =
@@ -399,11 +396,8 @@ public class CreatorProtocolEngineTest extends AbstractProtocolEngineTest {
CreatorSession session = getDefaultSession(INVITED); CreatorSession session = getDefaultSession(INVITED);
expectMarkMessageVisibleInUi(properLeaveMessage.getId()); expectMarkMessageVisibleInUi(properLeaveMessage.getId());
context.checking(new Expectations() {{ expectTrackUnreadMessage(properLeaveMessage.getTimestamp());
oneOf(messageTracker) expectReceiveAutoDeleteTimer(properLeaveMessage);
.trackMessage(txn, contactGroupId, inviteTimestamp + 1,
false);
}});
expectGetContactId(); expectGetContactId();
CreatorSession newSession = CreatorSession newSession =
engine.onLeaveMessage(txn, session, properLeaveMessage); engine.onLeaveMessage(txn, session, properLeaveMessage);

View File

@@ -366,9 +366,9 @@ public class InviteeProtocolEngineTest extends AbstractProtocolEngineTest {
}}); }});
expectMarkMessageVisibleInUi(properInviteMessage.getId()); expectMarkMessageVisibleInUi(properInviteMessage.getId());
expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true); expectMarkMessageAvailableToAnswer(properInviteMessage.getId(), true);
expectTrackUnreadMessage(properInviteMessage.getTimestamp());
expectReceiveAutoDeleteTimer(properInviteMessage);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(messageTracker).trackMessage(txn, contactGroupId,
properInviteMessage.getTimestamp(), false);
oneOf(privateGroupFactory) oneOf(privateGroupFactory)
.createPrivateGroup(properInviteMessage.getGroupName(), .createPrivateGroup(properInviteMessage.getGroupName(),
properInviteMessage.getCreator(), properInviteMessage.getCreator(),