Use namespaced strings for client IDs

This commit is contained in:
Torsten Grote
2016-11-07 19:30:23 -02:00
parent 1809943f1d
commit e96b3a8c68
48 changed files with 131 additions and 195 deletions

View File

@@ -57,6 +57,7 @@ import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import static org.briarproject.TestPluginsModule.MAX_LATENCY; import static org.briarproject.TestPluginsModule.MAX_LATENCY;
import static org.briarproject.api.blogs.BlogSharingManager.CLIENT_ID;
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.api.sync.ValidationManager.State.INVALID; import static org.briarproject.api.sync.ValidationManager.State.INVALID;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -189,9 +190,8 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
assertEquals(2, blogManager1.getBlogs().size()); assertEquals(2, blogManager1.getBlogs().size());
// get sharing group and assert group message count // get sharing group and assert group message count
GroupId g = contactGroupFactory GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID, contact1)
.createContactGroup(blogSharingManager0.getClientId(), .getId();
contact1).getId();
assertGroupCount(blogSharingManager0, g, 1, 0); assertGroupCount(blogSharingManager0, g, 1, 0);
// sync first request message // sync first request message

View File

@@ -68,6 +68,7 @@ import javax.inject.Inject;
import static org.briarproject.TestPluginsModule.MAX_LATENCY; import static org.briarproject.TestPluginsModule.MAX_LATENCY;
import static org.briarproject.api.forum.ForumConstants.FORUM_SALT_LENGTH; import static org.briarproject.api.forum.ForumConstants.FORUM_SALT_LENGTH;
import static org.briarproject.api.forum.ForumSharingManager.CLIENT_ID;
import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION; import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.api.sync.ValidationManager.State.INVALID; import static org.briarproject.api.sync.ValidationManager.State.INVALID;
@@ -495,8 +496,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
MessageQueueManager queue = t0.getMessageQueueManager(); MessageQueueManager queue = t0.getMessageQueueManager();
Contact c1 = contactManager0.getContact(contactId1); Contact c1 = contactManager0.getContact(contactId1);
ContactGroupFactory groupFactory = t0.getContactGroupFactory(); ContactGroupFactory groupFactory = t0.getContactGroupFactory();
Group group = groupFactory Group group = groupFactory.createContactGroup(CLIENT_ID, c1);
.createContactGroup(forumSharingManager0.getClientId(), c1);
long time = clock.currentTimeMillis(); long time = clock.currentTimeMillis();
BdfList bodyList = BdfList.of(SHARE_MSG_TYPE_INVITATION, BdfList bodyList = BdfList.of(SHARE_MSG_TYPE_INVITATION,
sessionId.getBytes(), sessionId.getBytes(),
@@ -691,8 +691,7 @@ public class ForumSharingIntegrationTest extends BriarTestCase {
MessageQueueManager queue = t0.getMessageQueueManager(); MessageQueueManager queue = t0.getMessageQueueManager();
Contact c1 = contactManager0.getContact(contactId1); Contact c1 = contactManager0.getContact(contactId1);
ContactGroupFactory groupFactory = t0.getContactGroupFactory(); ContactGroupFactory groupFactory = t0.getContactGroupFactory();
Group group = groupFactory Group group = groupFactory.createContactGroup(CLIENT_ID, c1);
.createContactGroup(forumSharingManager0.getClientId(), c1);
long time = clock.currentTimeMillis(); long time = clock.currentTimeMillis();
// construct a new message re-using the old SessionId // construct a new message re-using the old SessionId

View File

@@ -60,6 +60,7 @@ import javax.inject.Inject;
import static org.briarproject.TestPluginsModule.MAX_LATENCY; import static org.briarproject.TestPluginsModule.MAX_LATENCY;
import static org.briarproject.TestUtils.getRandomBytes; import static org.briarproject.TestUtils.getRandomBytes;
import static org.briarproject.api.identity.Author.Status.VERIFIED; import static org.briarproject.api.identity.Author.Status.VERIFIED;
import static org.briarproject.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
import static org.briarproject.api.sync.ValidationManager.State.DELIVERED; import static org.briarproject.api.sync.ValidationManager.State.DELIVERED;
import static org.briarproject.api.sync.ValidationManager.State.INVALID; import static org.briarproject.api.sync.ValidationManager.State.INVALID;
import static org.briarproject.api.sync.ValidationManager.State.PENDING; import static org.briarproject.api.sync.ValidationManager.State.PENDING;
@@ -341,8 +342,8 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
joinTime = clock.currentTimeMillis(); joinTime = clock.currentTimeMillis();
long inviteTime = joinTime; long inviteTime = joinTime;
Group invitationGroup = contactGroupFactory Group invitationGroup = contactGroupFactory
.createContactGroup(groupInvitationManager.getClientId(), .createContactGroup(CLIENT_ID, author0.getId(),
author0.getId(), author1.getId()); author1.getId());
BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(), BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
privateGroup0.getId()); privateGroup0.getId());
byte[] creatorSignature = byte[] creatorSignature =
@@ -386,8 +387,8 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
long joinTime = clock.currentTimeMillis(); long joinTime = clock.currentTimeMillis();
long inviteTime = joinTime - 1; long inviteTime = joinTime - 1;
Group invitationGroup = contactGroupFactory Group invitationGroup = contactGroupFactory
.createContactGroup(groupInvitationManager.getClientId(), .createContactGroup(CLIENT_ID, author0.getId(),
author0.getId(), author0.getId()); author0.getId());
BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(), BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
privateGroup0.getId()); privateGroup0.getId());
byte[] creatorSignature = byte[] creatorSignature =
@@ -412,8 +413,8 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
joinTime = clock.currentTimeMillis(); joinTime = clock.currentTimeMillis();
inviteTime = joinTime - 1; inviteTime = joinTime - 1;
invitationGroup = contactGroupFactory invitationGroup = contactGroupFactory
.createContactGroup(groupInvitationManager.getClientId(), .createContactGroup(CLIENT_ID, author0.getId(),
author0.getId(), author1.getId()); author1.getId());
toSign = BdfList.of(0, inviteTime, invitationGroup.getId(), toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
privateGroup0.getId()); privateGroup0.getId());
// signature uses joiner's key, not creator's key // signature uses joiner's key, not creator's key
@@ -540,8 +541,8 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
joinTime = clock.currentTimeMillis(); joinTime = clock.currentTimeMillis();
long inviteTime = joinTime - 1; long inviteTime = joinTime - 1;
Group invitationGroup = contactGroupFactory Group invitationGroup = contactGroupFactory
.createContactGroup(groupInvitationManager.getClientId(), .createContactGroup(CLIENT_ID, author0.getId(),
author0.getId(), author1.getId()); author1.getId());
BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(), BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
privateGroup0.getId()); privateGroup0.getId());
byte[] creatorSignature = byte[] creatorSignature =

View File

@@ -74,7 +74,7 @@ public class SyncIntegrationTest extends BriarTestCase {
headerKey = TestUtils.getSecretKey(); headerKey = TestUtils.getSecretKey();
streamNumber = 123; streamNumber = 123;
// Create a group // Create a group
ClientId clientId = new ClientId(TestUtils.getRandomId()); ClientId clientId = new ClientId(TestUtils.getRandomString(5));
byte[] descriptor = new byte[0]; byte[] descriptor = new byte[0];
Group group = groupFactory.createGroup(clientId, descriptor); Group group = groupFactory.createGroup(clientId, descriptor);
// Add two messages to the group // Add two messages to the group

View File

@@ -25,6 +25,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.blogs.BlogManager.CLIENT_ID;
public class FeedControllerImpl extends BaseControllerImpl public class FeedControllerImpl extends BaseControllerImpl
implements FeedController { implements FeedController {
@@ -62,7 +63,7 @@ public class FeedControllerImpl extends BaseControllerImpl
onBlogPostAdded(b.getHeader(), b.isLocal()); onBlogPostAdded(b.getHeader(), b.isLocal());
} else if (e instanceof GroupRemovedEvent) { } else if (e instanceof GroupRemovedEvent) {
GroupRemovedEvent g = (GroupRemovedEvent) e; GroupRemovedEvent g = (GroupRemovedEvent) e;
if (g.getGroup().getClientId().equals(blogManager.getClientId())) { if (g.getGroup().getClientId().equals(CLIENT_ID)) {
LOG.info("Blog removed"); LOG.info("Blog removed");
onBlogRemoved(); onBlogRemoved();
} }

View File

@@ -44,6 +44,7 @@ import javax.inject.Inject;
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE; import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.forum.ForumManager.CLIENT_ID;
public class ForumListFragment extends BaseEventFragment implements public class ForumListFragment extends BaseEventFragment implements
OnClickListener { OnClickListener {
@@ -236,13 +237,13 @@ public class ForumListFragment extends BaseEventFragment implements
loadAvailableForums(); loadAvailableForums();
} else if (e instanceof GroupAddedEvent) { } else if (e instanceof GroupAddedEvent) {
GroupAddedEvent g = (GroupAddedEvent) e; GroupAddedEvent g = (GroupAddedEvent) e;
if (g.getGroup().getClientId().equals(forumManager.getClientId())) { if (g.getGroup().getClientId().equals(CLIENT_ID)) {
LOG.info("Forum added, reloading forums"); LOG.info("Forum added, reloading forums");
loadForums(); loadForums();
} }
} else if (e instanceof GroupRemovedEvent) { } else if (e instanceof GroupRemovedEvent) {
GroupRemovedEvent g = (GroupRemovedEvent) e; GroupRemovedEvent g = (GroupRemovedEvent) e;
if (g.getGroup().getClientId().equals(forumManager.getClientId())) { if (g.getGroup().getClientId().equals(CLIENT_ID)) {
LOG.info("Forum removed, removing from list"); LOG.info("Forum removed, removing from list");
removeForum(g.getGroup().getId()); removeForum(g.getGroup().getId());
} }

View File

@@ -21,6 +21,7 @@ import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.privategroup.PrivateGroupManager.CLIENT_ID;
public class GroupInvitationControllerImpl public class GroupInvitationControllerImpl
extends InvitationControllerImpl<GroupInvitationItem> extends InvitationControllerImpl<GroupInvitationItem>
@@ -51,7 +52,7 @@ public class GroupInvitationControllerImpl
@Override @Override
protected ClientId getShareableClientId() { protected ClientId getShareableClientId() {
return privateGroupManager.getClientId(); return CLIENT_ID;
} }
@Override @Override

View File

@@ -33,6 +33,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.privategroup.PrivateGroupManager.CLIENT_ID;
public class GroupListControllerImpl extends DbControllerImpl public class GroupListControllerImpl extends DbControllerImpl
implements GroupListController, EventListener { implements GroupListController, EventListener {
@@ -92,14 +93,14 @@ public class GroupListControllerImpl extends DbControllerImpl
} else if (e instanceof GroupAddedEvent) { } else if (e instanceof GroupAddedEvent) {
GroupAddedEvent g = (GroupAddedEvent) e; GroupAddedEvent g = (GroupAddedEvent) e;
ClientId id = g.getGroup().getClientId(); ClientId id = g.getGroup().getClientId();
if (id.equals(groupManager.getClientId())) { if (id.equals(CLIENT_ID)) {
LOG.info("Private group added"); LOG.info("Private group added");
onGroupAdded(g.getGroup().getId()); onGroupAdded(g.getGroup().getId());
} }
} else if (e instanceof GroupRemovedEvent) { } else if (e instanceof GroupRemovedEvent) {
GroupRemovedEvent g = (GroupRemovedEvent) e; GroupRemovedEvent g = (GroupRemovedEvent) e;
ClientId id = g.getGroup().getClientId(); ClientId id = g.getGroup().getClientId();
if (id.equals(groupManager.getClientId())) { if (id.equals(CLIENT_ID)) {
LOG.info("Private group removed"); LOG.info("Private group removed");
onGroupRemoved(g.getGroup().getId()); onGroupRemoved(g.getGroup().getId());
} }

View File

@@ -20,6 +20,7 @@ import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.blogs.BlogManager.CLIENT_ID;
public class BlogInvitationControllerImpl public class BlogInvitationControllerImpl
extends InvitationControllerImpl<SharingInvitationItem> extends InvitationControllerImpl<SharingInvitationItem>
@@ -49,7 +50,7 @@ public class BlogInvitationControllerImpl
@Override @Override
protected ClientId getShareableClientId() { protected ClientId getShareableClientId() {
return blogManager.getClientId(); return CLIENT_ID;
} }
@Override @Override

View File

@@ -20,6 +20,7 @@ import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.forum.ForumManager.CLIENT_ID;
public class ForumInvitationControllerImpl public class ForumInvitationControllerImpl
extends InvitationControllerImpl<SharingInvitationItem> extends InvitationControllerImpl<SharingInvitationItem>
@@ -50,7 +51,7 @@ public class ForumInvitationControllerImpl
@Override @Override
protected ClientId getShareableClientId() { protected ClientId getShareableClientId() {
return forumManager.getClientId(); return CLIENT_ID;
} }
@Override @Override

View File

@@ -13,8 +13,8 @@ import java.util.Collection;
public interface BlogManager { public interface BlogManager {
/** Returns the unique ID of the blog client. */ /** Unique ID of the blog client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blogs");
/** Returns true if a blog can be removed. */ /** Returns true if a blog can be removed. */
boolean canBeRemoved(GroupId g) throws DbException; boolean canBeRemoved(GroupId g) throws DbException;

View File

@@ -1,7 +1,10 @@
package org.briarproject.api.blogs; package org.briarproject.api.blogs;
import org.briarproject.api.sharing.SharingManager; import org.briarproject.api.sharing.SharingManager;
import org.briarproject.api.sync.ClientId;
public interface BlogSharingManager extends SharingManager<Blog> { public interface BlogSharingManager extends SharingManager<Blog> {
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blogs.sharing");
} }

View File

@@ -9,8 +9,8 @@ import java.util.List;
public interface FeedManager { public interface FeedManager {
/** Returns the unique ID of the client. */ /** The unique ID of the RSS feed client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.feed");
/** Adds a RSS feed. */ /** Adds a RSS feed. */
void addFeed(String url, GroupId g) throws DbException, IOException; void addFeed(String url, GroupId g) throws DbException, IOException;

View File

@@ -14,8 +14,8 @@ import java.util.Collection;
public interface ForumManager extends MessageTracker { public interface ForumManager extends MessageTracker {
/** Returns the unique ID of the forum client. */ /** The unique ID of the forum client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum");
/** Subscribes to a forum. */ /** Subscribes to a forum. */
Forum addForum(String name) throws DbException; Forum addForum(String name) throws DbException;

View File

@@ -1,7 +1,10 @@
package org.briarproject.api.forum; package org.briarproject.api.forum;
import org.briarproject.api.sharing.SharingManager; import org.briarproject.api.sharing.SharingManager;
import org.briarproject.api.sync.ClientId;
public interface ForumSharingManager extends SharingManager<Forum> { public interface ForumSharingManager extends SharingManager<Forum> {
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.forum.sharing");
} }

View File

@@ -12,8 +12,8 @@ import java.util.Collection;
public interface IntroductionManager extends MessageTracker { public interface IntroductionManager extends MessageTracker {
/** Returns the unique ID of the introduction client. */ /** The unique ID of the introduction client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.introduction");
/** /**
* sends two initial introduction messages * sends two initial introduction messages

View File

@@ -11,8 +11,8 @@ import java.util.Collection;
public interface MessagingManager extends MessageTracker { public interface MessagingManager extends MessageTracker {
/** Returns the unique ID of the messaging client. */ /** The unique ID of the messaging client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.messaging");
/** Stores a local private message. */ /** Stores a local private message. */
void addLocalMessage(PrivateMessage m) throws DbException; void addLocalMessage(PrivateMessage m) throws DbException;

View File

@@ -14,8 +14,8 @@ import java.util.Collection;
@NotNullByDefault @NotNullByDefault
public interface PrivateGroupManager extends MessageTracker { public interface PrivateGroupManager extends MessageTracker {
/** Returns the unique ID of the private group client. */ /** The unique ID of the private group client. */
ClientId getClientId(); ClientId CLIENT_ID = new ClientId("org.briarproject.briar.privategroup");
/** /**
* Adds a new private group and joins it. * Adds a new private group and joins it.

View File

@@ -14,8 +14,9 @@ import java.util.Collection;
public interface GroupInvitationManager extends MessageTracker { public interface GroupInvitationManager extends MessageTracker {
/** Returns the unique ID of the private group invitation client. */ /** The unique ID of the private group invitation client. */
ClientId getClientId(); ClientId CLIENT_ID =
new ClientId("org.briarproject.briar.privategroup.invitation");
/** /**
* Sends an invitation to share the given forum with the given contact * Sends an invitation to share the given forum with the given contact

View File

@@ -4,11 +4,15 @@ import org.briarproject.api.TransportId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
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.sync.ClientId;
import java.util.Map; import java.util.Map;
public interface TransportPropertyManager { public interface TransportPropertyManager {
/** The unique ID of the transport property client. */
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.properties");
/** /**
* Stores the given properties received while adding a contact - they will * Stores the given properties received while adding a contact - they will
* be superseded by any properties synced from the contact. * be superseded by any properties synced from the contact.

View File

@@ -5,18 +5,12 @@ import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.Collection; import java.util.Collection;
public interface SharingManager<S extends Shareable> extends MessageTracker { public interface SharingManager<S extends Shareable> extends MessageTracker {
/**
* Returns the unique ID of the group sharing client.
*/
ClientId getClientId();
/** /**
* Sends an invitation to share the given group with the given contact * Sends an invitation to share the given group with the given contact
* and sends an optional message along with it. * and sends an optional message along with it.

View File

@@ -1,18 +1,39 @@
package org.briarproject.api.sync; package org.briarproject.api.sync;
import org.briarproject.api.UniqueId; import org.briarproject.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable;
/** /**
* Type-safe wrapper for a byte array that uniquely identifies a sync client. * Wrapper for a name-spaced string that uniquely identifies a sync client.
*/ */
public class ClientId extends UniqueId { @Immutable
@NotNullByDefault
public class ClientId implements Comparable<ClientId> {
public ClientId(byte[] id) { private final String id;
super(id);
public ClientId(String id) {
this.id = id;
}
public String getString() {
return id;
}
@Override
public int compareTo(ClientId clientId) {
return id.compareTo(clientId.getString());
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
return o instanceof ClientId && super.equals(o); return o instanceof ClientId && id.equals(((ClientId) o).id);
} }
@Override
public int hashCode() {
return id.hashCode();
}
} }

View File

@@ -27,13 +27,11 @@ import org.briarproject.api.identity.Author.Status;
import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.clients.BdfIncomingMessageHook; import org.briarproject.clients.BdfIncomingMessageHook;
import org.briarproject.util.StringUtils;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@@ -74,10 +72,6 @@ import static org.briarproject.blogs.BlogPostValidator.authorToBdfDictionary;
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
AddContactHook, RemoveContactHook, Client { AddContactHook, RemoveContactHook, Client {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"dafbe56f0c8971365cea4bb5f08ec9a6" +
"1d686e058b943997b6ff259ba423f613"));
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final ContactManager contactManager; private final ContactManager contactManager;
private final BlogFactory blogFactory; private final BlogFactory blogFactory;
@@ -98,11 +92,6 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
removeHooks = new CopyOnWriteArrayList<RemoveBlogHook>(); removeHooks = new CopyOnWriteArrayList<RemoveBlogHook>();
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
public void createLocalState(Transaction txn) throws DbException { public void createLocalState(Transaction txn) throws DbException {
// Ensure that the local identity has its own personal blog // Ensure that the local identity has its own personal blog

View File

@@ -67,8 +67,8 @@ import static org.briarproject.db.ExponentialBackoff.calculateExpiry;
*/ */
abstract class JdbcDatabase implements Database<Connection> { abstract class JdbcDatabase implements Database<Connection> {
private static final int SCHEMA_VERSION = 27; private static final int SCHEMA_VERSION = 28;
private static final int MIN_SCHEMA_VERSION = 27; private static final int MIN_SCHEMA_VERSION = 28;
private static final String CREATE_SETTINGS = private static final String CREATE_SETTINGS =
"CREATE TABLE settings" "CREATE TABLE settings"
@@ -103,7 +103,7 @@ abstract class JdbcDatabase implements Database<Connection> {
private static final String CREATE_GROUPS = private static final String CREATE_GROUPS =
"CREATE TABLE groups" "CREATE TABLE groups"
+ " (groupId HASH NOT NULL," + " (groupId HASH NOT NULL,"
+ " clientId HASH NOT NULL," + " clientId VARCHAR NOT NULL,"
+ " descriptor BINARY NOT NULL," + " descriptor BINARY NOT NULL,"
+ " PRIMARY KEY (groupId))"; + " PRIMARY KEY (groupId))";
@@ -504,7 +504,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " VALUES (?, ?, ?)"; + " VALUES (?, ?, ?)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getId().getBytes()); ps.setBytes(1, g.getId().getBytes());
ps.setBytes(2, g.getClientId().getBytes()); ps.setString(2, g.getClientId().getString());
ps.setBytes(3, g.getDescriptor()); ps.setBytes(3, g.getDescriptor());
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if (affected != 1) throw new DbStateException(); if (affected != 1) throw new DbStateException();
@@ -1091,7 +1091,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setBytes(1, g.getBytes()); ps.setBytes(1, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
if (!rs.next()) throw new DbStateException(); if (!rs.next()) throw new DbStateException();
ClientId clientId = new ClientId(rs.getBytes(1)); ClientId clientId = new ClientId(rs.getString(1));
byte[] descriptor = rs.getBytes(2); byte[] descriptor = rs.getBytes(2);
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1111,7 +1111,7 @@ abstract class JdbcDatabase implements Database<Connection> {
String sql = "SELECT groupId, descriptor FROM groups" String sql = "SELECT groupId, descriptor FROM groups"
+ " WHERE clientId = ?"; + " WHERE clientId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, c.getBytes()); ps.setString(1, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Group> groups = new ArrayList<Group>(); List<Group> groups = new ArrayList<Group>();
while (rs.next()) { while (rs.next()) {
@@ -1678,7 +1678,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " WHERE state = ? AND clientId = ? AND raw IS NOT NULL"; + " WHERE state = ? AND clientId = ? AND raw IS NOT NULL";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, state.getValue()); ps.setInt(1, state.getValue());
ps.setBytes(2, c.getBytes()); ps.setString(2, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<MessageId>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
@@ -1707,7 +1707,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " WHERE m.shared = FALSE AND m1.shared = TRUE" + " WHERE m.shared = FALSE AND m1.shared = TRUE"
+ " AND g.clientId = ?"; + " AND g.clientId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, c.getBytes()); ps.setString(1, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<MessageId>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));

View File

@@ -30,7 +30,6 @@ import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.lifecycle.IoExecutor; import org.briarproject.api.lifecycle.IoExecutor;
import org.briarproject.api.plugins.TorConstants; import org.briarproject.api.plugins.TorConstants;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
@@ -73,11 +72,6 @@ class FeedManagerImpl implements FeedManager, Client, EventListener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(FeedManagerImpl.class.getName()); Logger.getLogger(FeedManagerImpl.class.getName());
private static final ClientId CLIENT_ID =
new ClientId(StringUtils.fromHexString(
"466565644d616e6167657202fb797097"
+ "255af837abbf8c16e250b3c2ccc286eb"));
private static final int CONNECT_TIMEOUT = 60 * 1000; // Milliseconds private static final int CONNECT_TIMEOUT = 60 * 1000; // Milliseconds
private final ScheduledExecutorService feedExecutor; private final ScheduledExecutorService feedExecutor;
@@ -114,11 +108,6 @@ class FeedManagerImpl implements FeedManager, Client, EventListener {
this.torSocketFactory = torSocketFactory; this.torSocketFactory = torSocketFactory;
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof TransportEnabledEvent) { if (e instanceof TransportEnabledEvent) {
@@ -510,7 +499,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener {
} }
private Group getLocalGroup() { private Group getLocalGroup() {
return contactGroupFactory.createLocalGroup(getClientId()); return contactGroupFactory.createLocalGroup(CLIENT_ID);
} }
} }

View File

@@ -20,13 +20,11 @@ import org.briarproject.api.identity.Author.Status;
import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.clients.BdfIncomingMessageHook; import org.briarproject.clients.BdfIncomingMessageHook;
import org.briarproject.util.StringUtils;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@@ -56,10 +54,6 @@ import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager { class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"859a7be50dca035b64bd6902fb797097"
+ "795af837abbf8c16d750b3c2ccc186ea"));
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final ForumFactory forumFactory; private final ForumFactory forumFactory;
private final ForumPostFactory forumPostFactory; private final ForumPostFactory forumPostFactory;
@@ -92,11 +86,6 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
return true; return true;
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
public Forum addForum(String name) throws DbException { public Forum addForum(String name) throws DbException {
Forum f = forumFactory.createForum(name); Forum f = forumFactory.createForum(name);

View File

@@ -32,9 +32,8 @@ public class ForumModule {
ForumManager provideForumManager(ForumManagerImpl forumManager, ForumManager provideForumManager(ForumManagerImpl forumManager,
ValidationManager validationManager) { ValidationManager validationManager) {
validationManager validationManager.registerIncomingMessageHook(ForumManager.CLIENT_ID,
.registerIncomingMessageHook(forumManager.getClientId(), forumManager);
forumManager);
return forumManager; return forumManager;
} }

View File

@@ -23,14 +23,12 @@ import org.briarproject.api.introduction.IntroductionManager;
import org.briarproject.api.introduction.IntroductionMessage; import org.briarproject.api.introduction.IntroductionMessage;
import org.briarproject.api.introduction.IntroductionRequest; import org.briarproject.api.introduction.IntroductionRequest;
import org.briarproject.api.introduction.IntroductionResponse; import org.briarproject.api.introduction.IntroductionResponse;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.api.sync.MessageStatus; import org.briarproject.api.sync.MessageStatus;
import org.briarproject.clients.ConversationClientImpl; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -79,10 +77,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
implements IntroductionManager, Client, AddContactHook, implements IntroductionManager, Client, AddContactHook,
RemoveContactHook { RemoveContactHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"23b1897c198a90ae75b976ac023d0f32"
+ "80ca67b12f2346b2c23a34f34e2434c3"));
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(IntroductionManagerImpl.class.getName()); Logger.getLogger(IntroductionManagerImpl.class.getName());
@@ -102,11 +96,6 @@ class IntroductionManagerImpl extends ConversationClientImpl
this.introductionGroupFactory = introductionGroupFactory; this.introductionGroupFactory = introductionGroupFactory;
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
public void createLocalState(Transaction txn) throws DbException { public void createLocalState(Transaction txn) throws DbException {
db.addGroup(txn, introductionGroupFactory.createLocalGroup()); db.addGroup(txn, introductionGroupFactory.createLocalGroup());

View File

@@ -15,6 +15,7 @@ import javax.inject.Singleton;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import static org.briarproject.api.introduction.IntroductionManager.CLIENT_ID;
import static org.briarproject.api.sync.ValidationManager.MessageValidator; import static org.briarproject.api.sync.ValidationManager.MessageValidator;
@Module @Module
@@ -28,16 +29,14 @@ public class IntroductionModule {
@Provides @Provides
@Singleton @Singleton
MessageValidator provideValidator(MessageQueueManager messageQueueManager, MessageValidator provideValidator(MessageQueueManager messageQueueManager,
IntroductionManager introductionManager,
MetadataEncoder metadataEncoder, ClientHelper clientHelper, MetadataEncoder metadataEncoder, ClientHelper clientHelper,
Clock clock) { Clock clock) {
IntroductionValidator introductionValidator = new IntroductionValidator( IntroductionValidator introductionValidator = new IntroductionValidator(
clientHelper, metadataEncoder, clock); clientHelper, metadataEncoder, clock);
messageQueueManager.registerMessageValidator( messageQueueManager
introductionManager.getClientId(), .registerMessageValidator(CLIENT_ID, introductionValidator);
introductionValidator);
return introductionValidator; return introductionValidator;
} }
@@ -54,9 +53,8 @@ public class IntroductionModule {
lifecycleManager.registerClient(introductionManager); lifecycleManager.registerClient(introductionManager);
contactManager.registerAddContactHook(introductionManager); contactManager.registerAddContactHook(introductionManager);
contactManager.registerRemoveContactHook(introductionManager); contactManager.registerRemoveContactHook(introductionManager);
messageQueueManager.registerIncomingMessageHook( messageQueueManager
introductionManager.getClientId(), .registerIncomingMessageHook(CLIENT_ID, introductionManager);
introductionManager);
conversationManager.registerConversationClient(introductionManager); conversationManager.registerConversationClient(introductionManager);
return introductionManager; return introductionManager;

View File

@@ -18,14 +18,12 @@ import org.briarproject.api.event.PrivateMessageReceivedEvent;
import org.briarproject.api.messaging.MessagingManager; import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateMessage; import org.briarproject.api.messaging.PrivateMessage;
import org.briarproject.api.messaging.PrivateMessageHeader; import org.briarproject.api.messaging.PrivateMessageHeader;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.api.sync.MessageStatus; import org.briarproject.api.sync.MessageStatus;
import org.briarproject.clients.ConversationClientImpl; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -38,10 +36,6 @@ import static org.briarproject.clients.BdfConstants.MSG_KEY_READ;
class MessagingManagerImpl extends ConversationClientImpl class MessagingManagerImpl extends ConversationClientImpl
implements MessagingManager, Client, AddContactHook, RemoveContactHook { implements MessagingManager, Client, AddContactHook, RemoveContactHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"6bcdc006c0910b0f44e40644c3b31f1a"
+ "8bf9a6d6021d40d219c86b731b903070"));
private final ContactGroupFactory contactGroupFactory; private final ContactGroupFactory contactGroupFactory;
@Inject @Inject
@@ -87,11 +81,6 @@ class MessagingManagerImpl extends ConversationClientImpl
db.removeGroup(txn, getContactGroup(c)); db.removeGroup(txn, getContactGroup(c));
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
protected boolean incomingMessage(Transaction txn, Message m, BdfList body, protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
BdfDictionary meta) throws DbException, FormatException { BdfDictionary meta) throws DbException, FormatException {

View File

@@ -12,7 +12,6 @@ import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.privategroup.MessageType; import org.briarproject.api.privategroup.MessageType;
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.privategroup.invitation.GroupInvitationManager;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.InvalidMessageException; import org.briarproject.api.sync.InvalidMessageException;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
@@ -30,6 +29,7 @@ import static org.briarproject.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH
import static org.briarproject.api.privategroup.MessageType.JOIN; import static org.briarproject.api.privategroup.MessageType.JOIN;
import static org.briarproject.api.privategroup.MessageType.POST; import static org.briarproject.api.privategroup.MessageType.POST;
import static org.briarproject.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH; import static org.briarproject.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
import static org.briarproject.api.privategroup.invitation.GroupInvitationManager.CLIENT_ID;
import static org.briarproject.privategroup.Constants.KEY_MEMBER_ID; import static org.briarproject.privategroup.Constants.KEY_MEMBER_ID;
import static org.briarproject.privategroup.Constants.KEY_MEMBER_NAME; import static org.briarproject.privategroup.Constants.KEY_MEMBER_NAME;
import static org.briarproject.privategroup.Constants.KEY_MEMBER_PUBLIC_KEY; import static org.briarproject.privategroup.Constants.KEY_MEMBER_PUBLIC_KEY;
@@ -44,18 +44,15 @@ class GroupMessageValidator extends BdfMessageValidator {
private final ContactGroupFactory contactGroupFactory; private final ContactGroupFactory contactGroupFactory;
private final PrivateGroupFactory groupFactory; private final PrivateGroupFactory groupFactory;
private final AuthorFactory authorFactory; private final AuthorFactory authorFactory;
private final GroupInvitationManager groupInvitationManager; // TODO remove
GroupMessageValidator(ContactGroupFactory contactGroupFactory, GroupMessageValidator(ContactGroupFactory contactGroupFactory,
PrivateGroupFactory groupFactory, PrivateGroupFactory groupFactory,
ClientHelper clientHelper, MetadataEncoder metadataEncoder, ClientHelper clientHelper, MetadataEncoder metadataEncoder,
Clock clock, AuthorFactory authorFactory, Clock clock, AuthorFactory authorFactory) {
GroupInvitationManager groupInvitationManager) {
super(clientHelper, metadataEncoder, clock); super(clientHelper, metadataEncoder, clock);
this.contactGroupFactory = contactGroupFactory; this.contactGroupFactory = contactGroupFactory;
this.groupFactory = groupFactory; this.groupFactory = groupFactory;
this.authorFactory = authorFactory; this.authorFactory = authorFactory;
this.groupInvitationManager = groupInvitationManager;
} }
@Override @Override
@@ -125,8 +122,8 @@ class GroupMessageValidator extends BdfMessageValidator {
// derive invitation group // derive invitation group
Group invitationGroup = contactGroupFactory Group invitationGroup = contactGroupFactory
.createContactGroup(groupInvitationManager.getClientId(), .createContactGroup(CLIENT_ID, pg.getAuthor().getId(),
pg.getAuthor().getId(), member.getId()); member.getId());
// signature with the creator's private key // signature with the creator's private key
// over a list with four elements: // over a list with four elements:

View File

@@ -23,13 +23,11 @@ import org.briarproject.api.privategroup.MessageType;
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.privategroup.PrivateGroupManager; import org.briarproject.api.privategroup.PrivateGroupManager;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.clients.BdfIncomingMessageHook; import org.briarproject.clients.BdfIncomingMessageHook;
import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -64,10 +62,6 @@ import static org.briarproject.privategroup.Constants.KEY_TYPE;
public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
PrivateGroupManager { PrivateGroupManager {
static final ClientId CLIENT_ID = new ClientId(
StringUtils.fromHexString("5072697661746547726f75704d616e61"
+ "67657220627920546f727374656e2047"));
private final PrivateGroupFactory privateGroupFactory; private final PrivateGroupFactory privateGroupFactory;
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final List<PrivateGroupHook> hooks; private final List<PrivateGroupHook> hooks;
@@ -84,11 +78,6 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
hooks = new CopyOnWriteArrayList<PrivateGroupHook>(); hooks = new CopyOnWriteArrayList<PrivateGroupHook>();
} }
@Override
public ClientId getClientId() {
return CLIENT_ID;
}
@Override @Override
public void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg) public void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg)
throws DbException { throws DbException {
@@ -251,7 +240,7 @@ public class PrivateGroupManagerImpl extends BdfIncomingMessageHook implements
Collection<Group> groups; Collection<Group> groups;
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
groups = db.getGroups(txn, getClientId()); groups = db.getGroups(txn, CLIENT_ID);
db.commitTransaction(txn); db.commitTransaction(txn);
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);

View File

@@ -38,7 +38,7 @@ public class PrivateGroupModule {
ValidationManager validationManager) { ValidationManager validationManager) {
validationManager validationManager
.registerIncomingMessageHook(groupManager.getClientId(), .registerIncomingMessageHook(PrivateGroupManager.CLIENT_ID,
groupManager); groupManager);
return groupManager; return groupManager;
@@ -68,9 +68,9 @@ public class PrivateGroupModule {
GroupMessageValidator validator = new GroupMessageValidator( GroupMessageValidator validator = new GroupMessageValidator(
contactGroupFactory, groupFactory, clientHelper, contactGroupFactory, groupFactory, clientHelper,
metadataEncoder, clock, authorFactory, groupInvitationManager); metadataEncoder, clock, authorFactory);
validationManager.registerMessageValidator( validationManager.registerMessageValidator(
PrivateGroupManagerImpl.CLIENT_ID, validator); PrivateGroupManager.CLIENT_ID, validator);
return validator; return validator;
} }
@@ -84,7 +84,7 @@ public class PrivateGroupModule {
ValidationManager validationManager) { ValidationManager validationManager) {
validationManager.registerIncomingMessageHook( validationManager.registerIncomingMessageHook(
groupInvitationManager.getClientId(), groupInvitationManager); GroupInvitationManager.CLIENT_ID, groupInvitationManager);
lifecycleManager.registerClient(groupInvitationManager); lifecycleManager.registerClient(groupInvitationManager);
contactManager.registerAddContactHook(groupInvitationManager); contactManager.registerAddContactHook(groupInvitationManager);
contactManager.registerRemoveContactHook(groupInvitationManager); contactManager.registerRemoveContactHook(groupInvitationManager);

View File

@@ -19,12 +19,10 @@ import org.briarproject.api.privategroup.PrivateGroup;
import org.briarproject.api.privategroup.invitation.GroupInvitationItem; import org.briarproject.api.privategroup.invitation.GroupInvitationItem;
import org.briarproject.api.privategroup.invitation.GroupInvitationManager; import org.briarproject.api.privategroup.invitation.GroupInvitationManager;
import org.briarproject.api.sharing.InvitationMessage; import org.briarproject.api.sharing.InvitationMessage;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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.clients.ConversationClientImpl; import org.briarproject.clients.ConversationClientImpl;
import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -38,11 +36,6 @@ public class GroupInvitationManagerImpl extends ConversationClientImpl
ContactManager.AddContactHook, ContactManager.RemoveContactHook, ContactManager.AddContactHook, ContactManager.RemoveContactHook,
ConversationManager.ConversationClient { ConversationManager.ConversationClient {
private static final ClientId CLIENT_ID =
new ClientId(StringUtils.fromHexString(
"B55231ABFC4A10666CD93D649B1D7F4F"
+ "016E65B87BB4C04F4E35613713DBCD13"));
private final ContactGroupFactory contactGroupFactory; private final ContactGroupFactory contactGroupFactory;
private final Group localGroup; private final Group localGroup;
@@ -52,12 +45,7 @@ public class GroupInvitationManagerImpl extends ConversationClientImpl
ContactGroupFactory contactGroupFactory) { ContactGroupFactory contactGroupFactory) {
super(db, clientHelper, metadataParser); super(db, clientHelper, metadataParser);
this.contactGroupFactory = contactGroupFactory; this.contactGroupFactory = contactGroupFactory;
localGroup = contactGroupFactory.createLocalGroup(getClientId()); localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID);
}
@Override
public ClientId getClientId() {
return CLIENT_ID;
} }
@Override @Override
@@ -94,7 +82,7 @@ public class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
protected Group getContactGroup(Contact c) { protected Group getContactGroup(Contact c) {
return contactGroupFactory.createContactGroup(getClientId(), c); return contactGroupFactory.createContactGroup(CLIENT_ID, c);
} }
@Override @Override

View File

@@ -16,13 +16,11 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction; import org.briarproject.api.db.Transaction;
import org.briarproject.api.properties.TransportProperties; import org.briarproject.api.properties.TransportProperties;
import org.briarproject.api.properties.TransportPropertyManager; import org.briarproject.api.properties.TransportPropertyManager;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.util.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@@ -34,10 +32,6 @@ import javax.inject.Inject;
class TransportPropertyManagerImpl implements TransportPropertyManager, class TransportPropertyManagerImpl implements TransportPropertyManager,
Client, AddContactHook, RemoveContactHook { Client, AddContactHook, RemoveContactHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"673ea091673561e28f70122f6a8ea8f4"
+ "97c3624b86fa07f785bb15f09fb87b4b"));
private final DatabaseComponent db; private final DatabaseComponent db;
private final ClientHelper clientHelper; private final ClientHelper clientHelper;
private final ContactGroupFactory contactGroupFactory; private final ContactGroupFactory contactGroupFactory;

View File

@@ -33,7 +33,6 @@ import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.util.StringUtils;
import java.security.SecureRandom; import java.security.SecureRandom;
@@ -48,10 +47,6 @@ class BlogSharingManagerImpl extends
SharingManagerImpl<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent> SharingManagerImpl<Blog, BlogInvitation, BlogInviteeSessionState, BlogSharerSessionState, BlogInvitationReceivedEvent, BlogInvitationResponseReceivedEvent>
implements BlogSharingManager, RemoveBlogHook { implements BlogSharingManager, RemoveBlogHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"bee438b5de0b3a685badc4e49d76e72d"
+ "21e01c4b569a775112756bdae267a028"));
private final IdentityManager identityManager; private final IdentityManager identityManager;
private final BlogManager blogManager; private final BlogManager blogManager;
@@ -84,7 +79,7 @@ class BlogSharingManagerImpl extends
} }
@Override @Override
public ClientId getClientId() { protected ClientId getClientId() {
return CLIENT_ID; return CLIENT_ID;
} }

View File

@@ -27,7 +27,6 @@ import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.util.StringUtils;
import java.security.SecureRandom; import java.security.SecureRandom;
@@ -42,10 +41,6 @@ class ForumSharingManagerImpl extends
SharingManagerImpl<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent> SharingManagerImpl<Forum, ForumInvitation, ForumInviteeSessionState, ForumSharerSessionState, ForumInvitationReceivedEvent, ForumInvitationResponseReceivedEvent>
implements ForumSharingManager, ForumManager.RemoveForumHook { implements ForumSharingManager, ForumManager.RemoveForumHook {
static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString(
"cd11a5d04dccd9e2931d6fc3df456313"
+ "63bb3e9d9d0e9405fccdb051f41f5449"));
private final SFactory sFactory; private final SFactory sFactory;
private final IFactory iFactory; private final IFactory iFactory;
private final ISFactory isFactory; private final ISFactory isFactory;
@@ -75,7 +70,7 @@ class ForumSharingManagerImpl extends
} }
@Override @Override
public ClientId getClientId() { protected ClientId getClientId() {
return CLIENT_ID; return CLIENT_ID;
} }

View File

@@ -25,10 +25,11 @@ import org.briarproject.api.event.Event;
import org.briarproject.api.event.InvitationRequestReceivedEvent; import org.briarproject.api.event.InvitationRequestReceivedEvent;
import org.briarproject.api.event.InvitationResponseReceivedEvent; import org.briarproject.api.event.InvitationResponseReceivedEvent;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.sharing.SharingInvitationItem;
import org.briarproject.api.sharing.InvitationMessage; import org.briarproject.api.sharing.InvitationMessage;
import org.briarproject.api.sharing.Shareable; import org.briarproject.api.sharing.Shareable;
import org.briarproject.api.sharing.SharingInvitationItem;
import org.briarproject.api.sharing.SharingManager; import org.briarproject.api.sharing.SharingManager;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; 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;
@@ -115,6 +116,8 @@ abstract class SharingManagerImpl<S extends Shareable, I extends Invitation, IS
localGroup = contactGroupFactory.createLocalGroup(getClientId()); localGroup = contactGroupFactory.createLocalGroup(getClientId());
} }
protected abstract ClientId getClientId();
protected abstract InvitationMessage createInvitationRequest(MessageId id, protected abstract InvitationMessage createInvitationRequest(MessageId id,
I msg, ContactId contactId, boolean available, long time, I msg, ContactId contactId, boolean available, long time,
boolean local, boolean sent, boolean seen, boolean read); boolean local, boolean sent, boolean seen, boolean read);

View File

@@ -5,6 +5,7 @@ import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.util.StringUtils;
import javax.inject.Inject; import javax.inject.Inject;
@@ -18,7 +19,9 @@ class GroupFactoryImpl implements GroupFactory {
} }
public Group createGroup(ClientId c, byte[] descriptor) { public Group createGroup(ClientId c, byte[] descriptor) {
byte[] hash = crypto.hash(GroupId.LABEL, c.getBytes(), descriptor); byte[] hash =
crypto.hash(GroupId.LABEL, StringUtils.toUtf8(c.getString()),
descriptor);
return new Group(new GroupId(hash), c, descriptor); return new Group(new GroupId(hash), c, descriptor);
} }
} }

View File

@@ -85,11 +85,6 @@ public class BlogManagerImplTest extends BriarTestCase {
message = new Message(messageId, blog1.getId(), 42, getRandomBytes(42)); message = new Message(messageId, blog1.getId(), 42, getRandomBytes(42));
} }
@Test
public void testClientId() {
assertEquals(CLIENT_ID, blogManager.getClientId());
}
@Test @Test
public void testCreateLocalState() throws DbException { public void testCreateLocalState() throws DbException {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);

View File

@@ -43,7 +43,8 @@ import static org.junit.Assert.assertSame;
public class MessageQueueManagerImplTest extends BriarTestCase { public class MessageQueueManagerImplTest extends BriarTestCase {
private final GroupId groupId = new GroupId(TestUtils.getRandomId()); private final GroupId groupId = new GroupId(TestUtils.getRandomId());
private final ClientId clientId = new ClientId(TestUtils.getRandomId()); private final ClientId clientId =
new ClientId(TestUtils.getRandomString(5));
private final byte[] descriptor = new byte[0]; private final byte[] descriptor = new byte[0];
private final Group group = new Group(groupId, clientId, descriptor); private final Group group = new Group(groupId, clientId, descriptor);
private final long timestamp = System.currentTimeMillis(); private final long timestamp = System.currentTimeMillis();

View File

@@ -90,7 +90,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
private final Contact contact; private final Contact contact;
public DatabaseComponentImplTest() { public DatabaseComponentImplTest() {
clientId = new ClientId(TestUtils.getRandomId()); clientId = new ClientId(TestUtils.getRandomString(5));
groupId = new GroupId(TestUtils.getRandomId()); groupId = new GroupId(TestUtils.getRandomId());
byte[] descriptor = new byte[0]; byte[] descriptor = new byte[0];
group = new Group(groupId, clientId, descriptor); group = new Group(groupId, clientId, descriptor);

View File

@@ -81,7 +81,7 @@ public class H2DatabaseTest extends BriarTestCase {
public H2DatabaseTest() throws Exception { public H2DatabaseTest() throws Exception {
groupId = new GroupId(TestUtils.getRandomId()); groupId = new GroupId(TestUtils.getRandomId());
clientId = new ClientId(TestUtils.getRandomId()); clientId = new ClientId(TestUtils.getRandomString(5));
byte[] descriptor = new byte[0]; byte[] descriptor = new byte[0];
group = new Group(groupId, clientId, descriptor); group = new Group(groupId, clientId, descriptor);
AuthorId authorId = new AuthorId(TestUtils.getRandomId()); AuthorId authorId = new AuthorId(TestUtils.getRandomId());
@@ -601,7 +601,7 @@ public class H2DatabaseTest extends BriarTestCase {
List<Group> groups = new ArrayList<>(); List<Group> groups = new ArrayList<>();
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());
ClientId clientId = new ClientId(TestUtils.getRandomId()); ClientId clientId = new ClientId(TestUtils.getRandomString(5));
byte[] descriptor = new byte[0]; byte[] descriptor = new byte[0];
groups.add(new Group(id, clientId, descriptor)); groups.add(new Group(id, clientId, descriptor));
} }

View File

@@ -82,7 +82,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
introducee2 = introducee2 =
new Contact(contactId2, author2, localAuthorId2, true, true); new Contact(contactId2, author2, localAuthorId2, true, true);
ClientId clientId = new ClientId(TestUtils.getRandomId()); ClientId clientId = new ClientId(TestUtils.getRandomString(5));
introductionGroup1 = new Group(new GroupId(TestUtils.getRandomId()), introductionGroup1 = new Group(new GroupId(TestUtils.getRandomId()),
clientId, new byte[0]); clientId, new byte[0]);
introductionGroup2 = new Group(new GroupId(TestUtils.getRandomId()), introductionGroup2 = new Group(new GroupId(TestUtils.getRandomId()),

View File

@@ -59,7 +59,7 @@ public class IntroductionValidatorTest extends BriarTestCase {
public IntroductionValidatorTest() { public IntroductionValidatorTest() {
GroupId groupId = new GroupId(TestUtils.getRandomId()); GroupId groupId = new GroupId(TestUtils.getRandomId());
ClientId clientId = new ClientId(TestUtils.getRandomId()); ClientId clientId = new ClientId(TestUtils.getRandomString(5));
byte[] descriptor = TestUtils.getRandomBytes(12); byte[] descriptor = TestUtils.getRandomBytes(12);
group = new Group(groupId, clientId, descriptor); group = new Group(groupId, clientId, descriptor);

View File

@@ -61,7 +61,8 @@ public class MessageSenderTest extends BriarTestCase {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
final Group privateGroup = final Group privateGroup =
new Group(new GroupId(TestUtils.getRandomId()), new Group(new GroupId(TestUtils.getRandomId()),
new ClientId(TestUtils.getRandomId()), new byte[0]); new ClientId(TestUtils.getRandomString(5)),
new byte[0]);
final SessionId sessionId = new SessionId(TestUtils.getRandomId()); final SessionId sessionId = new SessionId(TestUtils.getRandomId());
byte[] mac = TestUtils.getRandomBytes(42); byte[] mac = TestUtils.getRandomBytes(42);
byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH); byte[] sig = TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH);

View File

@@ -36,7 +36,7 @@ public class TransportPropertyValidatorTest extends BriarTestCase {
bdfDictionary = new BdfDictionary(); bdfDictionary = new BdfDictionary();
GroupId groupId = new GroupId(TestUtils.getRandomId()); GroupId groupId = new GroupId(TestUtils.getRandomId());
ClientId clientId = new ClientId(TestUtils.getRandomId()); ClientId clientId = new ClientId(TestUtils.getRandomString(5));
byte[] descriptor = TestUtils.getRandomBytes(12); byte[] descriptor = TestUtils.getRandomBytes(12);
group = new Group(groupId, clientId, descriptor); group = new Group(groupId, clientId, descriptor);

View File

@@ -39,7 +39,8 @@ import static org.briarproject.api.sync.ValidationManager.State.UNKNOWN;
public class ValidationManagerImplTest extends BriarTestCase { public class ValidationManagerImplTest extends BriarTestCase {
private final ClientId clientId = new ClientId(TestUtils.getRandomId()); private final ClientId clientId =
new ClientId(TestUtils.getRandomString(5));
private final MessageId messageId = new MessageId(TestUtils.getRandomId()); private final MessageId messageId = new MessageId(TestUtils.getRandomId());
private final MessageId messageId1 = new MessageId(TestUtils.getRandomId()); private final MessageId messageId1 = new MessageId(TestUtils.getRandomId());
private final MessageId messageId2 = new MessageId(TestUtils.getRandomId()); private final MessageId messageId2 = new MessageId(TestUtils.getRandomId());