mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Create PrivateGroupManager Facade and stub implementation
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package org.briarproject.api.blogs;
|
||||
|
||||
import org.briarproject.api.forum.Forum;
|
||||
import org.briarproject.api.clients.BaseGroup;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Blog extends Forum {
|
||||
public class Blog extends BaseGroup implements Shareable {
|
||||
|
||||
@NotNull
|
||||
private final String description;
|
||||
@NotNull
|
||||
private final Author author;
|
||||
|
||||
public Blog(@NotNull Group group, @NotNull String name,
|
||||
@@ -29,4 +28,9 @@ public class Blog extends Forum {
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Blog && super.equals(o);
|
||||
}
|
||||
}
|
||||
|
||||
46
briar-api/src/org/briarproject/api/clients/BaseGroup.java
Normal file
46
briar-api/src/org/briarproject/api/clients/BaseGroup.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.briarproject.api.clients;
|
||||
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BaseGroup {
|
||||
|
||||
private final Group group;
|
||||
private final String name;
|
||||
private final byte[] salt;
|
||||
|
||||
public BaseGroup(@NotNull Group group, @NotNull String name, byte[] salt) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public byte[] getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return group.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof BaseGroup &&
|
||||
getGroup().equals(((BaseGroup) o).getGroup());
|
||||
}
|
||||
|
||||
}
|
||||
28
briar-api/src/org/briarproject/api/clients/BaseMessage.java
Normal file
28
briar-api/src/org/briarproject/api/clients/BaseMessage.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.briarproject.api.clients;
|
||||
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseMessage {
|
||||
|
||||
private final Message message;
|
||||
private final MessageId parent;
|
||||
|
||||
public BaseMessage(@NotNull Message message, @Nullable MessageId parent) {
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.briarproject.api.messaging;
|
||||
package org.briarproject.api.clients;
|
||||
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public abstract class BaseMessage {
|
||||
public abstract class BaseMessageHeader {
|
||||
|
||||
private final MessageId id;
|
||||
private final long timestamp;
|
||||
private final boolean local, read, sent, seen;
|
||||
|
||||
public BaseMessage(MessageId id, long timestamp, boolean local,
|
||||
public BaseMessageHeader(MessageId id, long timestamp, boolean local,
|
||||
boolean read, boolean sent, boolean seen) {
|
||||
|
||||
this.id = id;
|
||||
@@ -3,12 +3,14 @@ package org.briarproject.api.clients;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupFactory;
|
||||
|
||||
public interface PrivateGroupFactory {
|
||||
public interface ContactGroupFactory {
|
||||
|
||||
/** Creates a group that is not shared with any contacts. */
|
||||
Group createLocalGroup(ClientId clientId);
|
||||
|
||||
/** Creates a group for the given client to share with the given contact. */
|
||||
Group createPrivateGroup(ClientId clientId, Contact contact);
|
||||
Group createContactGroup(ClientId clientId, Contact contact);
|
||||
|
||||
}
|
||||
@@ -1,44 +1,18 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.clients.BaseGroup;
|
||||
import org.briarproject.api.sharing.Shareable;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
public class Forum implements Shareable {
|
||||
|
||||
private final Group group;
|
||||
private final String name;
|
||||
private final byte[] salt;
|
||||
public class Forum extends BaseGroup implements Shareable {
|
||||
|
||||
public Forum(Group group, String name, byte[] salt) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public byte[] getSalt() {
|
||||
return salt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return group.hashCode();
|
||||
super(group, name, salt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof Forum && group.equals(((Forum) o).group);
|
||||
return o instanceof Forum && super.equals(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,25 @@
|
||||
package org.briarproject.api.forum;
|
||||
|
||||
import org.briarproject.api.clients.BaseMessage;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForumPost {
|
||||
public class ForumPost extends BaseMessage {
|
||||
|
||||
private final Message message;
|
||||
private final MessageId parent;
|
||||
private final Author author;
|
||||
|
||||
public ForumPost(Message message, MessageId parent, Author author) {
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
public ForumPost(@NotNull Message message, @Nullable MessageId parent,
|
||||
@Nullable Author author) {
|
||||
super(message, parent);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.briarproject.api.introduction;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.messaging.BaseMessage;
|
||||
import org.briarproject.api.clients.BaseMessageHeader;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCEE;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCER;
|
||||
|
||||
public class IntroductionMessage extends BaseMessage {
|
||||
public class IntroductionMessage extends BaseMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final MessageId messageId;
|
||||
|
||||
@@ -1,30 +1,23 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.clients.BaseMessage;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PrivateMessage {
|
||||
public class PrivateMessage extends BaseMessage {
|
||||
|
||||
private final Message message;
|
||||
private final MessageId parent;
|
||||
private final String contentType;
|
||||
|
||||
public PrivateMessage(Message message, MessageId parent,
|
||||
String contentType) {
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
public PrivateMessage(@NotNull Message message, @Nullable MessageId parent,
|
||||
@NotNull String contentType) {
|
||||
super(message, parent);
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.clients.BaseMessageHeader;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class PrivateMessageHeader extends BaseMessage {
|
||||
public class PrivateMessageHeader extends BaseMessageHeader {
|
||||
|
||||
private final String contentType;
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.forum.ForumPost;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GroupMessage extends ForumPost {
|
||||
|
||||
public GroupMessage(@NotNull Message message, @Nullable MessageId parent,
|
||||
@NotNull Author author) {
|
||||
super(message, parent, author);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface GroupMessageFactory {
|
||||
|
||||
@NotNull
|
||||
GroupMessage createGroupMessage(GroupId groupId, long timestamp,
|
||||
MessageId parent, LocalAuthor author, String body)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.PostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class GroupMessageHeader extends PostHeader {
|
||||
|
||||
public GroupMessageHeader(MessageId id, MessageId parentId, long timestamp,
|
||||
Author author, Author.Status authorStatus, boolean read) {
|
||||
super(id, parentId, timestamp, author, authorStatus, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.BaseGroup;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PrivateGroup extends BaseGroup {
|
||||
|
||||
private final Author author;
|
||||
|
||||
public PrivateGroup(@NotNull Group group, @NotNull String name,
|
||||
@NotNull Author author, @NotNull byte[] salt) {
|
||||
super(group, name, salt);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrivateGroup && super.equals(o);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface PrivateGroupConstants {
|
||||
|
||||
/**
|
||||
* The maximum length of a group's name in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_GROUP_NAME_LENGTH = 100;
|
||||
|
||||
/**
|
||||
* The length of a group's random salt in bytes.
|
||||
*/
|
||||
int GROUP_SALT_LENGTH = 32;
|
||||
|
||||
/**
|
||||
* The maximum length of a group post's body in bytes.
|
||||
*/
|
||||
int MAX_GROUP_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PrivateGroupFactory {
|
||||
|
||||
/**
|
||||
* Creates a private group with the given name and author.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup createPrivateGroup(String name, Author author);
|
||||
|
||||
/**
|
||||
* Creates a private group with the given name, author and salt.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface PrivateGroupManager {
|
||||
|
||||
/** Returns the unique ID of the private group client. */
|
||||
@NotNull
|
||||
ClientId getClientId();
|
||||
|
||||
/** Stores (and sends) a local group message. */
|
||||
void addLocalMessage(GroupMessage p) throws DbException;
|
||||
|
||||
/** Returns the private group with the given ID. */
|
||||
@NotNull
|
||||
PrivateGroup getPrivateGroup(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the private group with the given ID within the given transaction.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup getPrivateGroup(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/** Returns all private groups the user is a member of. */
|
||||
@NotNull
|
||||
Collection<PrivateGroup> getPrivateGroups() throws DbException;
|
||||
|
||||
/** Returns the body of the group message with the given ID. */
|
||||
@NotNull
|
||||
String getMessageBody(MessageId m) throws DbException;
|
||||
|
||||
/** Returns the headers of all group messages in the given group. */
|
||||
@NotNull
|
||||
Collection<GroupMessageHeader> getHeaders(GroupId g) throws DbException;
|
||||
|
||||
/** Marks a group message as read or unread. */
|
||||
void setReadFlag(MessageId m, boolean read) throws DbException;
|
||||
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package org.briarproject.api.sharing;
|
||||
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.messaging.BaseMessage;
|
||||
import org.briarproject.api.clients.BaseMessageHeader;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public abstract class InvitationMessage extends BaseMessage {
|
||||
public abstract class InvitationMessage extends BaseMessageHeader {
|
||||
|
||||
private final SessionId sessionId;
|
||||
private final ContactId contactId;
|
||||
|
||||
Reference in New Issue
Block a user