Unverified Commit efa06527 authored by akwizgran's avatar akwizgran
Browse files

Moved validation interfaces into respective managers.

parent d308a30d
......@@ -31,7 +31,21 @@ public interface MessageQueueManager {
*/
void registerIncomingMessageHook(ClientId c, IncomingQueueMessageHook hook);
interface QueueMessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
*/
Metadata validateMessage(QueueMessage q, Group g);
}
interface IncomingQueueMessageHook {
/**
* Called once for each incoming message that passes validation.
* Messages are passed to the hook in order.
*/
void incomingMessage(Transaction txn, QueueMessage q, Metadata meta)
throws DbException;
}
......
package org.briarproject.api.clients;
import org.briarproject.api.db.Metadata;
import org.briarproject.api.sync.Group;
public interface QueueMessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
*/
Metadata validateMessage(QueueMessage q, Group g);
}
package org.briarproject.api.sync;
import org.briarproject.api.db.Metadata;
public interface MessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
*/
Metadata validateMessage(Message m, Group g);
}
......@@ -41,7 +41,20 @@ public interface ValidationManager {
*/
void registerIncomingMessageHook(ClientId c, IncomingMessageHook hook);
interface MessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
*/
Metadata validateMessage(Message m, Group g);
}
interface IncomingMessageHook {
/**
* Called once for each incoming message that passes validation.
*/
void incomingMessage(Transaction txn, Message m, Metadata meta)
throws DbException;
}
......
......@@ -2,15 +2,15 @@ package org.briarproject.clients;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.ClientHelper;
import org.briarproject.api.clients.MessageQueueManager.QueueMessageValidator;
import org.briarproject.api.clients.QueueMessage;
import org.briarproject.api.clients.QueueMessageValidator;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.db.Metadata;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageValidator;
import org.briarproject.api.sync.ValidationManager.MessageValidator;
import org.briarproject.api.system.Clock;
import org.briarproject.util.StringUtils;
......@@ -104,7 +104,7 @@ public abstract class BdfMessageValidator implements MessageValidator,
}
protected void checkSize(BdfList list, int minSize, int maxSize)
throws FormatException {
throws FormatException {
if (list != null) {
if (list.size() < minSize) throw new FormatException();
if (list.size() > maxSize) throw new FormatException();
......
......@@ -5,7 +5,6 @@ import org.briarproject.api.clients.ClientHelper;
import org.briarproject.api.clients.MessageQueueManager;
import org.briarproject.api.clients.QueueMessage;
import org.briarproject.api.clients.QueueMessageFactory;
import org.briarproject.api.clients.QueueMessageValidator;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.db.DatabaseComponent;
......@@ -17,7 +16,6 @@ import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageValidator;
import org.briarproject.api.sync.ValidationManager;
import org.briarproject.api.sync.ValidationManager.IncomingMessageHook;
import org.briarproject.util.ByteUtils;
......@@ -146,7 +144,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
}
private static class DelegatingMessageValidator
implements MessageValidator {
implements ValidationManager.MessageValidator {
private final QueueMessageValidator delegate;
......
......@@ -20,7 +20,6 @@ import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageValidator;
import org.briarproject.api.sync.ValidationManager;
import org.briarproject.util.ByteUtils;
......@@ -74,7 +73,8 @@ class ValidationManagerImpl implements ValidationManager, Service,
}
@Override
public void registerIncomingMessageHook(ClientId c, IncomingMessageHook hook) {
public void registerIncomingMessageHook(ClientId c,
IncomingMessageHook hook) {
hooks.put(c, hook);
}
......
......@@ -16,8 +16,8 @@ import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageValidator;
import org.briarproject.api.sync.ValidationManager.IncomingMessageHook;
import org.briarproject.api.sync.ValidationManager.MessageValidator;
import org.briarproject.util.ByteUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
......@@ -56,7 +56,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
final Executor dbExecutor = new ImmediateExecutor();
final Executor cryptoExecutor = new ImmediateExecutor();
final MessageValidator validator = context.mock(MessageValidator.class);
final IncomingMessageHook hook = context.mock(IncomingMessageHook.class);
final IncomingMessageHook hook =
context.mock(IncomingMessageHook.class);
final Transaction txn = new Transaction(null);
final Transaction txn1 = new Transaction(null);
final Transaction txn2 = new Transaction(null);
......@@ -124,7 +125,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
final Executor dbExecutor = new ImmediateExecutor();
final Executor cryptoExecutor = new ImmediateExecutor();
final MessageValidator validator = context.mock(MessageValidator.class);
final IncomingMessageHook hook = context.mock(IncomingMessageHook.class);
final IncomingMessageHook hook =
context.mock(IncomingMessageHook.class);
final Transaction txn = new Transaction(null);
final Transaction txn1 = new Transaction(null);
final Transaction txn2 = new Transaction(null);
......@@ -177,7 +179,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
final Executor dbExecutor = new ImmediateExecutor();
final Executor cryptoExecutor = new ImmediateExecutor();
final MessageValidator validator = context.mock(MessageValidator.class);
final IncomingMessageHook hook = context.mock(IncomingMessageHook.class);
final IncomingMessageHook hook =
context.mock(IncomingMessageHook.class);
final Transaction txn = new Transaction(null);
final Transaction txn1 = new Transaction(null);
final Transaction txn2 = new Transaction(null);
......@@ -232,7 +235,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
final Executor dbExecutor = new ImmediateExecutor();
final Executor cryptoExecutor = new ImmediateExecutor();
final MessageValidator validator = context.mock(MessageValidator.class);
final IncomingMessageHook hook = context.mock(IncomingMessageHook.class);
final IncomingMessageHook hook =
context.mock(IncomingMessageHook.class);
final Transaction txn = new Transaction(null);
final Transaction txn1 = new Transaction(null);
context.checking(new Expectations() {{
......@@ -272,7 +276,8 @@ public class ValidationManagerImplTest extends BriarTestCase {
final Executor dbExecutor = new ImmediateExecutor();
final Executor cryptoExecutor = new ImmediateExecutor();
final MessageValidator validator = context.mock(MessageValidator.class);
final IncomingMessageHook hook = context.mock(IncomingMessageHook.class);
final IncomingMessageHook hook =
context.mock(IncomingMessageHook.class);
ValidationManagerImpl vm = new ValidationManagerImpl(db, dbExecutor,
cryptoExecutor);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment