mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Parsing and retrieval of private groups in PrivateGroupManager
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PrivateGroupFactory {
|
||||
@@ -17,4 +19,9 @@ public interface PrivateGroupFactory {
|
||||
@NotNull
|
||||
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
|
||||
|
||||
/**
|
||||
* Parses a group and returns the corresponding PrivateGroup.
|
||||
*/
|
||||
PrivateGroup parsePrivateGroup(Group group) throws FormatException;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.data.BdfList;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.privategroup.PrivateGroupFactory;
|
||||
import org.briarproject.api.sync.Group;
|
||||
@@ -22,14 +23,17 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory {
|
||||
|
||||
private final GroupFactory groupFactory;
|
||||
private final ClientHelper clientHelper;
|
||||
private final AuthorFactory authorFactory;
|
||||
private final SecureRandom random;
|
||||
|
||||
@Inject
|
||||
PrivateGroupFactoryImpl(GroupFactory groupFactory,
|
||||
ClientHelper clientHelper, SecureRandom random) {
|
||||
ClientHelper clientHelper, AuthorFactory authorFactory,
|
||||
SecureRandom random) {
|
||||
|
||||
this.groupFactory = groupFactory;
|
||||
this.clientHelper = clientHelper;
|
||||
this.authorFactory = authorFactory;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
@@ -66,4 +70,13 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrivateGroup parsePrivateGroup(Group group) throws FormatException {
|
||||
byte[] descriptor = group.getDescriptor();
|
||||
BdfList list = clientHelper.toList(descriptor);
|
||||
Author a =
|
||||
authorFactory.createAuthor(list.getString(1), list.getRaw(2));
|
||||
return new PrivateGroup(group, list.getString(0), a, list.getRaw(3));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.api.data.MetadataParser;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.privategroup.GroupMessage;
|
||||
import org.briarproject.api.privategroup.GroupMessageHeader;
|
||||
@@ -16,6 +15,7 @@ import org.briarproject.api.privategroup.PrivateGroup;
|
||||
import org.briarproject.api.privategroup.PrivateGroupFactory;
|
||||
import org.briarproject.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
@@ -81,16 +81,27 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
|
||||
@NotNull
|
||||
@Override
|
||||
public PrivateGroup getPrivateGroup(GroupId g) throws DbException {
|
||||
Author a = identityManager.getLocalAuthor();
|
||||
return privateGroupFactory.createPrivateGroup("todo", a);
|
||||
PrivateGroup privateGroup;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
privateGroup = getPrivateGroup(txn, g);
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return privateGroup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PrivateGroup getPrivateGroup(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
Author a = identityManager.getLocalAuthor(txn);
|
||||
return privateGroupFactory.createPrivateGroup("todo", a);
|
||||
try {
|
||||
Group group = db.getGroup(txn, g);
|
||||
return privateGroupFactory.parsePrivateGroup(group);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user