mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Converted Group from an interface to an immutable class.
This commit is contained in:
@@ -1,17 +1,43 @@
|
|||||||
package net.sf.briar.api.protocol;
|
package net.sf.briar.api.protocol;
|
||||||
|
|
||||||
/** A group to which users may subscribe. */
|
/** A group to which users may subscribe. */
|
||||||
public interface Group {
|
public class Group {
|
||||||
|
|
||||||
|
private final GroupId id;
|
||||||
|
private final String name;
|
||||||
|
private final byte[] publicKey;
|
||||||
|
|
||||||
|
public Group(GroupId id, String name, byte[] publicKey) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the group's unique identifier. */
|
/** Returns the group's unique identifier. */
|
||||||
GroupId getId();
|
public GroupId getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the group's name. */
|
/** Returns the group's name. */
|
||||||
String getName();
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the group is restricted, returns the public key that is used to
|
* If the group is restricted, returns the public key that is used to
|
||||||
* authorise all messages sent to the group. Otherwise returns null.
|
* authorise all messages sent to the group. Otherwise returns null.
|
||||||
*/
|
*/
|
||||||
byte[] getPublicKey();
|
public byte[] getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return id.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof Group && id.equals(((Group) o).id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,4 @@ import java.io.IOException;
|
|||||||
public interface GroupFactory {
|
public interface GroupFactory {
|
||||||
|
|
||||||
Group createGroup(String name, byte[] publicKey) throws IOException;
|
Group createGroup(String name, byte[] publicKey) throws IOException;
|
||||||
|
|
||||||
Group createGroup(GroupId id, String name, byte[] publicKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import net.sf.briar.api.db.DatabaseComponent;
|
|||||||
import net.sf.briar.api.db.DatabaseConfig;
|
import net.sf.briar.api.db.DatabaseConfig;
|
||||||
import net.sf.briar.api.db.DatabaseExecutor;
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.api.protocol.PacketFactory;
|
import net.sf.briar.api.protocol.PacketFactory;
|
||||||
import net.sf.briar.util.BoundedExecutor;
|
import net.sf.briar.util.BoundedExecutor;
|
||||||
|
|
||||||
@@ -42,9 +41,8 @@ public class DatabaseModule extends AbstractModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
Database<Connection> getDatabase(DatabaseConfig config,
|
Database<Connection> getDatabase(Clock clock, DatabaseConfig config) {
|
||||||
GroupFactory groupFactory, Clock clock) {
|
return new H2Database(clock, config);
|
||||||
return new H2Database(config, groupFactory, clock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides @Singleton
|
@Provides @Singleton
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import net.sf.briar.api.clock.Clock;
|
|||||||
import net.sf.briar.api.crypto.Password;
|
import net.sf.briar.api.crypto.Password;
|
||||||
import net.sf.briar.api.db.DatabaseConfig;
|
import net.sf.briar.api.db.DatabaseConfig;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
import net.sf.briar.util.FileUtils;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -31,9 +30,8 @@ class H2Database extends JdbcDatabase {
|
|||||||
private final long maxSize;
|
private final long maxSize;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
H2Database(DatabaseConfig config, GroupFactory groupFactory, Clock clock) {
|
H2Database(Clock clock, DatabaseConfig config) {
|
||||||
super(groupFactory, clock, HASH_TYPE, BINARY_TYPE, COUNTER_TYPE,
|
super(clock, HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE);
|
||||||
SECRET_TYPE);
|
|
||||||
home = new File(config.getDataDirectory(), "db");
|
home = new File(config.getDataDirectory(), "db");
|
||||||
url = "jdbc:h2:split:" + home.getPath()
|
url = "jdbc:h2:split:" + home.getPath()
|
||||||
+ ";CIPHER=AES;DB_CLOSE_ON_EXIT=false";
|
+ ";CIPHER=AES;DB_CLOSE_ON_EXIT=false";
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import net.sf.briar.api.db.MessageHeader;
|
|||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
@@ -262,8 +261,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(JdbcDatabase.class.getName());
|
Logger.getLogger(JdbcDatabase.class.getName());
|
||||||
|
|
||||||
// FIXME: Can this factory be done away with?
|
|
||||||
private final GroupFactory groupFactory;
|
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
// Different database libraries use different names for certain types
|
// Different database libraries use different names for certain types
|
||||||
private final String hashType, binaryType, counterType, secretType;
|
private final String hashType, binaryType, counterType, secretType;
|
||||||
@@ -276,9 +273,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
|
|
||||||
protected abstract Connection createConnection() throws SQLException;
|
protected abstract Connection createConnection() throws SQLException;
|
||||||
|
|
||||||
JdbcDatabase(GroupFactory groupFactory, Clock clock, String hashType,
|
JdbcDatabase(Clock clock, String hashType, String binaryType,
|
||||||
String binaryType, String counterType, String secretType) {
|
String counterType, String secretType) {
|
||||||
this.groupFactory = groupFactory;
|
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.hashType = hashType;
|
this.hashType = hashType;
|
||||||
this.binaryType = binaryType;
|
this.binaryType = binaryType;
|
||||||
@@ -1772,7 +1768,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
GroupId id = new GroupId(rs.getBytes(1));
|
GroupId id = new GroupId(rs.getBytes(1));
|
||||||
String name = rs.getString(2);
|
String name = rs.getString(2);
|
||||||
byte[] publicKey = rs.getBytes(3);
|
byte[] publicKey = rs.getBytes(3);
|
||||||
subs.add(groupFactory.createGroup(id, name, publicKey));
|
subs.add(new Group(id, name, publicKey));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -1800,7 +1796,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
GroupId id = new GroupId(rs.getBytes(1));
|
GroupId id = new GroupId(rs.getBytes(1));
|
||||||
String name = rs.getString(2);
|
String name = rs.getString(2);
|
||||||
byte[] publicKey = rs.getBytes(3);
|
byte[] publicKey = rs.getBytes(3);
|
||||||
subs.add(groupFactory.createGroup(id, name, publicKey));
|
subs.add(new Group(id, name, publicKey));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -1962,7 +1958,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
byte[] publicKey = rs.getBytes(3);
|
byte[] publicKey = rs.getBytes(3);
|
||||||
long start = rs.getLong(4);
|
long start = rs.getLong(4);
|
||||||
if(subs == null) subs = new HashMap<Group, Long>();
|
if(subs == null) subs = new HashMap<Group, Long>();
|
||||||
subs.put(groupFactory.createGroup(id, name, publicKey), start);
|
subs.put(new Group(id, name, publicKey), start);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ class GroupFactoryImpl implements GroupFactory {
|
|||||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||||
messageDigest.update(out.toByteArray());
|
messageDigest.update(out.toByteArray());
|
||||||
GroupId id = new GroupId(messageDigest.digest());
|
GroupId id = new GroupId(messageDigest.digest());
|
||||||
return new GroupImpl(id, name, publicKey);
|
return new Group(id, name, publicKey);
|
||||||
}
|
|
||||||
|
|
||||||
public Group createGroup(GroupId id, String name, byte[] publicKey) {
|
|
||||||
return new GroupImpl(id, name, publicKey);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package net.sf.briar.protocol;
|
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.Group;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
|
||||||
|
|
||||||
class GroupImpl implements Group {
|
|
||||||
|
|
||||||
private final GroupId id;
|
|
||||||
private final String name;
|
|
||||||
private final byte[] publicKey;
|
|
||||||
|
|
||||||
GroupImpl(GroupId id, String name, byte[] publicKey) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.publicKey = publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GroupId getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPublicKey() {
|
|
||||||
return publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return id.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return o instanceof Group && id.equals(((Group) o).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ import java.io.IOException;
|
|||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.crypto.MessageDigest;
|
import net.sf.briar.api.crypto.MessageDigest;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Types;
|
import net.sf.briar.api.protocol.Types;
|
||||||
import net.sf.briar.api.serial.DigestingConsumer;
|
import net.sf.briar.api.serial.DigestingConsumer;
|
||||||
@@ -18,11 +17,9 @@ import net.sf.briar.api.serial.StructReader;
|
|||||||
class GroupReader implements StructReader<Group> {
|
class GroupReader implements StructReader<Group> {
|
||||||
|
|
||||||
private final MessageDigest messageDigest;
|
private final MessageDigest messageDigest;
|
||||||
private final GroupFactory groupFactory;
|
|
||||||
|
|
||||||
GroupReader(CryptoComponent crypto, GroupFactory groupFactory) {
|
GroupReader(CryptoComponent crypto) {
|
||||||
messageDigest = crypto.getMessageDigest();
|
messageDigest = crypto.getMessageDigest();
|
||||||
this.groupFactory = groupFactory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group readStruct(Reader r) throws IOException {
|
public Group readStruct(Reader r) throws IOException {
|
||||||
@@ -38,6 +35,6 @@ class GroupReader implements StructReader<Group> {
|
|||||||
r.removeConsumer(digesting);
|
r.removeConsumer(digesting);
|
||||||
// Build and return the group
|
// Build and return the group
|
||||||
GroupId id = new GroupId(messageDigest.digest());
|
GroupId id = new GroupId(messageDigest.digest());
|
||||||
return groupFactory.createGroup(id, name, publicKey);
|
return new Group(id, name, publicKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class ProtocolModule extends AbstractModule {
|
|||||||
|
|
||||||
/** The maximum number of verification threads. */
|
/** The maximum number of verification threads. */
|
||||||
private static final int MAX_VERIFIER_THREADS =
|
private static final int MAX_VERIFIER_THREADS =
|
||||||
Runtime.getRuntime().availableProcessors();
|
Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
@@ -76,9 +76,8 @@ public class ProtocolModule extends AbstractModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
StructReader<Group> getGroupReader(CryptoComponent crypto,
|
StructReader<Group> getGroupReader(CryptoComponent crypto) {
|
||||||
GroupFactory groupFactory) {
|
return new GroupReader(crypto);
|
||||||
return new GroupReader(crypto, groupFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
timestamp, raw);
|
timestamp, raw);
|
||||||
privateMessage = new TestMessage(messageId, null, null, null, subject,
|
privateMessage = new TestMessage(messageId, null, null, null, subject,
|
||||||
timestamp, raw);
|
timestamp, raw);
|
||||||
group = new TestGroup(groupId, "The really exciting group", null);
|
group = new Group(groupId, "The really exciting group", null);
|
||||||
transportId = new TransportId(TestUtils.getRandomId());
|
transportId = new TransportId(TestUtils.getRandomId());
|
||||||
TransportProperties properties = new TransportProperties(
|
TransportProperties properties = new TransportProperties(
|
||||||
Collections.singletonMap("foo", "bar"));
|
Collections.singletonMap("foo", "bar"));
|
||||||
@@ -104,7 +104,6 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
final DatabaseCleaner cleaner = context.mock(DatabaseCleaner.class);
|
||||||
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
final ShutdownManager shutdown = context.mock(ShutdownManager.class);
|
||||||
final PacketFactory packetFactory = context.mock(PacketFactory.class);
|
final PacketFactory packetFactory = context.mock(PacketFactory.class);
|
||||||
final Group group = context.mock(Group.class);
|
|
||||||
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
final DatabaseListener listener = context.mock(DatabaseListener.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
allowing(database).startTransaction();
|
allowing(database).startTransaction();
|
||||||
@@ -140,14 +139,10 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
oneOf(database).getRemoteProperties(txn, transportId);
|
oneOf(database).getRemoteProperties(txn, transportId);
|
||||||
will(returnValue(Collections.emptyMap()));
|
will(returnValue(Collections.emptyMap()));
|
||||||
// subscribe(group)
|
// subscribe(group)
|
||||||
oneOf(group).getId();
|
|
||||||
will(returnValue(groupId));
|
|
||||||
oneOf(database).containsSubscription(txn, groupId);
|
oneOf(database).containsSubscription(txn, groupId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).addSubscription(txn, group);
|
oneOf(database).addSubscription(txn, group);
|
||||||
// subscribe(group) again
|
// subscribe(group) again
|
||||||
oneOf(group).getId();
|
|
||||||
will(returnValue(groupId));
|
|
||||||
oneOf(database).containsSubscription(txn, groupId);
|
oneOf(database).containsSubscription(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
// getMessageHeaders(groupId)
|
// getMessageHeaders(groupId)
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import net.sf.briar.api.db.MessageHeader;
|
|||||||
import net.sf.briar.api.protocol.AuthorId;
|
import net.sf.briar.api.protocol.AuthorId;
|
||||||
import net.sf.briar.api.protocol.BatchId;
|
import net.sf.briar.api.protocol.BatchId;
|
||||||
import net.sf.briar.api.protocol.Group;
|
import net.sf.briar.api.protocol.Group;
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
import net.sf.briar.api.protocol.GroupId;
|
||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
@@ -52,7 +51,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
private final GroupFactory groupFactory;
|
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final AuthorId authorId;
|
private final AuthorId authorId;
|
||||||
private final BatchId batchId;
|
private final BatchId batchId;
|
||||||
@@ -68,14 +66,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
public H2DatabaseTest() throws Exception {
|
public H2DatabaseTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
groupFactory = new TestGroupFactory();
|
|
||||||
authorId = new AuthorId(TestUtils.getRandomId());
|
authorId = new AuthorId(TestUtils.getRandomId());
|
||||||
batchId = new BatchId(TestUtils.getRandomId());
|
batchId = new BatchId(TestUtils.getRandomId());
|
||||||
contactId = new ContactId(1);
|
contactId = new ContactId(1);
|
||||||
groupId = new GroupId(TestUtils.getRandomId());
|
groupId = new GroupId(TestUtils.getRandomId());
|
||||||
messageId = new MessageId(TestUtils.getRandomId());
|
messageId = new MessageId(TestUtils.getRandomId());
|
||||||
privateMessageId = new MessageId(TestUtils.getRandomId());
|
privateMessageId = new MessageId(TestUtils.getRandomId());
|
||||||
group = new TestGroup(groupId, "Foo", null);
|
group = new Group(groupId, "Foo", null);
|
||||||
subject = "Foo";
|
subject = "Foo";
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
size = 1234;
|
size = 1234;
|
||||||
@@ -798,7 +795,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId childId2 = new MessageId(TestUtils.getRandomId());
|
MessageId childId2 = new MessageId(TestUtils.getRandomId());
|
||||||
MessageId childId3 = new MessageId(TestUtils.getRandomId());
|
MessageId childId3 = new MessageId(TestUtils.getRandomId());
|
||||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||||
Group group1 = groupFactory.createGroup(groupId1, "Another group name",
|
Group group1 = new Group(groupId1, "Another group name",
|
||||||
null);
|
null);
|
||||||
Message child1 = new TestMessage(childId1, messageId, groupId,
|
Message child1 = new TestMessage(childId1, messageId, groupId,
|
||||||
authorId, subject, timestamp, raw);
|
authorId, subject, timestamp, raw);
|
||||||
@@ -1391,7 +1388,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
public void testGetGroupMessageParentWithParentInAnotherGroup()
|
public void testGetGroupMessageParentWithParentInAnotherGroup()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||||
Group group1 = groupFactory.createGroup(groupId1, "Group name", null);
|
Group group1 = new Group(groupId1, "Group name", null);
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
@@ -1641,8 +1638,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Subscribe to a couple of groups
|
// Subscribe to a couple of groups
|
||||||
db.addSubscription(txn, group);
|
db.addSubscription(txn, group);
|
||||||
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
GroupId groupId1 = new GroupId(TestUtils.getRandomId());
|
||||||
Group group1 = groupFactory.createGroup(groupId1, "Another group",
|
Group group1 = new Group(groupId1, "Another group", null);
|
||||||
null);
|
|
||||||
db.addSubscription(txn, group1);
|
db.addSubscription(txn, group1);
|
||||||
|
|
||||||
// Store two messages in the first group
|
// Store two messages in the first group
|
||||||
@@ -1695,7 +1691,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
List<Group> groups = new ArrayList<Group>();
|
List<Group> groups = new ArrayList<Group>();
|
||||||
for(int i = 0; i < 100; i++) {
|
for(int i = 0; i < 100; i++) {
|
||||||
GroupId id = new GroupId(TestUtils.getRandomId());
|
GroupId id = new GroupId(TestUtils.getRandomId());
|
||||||
groups.add(groupFactory.createGroup(id, "Group name", null));
|
groups.add(new Group(id, "Group name", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
@@ -2030,9 +2026,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Database<Connection> open(boolean resume) throws Exception {
|
private Database<Connection> open(boolean resume) throws Exception {
|
||||||
Database<Connection> db = new H2Database(
|
Database<Connection> db = new H2Database(new SystemClock(),
|
||||||
new TestDatabaseConfig(testDir, MAX_SIZE), groupFactory,
|
new TestDatabaseConfig(testDir, MAX_SIZE));
|
||||||
new SystemClock());
|
|
||||||
db.open(resume);
|
db.open(resume);
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package net.sf.briar.db;
|
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.Group;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
|
||||||
|
|
||||||
class TestGroup implements Group {
|
|
||||||
|
|
||||||
private final GroupId id;
|
|
||||||
private final String name;
|
|
||||||
private final byte[] publicKey;
|
|
||||||
|
|
||||||
public TestGroup(GroupId id, String name, byte[] publicKey) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.publicKey = publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GroupId getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPublicKey() {
|
|
||||||
return publicKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package net.sf.briar.db;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import net.sf.briar.TestUtils;
|
|
||||||
import net.sf.briar.api.protocol.Group;
|
|
||||||
import net.sf.briar.api.protocol.GroupFactory;
|
|
||||||
import net.sf.briar.api.protocol.GroupId;
|
|
||||||
|
|
||||||
class TestGroupFactory implements GroupFactory {
|
|
||||||
|
|
||||||
public Group createGroup(String name, byte[] publicKey) throws IOException {
|
|
||||||
GroupId id = new GroupId(TestUtils.getRandomId());
|
|
||||||
return new TestGroup(id, name, publicKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Group createGroup(GroupId id, String name, byte[] publicKey) {
|
|
||||||
return new TestGroup(id, name, publicKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -126,6 +126,9 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
final int signedByAuthor = 100, signedByGroup = 110;
|
final int signedByAuthor = 100, signedByGroup = 110;
|
||||||
final KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
final KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
||||||
final KeyPair groupKeyPair = crypto.generateSignatureKeyPair();
|
final KeyPair groupKeyPair = crypto.generateSignatureKeyPair();
|
||||||
|
GroupId groupId = new GroupId(TestUtils.getRandomId());
|
||||||
|
final Group group = new Group(groupId, "Group name",
|
||||||
|
groupKeyPair.getPublic().getEncoded());
|
||||||
Signature signature = crypto.getSignature();
|
Signature signature = crypto.getSignature();
|
||||||
// Calculate the expected author and group signatures
|
// Calculate the expected author and group signatures
|
||||||
signature.initSign(authorKeyPair.getPrivate());
|
signature.initSign(authorKeyPair.getPrivate());
|
||||||
@@ -139,7 +142,6 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
final UnverifiedMessage message =
|
final UnverifiedMessage message =
|
||||||
context.mock(UnverifiedMessage.class, "message");
|
context.mock(UnverifiedMessage.class, "message");
|
||||||
final Author author = context.mock(Author.class);
|
final Author author = context.mock(Author.class);
|
||||||
final Group group = context.mock(Group.class);
|
|
||||||
final UnverifiedMessage message1 =
|
final UnverifiedMessage message1 =
|
||||||
context.mock(UnverifiedMessage.class, "message1");
|
context.mock(UnverifiedMessage.class, "message1");
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -156,16 +158,12 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
|||||||
will(returnValue(authorSignature));
|
will(returnValue(authorSignature));
|
||||||
oneOf(message).getGroup();
|
oneOf(message).getGroup();
|
||||||
will(returnValue(group));
|
will(returnValue(group));
|
||||||
exactly(2).of(group).getPublicKey();
|
|
||||||
will(returnValue(groupKeyPair.getPublic().getEncoded()));
|
|
||||||
oneOf(message).getLengthSignedByGroup();
|
oneOf(message).getLengthSignedByGroup();
|
||||||
will(returnValue(signedByGroup));
|
will(returnValue(signedByGroup));
|
||||||
oneOf(message).getGroupSignature();
|
oneOf(message).getGroupSignature();
|
||||||
will(returnValue(groupSignature));
|
will(returnValue(groupSignature));
|
||||||
oneOf(author).getId();
|
oneOf(author).getId();
|
||||||
will(returnValue(new AuthorId(TestUtils.getRandomId())));
|
will(returnValue(new AuthorId(TestUtils.getRandomId())));
|
||||||
oneOf(group).getId();
|
|
||||||
will(returnValue(new GroupId(TestUtils.getRandomId())));
|
|
||||||
oneOf(message).getParent();
|
oneOf(message).getParent();
|
||||||
will(returnValue(null));
|
will(returnValue(null));
|
||||||
oneOf(message).getSubject();
|
oneOf(message).getSubject();
|
||||||
|
|||||||
Reference in New Issue
Block a user