mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Address bugs and comments from reblogging code review
This commit is contained in:
@@ -12,8 +12,8 @@ import static org.briarproject.api.blogs.MessageType.WRAPPED_COMMENT;
|
||||
|
||||
public class BlogCommentHeader extends BlogPostHeader {
|
||||
|
||||
private String comment;
|
||||
private BlogPostHeader parent;
|
||||
private final String comment;
|
||||
private final BlogPostHeader parent;
|
||||
|
||||
public BlogCommentHeader(@NotNull MessageType type,
|
||||
@NotNull GroupId groupId, @Nullable String comment,
|
||||
@@ -36,7 +36,6 @@ public class BlogCommentHeader extends BlogPostHeader {
|
||||
return comment;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BlogPostHeader getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ public interface BlogConstants {
|
||||
String KEY_COMMENT = "comment";
|
||||
String KEY_ORIGINAL_MSG_ID = "originalMessageId";
|
||||
String KEY_ORIGINAL_PARENT_MSG_ID = "originalParentMessageId";
|
||||
String KEY_WRAPPED_MSG_ID = "wrappedMessageId";
|
||||
/**
|
||||
* This is the ID of either a message wrapped from a different group
|
||||
* or of a message from the same group that therefore needed no wrapping.
|
||||
*/
|
||||
String KEY_PARENT_MSG_ID = "parentMessageId";
|
||||
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ public interface BlogPostFactory {
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
/** Wraps a blog post */
|
||||
Message createWrappedPost(GroupId groupId, byte[] descriptor,
|
||||
Message wrapPost(GroupId groupId, byte[] descriptor,
|
||||
long timestamp, BdfList body)
|
||||
throws FormatException;
|
||||
|
||||
/** Re-wraps a previously wrapped post */
|
||||
Message createWrappedPost(GroupId groupId, BdfList body)
|
||||
Message rewrapWrappedPost(GroupId groupId, BdfList body)
|
||||
throws FormatException;
|
||||
|
||||
/** Wraps a blog comment */
|
||||
Message createWrappedComment(GroupId groupId, byte[] descriptor,
|
||||
Message wrapComment(GroupId groupId, byte[] descriptor,
|
||||
long timestamp, BdfList body, MessageId currentId)
|
||||
throws FormatException;
|
||||
|
||||
/** Re-wraps a previously wrapped comment */
|
||||
Message createWrappedComment(GroupId groupId, BdfList body,
|
||||
Message rewrapWrappedComment(GroupId groupId, BdfList body,
|
||||
MessageId currentId) throws FormatException;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ import static org.briarproject.api.blogs.BlogConstants.KEY_READ;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_TIMESTAMP;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_TIME_RECEIVED;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_TYPE;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_WRAPPED_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.api.blogs.MessageType.COMMENT;
|
||||
import static org.briarproject.api.blogs.MessageType.POST;
|
||||
import static org.briarproject.api.blogs.MessageType.WRAPPED_COMMENT;
|
||||
@@ -189,12 +189,12 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
BdfDictionary d = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, h.getParentId());
|
||||
byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID);
|
||||
byte[] original2 = meta.getRaw(KEY_ORIGINAL_MSG_ID);
|
||||
byte[] original2 = meta.getRaw(KEY_ORIGINAL_PARENT_MSG_ID);
|
||||
if (!Arrays.equals(original1, original2)) {
|
||||
throw new FormatException();
|
||||
}
|
||||
}
|
||||
// share dependencies recursively
|
||||
// share dependencies recursively - TODO remove with #598
|
||||
share(txn, h);
|
||||
|
||||
// broadcast event about new post or comment
|
||||
@@ -205,7 +205,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
// Check that the original message ID in the dependency's metadata
|
||||
// matches the original parent ID of the wrapped comment
|
||||
MessageId dependencyId =
|
||||
new MessageId(meta.getRaw(KEY_WRAPPED_MSG_ID));
|
||||
new MessageId(meta.getRaw(KEY_PARENT_MSG_ID));
|
||||
BdfDictionary d = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, dependencyId);
|
||||
byte[] original1 = d.getRaw(KEY_ORIGINAL_MSG_ID);
|
||||
@@ -305,7 +305,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
GroupId groupId = p.getMessage().getGroupId();
|
||||
MessageId postId = p.getMessage().getId();
|
||||
BlogPostHeader h =
|
||||
getPostHeaderFromMetadata(txn, 0, groupId, postId, meta);
|
||||
getPostHeaderFromMetadata(txn, groupId, postId, meta);
|
||||
BlogPostAddedEvent event =
|
||||
new BlogPostAddedEvent(groupId, h, true);
|
||||
txn.attach(event);
|
||||
@@ -316,37 +316,33 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
|
||||
@Override
|
||||
public void addLocalComment(LocalAuthor author, GroupId groupId,
|
||||
@Nullable String comment, BlogPostHeader wHeader)
|
||||
@Nullable String comment, BlogPostHeader pOriginalHeader)
|
||||
throws DbException {
|
||||
|
||||
if (wHeader.getType() != POST && wHeader.getType() != COMMENT)
|
||||
MessageType type = pOriginalHeader.getType();
|
||||
if (type != POST && type != COMMENT)
|
||||
throw new IllegalArgumentException("Comment on unknown type!");
|
||||
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
// Wrap post that we are commenting on
|
||||
MessageId wMessageId = wrapMessage(txn, 0, groupId, wHeader);
|
||||
MessageId parentId = wrapMessage(txn, groupId, pOriginalHeader);
|
||||
|
||||
// Get ID of original message
|
||||
MessageId originalId = wHeader.getId();
|
||||
if (wHeader.getType() != POST && wMessageId.equals(originalId)) {
|
||||
// we comment on a non-post message that needs no wrapping,
|
||||
// so get original message ID from it
|
||||
BdfDictionary d = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, wMessageId);
|
||||
originalId = new MessageId(d.getRaw(KEY_ORIGINAL_MSG_ID));
|
||||
}
|
||||
// Get ID of new parent's original message.
|
||||
// Assumes that pOriginalHeader is a POST or COMMENT
|
||||
MessageId pOriginalId = pOriginalHeader.getId();
|
||||
|
||||
// Create actual comment
|
||||
Message message = blogPostFactory
|
||||
.createBlogComment(groupId, author, comment, originalId,
|
||||
wMessageId);
|
||||
.createBlogComment(groupId, author, comment, pOriginalId,
|
||||
parentId);
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_TYPE, COMMENT.getInt());
|
||||
if (comment != null) meta.put(KEY_COMMENT, comment);
|
||||
meta.put(KEY_TIMESTAMP, message.getTimestamp());
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, wHeader.getId());
|
||||
meta.put(KEY_WRAPPED_MSG_ID, wMessageId);
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, message.getId());
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||
meta.put(KEY_PARENT_MSG_ID, parentId);
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(author));
|
||||
|
||||
// Send comment
|
||||
@@ -362,72 +358,75 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new DbException(e);
|
||||
throw new IllegalArgumentException("Invalid key of author", e);
|
||||
} finally {
|
||||
//noinspection ThrowFromFinallyBlock
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
private MessageId wrapMessage(Transaction txn, int level, GroupId groupId,
|
||||
BlogPostHeader wHeader)
|
||||
private MessageId wrapMessage(Transaction txn, GroupId groupId,
|
||||
BlogPostHeader pOriginalHeader)
|
||||
throws DbException, FormatException {
|
||||
|
||||
if (groupId.equals(wHeader.getGroupId())) {
|
||||
if (groupId.equals(pOriginalHeader.getGroupId())) {
|
||||
// We are trying to wrap a post that is already in our group.
|
||||
// This is unnecessary, so just return the post's MessageId
|
||||
return wHeader.getId();
|
||||
return pOriginalHeader.getId();
|
||||
}
|
||||
|
||||
// Get Group and Body of Message to be wrapped
|
||||
Group wGroup = db.getGroup(txn, wHeader.getGroupId());
|
||||
BdfList wBody = clientHelper.getMessageAsList(txn, wHeader.getId());
|
||||
byte[] wDescriptor = wGroup.getDescriptor();
|
||||
long wTimestamp = wHeader.getTimestamp();
|
||||
// Get body of message to be wrapped
|
||||
BdfList body =
|
||||
clientHelper.getMessageAsList(txn, pOriginalHeader.getId());
|
||||
long wTimestamp = pOriginalHeader.getTimestamp();
|
||||
Message wMessage;
|
||||
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
MessageType type = wHeader.getType();
|
||||
MessageType type = pOriginalHeader.getType();
|
||||
if (type == POST) {
|
||||
Group wGroup = db.getGroup(txn, pOriginalHeader.getGroupId());
|
||||
byte[] wDescriptor = wGroup.getDescriptor();
|
||||
// Wrap post
|
||||
wMessage = blogPostFactory
|
||||
.createWrappedPost(groupId, wDescriptor, wTimestamp, wBody);
|
||||
.wrapPost(groupId, wDescriptor, wTimestamp, body);
|
||||
meta.put(KEY_TYPE, WRAPPED_POST.getInt());
|
||||
} else if (type == COMMENT) {
|
||||
BlogCommentHeader wComment = (BlogCommentHeader) wHeader;
|
||||
Group wGroup = db.getGroup(txn, pOriginalHeader.getGroupId());
|
||||
byte[] wDescriptor = wGroup.getDescriptor();
|
||||
BlogCommentHeader wComment = (BlogCommentHeader) pOriginalHeader;
|
||||
MessageId wrappedId =
|
||||
wrapMessage(txn, ++level, groupId, wComment.getParent());
|
||||
wrapMessage(txn, groupId, wComment.getParent());
|
||||
// Wrap comment
|
||||
wMessage = blogPostFactory
|
||||
.createWrappedComment(groupId, wDescriptor, wTimestamp,
|
||||
wBody, wrappedId);
|
||||
.wrapComment(groupId, wDescriptor, wTimestamp,
|
||||
body, wrappedId);
|
||||
meta.put(KEY_TYPE, WRAPPED_COMMENT.getInt());
|
||||
if(wComment.getComment() != null)
|
||||
meta.put(KEY_COMMENT, wComment.getComment());
|
||||
meta.put(KEY_WRAPPED_MSG_ID, wrappedId);
|
||||
meta.put(KEY_PARENT_MSG_ID, wrappedId);
|
||||
} else if (type == WRAPPED_POST) {
|
||||
// Re-wrap wrapped post without adding another wrapping layer
|
||||
wMessage = blogPostFactory.createWrappedPost(groupId, wBody);
|
||||
wMessage = blogPostFactory.rewrapWrappedPost(groupId, body);
|
||||
meta.put(KEY_TYPE, WRAPPED_POST.getInt());
|
||||
} else if (type == WRAPPED_COMMENT) {
|
||||
BlogCommentHeader wComment = (BlogCommentHeader) wHeader;
|
||||
BlogCommentHeader wComment = (BlogCommentHeader) pOriginalHeader;
|
||||
MessageId wrappedId =
|
||||
wrapMessage(txn, ++level, groupId, wComment.getParent());
|
||||
wrapMessage(txn, groupId, wComment.getParent());
|
||||
// Re-wrap wrapped comment
|
||||
wMessage = blogPostFactory
|
||||
.createWrappedComment(groupId, wBody, wrappedId);
|
||||
.rewrapWrappedComment(groupId, body, wrappedId);
|
||||
meta.put(KEY_TYPE, WRAPPED_COMMENT.getInt());
|
||||
if(wComment.getComment() != null)
|
||||
meta.put(KEY_COMMENT, wComment.getComment());
|
||||
meta.put(KEY_WRAPPED_MSG_ID, wrappedId);
|
||||
meta.put(KEY_PARENT_MSG_ID, wrappedId);
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Unknown Message Type: " + type);
|
||||
}
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, wHeader.getId());
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(wHeader.getAuthor()));
|
||||
meta.put(KEY_TIMESTAMP, wHeader.getTimestamp());
|
||||
meta.put(KEY_TIME_RECEIVED, wHeader.getTimeReceived());
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, pOriginalHeader.getId());
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(pOriginalHeader.getAuthor()));
|
||||
meta.put(KEY_TIMESTAMP, pOriginalHeader.getTimestamp());
|
||||
meta.put(KEY_TIME_RECEIVED, pOriginalHeader.getTimeReceived());
|
||||
|
||||
// Send wrapped message and store metadata
|
||||
clientHelper.addLocalMessage(txn, wMessage, CLIENT_ID, meta, true);
|
||||
@@ -553,7 +552,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt())
|
||||
);
|
||||
|
||||
// TODO this could be optimized to re-use existing headers
|
||||
// TODO this could be optimized by looking up author status once (#625)
|
||||
|
||||
Collection<BlogPostHeader> headers = new ArrayList<BlogPostHeader>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
@@ -605,19 +604,13 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
}
|
||||
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||
GroupId groupId, MessageId id, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
return getPostHeaderFromMetadata(txn, 0, groupId, id, meta);
|
||||
}
|
||||
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, int level,
|
||||
GroupId groupId, MessageId id) throws DbException, FormatException {
|
||||
BdfDictionary meta =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, id);
|
||||
return getPostHeaderFromMetadata(txn, level, groupId, id, meta);
|
||||
return getPostHeaderFromMetadata(txn, groupId, id, meta);
|
||||
}
|
||||
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, int level,
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||
GroupId groupId, MessageId id, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
|
||||
@@ -637,9 +630,9 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
|
||||
if (type == COMMENT || type == WRAPPED_COMMENT) {
|
||||
String comment = meta.getOptionalString(KEY_COMMENT);
|
||||
MessageId parentId = new MessageId(meta.getRaw(KEY_WRAPPED_MSG_ID));
|
||||
MessageId parentId = new MessageId(meta.getRaw(KEY_PARENT_MSG_ID));
|
||||
BlogPostHeader parent =
|
||||
getPostHeaderFromMetadata(txn, ++level, groupId, parentId);
|
||||
getPostHeaderFromMetadata(txn, groupId, parentId);
|
||||
return new BlogCommentHeader(type, groupId, comment, parent, id,
|
||||
timestamp, timeReceived, author, authorStatus, read);
|
||||
} else {
|
||||
@@ -653,6 +646,8 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
return MessageType.valueOf(longType.intValue());
|
||||
}
|
||||
|
||||
// TODO remove when implementing #589
|
||||
@Deprecated
|
||||
private void share(Transaction txn, BlogPostHeader h) throws DbException {
|
||||
clientHelper.setMessageShared(txn, h.getId(), true);
|
||||
if (h instanceof BlogCommentHeader) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.blogs;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.blogs.BlogPost;
|
||||
import org.briarproject.api.blogs.BlogPostFactory;
|
||||
import org.briarproject.api.blogs.MessageType;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
@@ -58,28 +59,31 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
|
||||
@Override
|
||||
public Message createBlogComment(GroupId groupId, LocalAuthor author,
|
||||
@Nullable String comment, MessageId originalId, MessageId wrappedId)
|
||||
@Nullable String comment, MessageId pOriginalId, MessageId parentId)
|
||||
throws FormatException, GeneralSecurityException {
|
||||
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
|
||||
// Generate the signature
|
||||
BdfList signed =
|
||||
BdfList.of(groupId, timestamp, comment, originalId, wrappedId);
|
||||
BdfList.of(groupId, timestamp, comment, pOriginalId, parentId);
|
||||
byte[] sig = clientHelper.sign(signed, author.getPrivateKey());
|
||||
|
||||
// Serialise the signed message
|
||||
BdfList message =
|
||||
BdfList.of(COMMENT.getInt(), comment, originalId, wrappedId,
|
||||
BdfList.of(COMMENT.getInt(), comment, pOriginalId, parentId,
|
||||
sig);
|
||||
return clientHelper.createMessage(groupId, timestamp, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createWrappedPost(GroupId groupId, byte[] descriptor,
|
||||
public Message wrapPost(GroupId groupId, byte[] descriptor,
|
||||
long timestamp, BdfList body)
|
||||
throws FormatException {
|
||||
|
||||
if (getType(body) != POST)
|
||||
throw new IllegalArgumentException("Needs to wrap a POST");
|
||||
|
||||
// Serialise the message
|
||||
String content = body.getString(1);
|
||||
byte[] signature = body.getRaw(2);
|
||||
@@ -91,9 +95,12 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createWrappedPost(GroupId groupId, BdfList body)
|
||||
public Message rewrapWrappedPost(GroupId groupId, BdfList body)
|
||||
throws FormatException {
|
||||
|
||||
if (getType(body) != WRAPPED_POST)
|
||||
throw new IllegalArgumentException("Needs to wrap a WRAPPED_POST");
|
||||
|
||||
// Serialise the message
|
||||
byte[] descriptor = body.getRaw(1);
|
||||
long timestamp = body.getLong(2);
|
||||
@@ -107,38 +114,48 @@ class BlogPostFactoryImpl implements BlogPostFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createWrappedComment(GroupId groupId, byte[] descriptor,
|
||||
long timestamp, BdfList body, MessageId currentId)
|
||||
public Message wrapComment(GroupId groupId, byte[] descriptor,
|
||||
long timestamp, BdfList body, MessageId parentId)
|
||||
throws FormatException {
|
||||
|
||||
if (getType(body) != COMMENT)
|
||||
throw new IllegalArgumentException("Needs to wrap a COMMENT");
|
||||
|
||||
// Serialise the message
|
||||
String comment = body.getOptionalString(1);
|
||||
byte[] originalId = body.getRaw(2);
|
||||
byte[] oldId = body.getRaw(3);
|
||||
byte[] pOriginalId = body.getRaw(2);
|
||||
byte[] oldParentId = body.getRaw(3);
|
||||
byte[] signature = body.getRaw(4);
|
||||
BdfList message =
|
||||
BdfList.of(WRAPPED_COMMENT.getInt(), descriptor, timestamp,
|
||||
comment, originalId, oldId, signature, currentId);
|
||||
comment, pOriginalId, oldParentId, signature, parentId);
|
||||
return clientHelper
|
||||
.createMessage(groupId, clock.currentTimeMillis(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message createWrappedComment(GroupId groupId, BdfList body,
|
||||
MessageId currentId) throws FormatException {
|
||||
public Message rewrapWrappedComment(GroupId groupId, BdfList body,
|
||||
MessageId parentId) throws FormatException {
|
||||
|
||||
if (getType(body) != WRAPPED_COMMENT)
|
||||
throw new IllegalArgumentException(
|
||||
"Needs to wrap a WRAPPED_COMMENT");
|
||||
|
||||
// Serialise the message
|
||||
byte[] descriptor = body.getRaw(1);
|
||||
long timestamp = body.getLong(2);
|
||||
String comment = body.getOptionalString(3);
|
||||
byte[] originalId = body.getRaw(4);
|
||||
byte[] oldId = body.getRaw(5);
|
||||
byte[] pOriginalId = body.getRaw(4);
|
||||
byte[] oldParentId = body.getRaw(5);
|
||||
byte[] signature = body.getRaw(6);
|
||||
BdfList message =
|
||||
BdfList.of(WRAPPED_COMMENT.getInt(), descriptor, timestamp,
|
||||
comment, originalId, oldId, signature, currentId);
|
||||
comment, pOriginalId, oldParentId, signature, parentId);
|
||||
return clientHelper
|
||||
.createMessage(groupId, clock.currentTimeMillis(), message);
|
||||
}
|
||||
|
||||
private MessageType getType(BdfList body) throws FormatException {
|
||||
return MessageType.valueOf(body.getLong(0).intValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_COMMENT;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_WRAPPED_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_READ;
|
||||
@@ -129,9 +129,9 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
|
||||
// parent_original_id
|
||||
// The ID of a post or comment in this group or another group
|
||||
byte[] originalIdBytes = body.getRaw(1);
|
||||
checkLength(originalIdBytes, MessageId.LENGTH);
|
||||
MessageId originalId = new MessageId(originalIdBytes);
|
||||
byte[] pOriginalIdBytes = body.getRaw(1);
|
||||
checkLength(pOriginalIdBytes, MessageId.LENGTH);
|
||||
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
|
||||
|
||||
// parent_id
|
||||
// The ID of a post, comment, wrapped post or wrapped comment in this
|
||||
@@ -145,7 +145,7 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
byte[] sig = body.getRaw(3);
|
||||
checkLength(sig, 0, MAX_SIGNATURE_LENGTH);
|
||||
BdfList signed =
|
||||
BdfList.of(g.getId(), m.getTimestamp(), comment, originalId,
|
||||
BdfList.of(g.getId(), m.getTimestamp(), comment, pOriginalId,
|
||||
currentId);
|
||||
Blog b = blogFactory.parseBlog(g, ""); // description doesn't matter
|
||||
Author a = b.getAuthor();
|
||||
@@ -154,8 +154,9 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
// Return the metadata and dependencies
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
if (comment != null) meta.put(KEY_COMMENT, comment);
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, originalId);
|
||||
meta.put(KEY_WRAPPED_MSG_ID, currentId);
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||
meta.put(KEY_PARENT_MSG_ID, currentId);
|
||||
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
|
||||
Collection<MessageId> dependencies = Collections.singleton(currentId);
|
||||
return new BdfMessageContext(meta, dependencies);
|
||||
@@ -219,9 +220,9 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
|
||||
// c_parent_original_id
|
||||
// Taken from the original comment
|
||||
byte[] originalIdBytes = body.getRaw(3);
|
||||
checkLength(originalIdBytes, MessageId.LENGTH);
|
||||
MessageId originalId = new MessageId(originalIdBytes);
|
||||
byte[] pOriginalIdBytes = body.getRaw(3);
|
||||
checkLength(pOriginalIdBytes, MessageId.LENGTH);
|
||||
MessageId pOriginalId = new MessageId(pOriginalIdBytes);
|
||||
|
||||
// c_parent_id
|
||||
// Taken from the original comment
|
||||
@@ -238,14 +239,14 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
// The ID of a post, comment, wrapped post or wrapped comment in this
|
||||
// group, which had the ID c_parent_original_id in the group
|
||||
// where it was originally posted
|
||||
byte[] currentIdBytes = body.getRaw(6);
|
||||
checkLength(currentIdBytes, MessageId.LENGTH);
|
||||
MessageId currentId = new MessageId(currentIdBytes);
|
||||
byte[] parentIdBytes = body.getRaw(6);
|
||||
checkLength(parentIdBytes, MessageId.LENGTH);
|
||||
MessageId parentId = new MessageId(parentIdBytes);
|
||||
|
||||
// Get and Validate the Wrapped Comment
|
||||
Group wGroup = groupFactory
|
||||
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
|
||||
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, originalId,
|
||||
BdfList wBodyList = BdfList.of(COMMENT.getInt(), comment, pOriginalId,
|
||||
oldId, signature);
|
||||
byte[] wBody = clientHelper.toByteArray(wBodyList);
|
||||
Message wMessage =
|
||||
@@ -254,11 +255,11 @@ class BlogPostValidator extends BdfMessageValidator {
|
||||
BdfMessageContext c = validateComment(wMessage, wGroup, wBodyList);
|
||||
|
||||
// Return the metadata and dependencies
|
||||
Collection<MessageId> dependencies = Collections.singleton(currentId);
|
||||
Collection<MessageId> dependencies = Collections.singleton(parentId);
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, originalId);
|
||||
meta.put(KEY_WRAPPED_MSG_ID, currentId);
|
||||
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
|
||||
meta.put(KEY_PARENT_MSG_ID, parentId);
|
||||
meta.put(KEY_TIMESTAMP, wTimestamp);
|
||||
if (comment != null) meta.put(KEY_COMMENT, comment);
|
||||
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_COMMENT;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_WRAPPED_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_MSG_ID;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_PUBLIC_KEY;
|
||||
import static org.briarproject.api.blogs.BlogConstants.KEY_READ;
|
||||
@@ -168,7 +168,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
assertEquals(comment, result.getString(KEY_COMMENT));
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(originalId.getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID));
|
||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_WRAPPED_MSG_ID));
|
||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
||||
assertFalse(result.getBoolean(KEY_READ));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
|
||||
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
|
||||
assertEquals(
|
||||
message.getId().getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID));
|
||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_WRAPPED_MSG_ID));
|
||||
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user