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

@@ -27,6 +27,7 @@ import org.briarproject.api.identity.Author.Status;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
@@ -69,6 +70,7 @@ import static org.briarproject.api.contact.ContactManager.AddContactHook;
import static org.briarproject.api.contact.ContactManager.RemoveContactHook;
import static org.briarproject.blogs.BlogPostValidator.authorToBdfDictionary;
@NotNullByDefault
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
AddContactHook, RemoveContactHook, Client {
@@ -127,10 +129,8 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override
public void removingContact(Transaction txn, Contact c) throws DbException {
if (c != null) {
Blog b = blogFactory.createBlog(c.getAuthor());
db.removeGroup(txn, b.getGroup());
}
Blog b = blogFactory.createBlog(c.getAuthor());
db.removeGroup(txn, b.getGroup());
}
@Override

View File

@@ -11,6 +11,7 @@ import org.briarproject.api.data.BdfEntry;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.sync.InvalidMessageException;
@@ -42,6 +43,7 @@ import static org.briarproject.api.blogs.MessageType.COMMENT;
import static org.briarproject.api.blogs.MessageType.POST;
import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
@NotNullByDefault
class BlogPostValidator extends BdfMessageValidator {
private final GroupFactory groupFactory;
@@ -76,10 +78,10 @@ class BlogPostValidator extends BdfMessageValidator {
addMessageMetadata(c, m.getTimestamp());
break;
case WRAPPED_POST:
c = validateWrappedPost(m, g, body);
c = validateWrappedPost(body);
break;
case WRAPPED_COMMENT:
c = validateWrappedComment(m, g, body);
c = validateWrappedComment(body);
break;
default:
throw new InvalidMessageException("Unknown Message Type");
@@ -164,8 +166,8 @@ class BlogPostValidator extends BdfMessageValidator {
return new BdfMessageContext(meta, dependencies);
}
private BdfMessageContext validateWrappedPost(Message m, Group g,
BdfList body) throws InvalidMessageException, FormatException {
private BdfMessageContext validateWrappedPost(BdfList body)
throws InvalidMessageException, FormatException {
// p_group descriptor, p_timestamp, p_content, p_signature
checkSize(body, 4);
@@ -202,8 +204,8 @@ class BlogPostValidator extends BdfMessageValidator {
return new BdfMessageContext(meta);
}
private BdfMessageContext validateWrappedComment(Message m, Group g,
BdfList body) throws InvalidMessageException, FormatException {
private BdfMessageContext validateWrappedComment(BdfList body)
throws InvalidMessageException, FormatException {
// c_group descriptor, c_timestamp, c_comment, c_parent_original_id,
// c_parent_id, c_signature, parent_id