diff --git a/briar-api/src/org/briarproject/api/contact/Contact.java b/briar-api/src/org/briarproject/api/contact/Contact.java index 62d7efa643f69b8779651be6ce4adf206f2f9ae4..18a2cb446c31334407bfca08f916f6a94eea2d65 100644 --- a/briar-api/src/org/briarproject/api/contact/Contact.java +++ b/briar-api/src/org/briarproject/api/contact/Contact.java @@ -1,37 +1,18 @@ package org.briarproject.api.contact; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorId; public class Contact { - public enum Status { - - ADDING(0), ACTIVE(1), REMOVING(2); - - private final int value; - - Status(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static Status fromValue(int value) { - for (Status s : values()) if (s.value == value) return s; - throw new IllegalArgumentException(); - } - } - private final ContactId id; private final Author author; private final AuthorId localAuthorId; - private final Status status; + private final StorageStatus status; public Contact(ContactId id, Author author, AuthorId localAuthorId, - Status status) { + StorageStatus status) { this.id = id; this.author = author; this.localAuthorId = localAuthorId; @@ -50,7 +31,7 @@ public class Contact { return localAuthorId; } - public Status getStatus() { + public StorageStatus getStatus() { return status; } diff --git a/briar-api/src/org/briarproject/api/contact/ContactManager.java b/briar-api/src/org/briarproject/api/contact/ContactManager.java index 9637d1491143f79e00c912a3f76e391ac1cfc0aa..08c9dc46a1509fa5efca37571502e49898af6830 100644 --- a/briar-api/src/org/briarproject/api/contact/ContactManager.java +++ b/briar-api/src/org/briarproject/api/contact/ContactManager.java @@ -9,10 +9,10 @@ import java.util.Collection; public interface ContactManager { /** Registers a hook to be called whenever a contact is added. */ - void registerContactAddedHook(ContactAddedHook hook); + void registerAddContactHook(AddContactHook hook); /** Registers a hook to be called whenever a contact is removed. */ - void registerContactRemovedHook(ContactRemovedHook hook); + void registerRemoveContactHook(RemoveContactHook hook); /** * Stores a contact associated with the given local and remote pseudonyms, @@ -29,11 +29,11 @@ public interface ContactManager { /** Removes a contact and all associated state. */ void removeContact(ContactId c) throws DbException; - interface ContactAddedHook { - void contactAdded(ContactId c); + interface AddContactHook { + void addingContact(ContactId c); } - interface ContactRemovedHook { - void contactRemoved(ContactId c); + interface RemoveContactHook { + void removingContact(ContactId c); } } diff --git a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java index b2ee63bde16944bf8a620d3021a29ab10c7c7fcb..e67f0cb912690bdcd529dbdaa5575caa935d425b 100644 --- a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java +++ b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java @@ -301,10 +301,10 @@ public interface DatabaseComponent { void removeTransport(TransportId t) throws DbException; /** Sets the status of the given contact. */ - void setContactStatus(ContactId c, Contact.Status s) throws DbException; + void setContactStatus(ContactId c, StorageStatus s) throws DbException; /** Sets the status of the given local pseudonym. */ - void setLocalAuthorStatus(AuthorId a, LocalAuthor.Status s) + void setLocalAuthorStatus(AuthorId a, StorageStatus s) throws DbException; /** Marks the given message as valid or invalid. */ diff --git a/briar-api/src/org/briarproject/api/db/StorageStatus.java b/briar-api/src/org/briarproject/api/db/StorageStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..dc2d554ffb08863f6409067ca727bc169aad05e0 --- /dev/null +++ b/briar-api/src/org/briarproject/api/db/StorageStatus.java @@ -0,0 +1,21 @@ +package org.briarproject.api.db; + +public enum StorageStatus { + + ADDING(0), ACTIVE(1), REMOVING(2); + + private final int value; + + StorageStatus(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static StorageStatus fromValue(int value) { + for (StorageStatus s : values()) if (s.value == value) return s; + throw new IllegalArgumentException(); + } +} diff --git a/briar-api/src/org/briarproject/api/identity/IdentityManager.java b/briar-api/src/org/briarproject/api/identity/IdentityManager.java index ec2383371b573d3d2ba74a72584149e8955bbd4d..9a5a030abdeab1d485ee7a22fd6f8d3a78ac1ea5 100644 --- a/briar-api/src/org/briarproject/api/identity/IdentityManager.java +++ b/briar-api/src/org/briarproject/api/identity/IdentityManager.java @@ -7,10 +7,10 @@ import java.util.Collection; public interface IdentityManager { /** Registers a hook to be called whenever a local pseudonym is added. */ - void registerIdentityAddedHook(IdentityAddedHook hook); + void registerAddIdentityHook(AddIdentityHook hook); /** Registers a hook to be called whenever a local pseudonym is removed. */ - void registerIdentityRemovedHook(IdentityRemovedHook hook); + void registerRemoveIdentityHook(RemoveIdentityHook hook); /** Stores a local pseudonym. */ void addLocalAuthor(LocalAuthor a) throws DbException; @@ -24,11 +24,11 @@ public interface IdentityManager { /** Removes a local pseudonym and all associated state. */ void removeLocalAuthor(AuthorId a) throws DbException; - interface IdentityAddedHook { - void identityAdded(AuthorId a); + interface AddIdentityHook { + void addingIdentity(AuthorId a); } - interface IdentityRemovedHook { - void identityRemoved(AuthorId a); + interface RemoveIdentityHook { + void removingIdentity(AuthorId a); } } diff --git a/briar-api/src/org/briarproject/api/identity/LocalAuthor.java b/briar-api/src/org/briarproject/api/identity/LocalAuthor.java index da5d4a908c87a2fda7b7edc3e9bade06c32861e1..08ee121e533a7fb666705d3583032a7029390f43 100644 --- a/briar-api/src/org/briarproject/api/identity/LocalAuthor.java +++ b/briar-api/src/org/briarproject/api/identity/LocalAuthor.java @@ -1,34 +1,16 @@ package org.briarproject.api.identity; +import org.briarproject.api.db.StorageStatus; + /** A pseudonym for the local user. */ public class LocalAuthor extends Author { - public enum Status { - - ADDING(0), ACTIVE(1), REMOVING(2); - - private final int value; - - Status(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static Status fromValue(int value) { - for (Status s : values()) if (s.value == value) return s; - throw new IllegalArgumentException(); - } - } - private final byte[] privateKey; private final long created; - private final Status status; + private final StorageStatus status; public LocalAuthor(AuthorId id, String name, byte[] publicKey, - byte[] privateKey, long created, Status status) { + byte[] privateKey, long created, StorageStatus status) { super(id, name, publicKey); this.privateKey = privateKey; this.created = created; @@ -49,7 +31,7 @@ public class LocalAuthor extends Author { } /** Returns the status of the pseudonym. */ - public Status getStatus() { + public StorageStatus getStatus() { return status; } } diff --git a/briar-core/src/org/briarproject/contact/ContactManagerImpl.java b/briar-core/src/org/briarproject/contact/ContactManagerImpl.java index 92d8020303806ae496a78449e1d5098581d0cc5b..fa1c096219f35df6889f892839273b8806af4b94 100644 --- a/briar-core/src/org/briarproject/contact/ContactManagerImpl.java +++ b/briar-core/src/org/briarproject/contact/ContactManagerImpl.java @@ -13,7 +13,7 @@ import org.briarproject.api.event.ContactRemovedEvent; import org.briarproject.api.event.EventBus; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorId; -import org.briarproject.api.identity.IdentityManager.IdentityRemovedHook; +import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook; import org.briarproject.api.lifecycle.Service; import java.util.ArrayList; @@ -24,27 +24,27 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Logger; import static java.util.logging.Level.WARNING; -import static org.briarproject.api.contact.Contact.Status.ACTIVE; -import static org.briarproject.api.contact.Contact.Status.ADDING; -import static org.briarproject.api.contact.Contact.Status.REMOVING; +import static org.briarproject.api.db.StorageStatus.ACTIVE; +import static org.briarproject.api.db.StorageStatus.ADDING; +import static org.briarproject.api.db.StorageStatus.REMOVING; class ContactManagerImpl implements ContactManager, Service, - IdentityRemovedHook { + RemoveIdentityHook { private static final Logger LOG = Logger.getLogger(ContactManagerImpl.class.getName()); private final DatabaseComponent db; private final EventBus eventBus; - private final List<ContactAddedHook> addHooks; - private final List<ContactRemovedHook> removeHooks; + private final List<AddContactHook> addHooks; + private final List<RemoveContactHook> removeHooks; @Inject ContactManagerImpl(DatabaseComponent db, EventBus eventBus) { this.db = db; this.eventBus = eventBus; - addHooks = new CopyOnWriteArrayList<ContactAddedHook>(); - removeHooks = new CopyOnWriteArrayList<ContactRemovedHook>(); + addHooks = new CopyOnWriteArrayList<AddContactHook>(); + removeHooks = new CopyOnWriteArrayList<RemoveContactHook>(); } @Override @@ -53,13 +53,13 @@ class ContactManagerImpl implements ContactManager, Service, try { for (Contact c : db.getContacts()) { if (c.getStatus().equals(ADDING)) { - for (ContactAddedHook hook : addHooks) - hook.contactAdded(c.getId()); + for (AddContactHook hook : addHooks) + hook.addingContact(c.getId()); db.setContactStatus(c.getId(), ACTIVE); eventBus.broadcast(new ContactAddedEvent(c.getId())); } else if (c.getStatus().equals(REMOVING)) { - for (ContactRemovedHook hook : removeHooks) - hook.contactRemoved(c.getId()); + for (RemoveContactHook hook : removeHooks) + hook.removingContact(c.getId()); db.removeContact(c.getId()); eventBus.broadcast(new ContactRemovedEvent(c.getId())); } @@ -77,12 +77,12 @@ class ContactManagerImpl implements ContactManager, Service, } @Override - public void registerContactAddedHook(ContactAddedHook hook) { + public void registerAddContactHook(AddContactHook hook) { addHooks.add(hook); } @Override - public void registerContactRemovedHook(ContactRemovedHook hook) { + public void registerRemoveContactHook(RemoveContactHook hook) { removeHooks.add(hook); } @@ -90,7 +90,7 @@ class ContactManagerImpl implements ContactManager, Service, public ContactId addContact(Author remote, AuthorId local) throws DbException { ContactId c = db.addContact(remote, local); - for (ContactAddedHook hook : addHooks) hook.contactAdded(c); + for (AddContactHook hook : addHooks) hook.addingContact(c); db.setContactStatus(c, ACTIVE); eventBus.broadcast(new ContactAddedEvent(c)); return c; @@ -116,13 +116,13 @@ class ContactManagerImpl implements ContactManager, Service, @Override public void removeContact(ContactId c) throws DbException { db.setContactStatus(c, REMOVING); - for (ContactRemovedHook hook : removeHooks) hook.contactRemoved(c); + for (RemoveContactHook hook : removeHooks) hook.removingContact(c); db.removeContact(c); eventBus.broadcast(new ContactRemovedEvent(c)); } @Override - public void identityRemoved(AuthorId a) { + public void removingIdentity(AuthorId a) { // Remove any contacts of the local pseudonym that's being removed try { for (ContactId c : db.getContacts(a)) removeContact(c); diff --git a/briar-core/src/org/briarproject/contact/ContactModule.java b/briar-core/src/org/briarproject/contact/ContactModule.java index 3a374ab5e369551bc6596a45191b4606a187b0c4..5bfb8e404e0748b33a6095c3a5c263f6a3c2086b 100644 --- a/briar-core/src/org/briarproject/contact/ContactModule.java +++ b/briar-core/src/org/briarproject/contact/ContactModule.java @@ -19,7 +19,7 @@ public class ContactModule extends AbstractModule { IdentityManager identityManager, ContactManagerImpl contactManager) { lifecycleManager.register(contactManager); - identityManager.registerIdentityRemovedHook(contactManager); + identityManager.registerRemoveIdentityHook(contactManager); return contactManager; } } diff --git a/briar-core/src/org/briarproject/db/Database.java b/briar-core/src/org/briarproject/db/Database.java index 65518cc5f4a92433919d19c39612f1805e65fd3a..30e1754530c28d6a8e622dcdf0968b9c661b1d33 100644 --- a/briar-core/src/org/briarproject/db/Database.java +++ b/briar-core/src/org/briarproject/db/Database.java @@ -7,6 +7,7 @@ import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.ContactId; import org.briarproject.api.db.DbException; import org.briarproject.api.db.Metadata; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.LocalAuthor; @@ -636,7 +637,7 @@ interface Database<T> { * <p> * Locking: write. */ - void setContactStatus(T txn, ContactId c, Contact.Status s) + void setContactStatus(T txn, ContactId c, StorageStatus s) throws DbException; /** @@ -644,7 +645,7 @@ interface Database<T> { * <p> * Locking: write. */ - void setLocalAuthorStatus(T txn, AuthorId a, LocalAuthor.Status s) + void setLocalAuthorStatus(T txn, AuthorId a, StorageStatus s) throws DbException; /** diff --git a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java index 13d650912dd0bd4a6d6a11746504aa20b91664f0..07aaee5ccd879fae76b1ef43c77c030e044df8b9 100644 --- a/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java +++ b/briar-core/src/org/briarproject/db/DatabaseComponentImpl.java @@ -16,6 +16,7 @@ import org.briarproject.api.db.NoSuchLocalAuthorException; import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchTransportException; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.event.EventBus; import org.briarproject.api.event.LocalSubscriptionsUpdatedEvent; import org.briarproject.api.event.LocalTransportsUpdatedEvent; @@ -1293,7 +1294,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { eventBus.broadcast(new TransportRemovedEvent(t)); } - public void setContactStatus(ContactId c, Contact.Status s) + public void setContactStatus(ContactId c, StorageStatus s) throws DbException { lock.writeLock().lock(); try { @@ -1312,7 +1313,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent { } } - public void setLocalAuthorStatus(AuthorId a, LocalAuthor.Status s) + public void setLocalAuthorStatus(AuthorId a, StorageStatus s) throws DbException { lock.writeLock().lock(); try { diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index 54be105b241f3693940130413bc5c2108d000d9b..c2ea25a9ce72e173f14d1022589fbd63b91a9f1f 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -9,6 +9,7 @@ import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.db.DbClosedException; import org.briarproject.api.db.DbException; import org.briarproject.api.db.Metadata; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.LocalAuthor; @@ -50,8 +51,8 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; import static java.util.logging.Level.WARNING; -import static org.briarproject.api.contact.Contact.Status.ADDING; import static org.briarproject.api.db.Metadata.REMOVE; +import static org.briarproject.api.db.StorageStatus.ADDING; import static org.briarproject.api.sync.SyncConstants.MAX_SUBSCRIPTIONS; import static org.briarproject.api.sync.ValidationManager.Status.INVALID; import static org.briarproject.api.sync.ValidationManager.Status.UNKNOWN; @@ -1208,7 +1209,7 @@ abstract class JdbcDatabase implements Database<Connection> { String name = rs.getString(2); byte[] publicKey = rs.getBytes(3); AuthorId localAuthorId = new AuthorId(rs.getBytes(4)); - Contact.Status status = Contact.Status.fromValue(rs.getInt(5)); + StorageStatus status = StorageStatus.fromValue(rs.getInt(5)); rs.close(); ps.close(); Author author = new Author(authorId, name, publicKey); @@ -1258,7 +1259,7 @@ abstract class JdbcDatabase implements Database<Connection> { byte[] publicKey = rs.getBytes(4); Author author = new Author(authorId, name, publicKey); AuthorId localAuthorId = new AuthorId(rs.getBytes(5)); - Contact.Status status = Contact.Status.fromValue(rs.getInt(6)); + StorageStatus status = StorageStatus.fromValue(rs.getInt(6)); contacts.add(new Contact(contactId, author, localAuthorId, status)); } @@ -1358,8 +1359,7 @@ abstract class JdbcDatabase implements Database<Connection> { byte[] publicKey = rs.getBytes(2); byte[] privateKey = rs.getBytes(3); long created = rs.getLong(4); - LocalAuthor.Status status = LocalAuthor.Status.fromValue( - rs.getInt(5)); + StorageStatus status = StorageStatus.fromValue(rs.getInt(5)); LocalAuthor localAuthor = new LocalAuthor(a, name, publicKey, privateKey, created, status); if (rs.next()) throw new DbStateException(); @@ -1390,8 +1390,7 @@ abstract class JdbcDatabase implements Database<Connection> { byte[] publicKey = rs.getBytes(3); byte[] privateKey = rs.getBytes(4); long created = rs.getLong(5); - LocalAuthor.Status status = LocalAuthor.Status.fromValue( - rs.getInt(6)); + StorageStatus status = StorageStatus.fromValue(rs.getInt(6)); authors.add(new LocalAuthor(authorId, name, publicKey, privateKey, created, status)); } @@ -1875,7 +1874,7 @@ abstract class JdbcDatabase implements Database<Connection> { byte[] publicKey = rs.getBytes(4); Author author = new Author(authorId, name, publicKey); AuthorId localAuthorId = new AuthorId(rs.getBytes(5)); - Contact.Status status = Contact.Status.fromValue(rs.getInt(6)); + StorageStatus status = StorageStatus.fromValue(rs.getInt(6)); contacts.add(new Contact(contactId, author, localAuthorId, status)); } @@ -2703,7 +2702,7 @@ abstract class JdbcDatabase implements Database<Connection> { } } - public void setContactStatus(Connection txn, ContactId c, Contact.Status s) + public void setContactStatus(Connection txn, ContactId c, StorageStatus s) throws DbException { PreparedStatement ps = null; try { @@ -2721,7 +2720,7 @@ abstract class JdbcDatabase implements Database<Connection> { } public void setLocalAuthorStatus(Connection txn, AuthorId a, - LocalAuthor.Status s) throws DbException { + StorageStatus s) throws DbException { PreparedStatement ps = null; try { String sql = "UPDATE localAuthors SET status = ?" diff --git a/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java b/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java index 2e6350cbe719cd8764edb82c7d5fe32f93c877c5..a51ce023880530c5ffc915823a78d2209fe8271c 100644 --- a/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java +++ b/briar-core/src/org/briarproject/identity/IdentityManagerImpl.java @@ -21,9 +21,9 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Logger; import static java.util.logging.Level.WARNING; -import static org.briarproject.api.identity.LocalAuthor.Status.ACTIVE; -import static org.briarproject.api.identity.LocalAuthor.Status.ADDING; -import static org.briarproject.api.identity.LocalAuthor.Status.REMOVING; +import static org.briarproject.api.db.StorageStatus.ACTIVE; +import static org.briarproject.api.db.StorageStatus.ADDING; +import static org.briarproject.api.db.StorageStatus.REMOVING; class IdentityManagerImpl implements IdentityManager, Service { @@ -32,15 +32,15 @@ class IdentityManagerImpl implements IdentityManager, Service { private final DatabaseComponent db; private final EventBus eventBus; - private final List<IdentityAddedHook> addHooks; - private final List<IdentityRemovedHook> removeHooks; + private final List<AddIdentityHook> addHooks; + private final List<RemoveIdentityHook> removeHooks; @Inject IdentityManagerImpl(DatabaseComponent db, EventBus eventBus) { this.db = db; this.eventBus = eventBus; - addHooks = new CopyOnWriteArrayList<IdentityAddedHook>(); - removeHooks = new CopyOnWriteArrayList<IdentityRemovedHook>(); + addHooks = new CopyOnWriteArrayList<AddIdentityHook>(); + removeHooks = new CopyOnWriteArrayList<RemoveIdentityHook>(); } @Override @@ -49,13 +49,13 @@ class IdentityManagerImpl implements IdentityManager, Service { try { for (LocalAuthor a : db.getLocalAuthors()) { if (a.getStatus().equals(ADDING)) { - for (IdentityAddedHook hook : addHooks) - hook.identityAdded(a.getId()); + for (AddIdentityHook hook : addHooks) + hook.addingIdentity(a.getId()); db.setLocalAuthorStatus(a.getId(), ACTIVE); eventBus.broadcast(new LocalAuthorAddedEvent(a.getId())); } else if (a.getStatus().equals(REMOVING)) { - for (IdentityRemovedHook hook : removeHooks) - hook.identityRemoved(a.getId()); + for (RemoveIdentityHook hook : removeHooks) + hook.removingIdentity(a.getId()); db.removeLocalAuthor(a.getId()); eventBus.broadcast(new LocalAuthorRemovedEvent(a.getId())); } @@ -73,19 +73,19 @@ class IdentityManagerImpl implements IdentityManager, Service { } @Override - public void registerIdentityAddedHook(IdentityAddedHook hook) { + public void registerAddIdentityHook(AddIdentityHook hook) { addHooks.add(hook); } @Override - public void registerIdentityRemovedHook(IdentityRemovedHook hook) { + public void registerRemoveIdentityHook(RemoveIdentityHook hook) { removeHooks.add(hook); } @Override public void addLocalAuthor(LocalAuthor a) throws DbException { db.addLocalAuthor(a); - for (IdentityAddedHook hook : addHooks) hook.identityAdded(a.getId()); + for (AddIdentityHook hook : addHooks) hook.addingIdentity(a.getId()); db.setLocalAuthorStatus(a.getId(), ACTIVE); eventBus.broadcast(new LocalAuthorAddedEvent(a.getId())); } @@ -110,7 +110,7 @@ class IdentityManagerImpl implements IdentityManager, Service { @Override public void removeLocalAuthor(AuthorId a) throws DbException { db.setLocalAuthorStatus(a, REMOVING); - for (IdentityRemovedHook hook : removeHooks) hook.identityRemoved(a); + for (RemoveIdentityHook hook : removeHooks) hook.removingIdentity(a); db.removeLocalAuthor(a); eventBus.broadcast(new LocalAuthorRemovedEvent(a)); } diff --git a/briar-core/src/org/briarproject/messaging/MessagingManagerImpl.java b/briar-core/src/org/briarproject/messaging/MessagingManagerImpl.java index 37f5acafe8f4b15c1bd5725e9a58c860f12f22c2..49502aa043ee0be44d7448565d415023fc2e4089 100644 --- a/briar-core/src/org/briarproject/messaging/MessagingManagerImpl.java +++ b/briar-core/src/org/briarproject/messaging/MessagingManagerImpl.java @@ -6,8 +6,8 @@ import org.briarproject.api.FormatException; import org.briarproject.api.UniqueId; import org.briarproject.api.contact.Contact; import org.briarproject.api.contact.ContactId; -import org.briarproject.api.contact.ContactManager.ContactAddedHook; -import org.briarproject.api.contact.ContactManager.ContactRemovedHook; +import org.briarproject.api.contact.ContactManager.AddContactHook; +import org.briarproject.api.contact.ContactManager.RemoveContactHook; import org.briarproject.api.data.BdfDictionary; import org.briarproject.api.data.BdfReader; import org.briarproject.api.data.BdfReaderFactory; @@ -44,8 +44,8 @@ import static java.util.logging.Level.WARNING; import static org.briarproject.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH; import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH; -class MessagingManagerImpl implements MessagingManager, ContactAddedHook, - ContactRemovedHook { +class MessagingManagerImpl implements MessagingManager, AddContactHook, + RemoveContactHook { static final ClientId CLIENT_ID = new ClientId(StringUtils.fromHexString( "6bcdc006c0910b0f44e40644c3b31f1a" @@ -75,10 +75,10 @@ class MessagingManagerImpl implements MessagingManager, ContactAddedHook, } @Override - public void contactAdded(ContactId c) { + public void addingContact(ContactId c) { try { // Create the conversation group - Group g = createConversationGroup(db.getContact(c)); + Group g = getConversationGroup(db.getContact(c)); // Subscribe to the group and share it with the contact db.addGroup(g); db.addContactGroup(c, g); @@ -88,7 +88,7 @@ class MessagingManagerImpl implements MessagingManager, ContactAddedHook, } } - private Group createConversationGroup(Contact c) { + private Group getConversationGroup(Contact c) { AuthorId local = c.getLocalAuthorId(); AuthorId remote = c.getAuthor().getId(); byte[] descriptor = createGroupDescriptor(local, remote); @@ -116,9 +116,9 @@ class MessagingManagerImpl implements MessagingManager, ContactAddedHook, } @Override - public void contactRemoved(ContactId c) { + public void removingContact(ContactId c) { try { - db.removeGroup(createConversationGroup(db.getContact(c))); + db.removeGroup(getConversationGroup(db.getContact(c))); } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } @@ -149,7 +149,7 @@ class MessagingManagerImpl implements MessagingManager, ContactAddedHook, public ContactId getContactId(GroupId g) throws DbException { // TODO: Use metadata to attach the contact ID to the group for (Contact c : db.getContacts()) { - Group conversation = createConversationGroup(c); + Group conversation = getConversationGroup(c); if (conversation.getId().equals(g)) return c.getId(); } throw new NoSuchContactException(); @@ -157,7 +157,7 @@ class MessagingManagerImpl implements MessagingManager, ContactAddedHook, @Override public GroupId getConversationId(ContactId c) throws DbException { - return createConversationGroup(db.getContact(c)).getId(); + return getConversationGroup(db.getContact(c)).getId(); } @Override diff --git a/briar-core/src/org/briarproject/messaging/MessagingModule.java b/briar-core/src/org/briarproject/messaging/MessagingModule.java index 42827c2c076e6f1e0b0bb934de4fc25cda00fc6e..1854afcc769a0600036ddf9cc7eb0ad8167af0ff 100644 --- a/briar-core/src/org/briarproject/messaging/MessagingModule.java +++ b/briar-core/src/org/briarproject/messaging/MessagingModule.java @@ -35,8 +35,8 @@ public class MessagingModule extends AbstractModule { @Provides @Singleton MessagingManager getMessagingManager(ContactManager contactManager, MessagingManagerImpl messagingManager) { - contactManager.registerContactAddedHook(messagingManager); - contactManager.registerContactRemovedHook(messagingManager); + contactManager.registerAddContactHook(messagingManager); + contactManager.registerRemoveContactHook(messagingManager); return messagingManager; } } diff --git a/briar-core/src/org/briarproject/sync/AuthorFactoryImpl.java b/briar-core/src/org/briarproject/sync/AuthorFactoryImpl.java index 102ea1ee89d97fffefcf1e10b8f26fd823d7da53..da217728a3221daacd937b8d617f14a6e275b8fa 100644 --- a/briar-core/src/org/briarproject/sync/AuthorFactoryImpl.java +++ b/briar-core/src/org/briarproject/sync/AuthorFactoryImpl.java @@ -14,7 +14,7 @@ import java.io.IOException; import javax.inject.Inject; -import static org.briarproject.api.identity.LocalAuthor.Status.ADDING; +import static org.briarproject.api.db.StorageStatus.ADDING; class AuthorFactoryImpl implements AuthorFactory { diff --git a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java index 285da1aebfaba12e5715a3ad5ea080e3e013439f..b4ff178a566555b8deee33b651d16d7233c7a507 100644 --- a/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java +++ b/briar-tests/src/org/briarproject/db/DatabaseComponentImplTest.java @@ -15,6 +15,7 @@ import org.briarproject.api.db.NoSuchLocalAuthorException; import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchTransportException; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.event.EventBus; import org.briarproject.api.event.LocalSubscriptionsUpdatedEvent; import org.briarproject.api.event.LocalTransportsUpdatedEvent; @@ -96,7 +97,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { long timestamp = System.currentTimeMillis(); localAuthor = new LocalAuthor(localAuthorId, "Bob", new byte[MAX_PUBLIC_KEY_LENGTH], new byte[123], timestamp, - LocalAuthor.Status.ACTIVE); + StorageStatus.ACTIVE); messageId = new MessageId(TestUtils.getRandomId()); messageId1 = new MessageId(TestUtils.getRandomId()); size = 1234; @@ -110,7 +111,7 @@ public class DatabaseComponentImplTest extends BriarTestCase { maxLatency = Integer.MAX_VALUE; contactId = new ContactId(234); contact = new Contact(contactId, author, localAuthorId, - Contact.Status.ACTIVE); + StorageStatus.ACTIVE); } private <T> DatabaseComponent createDatabaseComponent(Database<T> database, diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index 5f13ad4631792e911e20f4c27873f604b4198fa5..c0cde9e40dab1358eef222487e6327dd743ae689 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -10,6 +10,7 @@ import org.briarproject.api.contact.ContactId; import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.db.DbException; import org.briarproject.api.db.Metadata; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.identity.Author; import org.briarproject.api.identity.AuthorId; import org.briarproject.api.identity.LocalAuthor; @@ -83,7 +84,7 @@ public class H2DatabaseTest extends BriarTestCase { timestamp = System.currentTimeMillis(); localAuthor = new LocalAuthor(localAuthorId, "Bob", new byte[MAX_PUBLIC_KEY_LENGTH], new byte[123], timestamp, - LocalAuthor.Status.ACTIVE); + StorageStatus.ACTIVE); messageId = new MessageId(TestUtils.getRandomId()); size = 1234; raw = new byte[size]; diff --git a/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java index dcb7292816490b11f582f656ae1f7d293646f4c1..198ac61a33ac967be0fe4f6730f430b7e7b35263 100644 --- a/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java +++ b/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java @@ -12,6 +12,7 @@ import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactManager; import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.db.DatabaseComponent; +import org.briarproject.api.db.StorageStatus; import org.briarproject.api.event.Event; import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventListener; @@ -124,7 +125,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { // Add an identity for Alice LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH], new byte[123], timestamp, - LocalAuthor.Status.ADDING); + StorageStatus.ADDING); identityManager.addLocalAuthor(aliceAuthor); // Add Bob as a contact Author bobAuthor = new Author(bobId, "Bob", @@ -190,7 +191,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase { // Add an identity for Bob LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob", new byte[MAX_PUBLIC_KEY_LENGTH], new byte[123], timestamp, - LocalAuthor.Status.ADDING); + StorageStatus.ADDING); identityManager.addLocalAuthor(bobAuthor); // Add Alice as a contact Author aliceAuthor = new Author(aliceId, "Alice",