added a cache to the IdentityManager, changed its signature, modified when and where the author is stored

made the author creation single-threaded again in the LifecycleManager, removed redundant code
This commit is contained in:
Ernir Erlingsson
2016-10-13 11:01:25 +02:00
parent 47d6fc526f
commit eaa393a7ed
45 changed files with 299 additions and 552 deletions

View File

@@ -1,9 +1,9 @@
package org.briarproject.api.db;
import java.io.File;
import org.briarproject.api.crypto.SecretKey;
import java.io.File;
public interface DatabaseConfig {
boolean databaseExists();
@@ -14,5 +14,9 @@ public interface DatabaseConfig {
SecretKey getEncryptionKey();
void setAuthorNick(String nickName);
String getAuthorNick();
long getMaxSize();
}

View File

@@ -4,49 +4,23 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.identity.Author.Status;
import java.util.Collection;
public interface IdentityManager {
/** Registers a hook to be called whenever a local pseudonym is added. */
void registerAddIdentityHook(AddIdentityHook hook);
/** Stores the local pseudonym. */
void registerLocalAuthor(LocalAuthor a) throws DbException;
/** Registers a hook to be called whenever a local pseudonym is removed. */
void registerRemoveIdentityHook(RemoveIdentityHook hook);
/** Stores a local pseudonym. */
void addLocalAuthor(LocalAuthor a) throws DbException;
/** Returns the local pseudonym with the given ID. */
LocalAuthor getLocalAuthor(AuthorId a) throws DbException;
/** Returns the local pseudonym with the given ID. */
LocalAuthor getLocalAuthor(Transaction txn, AuthorId a) throws DbException;
/** Returns the main local identity. */
/** Returns the cached main local identity, non-blocking, or loads it from
* the db, blocking*/
LocalAuthor getLocalAuthor() throws DbException;
/** Returns the main local identity within the given Transaction. */
/** Returns the cached main local identity, non-blocking, or loads it from
* the db, blocking, within the given Transaction. */
LocalAuthor getLocalAuthor(Transaction txn) throws DbException;
/** Returns all local pseudonyms. */
Collection<LocalAuthor> getLocalAuthors() throws DbException;
/** Removes a local pseudonym and all associated state. */
void removeLocalAuthor(AuthorId a) throws DbException;
/** Returns the trust-level status of the author */
Status getAuthorStatus(AuthorId a) throws DbException;
/** Returns the trust-level status of the author */
Status getAuthorStatus(Transaction txn, AuthorId a) throws DbException;
interface AddIdentityHook {
void addingIdentity(Transaction txn, LocalAuthor a) throws DbException;
}
interface RemoveIdentityHook {
void removingIdentity(Transaction txn, LocalAuthor a)
throws DbException;
}
}

View File

@@ -1,11 +1,8 @@
package org.briarproject.api.invitation;
import org.briarproject.api.identity.AuthorId;
/** Creates tasks for exchanging invitations with remote peers. */
public interface InvitationTaskFactory {
/** Creates a task using the given pseudonym and invitation codes. */
InvitationTask createTask(AuthorId localAuthorId, int localCode,
int remoteCode);
/** Creates a task using the local author and invitation codes. */
InvitationTask createTask(int localCode, int remoteCode);
}

View File

@@ -4,6 +4,8 @@ import org.briarproject.api.clients.Client;
import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable;
/**
* Manages the lifecycle of the app, starting {@link
* org.briarproject.api.clients.Client Clients}, starting and stopping {@link
@@ -14,7 +16,7 @@ import java.util.concurrent.ExecutorService;
public interface LifecycleManager {
/**
* The result of calling {@link LifecycleManager#startServices()}.
* The result of calling {@link LifecycleManager#startServices(String)}.
*/
enum StartResult {
ALREADY_RUNNING, DB_ERROR, SERVICE_ERROR, SUCCESS
@@ -39,11 +41,11 @@ public interface LifecycleManager {
/**
* Opens the {@link org.briarproject.api.db.DatabaseComponent
* DatabaseComponent} and starts any registered {@link
* org.briarproject.api.clients.Client Clients} and {@link Service
* Services}.
* DatabaseComponent}, creates a local author with the provided nick, and
* starts any registered {@link org.briarproject.api.clients.Client Clients}
* and {@link Service Services}.
*/
StartResult startServices();
StartResult startServices(@Nullable String authorNick);
/**
* Stops any registered {@link Service Services}, shuts down any