Factor MessageTracker out of BdfIncomingMessageHook.

This commit is contained in:
akwizgran
2016-11-11 16:55:06 +00:00
parent ab16ee7465
commit aa210fc555
46 changed files with 628 additions and 379 deletions

View File

@@ -1,14 +1,15 @@
package org.briarproject.api.clients;
import org.briarproject.api.FormatException;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Metadata;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.InvalidMessageException;
import org.briarproject.api.sync.MessageContext;
@NotNullByDefault
public interface MessageQueueManager {
/**
@@ -52,17 +53,17 @@ public interface MessageQueueManager {
*
* @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 FormatException is thrown,
* whereas if an InvalidMessageException is thrown,
* the message will be permanently invalidated.
* @throws FormatException for any non-database error
* @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).
* Never rethrow DbException as FormatException!
* Never rethrow DbException as InvalidMessageException!
*/
void incomingMessage(Transaction txn, QueueMessage q, Metadata meta)
throws DbException, FormatException;
throws DbException, InvalidMessageException;
}
}

View File

@@ -1,9 +1,13 @@
package org.briarproject.api.clients;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
@NotNullByDefault
public interface MessageTracker {
/**
@@ -13,11 +17,34 @@ public interface MessageTracker {
GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group counts in g.
* Gets the number of visible and unread messages in the group
* as well as the timestamp of the latest message
**/
GroupCount getGroupCount(Transaction txn, GroupId g) throws DbException;
/**
* Updates the group count for the given incoming message.
*/
void trackIncomingMessage(Transaction txn, Message m) throws DbException;
/**
* Updates the group count for the given outgoing message.
*/
void trackOutgoingMessage(Transaction txn, Message m) throws DbException;
/**
* Updates the group count for the given message.
*/
void trackMessage(Transaction txn, GroupId g, long timestamp, boolean read)
throws DbException;
/**
* Marks a message as read or unread and updates the group count.
*/
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
class GroupCount {
private final int msgCount, unreadCount;
private final long latestMsgTime;

View File

@@ -1,10 +1,11 @@
package org.briarproject.api.forum;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
@@ -12,43 +13,76 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
public interface ForumManager extends MessageTracker {
@NotNullByDefault
public interface ForumManager {
/** The unique ID of the forum client. */
/**
* The unique ID of the forum client.
*/
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum");
/** Subscribes to a forum. */
/**
* Subscribes to a forum.
*/
Forum addForum(String name) throws DbException;
/** Unsubscribes from a forum. */
/**
* Unsubscribes from a forum.
*/
void removeForum(Forum f) throws DbException;
/** Creates a local forum post. */
/**
* Creates a local forum post.
*/
@CryptoExecutor
ForumPost createLocalPost(GroupId groupId, String body, long timestamp,
@Nullable MessageId parentId, LocalAuthor author);
/** Stores a local forum post. */
/**
* Stores a local forum post.
*/
ForumPostHeader addLocalPost(ForumPost p) throws DbException;
/** Returns the forum with the given ID. */
/**
* Returns the forum with the given ID.
*/
Forum getForum(GroupId g) throws DbException;
/** Returns the forum with the given ID. */
/**
* Returns the forum with the given ID.
*/
Forum getForum(Transaction txn, GroupId g) throws DbException;
/** Returns all forums to which the user subscribes. */
/**
* Returns all forums to which the user subscribes.
*/
Collection<Forum> getForums() throws DbException;
/** Returns the body of the forum post with the given ID. */
/**
* Returns the body of the forum post with the given ID.
*/
String getPostBody(MessageId m) throws DbException;
/** Returns the headers of all posts in the given forum. */
/**
* Returns the headers of all posts in the given forum.
*/
Collection<ForumPostHeader> getPostHeaders(GroupId g) throws DbException;
/** Registers a hook to be called whenever a forum is removed. */
/**
* Registers a hook to be called whenever a forum is removed.
*/
void registerRemoveForumHook(RemoveForumHook hook);
/**
* Returns the group count for the given forum.
*/
GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group count.
*/
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
interface RemoveForumHook {
void removingForum(Transaction txn, Forum f) throws DbException;
}

View File

@@ -1,16 +1,18 @@
package org.briarproject.api.introduction;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import java.util.Collection;
public interface IntroductionManager extends MessageTracker {
@NotNullByDefault
public interface IntroductionManager extends ConversationClient {
/** The unique ID of the introduction client. */
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.introduction");

View File

@@ -1,10 +1,16 @@
package org.briarproject.api.messaging;
import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
@NotNullByDefault
public interface ConversationManager {
/**
@@ -13,11 +19,19 @@ public interface ConversationManager {
*/
void registerConversationClient(ConversationClient client);
/** Get the unified group count for all private conversation messages. */
GroupCount getGroupCount(ContactId contactId) throws DbException;
/**
* Get the unified group count for all private conversation messages.
*/
GroupCount getGroupCount(ContactId c) throws DbException;
interface ConversationClient {
GroupCount getGroupCount(Transaction txn, ContactId contactId)
Group getContactGroup(Contact c);
GroupCount getGroupCount(Transaction txn, ContactId c)
throws DbException;
void setReadFlag(GroupId g, MessageId m, boolean read)
throws DbException;
}

View File

@@ -1,15 +1,17 @@
package org.briarproject.api.messaging;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import java.util.Collection;
public interface MessagingManager extends MessageTracker {
@NotNullByDefault
public interface MessagingManager extends ConversationClient {
/** The unique ID of the messaging client. */
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.messaging");

View File

@@ -1,7 +1,7 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.MessageTracker.GroupCount;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.identity.Author;
@@ -14,7 +14,7 @@ import org.briarproject.api.sync.MessageId;
import java.util.Collection;
@NotNullByDefault
public interface PrivateGroupManager extends MessageTracker {
public interface PrivateGroupManager {
/**
* The unique ID of the private group client.
@@ -24,9 +24,9 @@ public interface PrivateGroupManager extends MessageTracker {
/**
* Adds a new private group and joins it.
*
* @param group The private group to add
* @param joinMsg The creators's join message
* @param creator True if the group is added by its creator
* @param group The private group to add
* @param joinMsg The creators's join message
* @param creator True if the group is added by its creator
*/
void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg,
boolean creator) throws DbException;
@@ -34,9 +34,9 @@ public interface PrivateGroupManager extends MessageTracker {
/**
* Adds a new private group and joins it.
*
* @param group The private group to add
* @param joinMsg The new member's join message
* @param creator True if the group is added by its creator
* @param group The private group to add
* @param joinMsg The new member's join message
* @param creator True if the group is added by its creator
*/
void addPrivateGroup(Transaction txn, PrivateGroup group,
GroupMessage joinMsg, boolean creator) throws DbException;
@@ -107,13 +107,23 @@ public interface PrivateGroupManager extends MessageTracker {
*/
boolean isMember(Transaction txn, GroupId g, Author a) throws DbException;
/**
* Returns the group count for the given group.
*/
GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group count.
*/
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
/**
* This method needs to be called when a contact relationship
* has been revealed between the user and the Author with AuthorId a
* in the Group identified by the GroupId g.
*
* @param byContact true if the remote contact has revealed
* the relationship first. Otherwise false.
* the relationship first. Otherwise false.
*/
void relationshipRevealed(Transaction txn, GroupId g, AuthorId a,
boolean byContact) throws FormatException, DbException;

View File

@@ -1,15 +1,18 @@
package org.briarproject.api.sharing;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.ConversationManager.ConversationClient;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import java.util.Collection;
public interface SharingManager<S extends Shareable> extends MessageTracker {
@NotNullByDefault
public interface SharingManager<S extends Shareable>
extends ConversationClient {
/**
* Sends an invitation to share the given group with the given contact

View File

@@ -1,5 +1,8 @@
package org.briarproject.api.sync;
import org.briarproject.api.nullsafety.NotNullByDefault;
@NotNullByDefault
public interface MessageFactory {
Message createMessage(GroupId g, long timestamp, byte[] body);

View File

@@ -3,11 +3,13 @@ package org.briarproject.api.sync;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Metadata;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
/**
* Responsible for managing message validators and passing them messages to
* validate.
*/
@NotNullByDefault
public interface ValidationManager {
enum State {