mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Converted Group from an interface to an immutable class.
This commit is contained in:
@@ -8,7 +8,6 @@ import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DatabaseConfig;
|
||||
import net.sf.briar.api.db.DatabaseExecutor;
|
||||
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.util.BoundedExecutor;
|
||||
|
||||
@@ -42,9 +41,8 @@ public class DatabaseModule extends AbstractModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
Database<Connection> getDatabase(DatabaseConfig config,
|
||||
GroupFactory groupFactory, Clock clock) {
|
||||
return new H2Database(config, groupFactory, clock);
|
||||
Database<Connection> getDatabase(Clock clock, DatabaseConfig config) {
|
||||
return new H2Database(clock, config);
|
||||
}
|
||||
|
||||
@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.db.DatabaseConfig;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
import net.sf.briar.api.protocol.GroupFactory;
|
||||
import net.sf.briar.util.FileUtils;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
@@ -31,9 +30,8 @@ class H2Database extends JdbcDatabase {
|
||||
private final long maxSize;
|
||||
|
||||
@Inject
|
||||
H2Database(DatabaseConfig config, GroupFactory groupFactory, Clock clock) {
|
||||
super(groupFactory, clock, HASH_TYPE, BINARY_TYPE, COUNTER_TYPE,
|
||||
SECRET_TYPE);
|
||||
H2Database(Clock clock, DatabaseConfig config) {
|
||||
super(clock, HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE);
|
||||
home = new File(config.getDataDirectory(), "db");
|
||||
url = "jdbc:h2:split:" + home.getPath()
|
||||
+ ";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.BatchId;
|
||||
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.Message;
|
||||
import net.sf.briar.api.protocol.MessageId;
|
||||
@@ -262,8 +261,6 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(JdbcDatabase.class.getName());
|
||||
|
||||
// FIXME: Can this factory be done away with?
|
||||
private final GroupFactory groupFactory;
|
||||
private final Clock clock;
|
||||
// Different database libraries use different names for certain types
|
||||
private final String hashType, binaryType, counterType, secretType;
|
||||
@@ -276,9 +273,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
protected abstract Connection createConnection() throws SQLException;
|
||||
|
||||
JdbcDatabase(GroupFactory groupFactory, Clock clock, String hashType,
|
||||
String binaryType, String counterType, String secretType) {
|
||||
this.groupFactory = groupFactory;
|
||||
JdbcDatabase(Clock clock, String hashType, String binaryType,
|
||||
String counterType, String secretType) {
|
||||
this.clock = clock;
|
||||
this.hashType = hashType;
|
||||
this.binaryType = binaryType;
|
||||
@@ -1772,7 +1768,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
String name = rs.getString(2);
|
||||
byte[] publicKey = rs.getBytes(3);
|
||||
subs.add(groupFactory.createGroup(id, name, publicKey));
|
||||
subs.add(new Group(id, name, publicKey));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1800,7 +1796,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
String name = rs.getString(2);
|
||||
byte[] publicKey = rs.getBytes(3);
|
||||
subs.add(groupFactory.createGroup(id, name, publicKey));
|
||||
subs.add(new Group(id, name, publicKey));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1962,7 +1958,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
byte[] publicKey = rs.getBytes(3);
|
||||
long start = rs.getLong(4);
|
||||
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();
|
||||
ps.close();
|
||||
|
||||
@@ -35,10 +35,6 @@ class GroupFactoryImpl implements GroupFactory {
|
||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||
messageDigest.update(out.toByteArray());
|
||||
GroupId id = new GroupId(messageDigest.digest());
|
||||
return new GroupImpl(id, name, publicKey);
|
||||
}
|
||||
|
||||
public Group createGroup(GroupId id, String name, byte[] publicKey) {
|
||||
return new GroupImpl(id, name, publicKey);
|
||||
return new Group(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.MessageDigest;
|
||||
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.Types;
|
||||
import net.sf.briar.api.serial.DigestingConsumer;
|
||||
@@ -18,11 +17,9 @@ import net.sf.briar.api.serial.StructReader;
|
||||
class GroupReader implements StructReader<Group> {
|
||||
|
||||
private final MessageDigest messageDigest;
|
||||
private final GroupFactory groupFactory;
|
||||
|
||||
GroupReader(CryptoComponent crypto, GroupFactory groupFactory) {
|
||||
GroupReader(CryptoComponent crypto) {
|
||||
messageDigest = crypto.getMessageDigest();
|
||||
this.groupFactory = groupFactory;
|
||||
}
|
||||
|
||||
public Group readStruct(Reader r) throws IOException {
|
||||
@@ -38,6 +35,6 @@ class GroupReader implements StructReader<Group> {
|
||||
r.removeConsumer(digesting);
|
||||
// Build and return the group
|
||||
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. */
|
||||
private static final int MAX_VERIFIER_THREADS =
|
||||
Runtime.getRuntime().availableProcessors();
|
||||
Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
@@ -76,9 +76,8 @@ public class ProtocolModule extends AbstractModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
StructReader<Group> getGroupReader(CryptoComponent crypto,
|
||||
GroupFactory groupFactory) {
|
||||
return new GroupReader(crypto, groupFactory);
|
||||
StructReader<Group> getGroupReader(CryptoComponent crypto) {
|
||||
return new GroupReader(crypto);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
Reference in New Issue
Block a user