mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Updated java.library.path.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package org.briarproject.api.blogs;
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.api.clients.BaseGroup;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.briar.api.client.BaseGroup;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Author.Status;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.blog.MessageType.COMMENT;
|
||||
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogCommentHeader extends BlogPostHeader {
|
||||
|
||||
@Nullable
|
||||
private final String comment;
|
||||
private final BlogPostHeader parent;
|
||||
|
||||
public BlogCommentHeader(MessageType type, GroupId groupId,
|
||||
@Nullable String comment, BlogPostHeader parent, MessageId id,
|
||||
long timestamp, long timeReceived, Author author,
|
||||
Status authorStatus, boolean read) {
|
||||
|
||||
super(type, groupId, id, parent.getId(), timestamp,
|
||||
timeReceived, author, authorStatus, read);
|
||||
|
||||
if (type != COMMENT && type != WRAPPED_COMMENT)
|
||||
throw new IllegalArgumentException("Incompatible Message Type");
|
||||
|
||||
this.comment = comment;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public BlogPostHeader getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,27 @@
|
||||
package org.briarproject.api.blogs;
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface BlogConstants {
|
||||
|
||||
/** The maximum length of a blogs's name in UTF-8 bytes. */
|
||||
/**
|
||||
* The maximum length of a blogs's name in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_BLOG_TITLE_LENGTH = 100;
|
||||
|
||||
/** The length of a blogs's description in UTF-8 bytes. */
|
||||
/**
|
||||
* The length of a blogs's description in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_BLOG_DESC_LENGTH = 240;
|
||||
|
||||
/** The maximum length of a blog post's body in bytes. */
|
||||
/**
|
||||
* The maximum length of a blog post's body in bytes.
|
||||
*/
|
||||
int MAX_BLOG_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
/** The maximum length of a blog comment in bytes. */
|
||||
/**
|
||||
* The maximum length of a blog comment in bytes.
|
||||
*/
|
||||
int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH;
|
||||
|
||||
/* Blog Sharing Constants */
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface BlogFactory {
|
||||
|
||||
/**
|
||||
* Creates a personal blog for a given author.
|
||||
*/
|
||||
Blog createBlog(Author author);
|
||||
|
||||
/**
|
||||
* Parses a blog with the given Group
|
||||
*/
|
||||
Blog parseBlog(Group g) throws FormatException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationRequest extends InvitationRequest {
|
||||
|
||||
private final String blogAuthorName;
|
||||
|
||||
public BlogInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, String blogAuthorName,
|
||||
@Nullable String message, boolean available, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, message, available, time,
|
||||
local, sent, seen, read);
|
||||
this.blogAuthorName = blogAuthorName;
|
||||
}
|
||||
|
||||
public String getBlogAuthorName() {
|
||||
return blogAuthorName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationResponse extends InvitationResponse {
|
||||
|
||||
public BlogInvitationResponse(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, accept, time, local, sent,
|
||||
seen, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface BlogManager {
|
||||
|
||||
/**
|
||||
* Unique ID of the blog client.
|
||||
*/
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog");
|
||||
|
||||
/**
|
||||
* Returns true if a blog can be removed.
|
||||
*/
|
||||
boolean canBeRemoved(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Removes and deletes a blog.
|
||||
*/
|
||||
void removeBlog(Blog b) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a local blog post.
|
||||
*/
|
||||
void addLocalPost(BlogPost p) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a local blog post.
|
||||
*/
|
||||
void addLocalPost(Transaction txn, BlogPost p) throws DbException;
|
||||
|
||||
/**
|
||||
* Adds a comment to an existing blog post or reblogs it.
|
||||
*/
|
||||
void addLocalComment(LocalAuthor author, GroupId groupId,
|
||||
@Nullable String comment, BlogPostHeader wHeader)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the blog with the given ID.
|
||||
*/
|
||||
Blog getBlog(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the blog with the given ID.
|
||||
*/
|
||||
Blog getBlog(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all blogs owned by the given localAuthor.
|
||||
*/
|
||||
Collection<Blog> getBlogs(LocalAuthor localAuthor) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns only the personal blog of the given author.
|
||||
*/
|
||||
Blog getPersonalBlog(Author author);
|
||||
|
||||
/**
|
||||
* Returns all blogs to which the user subscribes.
|
||||
*/
|
||||
Collection<Blog> getBlogs() throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the header of the blog post with the given ID.
|
||||
*/
|
||||
BlogPostHeader getPostHeader(GroupId g, MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the body of the blog post with the given ID.
|
||||
*/
|
||||
String getPostBody(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all posts in the given blog.
|
||||
*/
|
||||
Collection<BlogPostHeader> getPostHeaders(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Marks a blog post as read or unread.
|
||||
*/
|
||||
void setReadFlag(MessageId m, boolean read) throws DbException;
|
||||
|
||||
/**
|
||||
* Registers a hook to be called whenever a blog is removed.
|
||||
*/
|
||||
void registerRemoveBlogHook(RemoveBlogHook hook);
|
||||
|
||||
interface RemoveBlogHook {
|
||||
void removingBlog(Transaction txn, Blog b) throws DbException;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.forum.ForumPost;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogPost extends ForumPost {
|
||||
|
||||
public BlogPost(Message message, @Nullable MessageId parent,
|
||||
Author author) {
|
||||
super(message, parent, author);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface BlogPostFactory {
|
||||
|
||||
String SIGNING_LABEL_POST = CLIENT_ID + "/POST";
|
||||
String SIGNING_LABEL_COMMENT = CLIENT_ID + "/COMMENT";
|
||||
|
||||
BlogPost createBlogPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
Message createBlogComment(GroupId groupId, LocalAuthor author,
|
||||
@Nullable String comment, MessageId originalId, MessageId wrappedId)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
/**
|
||||
* Wraps a blog post
|
||||
*/
|
||||
Message wrapPost(GroupId groupId, byte[] descriptor, long timestamp,
|
||||
BdfList body) throws FormatException;
|
||||
|
||||
/**
|
||||
* Re-wraps a previously wrapped post
|
||||
*/
|
||||
Message rewrapWrappedPost(GroupId groupId, BdfList body)
|
||||
throws FormatException;
|
||||
|
||||
/**
|
||||
* Wraps a blog comment
|
||||
*/
|
||||
Message wrapComment(GroupId groupId, byte[] descriptor, long timestamp,
|
||||
BdfList body, MessageId currentId) throws FormatException;
|
||||
|
||||
/**
|
||||
* Re-wraps a previously wrapped comment
|
||||
*/
|
||||
Message rewrapWrappedComment(GroupId groupId, BdfList body,
|
||||
MessageId currentId) throws FormatException;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Author.Status;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.PostHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogPostHeader extends PostHeader {
|
||||
|
||||
private final MessageType type;
|
||||
private final GroupId groupId;
|
||||
private final long timeReceived;
|
||||
|
||||
public BlogPostHeader(MessageType type, GroupId groupId, MessageId id,
|
||||
@Nullable MessageId parentId, long timestamp, long timeReceived,
|
||||
Author author, Status authorStatus, boolean read) {
|
||||
super(id, parentId, timestamp, author, authorStatus, read);
|
||||
this.type = type;
|
||||
this.groupId = groupId;
|
||||
this.timeReceived = timeReceived;
|
||||
}
|
||||
|
||||
public BlogPostHeader(MessageType type, GroupId groupId, MessageId id,
|
||||
long timestamp, long timeReceived, Author author,
|
||||
Status authorStatus, boolean read) {
|
||||
this(type, groupId, id, null, timestamp, timeReceived, author,
|
||||
authorStatus, read);
|
||||
}
|
||||
|
||||
public MessageType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public long getTimeReceived() {
|
||||
return timeReceived;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.sharing.SharingManager;
|
||||
|
||||
public interface BlogSharingManager extends SharingManager<Blog> {
|
||||
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog.sharing");
|
||||
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
package org.briarproject.api.blogs;
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.sharing.SharingMessage.Invitation;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.SharingMessage.Invitation;
|
||||
|
||||
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
|
||||
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
|
||||
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.BLOG_AUTHOR_NAME;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.BLOG_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface BlogSharingMessage {
|
||||
|
||||
class BlogInvitation extends Invitation {
|
||||
@@ -22,7 +26,7 @@ public interface BlogSharingMessage {
|
||||
|
||||
public BlogInvitation(GroupId groupId, SessionId sessionId,
|
||||
String blogAuthorName, byte[] blogPublicKey, long time,
|
||||
String message) {
|
||||
@Nullable String message) {
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
this.blogAuthorName = blogAuthorName;
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.api.blogs;
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
public enum MessageType {
|
||||
|
||||
POST(0),
|
||||
COMMENT(1),
|
||||
WRAPPED_POST(2),
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.blog.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.blog.Blog;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationRequestReceivedEvent extends
|
||||
InvitationRequestReceivedEvent<Blog> {
|
||||
|
||||
public BlogInvitationRequestReceivedEvent(Blog blog, ContactId contactId,
|
||||
InvitationRequest request) {
|
||||
super(blog, contactId, request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.briar.api.blog.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.blog.BlogInvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationResponseReceivedEvent
|
||||
extends InvitationResponseReceivedEvent {
|
||||
|
||||
public BlogInvitationResponseReceivedEvent(ContactId contactId,
|
||||
BlogInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,17 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.blog.event;
|
||||
|
||||
import org.briarproject.api.blogs.BlogPostHeader;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
|
||||
/** An event that is broadcast when a blog post was added to the database. */
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a blog post is added to the database.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class BlogPostAddedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class BaseMessageHeader {
|
||||
|
||||
private final MessageId id;
|
||||
@@ -11,9 +15,8 @@ public abstract class BaseMessageHeader {
|
||||
private final long timestamp;
|
||||
private final boolean local, read, sent, seen;
|
||||
|
||||
public BaseMessageHeader(@NotNull MessageId id, @NotNull GroupId groupId,
|
||||
long timestamp, boolean local, boolean read, boolean sent,
|
||||
boolean seen) {
|
||||
public BaseMessageHeader(MessageId id, GroupId groupId, long timestamp,
|
||||
boolean local, boolean read, boolean sent, boolean seen) {
|
||||
|
||||
this.id = id;
|
||||
this.groupId = groupId;
|
||||
@@ -24,12 +27,10 @@ public abstract class BaseMessageHeader {
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MessageId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
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;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.InvalidMessageException;
|
||||
import org.briarproject.bramble.api.sync.MessageContext;
|
||||
|
||||
@Deprecated
|
||||
@NotNullByDefault
|
||||
public interface MessageQueueManager {
|
||||
|
||||
@@ -35,6 +36,7 @@ public interface MessageQueueManager {
|
||||
*/
|
||||
void registerIncomingMessageHook(ClientId c, IncomingQueueMessageHook hook);
|
||||
|
||||
@Deprecated
|
||||
interface QueueMessageValidator {
|
||||
|
||||
/**
|
||||
@@ -45,6 +47,7 @@ public interface MessageQueueManager {
|
||||
throws InvalidMessageException;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
interface IncomingQueueMessageHook {
|
||||
|
||||
/**
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
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;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessageTracker {
|
||||
@@ -36,7 +36,7 @@ public interface MessageTracker {
|
||||
* Updates the group count for the given message.
|
||||
*/
|
||||
void trackMessage(Transaction txn, GroupId g, long timestamp, boolean read)
|
||||
throws DbException;
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Marks a message as read or unread and updates the group count.
|
||||
@@ -1,23 +1,38 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessageTree<T extends MessageTree.MessageNode> {
|
||||
|
||||
void add(Collection<T> nodes);
|
||||
|
||||
void add(T node);
|
||||
|
||||
void setComparator(Comparator<T> comparator);
|
||||
|
||||
void clear();
|
||||
|
||||
Collection<T> depthFirstOrder();
|
||||
|
||||
@NotNullByDefault
|
||||
interface MessageNode {
|
||||
|
||||
MessageId getId();
|
||||
|
||||
@Nullable
|
||||
MessageId getParentId();
|
||||
|
||||
void setLevel(int level);
|
||||
|
||||
void setDescendantCount(int descendantCount);
|
||||
|
||||
long getTimestamp();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Author.Status;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class PostHeader {
|
||||
|
||||
private final MessageId id;
|
||||
@Nullable
|
||||
private final MessageId parentId;
|
||||
private final long timestamp;
|
||||
private final Author author;
|
||||
private final Status authorStatus;
|
||||
private final boolean read;
|
||||
|
||||
public PostHeader(MessageId id, MessageId parentId, long timestamp,
|
||||
Author author, Status authorStatus, boolean read) {
|
||||
public PostHeader(MessageId id, @Nullable MessageId parentId,
|
||||
long timestamp, Author author, Status authorStatus, boolean read) {
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
this.timestamp = timestamp;
|
||||
@@ -43,6 +50,7 @@ public abstract class PostHeader {
|
||||
return read;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MessageId getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
@NotNullByDefault
|
||||
public interface ProtocolEngine<A, S, M> {
|
||||
|
||||
StateUpdate<S, M> onLocalAction(S localState, A action);
|
||||
|
||||
StateUpdate<S, M> onMessageReceived(S localState, M received);
|
||||
@@ -23,11 +27,15 @@ public interface ProtocolEngine<A, S, M> {
|
||||
* It only shows how the state should be updated,
|
||||
* but does not carry out the updates on its own.
|
||||
*
|
||||
* @param deleteMessage whether to delete the message that triggered the state update. This will be ignored for {@link ProtocolEngine#onLocalAction}.
|
||||
* @param deleteState whether to delete the localState {@link S}
|
||||
* @param localState the new local state
|
||||
* @param toSend a list of messages to be sent as part of the state update
|
||||
* @param toBroadcast a list of events to broadcast as result of the state update
|
||||
* @param deleteMessage whether to delete the message that triggered
|
||||
* the state update. This will be ignored for
|
||||
* {@link ProtocolEngine#onLocalAction}.
|
||||
* @param deleteState whether to delete the localState {@link S}
|
||||
* @param localState the new local state
|
||||
* @param toSend a list of messages to be sent as part of the
|
||||
* state update
|
||||
* @param toBroadcast a list of events to broadcast as result of the
|
||||
* state update
|
||||
*/
|
||||
public StateUpdate(boolean deleteMessage, boolean deleteState,
|
||||
S localState, List<M> toSend, List<Event> toBroadcast) {
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
|
||||
/**
|
||||
* Thrown when a database operation is attempted as part of a protocol session
|
||||
* and the operation is not applicable to the current protocol state.
|
||||
* and the operation is not applicable to the current protocol state. This
|
||||
* exception may occur due to concurrent updates and does not indicate a
|
||||
* database error.
|
||||
*/
|
||||
public class ProtocolStateException extends DbException {
|
||||
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
|
||||
|
||||
@Deprecated
|
||||
@NotNullByDefault
|
||||
public class QueueMessage extends Message {
|
||||
|
||||
public static final int QUEUE_MESSAGE_HEADER_LENGTH =
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
@Deprecated
|
||||
@NotNullByDefault
|
||||
public interface QueueMessageFactory {
|
||||
|
||||
QueueMessage createMessage(GroupId groupId, long timestamp,
|
||||
long queuePosition, byte[] body);
|
||||
|
||||
QueueMessage createMessage(MessageId id, byte[] raw);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.bramble.api.UniqueId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
* Type-safe wrapper for a byte array that uniquely identifies a protocol
|
||||
* session.
|
||||
*/
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
public class SessionId extends UniqueId {
|
||||
|
||||
public SessionId(byte[] id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof SessionId && super.equals(o);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.briarproject.api.clients;
|
||||
package org.briarproject.briar.api.client;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.messaging.PrivateMessage;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@@ -1,26 +1,32 @@
|
||||
package org.briarproject.api.feed;
|
||||
package org.briarproject.briar.api.feed;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfEntry;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_BLOG_GROUP_ID;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_ADDED;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_DESC;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_TITLE;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||
import static org.briarproject.api.feed.FeedConstants.KEY_FEED_URL;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_BLOG_GROUP_ID;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_ADDED;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_AUTHOR;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_DESC;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_TITLE;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
|
||||
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class Feed {
|
||||
|
||||
final private String url;
|
||||
final private GroupId blogId;
|
||||
final private String title, description, author;
|
||||
final private long added, updated, lastEntryTime;
|
||||
private final String url;
|
||||
private final GroupId blogId;
|
||||
@Nullable
|
||||
private final String title, description, author;
|
||||
private final long added, updated, lastEntryTime;
|
||||
|
||||
public Feed(String url, GroupId blogId, @Nullable String title,
|
||||
@Nullable String description, @Nullable String author,
|
||||
@@ -37,14 +43,11 @@ public class Feed {
|
||||
}
|
||||
|
||||
public Feed(String url, GroupId blogId, @Nullable String title,
|
||||
@Nullable String description, @Nullable String author,
|
||||
long added) {
|
||||
|
||||
@Nullable String description, @Nullable String author, long added) {
|
||||
this(url, blogId, title, description, author, added, 0L, 0L);
|
||||
}
|
||||
|
||||
public Feed(String url, GroupId blogId, long added) {
|
||||
|
||||
this(url, blogId, null, null, null, added, 0L, 0L);
|
||||
}
|
||||
|
||||
@@ -126,9 +129,9 @@ public class Feed {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean equalsWithNull(Object a, Object b) {
|
||||
private boolean equalsWithNull(@Nullable Object a, @Nullable Object b) {
|
||||
if (a == b) return true;
|
||||
if (a == null || b==null) return false;
|
||||
if (a == null || b == null) return false;
|
||||
return a.equals(b);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.api.feed;
|
||||
package org.briarproject.briar.api.feed;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.briarproject.briar.api.feed;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface FeedManager {
|
||||
|
||||
/**
|
||||
* The unique ID of the RSS feed client.
|
||||
*/
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.feed");
|
||||
|
||||
/**
|
||||
* Adds an RSS feed.
|
||||
*/
|
||||
void addFeed(String url, GroupId g) throws DbException, IOException;
|
||||
|
||||
/**
|
||||
* Removes an RSS feed.
|
||||
*/
|
||||
void removeFeed(String url) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a list of all added RSS feeds
|
||||
*/
|
||||
List<Feed> getFeeds() throws DbException;
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.briarproject.api.forum;
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.api.clients.NamedGroup;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.briar.api.client.NamedGroup;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
package org.briarproject.api.forum;
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface ForumConstants {
|
||||
|
||||
/** The maximum length of a forum's name in UTF-8 bytes. */
|
||||
/**
|
||||
* The maximum length of a forum's name in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_FORUM_NAME_LENGTH = 100;
|
||||
|
||||
/** The length of a forum's random salt in bytes. */
|
||||
/**
|
||||
* The length of a forum's random salt in bytes.
|
||||
*/
|
||||
int FORUM_SALT_LENGTH = 32;
|
||||
|
||||
/** The maximum length of a forum post's content type in UTF-8 bytes. */
|
||||
/**
|
||||
* The maximum length of a forum post's content type in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_CONTENT_TYPE_LENGTH = 50;
|
||||
|
||||
/** The maximum length of a forum post's body in bytes. */
|
||||
/**
|
||||
* The maximum length of a forum post's body in bytes.
|
||||
*/
|
||||
int MAX_FORUM_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
/* Forum Sharing Constants */
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ForumFactory {
|
||||
|
||||
/**
|
||||
* Creates a forum with the given name.
|
||||
*/
|
||||
Forum createForum(String name);
|
||||
|
||||
/**
|
||||
* Creates a forum with the given name and salt.
|
||||
*/
|
||||
Forum createForum(String name, byte[] salt);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumInvitationRequest extends InvitationRequest {
|
||||
|
||||
private final String forumName;
|
||||
|
||||
public ForumInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, String forumName,
|
||||
@Nullable String message, boolean available, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, message, available, time,
|
||||
local, sent, seen, read);
|
||||
this.forumName = forumName;
|
||||
}
|
||||
|
||||
public String getForumName() {
|
||||
return forumName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumInvitationResponse extends InvitationResponse {
|
||||
|
||||
public ForumInvitationResponse(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, accept, time, local, sent,
|
||||
seen, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.briarproject.api.forum;
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ForumManager {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.ThreadedMessage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumPost extends ThreadedMessage {
|
||||
|
||||
public ForumPost(Message message, @Nullable MessageId parent,
|
||||
Author author) {
|
||||
super(message, parent, author);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.forum.ForumManager.CLIENT_ID;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ForumPostFactory {
|
||||
|
||||
String SIGNING_LABEL_POST = CLIENT_ID + "/POST";
|
||||
|
||||
@CryptoExecutor
|
||||
ForumPost createPost(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parent, LocalAuthor author, String body)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.PostHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumPostHeader extends PostHeader {
|
||||
|
||||
public ForumPostHeader(MessageId id, @Nullable MessageId parentId,
|
||||
long timestamp, Author author, Author.Status authorStatus,
|
||||
boolean read) {
|
||||
super(id, parentId, timestamp, author, authorStatus, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.api.forum;
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.api.sharing.SharingManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.sharing.SharingManager;
|
||||
|
||||
public interface ForumSharingManager extends SharingManager<Forum> {
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
package org.briarproject.api.forum;
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.sharing.SharingMessage.Invitation;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.SharingMessage.Invitation;
|
||||
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT;
|
||||
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ForumSharingMessage {
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class ForumInvitation extends Invitation {
|
||||
|
||||
private final String forumName;
|
||||
private final byte[] forumSalt;
|
||||
|
||||
public ForumInvitation(GroupId groupId, SessionId sessionId,
|
||||
String forumName, byte[] forumSalt, long time, String message) {
|
||||
String forumName, byte[] forumSalt, long time,
|
||||
@Nullable String message) {
|
||||
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.forum.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationRequest;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumInvitationRequestReceivedEvent extends
|
||||
InvitationRequestReceivedEvent<Forum> {
|
||||
|
||||
public ForumInvitationRequestReceivedEvent(Forum forum, ContactId contactId,
|
||||
ForumInvitationRequest request) {
|
||||
super(forum, contactId, request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.forum.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
|
||||
|
||||
public class ForumInvitationResponseReceivedEvent extends
|
||||
InvitationResponseReceivedEvent {
|
||||
|
||||
private final String forumName;
|
||||
|
||||
public ForumInvitationResponseReceivedEvent(String forumName,
|
||||
ContactId contactId, ForumInvitationResponse response) {
|
||||
super(contactId, response);
|
||||
this.forumName = forumName;
|
||||
}
|
||||
|
||||
public String getForumName() {
|
||||
return forumName;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.forum.event;
|
||||
|
||||
import org.briarproject.api.forum.ForumPostHeader;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a new forum post was received.
|
||||
* An event that is broadcast when a new forum post is received.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ForumPostReceivedEvent extends Event {
|
||||
|
||||
private final ForumPostHeader forumPostHeader;
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.briarproject.api.introduction;
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ABORT;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ABORT;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
|
||||
@NotNullByDefault
|
||||
public enum IntroduceeAction {
|
||||
|
||||
LOCAL_ACCEPT,
|
||||
@@ -16,6 +21,7 @@ public enum IntroduceeAction {
|
||||
REMOTE_ABORT,
|
||||
ACK;
|
||||
|
||||
@Nullable
|
||||
public static IntroduceeAction getRemote(int type, boolean accept) {
|
||||
if (type == TYPE_REQUEST) return REMOTE_REQUEST;
|
||||
if (type == TYPE_RESPONSE && accept) return REMOTE_ACCEPT;
|
||||
@@ -25,10 +31,12 @@ public enum IntroduceeAction {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IntroduceeAction getRemote(int type) {
|
||||
return getRemote(type, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IntroduceeAction getLocal(int type, boolean accept) {
|
||||
if (type == TYPE_RESPONSE && accept) return LOCAL_ACCEPT;
|
||||
if (type == TYPE_RESPONSE) return LOCAL_DECLINE;
|
||||
@@ -37,6 +45,7 @@ public enum IntroduceeAction {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IntroduceeAction getLocal(int type) {
|
||||
return getLocal(type, true);
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package org.briarproject.api.introduction;
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.ACK;
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.LOCAL_ACCEPT;
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.LOCAL_DECLINE;
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_ACCEPT;
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_DECLINE;
|
||||
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_REQUEST;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.ACK;
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.LOCAL_ACCEPT;
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.LOCAL_DECLINE;
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.REMOTE_ACCEPT;
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.REMOTE_DECLINE;
|
||||
import static org.briarproject.briar.api.introduction.IntroduceeAction.REMOTE_REQUEST;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public enum IntroduceeProtocolState {
|
||||
|
||||
ERROR(0),
|
||||
@@ -1,10 +1,15 @@
|
||||
package org.briarproject.api.introduction;
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ABORT;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ABORT;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_ACK;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.TYPE_RESPONSE;
|
||||
|
||||
@NotNullByDefault
|
||||
public enum IntroducerAction {
|
||||
|
||||
LOCAL_REQUEST,
|
||||
@@ -17,12 +22,14 @@ public enum IntroducerAction {
|
||||
ACK_1,
|
||||
ACK_2;
|
||||
|
||||
@Nullable
|
||||
public static IntroducerAction getLocal(int type) {
|
||||
if (type == TYPE_REQUEST) return LOCAL_REQUEST;
|
||||
if (type == TYPE_ABORT) return LOCAL_ABORT;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IntroducerAction getRemote(int type, boolean one,
|
||||
boolean accept) {
|
||||
|
||||
@@ -39,6 +46,7 @@ public enum IntroducerAction {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IntroducerAction getRemote(int type, boolean one) {
|
||||
return getRemote(type, one, true);
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package org.briarproject.api.introduction;
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import static org.briarproject.api.introduction.IntroducerAction.ACK_1;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.ACK_2;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.LOCAL_REQUEST;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.REMOTE_ABORT;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.REMOTE_ACCEPT_1;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.REMOTE_ACCEPT_2;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.REMOTE_DECLINE_1;
|
||||
import static org.briarproject.api.introduction.IntroducerAction.REMOTE_DECLINE_2;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.ACK_1;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.ACK_2;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.LOCAL_REQUEST;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.REMOTE_ABORT;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.REMOTE_ACCEPT_1;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.REMOTE_ACCEPT_2;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.REMOTE_DECLINE_1;
|
||||
import static org.briarproject.briar.api.introduction.IntroducerAction.REMOTE_DECLINE_2;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public enum IntroducerProtocolState {
|
||||
|
||||
ERROR(0),
|
||||
@@ -30,6 +36,7 @@ public enum IntroducerProtocolState {
|
||||
}
|
||||
},
|
||||
AWAIT_RESPONSE_1(3) {
|
||||
@Override
|
||||
public IntroducerProtocolState next(IntroducerAction a) {
|
||||
if (a == REMOTE_ACCEPT_1) return AWAIT_ACKS;
|
||||
if (a == REMOTE_DECLINE_1) return FINISHED;
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.api.introduction;
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface IntroductionConstants {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface IntroductionManager extends ConversationClient {
|
||||
|
||||
/**
|
||||
* The unique ID of the introduction client.
|
||||
*/
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.introduction");
|
||||
|
||||
/**
|
||||
* Sends two initial introduction messages.
|
||||
*/
|
||||
void makeIntroduction(Contact c1, Contact c2, @Nullable String msg,
|
||||
final long timestamp) throws DbException, FormatException;
|
||||
|
||||
/**
|
||||
* Accepts an introduction.
|
||||
*/
|
||||
void acceptIntroduction(final ContactId contactId,
|
||||
final SessionId sessionId, final long timestamp)
|
||||
throws DbException, FormatException;
|
||||
|
||||
/**
|
||||
* Declines an introduction.
|
||||
*/
|
||||
void declineIntroduction(final ContactId contactId,
|
||||
final SessionId sessionId, final long timestamp)
|
||||
throws DbException, FormatException;
|
||||
|
||||
/**
|
||||
* Returns all introduction messages for the given contact.
|
||||
*/
|
||||
Collection<IntroductionMessage> getIntroductionMessages(ContactId contactId)
|
||||
throws DbException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.BaseMessageHeader;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.ROLE_INTRODUCER;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionMessage extends BaseMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final MessageId messageId;
|
||||
private final int role;
|
||||
|
||||
IntroductionMessage(SessionId sessionId, MessageId messageId,
|
||||
GroupId groupId, int role, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
super(messageId, groupId, time, local, read, sent, seen);
|
||||
this.sessionId = sessionId;
|
||||
this.messageId = messageId;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public MessageId getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public boolean isIntroducer() {
|
||||
return role == ROLE_INTRODUCER;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionRequest extends IntroductionResponse {
|
||||
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final boolean answered, exists, introducesOtherIdentity;
|
||||
|
||||
public IntroductionRequest(SessionId sessionId, MessageId messageId,
|
||||
GroupId groupId, int role, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read, AuthorId authorId, String name,
|
||||
boolean accepted, @Nullable String message, boolean answered,
|
||||
boolean exists, boolean introducesOtherIdentity) {
|
||||
|
||||
super(sessionId, messageId, groupId, role, time, local, sent, seen,
|
||||
read, authorId, name, accepted);
|
||||
|
||||
this.message = message;
|
||||
this.answered = answered;
|
||||
this.exists = exists;
|
||||
this.introducesOtherIdentity = introducesOtherIdentity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean wasAnswered() {
|
||||
return answered;
|
||||
}
|
||||
|
||||
public boolean contactExists() {
|
||||
return exists;
|
||||
}
|
||||
|
||||
public boolean doesIntroduceOtherIdentity() {
|
||||
return introducesOtherIdentity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.briarproject.briar.api.introduction;
|
||||
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionResponse extends IntroductionMessage {
|
||||
|
||||
private final AuthorId remoteAuthorId;
|
||||
private final String name;
|
||||
private final boolean accepted;
|
||||
|
||||
public IntroductionResponse(SessionId sessionId, MessageId messageId,
|
||||
GroupId groupId, int role, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read, AuthorId remoteAuthorId, String name,
|
||||
boolean accepted) {
|
||||
|
||||
super(sessionId, messageId, groupId, role, time, local, sent, seen,
|
||||
read);
|
||||
|
||||
this.remoteAuthorId = remoteAuthorId;
|
||||
this.name = name;
|
||||
this.accepted = accepted;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean wasAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
public AuthorId getRemoteAuthorId() {
|
||||
return remoteAuthorId;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.introduction.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionAbortedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.introduction.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.introduction.IntroductionRequest;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.introduction.IntroductionRequest;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionRequestReceivedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.introduction.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionResponseReceivedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.briar.api.introduction.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class IntroductionSucceededEvent extends Event {
|
||||
|
||||
private final Contact contact;
|
||||
|
||||
public IntroductionSucceededEvent(Contact contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public Contact getContact() {
|
||||
return contact;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ConversationManager {
|
||||
|
||||
/**
|
||||
* Clients that present messages in a private conversation need to
|
||||
* register themselves here.
|
||||
*/
|
||||
void registerConversationClient(ConversationClient client);
|
||||
|
||||
/**
|
||||
* Returns the unified group count for all private conversation messages.
|
||||
*/
|
||||
GroupCount getGroupCount(ContactId c) throws DbException;
|
||||
|
||||
@NotNullByDefault
|
||||
interface ConversationClient {
|
||||
|
||||
Group getContactGroup(Contact c);
|
||||
|
||||
GroupCount getGroupCount(Transaction txn, ContactId c)
|
||||
throws DbException;
|
||||
|
||||
void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||
throws DbException;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface MessagingConstants {
|
||||
|
||||
/**
|
||||
* The maximum length of a private message's body in bytes.
|
||||
*/
|
||||
int MAX_PRIVATE_MESSAGE_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface MessagingManager extends ConversationClient {
|
||||
|
||||
/**
|
||||
* The unique ID of the messaging client.
|
||||
*/
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.messaging");
|
||||
|
||||
/**
|
||||
* Stores a local private message.
|
||||
*/
|
||||
void addLocalMessage(PrivateMessage m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the ID of the contact with the given private conversation.
|
||||
*/
|
||||
ContactId getContactId(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the ID of the private conversation with the given contact.
|
||||
*/
|
||||
GroupId getConversationId(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
*/
|
||||
Collection<PrivateMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the body of the private message with the given ID.
|
||||
*/
|
||||
String getMessageBody(MessageId m) throws DbException;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.api.messaging;
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PrivateMessageFactory {
|
||||
|
||||
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
|
||||
String body) throws FormatException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.briar.api.messaging;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.BaseMessageHeader;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class PrivateMessageHeader extends BaseMessageHeader {
|
||||
|
||||
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
|
||||
boolean local, boolean read, boolean sent, boolean seen) {
|
||||
|
||||
super(id, groupId, timestamp, local, read, sent, seen);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.messaging.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a new private message was received.
|
||||
* An event that is broadcast when a new private message is received.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class PrivateMessageReceivedEvent extends Event {
|
||||
|
||||
private final PrivateMessageHeader messageHeader;
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Author.Status;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.ThreadedMessage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class GroupMessage extends ThreadedMessage {
|
||||
|
||||
public GroupMessage(Message message, @Nullable MessageId parent,
|
||||
Author member) {
|
||||
super(message, parent, member);
|
||||
}
|
||||
|
||||
public Author getMember() {
|
||||
return super.getAuthor();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.privategroup.PrivateGroupManager.CLIENT_ID;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface GroupMessageFactory {
|
||||
|
||||
String SIGNING_LABEL_JOIN = CLIENT_ID + "/JOIN";
|
||||
String SIGNING_LABEL_POST = CLIENT_ID + "/POST";
|
||||
|
||||
/**
|
||||
* Creates a join announcement message for the creator of a group.
|
||||
*
|
||||
* @param groupId The ID of the private group that is being joined
|
||||
* @param timestamp The timestamp to be used in the join announcement
|
||||
* @param creator The creator's identity
|
||||
*/
|
||||
@CryptoExecutor
|
||||
GroupMessage createJoinMessage(GroupId groupId, long timestamp,
|
||||
LocalAuthor creator);
|
||||
|
||||
/**
|
||||
* Creates a join announcement message for a joining member.
|
||||
*
|
||||
* @param groupId The ID of the private group that is being joined
|
||||
* @param timestamp The timestamp to be used in the join announcement,
|
||||
* which must be greater than the timestamp of the invitation message
|
||||
* @param member The member's identity
|
||||
* @param inviteTimestamp The timestamp of the invitation message
|
||||
* @param creatorSignature The creator's signature from the invitation
|
||||
* message
|
||||
*/
|
||||
@CryptoExecutor
|
||||
GroupMessage createJoinMessage(GroupId groupId, long timestamp,
|
||||
LocalAuthor member, long inviteTimestamp, byte[] creatorSignature);
|
||||
|
||||
/**
|
||||
* Creates a private group post.
|
||||
*
|
||||
* @param groupId The ID of the private group
|
||||
* @param timestamp Must be greater than the timestamps of the parent
|
||||
* post, if any, and the member's previous message
|
||||
* @param parentId The ID of the parent post, or null if the post has no
|
||||
* parent
|
||||
* @param author The author of the post
|
||||
* @param body The content of the post
|
||||
* @param previousMsgId The ID of the author's previous message
|
||||
* in this group
|
||||
*/
|
||||
@CryptoExecutor
|
||||
GroupMessage createGroupMessage(GroupId groupId, long timestamp,
|
||||
@Nullable MessageId parentId, LocalAuthor author, String body,
|
||||
MessageId previousMsgId);
|
||||
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.PostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.Author.Status;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Author.Status;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.PostHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@@ -24,7 +23,6 @@ public class GroupMessageHeader extends PostHeader {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -11,7 +11,8 @@ public class JoinMessageHeader extends GroupMessageHeader {
|
||||
private final Visibility visibility;
|
||||
private final boolean isInitial;
|
||||
|
||||
public JoinMessageHeader(GroupMessageHeader h, Visibility visibility, boolean isInitial) {
|
||||
public JoinMessageHeader(GroupMessageHeader h, Visibility visibility,
|
||||
boolean isInitial) {
|
||||
super(h.getGroupId(), h.getId(), h.getParentId(), h.getTimestamp(),
|
||||
h.getAuthor(), h.getAuthorStatus(), h.isRead());
|
||||
this.visibility = visibility;
|
||||
@@ -1,10 +1,17 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public enum MessageType {
|
||||
|
||||
JOIN(0),
|
||||
POST(1);
|
||||
|
||||
int value;
|
||||
private final int value;
|
||||
|
||||
MessageType(int value) {
|
||||
this.value = value;
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.NamedGroup;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.briar.api.client.NamedGroup;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PrivateGroup extends NamedGroup implements Shareable {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrivateGroup && super.equals(o);
|
||||
return o instanceof PrivateGroup && super.equals(o);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface PrivateGroupConstants {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface PrivateGroupFactory {
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
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;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
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 org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -24,8 +24,8 @@ public interface PrivateGroupManager {
|
||||
/**
|
||||
* Adds a new private group and joins it.
|
||||
*
|
||||
* @param group The private group to add
|
||||
* @param joinMsg The creators's join message
|
||||
* @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(PrivateGroup group, GroupMessage joinMsg,
|
||||
@@ -34,7 +34,7 @@ public interface PrivateGroupManager {
|
||||
/**
|
||||
* Adds a new private group and joins it.
|
||||
*
|
||||
* @param group The private group to add
|
||||
* @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
|
||||
*/
|
||||
@@ -47,22 +47,22 @@ public interface PrivateGroupManager {
|
||||
void removePrivateGroup(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Gets the MessageId of the user's previous message sent to the group
|
||||
* Returns the ID of the user's previous message sent to the group
|
||||
*/
|
||||
MessageId getPreviousMsgId(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the group with GroupId g as resolved
|
||||
* Marks the given private group as dissolved.
|
||||
*/
|
||||
void markGroupDissolved(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the private group has been dissolved.
|
||||
* Returns true if the given private group has been dissolved.
|
||||
*/
|
||||
boolean isDissolved(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores (and sends) a local group message.
|
||||
* Stores and sends a local private group message.
|
||||
*/
|
||||
GroupMessageHeader addLocalMessage(GroupMessage p) throws DbException;
|
||||
|
||||
@@ -72,7 +72,7 @@ public interface PrivateGroupManager {
|
||||
PrivateGroup getPrivateGroup(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the private group with the given ID within the given transaction.
|
||||
* Returns the private group with the given ID.
|
||||
*/
|
||||
PrivateGroup getPrivateGroup(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
@@ -82,27 +82,27 @@ public interface PrivateGroupManager {
|
||||
Collection<PrivateGroup> getPrivateGroups() throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the body of the group message with the given ID.
|
||||
* Returns the body of the private group message with the given ID.
|
||||
*/
|
||||
String getMessageBody(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all group messages in the given group.
|
||||
* Returns the headers of all messages in the given private group.
|
||||
*/
|
||||
Collection<GroupMessageHeader> getHeaders(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all members of the group with ID g
|
||||
* Returns all members of the given private group.
|
||||
*/
|
||||
Collection<GroupMember> getMembers(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the given Author a is member of the group with ID g
|
||||
* Returns true if the given author is a member of the given private group.
|
||||
*/
|
||||
boolean isMember(Transaction txn, GroupId g, Author a) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the group count for the given group.
|
||||
* Returns the group count for the given private group.
|
||||
*/
|
||||
GroupCount getGroupCount(GroupId g) throws DbException;
|
||||
|
||||
@@ -112,19 +112,18 @@ public interface PrivateGroupManager {
|
||||
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.
|
||||
* Called when a contact relationship has been revealed between the user
|
||||
* and the given author in the given private group.
|
||||
*
|
||||
* @param byContact true if the remote contact has revealed
|
||||
* the relationship first. Otherwise false.
|
||||
* @param byContact True if the contact revealed the relationship first,
|
||||
* otherwise false.
|
||||
*/
|
||||
void relationshipRevealed(Transaction txn, GroupId g, AuthorId a,
|
||||
boolean byContact) throws FormatException, DbException;
|
||||
|
||||
/**
|
||||
* Registers a hook to be called when members are added
|
||||
* or groups are removed.
|
||||
* Registers a hook to be called when members are added or private groups
|
||||
* are removed.
|
||||
*/
|
||||
void registerPrivateGroupHook(PrivateGroupHook hook);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public enum Visibility {
|
||||
|
||||
INVISIBLE(0),
|
||||
@@ -9,7 +14,7 @@ public enum Visibility {
|
||||
REVEALED_BY_US(2),
|
||||
REVEALED_BY_CONTACT(3);
|
||||
|
||||
int value;
|
||||
private final int value;
|
||||
|
||||
Visibility(int value) {
|
||||
this.value = value;
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
package org.briarproject.briar.api.privategroup.event;
|
||||
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.privategroup.Visibility;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.briarproject.briar.api.privategroup.event;
|
||||
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a private group is dissolved by a remote
|
||||
* creator.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class GroupDissolvedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
|
||||
public GroupDissolvedEvent(GroupId groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.briarproject.briar.api.privategroup.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationRequestReceivedEvent;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class GroupInvitationRequestReceivedEvent extends
|
||||
InvitationRequestReceivedEvent<PrivateGroup> {
|
||||
|
||||
public GroupInvitationRequestReceivedEvent(PrivateGroup group,
|
||||
ContactId contactId, GroupInvitationRequest request) {
|
||||
super(group, contactId, request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.briarproject.briar.api.privategroup.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class GroupInvitationResponseReceivedEvent
|
||||
extends InvitationResponseReceivedEvent {
|
||||
|
||||
public GroupInvitationResponseReceivedEvent(ContactId contactId,
|
||||
InvitationResponse response) {
|
||||
super(contactId, response);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.privategroup.event;
|
||||
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a private group message was added
|
||||
* to the database.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class GroupMessageAddedEvent extends Event {
|
||||
|
||||
private final GroupId groupId;
|
||||
@@ -1,13 +1,15 @@
|
||||
package org.briarproject.api.privategroup.invitation;
|
||||
package org.briarproject.briar.api.privategroup.invitation;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import static org.briarproject.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface GroupInvitationFactory {
|
||||
|
||||
String SIGNING_LABEL_INVITE = CLIENT_ID + "/INVITE";
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.briarproject.api.privategroup.invitation;
|
||||
package org.briarproject.briar.api.privategroup.invitation;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.sharing.InvitationItem;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.briar.api.sharing.InvitationItem;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package org.briarproject.api.privategroup.invitation;
|
||||
package org.briarproject.briar.api.privategroup.invitation;
|
||||
|
||||
import org.briarproject.api.clients.ProtocolStateException;
|
||||
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.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.sharing.InvitationMessage;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.ProtocolStateException;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.briar.api.sharing.InvitationMessage;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.briarproject.api.privategroup.invitation;
|
||||
package org.briarproject.briar.api.privategroup.invitation;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.briarproject.api.privategroup.invitation;
|
||||
package org.briarproject.briar.api.privategroup.invitation;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
public interface InvitationFactory<I extends SharingMessage.Invitation> {
|
||||
|
||||
I build(GroupId groupId, BdfDictionary d) throws FormatException;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.api.sharing;
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.BaseMessageHeader;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class InvitationMessage extends BaseMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final ContactId contactId;
|
||||
|
||||
public InvitationMessage(MessageId id, SessionId sessionId, GroupId groupId,
|
||||
ContactId contactId, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
|
||||
super(id, groupId, time, local, read, sent, seen);
|
||||
this.sessionId = sessionId;
|
||||
this.contactId = contactId;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class InvitationRequest extends InvitationMessage {
|
||||
|
||||
@Nullable
|
||||
private final String message;
|
||||
private final boolean available;
|
||||
|
||||
public InvitationRequest(MessageId id, SessionId sessionId, GroupId groupId,
|
||||
ContactId contactId, @Nullable String message, boolean available,
|
||||
long time, boolean local, boolean sent, boolean seen,
|
||||
boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, time, local, sent, seen, read);
|
||||
this.message = message;
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class InvitationResponse extends InvitationMessage {
|
||||
|
||||
private final boolean accept;
|
||||
|
||||
public InvitationResponse(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, boolean accept, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read) {
|
||||
|
||||
super(id, sessionId, groupId, contactId, time, local, sent, seen, read);
|
||||
this.accept = accept;
|
||||
}
|
||||
|
||||
public boolean wasAccepted() {
|
||||
return accept;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface Shareable {
|
||||
|
||||
GroupId getId();
|
||||
|
||||
Group getGroup();
|
||||
|
||||
String getName();
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.api.sharing;
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface SharingConstants {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.api.sharing;
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package org.briarproject.api.sharing;
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.messaging.ConversationManager.ConversationClient;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface SharingManager<S extends Shareable>
|
||||
extends ConversationClient {
|
||||
@@ -1,25 +1,33 @@
|
||||
package org.briarproject.api.sharing;
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.data.BdfDictionary;
|
||||
import org.briarproject.api.data.BdfEntry;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import static org.briarproject.api.sharing.SharingConstants.GROUP_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ACCEPT;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_DECLINE;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
|
||||
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_LEAVE;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TIME;
|
||||
import static org.briarproject.api.sharing.SharingConstants.TYPE;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.GROUP_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_ACCEPT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_DECLINE;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_LEAVE;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TYPE;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface SharingMessage {
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
abstract class BaseMessage {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final SessionId sessionId;
|
||||
private final long time;
|
||||
@@ -71,12 +79,15 @@ public interface SharingMessage {
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
abstract class Invitation extends BaseMessage {
|
||||
|
||||
@Nullable
|
||||
protected final String message;
|
||||
|
||||
public Invitation(GroupId groupId, SessionId sessionId, long time,
|
||||
String message) {
|
||||
@Nullable String message) {
|
||||
|
||||
super(groupId, sessionId, time);
|
||||
|
||||
@@ -88,11 +99,14 @@ public interface SharingMessage {
|
||||
return SHARE_MSG_TYPE_INVITATION;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class SimpleMessage extends BaseMessage {
|
||||
|
||||
private final long type;
|
||||
@@ -1,9 +1,15 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.sharing.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationRequest;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||
import org.briarproject.briar.api.sharing.Shareable;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class InvitationRequestReceivedEvent<S extends Shareable>
|
||||
extends Event {
|
||||
|
||||
@@ -11,7 +17,7 @@ public abstract class InvitationRequestReceivedEvent<S extends Shareable>
|
||||
private final ContactId contactId;
|
||||
private final InvitationRequest request;
|
||||
|
||||
InvitationRequestReceivedEvent(S shareable, ContactId contactId,
|
||||
protected InvitationRequestReceivedEvent(S shareable, ContactId contactId,
|
||||
InvitationRequest request) {
|
||||
this.shareable = shareable;
|
||||
this.contactId = contactId;
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.briarproject.api.event;
|
||||
package org.briarproject.briar.api.sharing.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.sharing.InvitationResponse;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public abstract class InvitationResponseReceivedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
@@ -1,57 +0,0 @@
|
||||
package org.briarproject.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* A wrapper around a byte array, to allow it to be stored in maps etc.
|
||||
*/
|
||||
public class Bytes implements Comparable<Bytes> {
|
||||
|
||||
public static final BytesComparator COMPARATOR = new BytesComparator();
|
||||
|
||||
private final byte[] bytes;
|
||||
|
||||
private int hashCode = -1;
|
||||
|
||||
public Bytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Thread-safe because if two or more threads check and update the
|
||||
// value, they'll calculate the same value
|
||||
if (hashCode == -1) hashCode = Arrays.hashCode(bytes);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Bytes && Arrays.equals(bytes, ((Bytes) o).bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Bytes other) {
|
||||
byte[] aBytes = bytes, bBytes = other.bytes;
|
||||
int length = Math.min(aBytes.length, bBytes.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
int aUnsigned = aBytes[i] & 0xFF, bUnsigned = bBytes[i] & 0xFF;
|
||||
if (aUnsigned < bUnsigned) return -1;
|
||||
if (aUnsigned > bUnsigned) return 1;
|
||||
}
|
||||
return aBytes.length - bBytes.length;
|
||||
}
|
||||
|
||||
public static class BytesComparator implements Comparator<Bytes> {
|
||||
|
||||
@Override
|
||||
public int compare(Bytes a, Bytes b) {
|
||||
return a.compareTo(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user