Nickname is all one word.

This commit is contained in:
akwizgran
2016-11-01 17:05:32 +00:00
parent 88272c5d61
commit c85767d2a0
13 changed files with 28 additions and 39 deletions

View File

@@ -77,7 +77,7 @@ public class AppModule {
return new DatabaseConfig() { return new DatabaseConfig() {
private volatile SecretKey key = null; private volatile SecretKey key = null;
private volatile String nickName; private volatile String nickname;
@Override @Override
public boolean databaseExists() { public boolean databaseExists() {
@@ -97,13 +97,13 @@ public class AppModule {
} }
@Override @Override
public void setAuthorNick(String nickName) { public void setAuthorNick(String nickname) {
this.nickName = nickName; this.nickname = nickname;
} }
@Override @Override
public String getAuthorNick() { public String getAuthorNick() {
return nickName; return nickname;
} }
@Override @Override

View File

@@ -93,8 +93,8 @@ public class BriarService extends Service {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
StartResult result = lifecycleManager String nickname = databaseConfig.getAuthorNick();
.startServices(databaseConfig.getAuthorNick()); StartResult result = lifecycleManager.startServices(nickname);
if (result == SUCCESS) { if (result == SUCCESS) {
started = true; started = true;
} else if (result == ALREADY_RUNNING) { } else if (result == ALREADY_RUNNING) {

View File

@@ -135,7 +135,7 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
String nickname = nicknameEntry.getText().toString(); String nickname = nicknameEntry.getText().toString();
String password = passwordEntry.getText().toString(); String password = passwordEntry.getText().toString();
setupController.storeAuthorInfo(password, nickname, setupController.storeAuthorInfo(nickname, password,
new UiResultHandler<Void>(this) { new UiResultHandler<Void>(this) {
@Override @Override
public void onResultUi(Void result) { public void onResultUi(Void result) {

View File

@@ -6,7 +6,7 @@ public interface SetupController {
float estimatePasswordStrength(String password); float estimatePasswordStrength(String password);
void storeAuthorInfo(String password, String nickname, void storeAuthorInfo(String nickname, String password,
ResultHandler<Void> resultHandler); ResultHandler<Void> resultHandler);
} }

View File

@@ -10,16 +10,12 @@ import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DatabaseConfig; import org.briarproject.api.db.DatabaseConfig;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
public class SetupControllerImpl extends PasswordControllerImpl public class SetupControllerImpl extends PasswordControllerImpl
implements SetupController { implements SetupController {
private static final Logger LOG =
Logger.getLogger(SetupControllerImpl.class.getName());
private final PasswordStrengthEstimator strengthEstimator; private final PasswordStrengthEstimator strengthEstimator;
@Inject @Inject
@@ -37,16 +33,16 @@ public class SetupControllerImpl extends PasswordControllerImpl
} }
@Override @Override
public void storeAuthorInfo(final String password, final String nickname, public void storeAuthorInfo(final String nickname, final String password,
final ResultHandler<Void> resultHandler) { final ResultHandler<Void> resultHandler) {
cryptoExecutor.execute(new Runnable() { cryptoExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
databaseConfig.setAuthorNick(nickname);
SecretKey key = crypto.generateSecretKey(); SecretKey key = crypto.generateSecretKey();
databaseConfig.setEncryptionKey(key); databaseConfig.setEncryptionKey(key);
String hex = encryptDatabaseKey(key, password); String hex = encryptDatabaseKey(key, password);
storeEncryptedDatabaseKey(hex); storeEncryptedDatabaseKey(hex);
databaseConfig.setAuthorNick(nickname);
resultHandler.onResult(null); resultHandler.onResult(null);
} }
}); });

View File

@@ -52,7 +52,6 @@ public class SetupActivityTest {
private TestSetupActivity setupActivity; private TestSetupActivity setupActivity;
private TextInputLayout nicknameEntryWrapper; private TextInputLayout nicknameEntryWrapper;
private TextInputLayout passwordEntryWrapper;
private TextInputLayout passwordConfirmationWrapper; private TextInputLayout passwordConfirmationWrapper;
private EditText nicknameEntry; private EditText nicknameEntry;
private EditText passwordEntry; private EditText passwordEntry;
@@ -71,8 +70,6 @@ public class SetupActivityTest {
setupActivity = Robolectric.setupActivity(TestSetupActivity.class); setupActivity = Robolectric.setupActivity(TestSetupActivity.class);
nicknameEntryWrapper = (TextInputLayout) setupActivity nicknameEntryWrapper = (TextInputLayout) setupActivity
.findViewById(R.id.nickname_entry_wrapper); .findViewById(R.id.nickname_entry_wrapper);
passwordEntryWrapper = (TextInputLayout) setupActivity
.findViewById(R.id.password_entry_wrapper);
passwordConfirmationWrapper = (TextInputLayout) setupActivity passwordConfirmationWrapper = (TextInputLayout) setupActivity
.findViewById(R.id.password_confirm_wrapper); .findViewById(R.id.password_confirm_wrapper);
nicknameEntry = nicknameEntry =
@@ -130,7 +127,7 @@ public class SetupActivityTest {
// Verify that the controller's method was called with the correct // Verify that the controller's method was called with the correct
// params and get the callback // params and get the callback
verify(mockedController, times(1)) verify(mockedController, times(1))
.storeAuthorInfo(eq(safePass), eq(nick), .storeAuthorInfo(eq(nick), eq(safePass),
authorCaptor.capture()); authorCaptor.capture());
authorCaptor.getValue().onResult(null); authorCaptor.getValue().onResult(null);
// execute the callback // execute the callback

View File

@@ -14,7 +14,7 @@ public interface DatabaseConfig {
SecretKey getEncryptionKey(); SecretKey getEncryptionKey();
void setAuthorNick(String nickName); void setAuthorNick(String nickname);
String getAuthorNick(); String getAuthorNick();

View File

@@ -41,11 +41,11 @@ public interface LifecycleManager {
/** /**
* Opens the {@link org.briarproject.api.db.DatabaseComponent * Opens the {@link org.briarproject.api.db.DatabaseComponent
* DatabaseComponent}, creates a local author with the provided nick, and * DatabaseComponent}, creates a local author with the provided nickname,
* starts any registered {@link org.briarproject.api.clients.Client Clients} * and starts any registered {@link org.briarproject.api.clients.Client
* and {@link Service Services}. * Clients} and {@link Service Services}.
*/ */
StartResult startServices(@Nullable String authorNick); StartResult startServices(@Nullable String nickname);
/** /**
* Stops any registered {@link Service Services}, shuts down any * Stops any registered {@link Service Services}, shuts down any

View File

@@ -25,7 +25,7 @@ class IdentityManagerImpl implements IdentityManager {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(IdentityManagerImpl.class.getName()); Logger.getLogger(IdentityManagerImpl.class.getName());
// Make sure that this variable is immutable // The local author is immutable so we can cache it
private volatile LocalAuthor cachedAuthor; private volatile LocalAuthor cachedAuthor;
@Inject @Inject
@@ -40,7 +40,7 @@ class IdentityManagerImpl implements IdentityManager {
db.addLocalAuthor(txn, localAuthor); db.addLocalAuthor(txn, localAuthor);
txn.setComplete(); txn.setComplete();
cachedAuthor = localAuthor; cachedAuthor = localAuthor;
LOG.info("Local Author created"); LOG.info("Local author registered");
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
} }
@@ -52,7 +52,7 @@ class IdentityManagerImpl implements IdentityManager {
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
cachedAuthor = loadLocalAuthor(txn); cachedAuthor = loadLocalAuthor(txn);
LOG.info("Author loaded from db"); LOG.info("Local author loaded");
txn.setComplete(); txn.setComplete();
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
@@ -66,6 +66,7 @@ class IdentityManagerImpl implements IdentityManager {
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException { public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
if (cachedAuthor == null) { if (cachedAuthor == null) {
cachedAuthor = loadLocalAuthor(txn); cachedAuthor = loadLocalAuthor(txn);
LOG.info("Local author loaded");
} }
return cachedAuthor; return cachedAuthor;
} }
@@ -87,10 +88,7 @@ class IdentityManagerImpl implements IdentityManager {
@Override @Override
public Status getAuthorStatus(Transaction txn, AuthorId authorId) public Status getAuthorStatus(Transaction txn, AuthorId authorId)
throws DbException { throws DbException {
// Compare to the IDs of the user's identity
if (getLocalAuthor(txn).getId().equals(authorId)) return OURSELVES; if (getLocalAuthor(txn).getId().equals(authorId)) return OURSELVES;
Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId); Collection<Contact> contacts = db.getContactsByAuthorId(txn, authorId);
if (contacts.isEmpty()) return UNKNOWN; if (contacts.isEmpty()) return UNKNOWN;
for (Contact c : contacts) { for (Contact c : contacts) {

View File

@@ -305,8 +305,7 @@ class IntroduceeManager {
boolean alice = comp < 0; boolean alice = comp < 0;
// get our local author // get our local author
LocalAuthor author = LocalAuthor author = identityManager.getLocalAuthor(txn);
identityManager.getLocalAuthor(txn);
SecretKey secretKey; SecretKey secretKey;
byte[] privateKeyBytes = localState.getRaw(OUR_PRIVATE_KEY); byte[] privateKeyBytes = localState.getRaw(OUR_PRIVATE_KEY);

View File

@@ -93,7 +93,7 @@ class LifecycleManagerImpl implements LifecycleManager {
.createLocalAuthor(nickname, publicKey, privateKey); .createLocalAuthor(nickname, publicKey, privateKey);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Identity creation took " + duration + " ms"); LOG.info("Creating local author took " + duration + " ms");
return localAuthor; return localAuthor;
} }
@@ -102,12 +102,11 @@ class LifecycleManagerImpl implements LifecycleManager {
identityManager.registerLocalAuthor(author); identityManager.registerLocalAuthor(author);
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Author registration took " + duration + LOG.info("Registering local author took " + duration + " ms");
" ms");
} }
@Override @Override
public StartResult startServices(@Nullable String authorNick) { public StartResult startServices(@Nullable String nickname) {
if (!startStopSemaphore.tryAcquire()) { if (!startStopSemaphore.tryAcquire()) {
LOG.info("Already starting or stopping"); LOG.info("Already starting or stopping");
return ALREADY_RUNNING; return ALREADY_RUNNING;
@@ -124,8 +123,8 @@ class LifecycleManagerImpl implements LifecycleManager {
else LOG.info("Creating database took " + duration + " ms"); else LOG.info("Creating database took " + duration + " ms");
} }
if (authorNick != null) { if (nickname != null) {
registerLocalAuthor(createLocalAuthor(authorNick)); registerLocalAuthor(createLocalAuthor(nickname));
} }
dbLatch.countDown(); dbLatch.countDown();

View File

@@ -39,7 +39,7 @@ public class TestDatabaseConfig implements DatabaseConfig {
} }
@Override @Override
public void setAuthorNick(String nickName) { public void setAuthorNick(String nickname) {
} }

View File

@@ -38,7 +38,7 @@ public class TestLifecycleModule {
} }
@Override @Override
public StartResult startServices(String authorNick) { public StartResult startServices(String nickname) {
return StartResult.SUCCESS; return StartResult.SUCCESS;
} }