mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Allow sync clients to defer delivery of messages.
This commit is contained in:
@@ -32,28 +32,31 @@ public abstract class BdfIncomingMessageHook implements IncomingMessageHook {
|
||||
|
||||
/**
|
||||
* Called once for each incoming message that passes validation.
|
||||
* <p>
|
||||
* If an unexpected exception occurs while handling data that is assumed
|
||||
* to be valid (e.g. locally created metadata), it may be sensible to
|
||||
* rethrow the unexpected exception as a DbException so that delivery is
|
||||
* attempted again at next startup. This will allow delivery to succeed if
|
||||
* the unexpected exception was caused by a bug that has subsequently been
|
||||
* fixed.
|
||||
*
|
||||
* @param txn A read-write transaction
|
||||
* @return Whether or not this message should be shared
|
||||
* @throws DbException Should only be used for real database errors.
|
||||
* If this is thrown, delivery will be attempted again at next startup,
|
||||
* whereas if a FormatException is thrown, the message will be permanently
|
||||
* invalidated.
|
||||
* @throws FormatException Use this for any non-database error
|
||||
* that occurs while handling remotely created data.
|
||||
* This includes errors that occur while handling locally created data
|
||||
* in a context controlled by remotely created data
|
||||
* (for example, parsing the metadata of a dependency
|
||||
* of an incoming message).
|
||||
* Never rethrow DbException as FormatException!
|
||||
* @throws DbException if a database error occurs while delivering the
|
||||
* message. Delivery will be attempted again at next startup. Throwing
|
||||
* this exception has the same effect as returning
|
||||
* {@link DeliveryAction#DEFER}.
|
||||
* @throws FormatException if the message is invalid in the context of its
|
||||
* dependencies. The message and any dependents will be marked as invalid
|
||||
* and deleted along with their metadata. Throwing this exception has the
|
||||
* same effect as returning {@link DeliveryAction#REJECT}.
|
||||
*/
|
||||
protected abstract boolean incomingMessage(Transaction txn, Message m,
|
||||
BdfList body, BdfDictionary meta) throws DbException,
|
||||
FormatException;
|
||||
protected abstract DeliveryAction incomingMessage(Transaction txn,
|
||||
Message m, BdfList body, BdfDictionary meta)
|
||||
throws DbException, FormatException;
|
||||
|
||||
@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 {
|
||||
BdfList body = clientHelper.toList(m);
|
||||
BdfDictionary metaDictionary = metadataParser.parse(meta);
|
||||
|
||||
@@ -10,23 +10,54 @@ public interface IncomingMessageHook {
|
||||
|
||||
/**
|
||||
* Called once for each incoming message that passes validation.
|
||||
* <p>
|
||||
* If an unexpected exception occurs while handling data that is assumed
|
||||
* to be valid (e.g. locally created metadata), it may be sensible to
|
||||
* rethrow the unexpected exception as a DbException so that delivery is
|
||||
* attempted again at next startup. This will allow delivery to succeed if
|
||||
* the unexpected exception was caused by a bug that has subsequently been
|
||||
* fixed.
|
||||
*
|
||||
* @param txn A read-write transaction
|
||||
* @return Whether or not this message should be shared
|
||||
* @throws DbException Should only be used for real database errors.
|
||||
* If this is thrown, delivery will be attempted again at next startup,
|
||||
* whereas if an InvalidMessageException is thrown,
|
||||
* the message will be permanently invalidated.
|
||||
* @throws InvalidMessageException for any non-database error
|
||||
* that occurs while handling remotely created data.
|
||||
* This includes errors that occur while handling locally created data
|
||||
* in a context controlled by remotely created data
|
||||
* (for example, parsing the metadata of a dependency
|
||||
* of an incoming message).
|
||||
* Throwing this will delete the incoming message and its metadata
|
||||
* marking it as invalid in the database.
|
||||
* Never rethrow DbException as InvalidMessageException!
|
||||
* @throws DbException if a database error occurs while delivering the
|
||||
* message. Delivery will be attempted again at next startup. Throwing
|
||||
* this exception has the same effect as returning
|
||||
* {@link DeliveryAction#DEFER}.
|
||||
* @throws InvalidMessageException if the message is invalid in the context
|
||||
* of its dependencies. The message and any dependents will be marked as
|
||||
* invalid and deleted along with their metadata. Throwing this exception
|
||||
* has the same effect as returning {@link DeliveryAction#REJECT}.
|
||||
*/
|
||||
boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||
DeliveryAction incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||
throws DbException, InvalidMessageException;
|
||||
|
||||
enum DeliveryAction {
|
||||
|
||||
/**
|
||||
* The message and any dependent messages will be moved to the
|
||||
* {@link MessageState#INVALID INVALID state} and deleted, along with
|
||||
* their metadata.
|
||||
*/
|
||||
REJECT,
|
||||
|
||||
/**
|
||||
* The message will be moved to the
|
||||
* {@link MessageState#PENDING PENDING state}. Delivery will be
|
||||
* attempted again at next startup.
|
||||
*/
|
||||
DEFER,
|
||||
|
||||
/**
|
||||
* The message will be moved to the
|
||||
* {@link MessageState#DELIVERED DELIVERED state} and shared.
|
||||
*/
|
||||
ACCEPT_SHARE,
|
||||
|
||||
/**
|
||||
* The message will be moved to the
|
||||
* {@link MessageState#DELIVERED DELIVERED state} and will not be
|
||||
* shared.
|
||||
*/
|
||||
ACCEPT_DO_NOT_SHARE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import static org.briarproject.bramble.api.properties.TransportPropertyConstants
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MSG_KEY_TRANSPORT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MSG_KEY_VERSION;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.REFLECTED_PROPERTY_PREFIX;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
@Immutable
|
||||
@@ -115,8 +116,8 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
}
|
||||
|
||||
@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 {
|
||||
// Find the latest update for this transport, if any
|
||||
BdfDictionary d = metadataParser.parse(meta);
|
||||
@@ -131,14 +132,14 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
// We've already received a newer update - delete this one
|
||||
db.deleteMessage(txn, m.getId());
|
||||
db.deleteMessageMetadata(txn, m.getId());
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
}
|
||||
txn.attach(new RemoteTransportPropertiesUpdatedEvent(t));
|
||||
} catch (FormatException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.briarproject.bramble.api.sync.MessageContext;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.sync.event.MessageAddedEvent;
|
||||
import org.briarproject.bramble.api.sync.validation.IncomingMessageHook;
|
||||
import org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction;
|
||||
import org.briarproject.bramble.api.sync.validation.MessageState;
|
||||
import org.briarproject.bramble.api.sync.validation.MessageValidator;
|
||||
import org.briarproject.bramble.api.sync.validation.ValidationManager;
|
||||
@@ -40,6 +41,10 @@ import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
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.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.DEFER;
|
||||
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.REJECT;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.INVALID;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
|
||||
@@ -185,16 +190,19 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
int majorVersion = g.getMajorVersion();
|
||||
Metadata meta =
|
||||
db.getMessageMetadataForValidator(txn, id);
|
||||
DeliveryResult result =
|
||||
DeliveryAction action =
|
||||
deliverMessage(txn, m, c, majorVersion, meta);
|
||||
if (result.valid) {
|
||||
addPendingDependents(txn, id, pending);
|
||||
if (result.share) {
|
||||
db.setMessageShared(txn, id);
|
||||
toShare.addAll(states.keySet());
|
||||
}
|
||||
} else {
|
||||
if (action == REJECT) {
|
||||
invalidateMessage(txn, id);
|
||||
addDependentsToInvalidate(txn, id, invalidate);
|
||||
} else if (action == ACCEPT_SHARE) {
|
||||
db.setMessageState(txn, m.getId(), DELIVERED);
|
||||
addPendingDependents(txn, id, pending);
|
||||
db.setMessageShared(txn, id);
|
||||
toShare.addAll(states.keySet());
|
||||
} else if (action == ACCEPT_DO_NOT_SHARE) {
|
||||
db.setMessageState(txn, m.getId(), DELIVERED);
|
||||
addPendingDependents(txn, id, pending);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,16 +283,21 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
Metadata meta = context.getMetadata();
|
||||
db.mergeMessageMetadata(txn, id, meta);
|
||||
if (allDelivered) {
|
||||
DeliveryResult result =
|
||||
DeliveryAction action =
|
||||
deliverMessage(txn, m, c, majorVersion, meta);
|
||||
if (result.valid) {
|
||||
addPendingDependents(txn, id, pending);
|
||||
if (result.share) {
|
||||
db.setMessageShared(txn, id);
|
||||
toShare.addAll(dependencies);
|
||||
}
|
||||
} else {
|
||||
if (action == REJECT) {
|
||||
invalidateMessage(txn, id);
|
||||
addDependentsToInvalidate(txn, id, invalidate);
|
||||
} else if (action == DEFER) {
|
||||
db.setMessageState(txn, id, PENDING);
|
||||
} else if (action == ACCEPT_SHARE) {
|
||||
db.setMessageState(txn, id, DELIVERED);
|
||||
addPendingDependents(txn, id, pending);
|
||||
db.setMessageShared(txn, id);
|
||||
toShare.addAll(dependencies);
|
||||
} else if (action == ACCEPT_DO_NOT_SHARE) {
|
||||
db.setMessageState(txn, id, DELIVERED);
|
||||
addPendingDependents(txn, id, pending);
|
||||
}
|
||||
} else {
|
||||
db.setMessageState(txn, id, PENDING);
|
||||
@@ -304,23 +317,21 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
private DeliveryResult deliverMessage(Transaction txn, Message m,
|
||||
ClientId c, int majorVersion, Metadata meta) throws DbException {
|
||||
// Deliver the message to the client if it's registered a hook
|
||||
boolean shareMsg = false;
|
||||
private DeliveryAction deliverMessage(Transaction txn, Message m,
|
||||
ClientId c, int majorVersion, Metadata meta) {
|
||||
// Deliver the message to the client if it has registered a hook
|
||||
ClientMajorVersion cv = new ClientMajorVersion(c, majorVersion);
|
||||
IncomingMessageHook hook = hooks.get(cv);
|
||||
if (hook != null) {
|
||||
try {
|
||||
shareMsg = hook.incomingMessage(txn, m, meta);
|
||||
} catch (InvalidMessageException e) {
|
||||
logException(LOG, INFO, e);
|
||||
invalidateMessage(txn, m.getId());
|
||||
return new DeliveryResult(false, false);
|
||||
}
|
||||
if (hook == null) return ACCEPT_DO_NOT_SHARE;
|
||||
try {
|
||||
return hook.incomingMessage(txn, m, meta);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, INFO, e);
|
||||
return DEFER;
|
||||
} catch (InvalidMessageException e) {
|
||||
logException(LOG, INFO, e);
|
||||
return REJECT;
|
||||
}
|
||||
db.setMessageState(txn, m.getId(), DELIVERED);
|
||||
return new DeliveryResult(true, shareMsg);
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
@@ -447,14 +458,4 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeliveryResult {
|
||||
|
||||
private final boolean valid, share;
|
||||
|
||||
private DeliveryResult(boolean valid, boolean share) {
|
||||
this.valid = valid;
|
||||
this.share = share;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import static java.util.Collections.emptyList;
|
||||
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.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||
|
||||
@@ -173,8 +174,8 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
}
|
||||
|
||||
@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 {
|
||||
// Parse the new remote update
|
||||
Update newRemoteUpdate = parseUpdate(clientHelper.toList(m));
|
||||
@@ -187,7 +188,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
&& latest.remote.updateVersion > newRemoteUpdateVersion) {
|
||||
db.deleteMessage(txn, m.getId());
|
||||
db.deleteMessageMetadata(txn, m.getId());
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
// Load and parse the latest local update
|
||||
if (latest.local == null) throw new DbException();
|
||||
@@ -241,7 +242,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
||||
} catch (FormatException e) {
|
||||
throw new InvalidMessageException(e);
|
||||
}
|
||||
return false;
|
||||
return ACCEPT_DO_NOT_SHARE;
|
||||
}
|
||||
|
||||
private void storeClientVersions(Transaction txn,
|
||||
|
||||
@@ -43,6 +43,7 @@ import static org.briarproject.bramble.api.properties.TransportPropertyConstants
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
|
||||
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.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
@@ -230,7 +231,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
|
||||
TransportPropertyManagerImpl t = createInstance();
|
||||
assertFalse(t.incomingMessage(txn, message, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
t.incomingMessage(txn, message, meta));
|
||||
assertTrue(hasEvent(txn, RemoteTransportPropertiesUpdatedEvent.class));
|
||||
}
|
||||
|
||||
@@ -269,7 +271,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
|
||||
TransportPropertyManagerImpl t = createInstance();
|
||||
assertFalse(t.incomingMessage(txn, message, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
t.incomingMessage(txn, message, meta));
|
||||
assertTrue(hasEvent(txn, RemoteTransportPropertiesUpdatedEvent.class));
|
||||
}
|
||||
|
||||
@@ -308,7 +311,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
}});
|
||||
|
||||
TransportPropertyManagerImpl t = createInstance();
|
||||
assertFalse(t.incomingMessage(txn, message, meta));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
t.incomingMessage(txn, message, meta));
|
||||
assertFalse(hasEvent(txn, RemoteTransportPropertiesUpdatedEvent.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
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.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.INVALID;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
|
||||
@@ -111,7 +113,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the first message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
@@ -167,7 +169,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(new Metadata()));
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn, messageId);
|
||||
@@ -187,7 +189,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(metadata));
|
||||
// Deliver the dependent
|
||||
oneOf(hook).incomingMessage(txn1, message2, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId2, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId2);
|
||||
@@ -247,7 +249,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(true));
|
||||
will(returnValue(ACCEPT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
@@ -367,7 +369,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
@@ -432,7 +434,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
@@ -602,7 +604,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// The message has two pending dependents: 1 and 2
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
@@ -622,7 +624,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(metadata));
|
||||
// Deliver message 1
|
||||
oneOf(hook).incomingMessage(txn2, message1, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn2, messageId1, DELIVERED);
|
||||
// Message 1 has one pending dependent: 3
|
||||
oneOf(db).getMessageDependents(txn2, messageId1);
|
||||
@@ -642,7 +644,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(metadata));
|
||||
// Deliver message 2
|
||||
oneOf(hook).incomingMessage(txn3, message2, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn3, messageId2, DELIVERED);
|
||||
// Message 2 has one pending dependent: 3 (same dependent as 1)
|
||||
oneOf(db).getMessageDependents(txn3, messageId2);
|
||||
@@ -662,6 +664,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(metadata));
|
||||
// Deliver message 3
|
||||
oneOf(hook).incomingMessage(txn4, message3, metadata);
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn4, messageId3, DELIVERED);
|
||||
// Message 3 has one pending dependent: 4
|
||||
oneOf(db).getMessageDependents(txn4, messageId3);
|
||||
@@ -685,7 +688,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(metadata));
|
||||
// Deliver message 4
|
||||
oneOf(hook).incomingMessage(txn6, message4, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn6, messageId4, DELIVERED);
|
||||
// Message 4 has no pending dependents
|
||||
oneOf(db).getMessageDependents(txn6, messageId4);
|
||||
@@ -717,7 +720,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).mergeMessageMetadata(txn1, messageId, metadata);
|
||||
// Deliver the message
|
||||
oneOf(hook).incomingMessage(txn1, message, metadata);
|
||||
will(returnValue(false));
|
||||
will(returnValue(ACCEPT_DO_NOT_SHARE));
|
||||
oneOf(db).setMessageState(txn1, messageId, DELIVERED);
|
||||
// Get any pending dependents
|
||||
oneOf(db).getMessageDependents(txn1, messageId);
|
||||
|
||||
@@ -31,6 +31,7 @@ import static java.util.Collections.singletonMap;
|
||||
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.api.versioning.ClientVersioningManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MAJOR_VERSION;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
@@ -41,7 +42,6 @@ import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@@ -419,7 +419,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
ClientVersioningManagerImpl c = createInstance();
|
||||
c.registerClient(clientId, 123, 234, hook);
|
||||
assertFalse(c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -464,7 +465,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
ClientVersioningManagerImpl c = createInstance();
|
||||
c.registerClient(clientId, 123, 234, hook);
|
||||
assertFalse(c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -496,7 +498,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
ClientVersioningManagerImpl c = createInstance();
|
||||
c.registerClient(clientId, 123, 234, hook);
|
||||
assertFalse(c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -579,7 +582,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
ClientVersioningManagerImpl c = createInstance();
|
||||
c.registerClient(clientId, 123, 234, hook);
|
||||
assertFalse(c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -649,7 +653,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
ClientVersioningManagerImpl c = createInstance();
|
||||
c.registerClient(clientId, 123, 234, hook);
|
||||
assertFalse(c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
assertEquals(ACCEPT_DO_NOT_SHARE,
|
||||
c.incomingMessage(txn, newRemoteUpdate, new Metadata()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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