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