mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Allow sync clients to defer delivery of messages.
This commit is contained in:
@@ -40,6 +40,7 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.briar.api.attachment.MediaConstants.MSG_KEY_CONTENT_TYPE;
|
||||
import static org.briarproject.briar.avatar.AvatarConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.briar.avatar.AvatarConstants.MSG_KEY_VERSION;
|
||||
@@ -124,8 +125,8 @@ class AvatarManagerImpl implements AvatarManager, OpenDatabaseHook, ContactHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||
throws DbException, InvalidMessageException {
|
||||
public DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
Metadata meta) throws DbException, InvalidMessageException {
|
||||
Group ourGroup = getOurGroup(txn);
|
||||
if (m.getGroupId().equals(ourGroup.getId())) {
|
||||
throw new InvalidMessageException(
|
||||
@@ -144,7 +145,7 @@ class AvatarManagerImpl implements AvatarManager, OpenDatabaseHook, ContactHook,
|
||||
// We've already received a newer update - delete this one
|
||||
db.deleteMessage(txn, m.getId());
|
||||
db.deleteMessageMetadata(txn, m.getId());
|
||||
return false; // don't broadcast update
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
}
|
||||
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||
@@ -155,7 +156,7 @@ class AvatarManagerImpl implements AvatarManager, OpenDatabaseHook, ContactHook,
|
||||
} catch (FormatException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,6 +50,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
|
||||
@@ -109,8 +111,9 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList list,
|
||||
BdfDictionary meta) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList list, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
|
||||
GroupId groupId = m.getGroupId();
|
||||
MessageType type = getMessageType(meta);
|
||||
@@ -138,7 +141,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
txn.attach(event);
|
||||
|
||||
// shares message and its dependencies
|
||||
return true;
|
||||
return ACCEPT_SHARE;
|
||||
} else if (type == WRAPPED_COMMENT) {
|
||||
// Check that the original message ID in the dependency's metadata
|
||||
// matches the original parent ID of the wrapped comment
|
||||
@@ -153,7 +156,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
}
|
||||
}
|
||||
// don't share message until parent arrives
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,6 +45,7 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
|
||||
@@ -75,8 +76,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||
BdfDictionary meta) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
|
||||
messageTracker.trackIncomingMessage(txn, m);
|
||||
|
||||
@@ -86,8 +88,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
new ForumPostReceivedEvent(m.getGroupId(), header, text);
|
||||
txn.attach(event);
|
||||
|
||||
// share message
|
||||
return true;
|
||||
return ACCEPT_SHARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,6 +56,7 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
|
||||
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
|
||||
@@ -171,8 +172,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||
BdfDictionary bdfMeta) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary bdfMeta)
|
||||
throws DbException, FormatException {
|
||||
// Parse the metadata
|
||||
MessageMetadata meta = messageParser.parseMetadata(bdfMeta);
|
||||
// set the clean-up timer that will be started when message gets read
|
||||
@@ -213,7 +215,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
private IntroduceeSession createNewIntroduceeSession(Transaction txn,
|
||||
|
||||
@@ -63,6 +63,7 @@ import static java.util.Collections.emptyList;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
@@ -172,8 +173,8 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||
throws DbException, InvalidMessageException {
|
||||
public DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
Metadata meta) throws DbException, InvalidMessageException {
|
||||
try {
|
||||
BdfDictionary metaDict = metadataParser.parse(meta);
|
||||
// Message type is null for version 0.0 private messages
|
||||
@@ -193,8 +194,7 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
} catch (FormatException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
// Don't share message
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
private void incomingPrivateMessage(Transaction txn, Message m,
|
||||
|
||||
@@ -55,6 +55,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
||||
import static org.briarproject.briar.api.identity.AuthorInfo.Status.UNVERIFIED;
|
||||
import static org.briarproject.briar.api.identity.AuthorInfo.Status.VERIFIED;
|
||||
import static org.briarproject.briar.api.privategroup.MessageType.JOIN;
|
||||
@@ -518,18 +519,19 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||
BdfDictionary meta) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
|
||||
MessageType type =
|
||||
MessageType.valueOf(meta.getLong(KEY_TYPE).intValue());
|
||||
switch (type) {
|
||||
case JOIN:
|
||||
handleJoinMessage(txn, m, meta);
|
||||
return true;
|
||||
return ACCEPT_SHARE;
|
||||
case POST:
|
||||
handleGroupMessage(txn, m, meta);
|
||||
return true;
|
||||
return ACCEPT_SHARE;
|
||||
default:
|
||||
// the validator should only let valid types pass
|
||||
throw new RuntimeException("Unknown MessageType");
|
||||
|
||||
@@ -54,6 +54,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
|
||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||
@@ -147,8 +148,9 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||
BdfDictionary bdfMeta) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary bdfMeta)
|
||||
throws DbException, FormatException {
|
||||
// Parse the metadata
|
||||
MessageMetadata meta = messageParser.parseMetadata(bdfMeta);
|
||||
// set the clean-up timer that will be started when message gets read
|
||||
@@ -171,7 +173,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
private SessionId getSessionId(GroupId privateGroupId) {
|
||||
|
||||
@@ -49,6 +49,7 @@ import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.briar.sharing.MessageType.ABORT;
|
||||
import static org.briarproject.briar.sharing.MessageType.ACCEPT;
|
||||
@@ -133,8 +134,8 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||
BdfDictionary d) throws DbException, FormatException {
|
||||
protected DeliveryAction incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary d) throws DbException, FormatException {
|
||||
// Parse the metadata
|
||||
MessageMetadata meta = messageParser.parseMetadata(d);
|
||||
// set the clean-up timer that will be started when message gets read
|
||||
@@ -157,7 +158,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
}
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,6 +44,7 @@ import javax.annotation.Nullable;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
@@ -59,7 +60,6 @@ import static org.briarproject.briar.api.avatar.AvatarManager.MAJOR_VERSION;
|
||||
import static org.briarproject.briar.avatar.AvatarConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.briar.avatar.AvatarConstants.MSG_KEY_VERSION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@@ -196,7 +196,8 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
null);
|
||||
expectGetContactId(txn, contactGroupId, contact.getId());
|
||||
|
||||
assertFalse(avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
assertEquals(1, txn.getActions().size());
|
||||
Event event = ((EventAction) txn.getActions().get(0)).getEvent();
|
||||
AvatarUpdatedEvent avatarUpdatedEvent = (AvatarUpdatedEvent) event;
|
||||
@@ -230,7 +231,8 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
expectFindLatest(txn, contactGroupId, latestMsgId, latest);
|
||||
expectGetContactId(txn, contactGroupId, contact.getId());
|
||||
|
||||
assertFalse(avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
|
||||
// event to broadcast
|
||||
assertEquals(1, txn.getActions().size());
|
||||
@@ -260,7 +262,8 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
expectFindLatest(txn, contactGroupId, latestMsgId, latest);
|
||||
|
||||
assertFalse(avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
avatarManager.incomingMessage(txn, contactMsg, meta));
|
||||
|
||||
// no event to broadcast
|
||||
assertEquals(0, txn.getActions().size());
|
||||
@@ -271,7 +274,8 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
throws DbException, InvalidMessageException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
expectGetOurGroup(txn);
|
||||
avatarManager.incomingMessage(txn, ourMsg, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
avatarManager.incomingMessage(txn, ourMsg, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_SHARE;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
@@ -184,7 +185,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(verifiedInfo));
|
||||
}});
|
||||
|
||||
blogManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_SHARE,
|
||||
blogManager.incomingMessage(txn, message, body, meta));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
assertEquals(1, txn.getActions().size());
|
||||
@@ -225,7 +227,8 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(rssLocalAuthor));
|
||||
}});
|
||||
|
||||
blogManager.incomingMessage(txn, rssMessage, body, meta);
|
||||
assertEquals(ACCEPT_SHARE,
|
||||
blogManager.incomingMessage(txn, rssMessage, body, meta));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
assertEquals(1, txn.getActions().size());
|
||||
|
||||
@@ -47,6 +47,7 @@ import javax.annotation.Nullable;
|
||||
import static java.util.Arrays.asList;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
@@ -275,43 +276,50 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testIncomingFirstInviteMessage() throws Exception {
|
||||
expectFirstIncomingMessage(Role.INVITEE, INVITE);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingFirstJoinMessage() throws Exception {
|
||||
expectFirstIncomingMessage(Role.PEER, JOIN);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingInviteMessage() throws Exception {
|
||||
expectIncomingMessage(Role.INVITEE, INVITE);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingJoinMessage() throws Exception {
|
||||
expectIncomingMessage(Role.INVITEE, JOIN);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingJoinMessageForCreator() throws Exception {
|
||||
expectIncomingMessage(Role.CREATOR, JOIN);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingLeaveMessage() throws Exception {
|
||||
expectIncomingMessage(Role.INVITEE, LEAVE);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingAbortMessage() throws Exception {
|
||||
expectIncomingMessage(Role.INVITEE, ABORT);
|
||||
groupInvitationManager.incomingMessage(txn, message, body, meta);
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE, groupInvitationManager
|
||||
.incomingMessage(txn, message, body, meta));
|
||||
}
|
||||
|
||||
private void expectFirstIncomingMessage(Role role, MessageType type)
|
||||
|
||||
Reference in New Issue
Block a user