mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Introduce a MessageContext class for more flexibility
This change will allow to pass message dependencies from the client validators to the ValidationManager.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package org.briarproject.api.clients;
|
||||
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.sync.BaseMessageContext;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class BdfMessageContext extends BaseMessageContext {
|
||||
|
||||
private final BdfDictionary dictionary;
|
||||
|
||||
public BdfMessageContext(BdfDictionary dictionary,
|
||||
Collection<MessageId> dependencies) {
|
||||
|
||||
super(dependencies);
|
||||
this.dictionary = dictionary;
|
||||
}
|
||||
|
||||
public BdfMessageContext(BdfDictionary dictionary) {
|
||||
this(dictionary, null);
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary() {
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import org.briarproject.api.db.Metadata;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.InvalidMessageException;
|
||||
import org.briarproject.api.sync.MessageContext;
|
||||
|
||||
public interface MessageQueueManager {
|
||||
|
||||
@@ -34,10 +36,11 @@ public interface MessageQueueManager {
|
||||
interface QueueMessageValidator {
|
||||
|
||||
/**
|
||||
* Validates the given message and returns its metadata if the message
|
||||
* is valid, or null if the message is invalid.
|
||||
* Validates the given message and returns its metadata and
|
||||
* dependencies.
|
||||
*/
|
||||
Metadata validateMessage(QueueMessage q, Group g);
|
||||
MessageContext validateMessage(QueueMessage q, Group g)
|
||||
throws InvalidMessageException;
|
||||
}
|
||||
|
||||
interface IncomingQueueMessageHook {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.api.sync;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class BaseMessageContext {
|
||||
|
||||
private final Collection<MessageId> dependencies;
|
||||
|
||||
public BaseMessageContext(Collection<MessageId> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
||||
public Collection<MessageId> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.sync;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** An exception that indicates an invalid message. */
|
||||
public class InvalidMessageException extends IOException {
|
||||
|
||||
public InvalidMessageException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidMessageException(String str) {
|
||||
super(str);
|
||||
}
|
||||
|
||||
public InvalidMessageException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
}
|
||||
26
briar-api/src/org/briarproject/api/sync/MessageContext.java
Normal file
26
briar-api/src/org/briarproject/api/sync/MessageContext.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.briarproject.api.sync;
|
||||
|
||||
import org.briarproject.api.db.Metadata;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class MessageContext extends BaseMessageContext {
|
||||
|
||||
private final Metadata metadata;
|
||||
|
||||
public MessageContext(Metadata metadata,
|
||||
Collection<MessageId> dependencies) {
|
||||
|
||||
super(dependencies);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
public MessageContext(Metadata metadata) {
|
||||
this(metadata, null);
|
||||
}
|
||||
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,10 +44,11 @@ public interface ValidationManager {
|
||||
interface MessageValidator {
|
||||
|
||||
/**
|
||||
* Validates the given message and returns its metadata if the message
|
||||
* is valid, or null if the message is invalid.
|
||||
* Validates the given message and returns its metadata and
|
||||
* dependencies.
|
||||
*/
|
||||
Metadata validateMessage(Message m, Group g);
|
||||
MessageContext validateMessage(Message m, Group g)
|
||||
throws InvalidMessageException;
|
||||
}
|
||||
|
||||
interface IncomingMessageHook {
|
||||
|
||||
Reference in New Issue
Block a user