mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Clean up some duplicated code.
This commit is contained in:
@@ -98,9 +98,7 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatabaseOpened(Transaction txn) throws DbException {
|
public void onDatabaseOpened(Transaction txn) throws DbException {
|
||||||
Account cached = cachedAccount;
|
Account cached = getCachedAccount(txn);
|
||||||
if (cached == null)
|
|
||||||
cachedAccount = cached = loadAccountWithKeyPair(txn);
|
|
||||||
if (shouldStoreAccount) {
|
if (shouldStoreAccount) {
|
||||||
db.addAccount(txn, cached);
|
db.addAccount(txn, cached);
|
||||||
LOG.info("Account stored");
|
LOG.info("Account stored");
|
||||||
@@ -116,32 +114,32 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
@Override
|
@Override
|
||||||
public LocalAuthor getLocalAuthor() throws DbException {
|
public LocalAuthor getLocalAuthor() throws DbException {
|
||||||
Account cached = cachedAccount;
|
Account cached = cachedAccount;
|
||||||
if (cached == null) {
|
if (cached == null)
|
||||||
cachedAccount = cached = db.transactionWithResult(true,
|
cached = db.transactionWithResult(true, this::getCachedAccount);
|
||||||
this::loadAccountWithKeyPair);
|
|
||||||
}
|
|
||||||
return cached.getLocalAuthor();
|
return cached.getLocalAuthor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
||||||
Account cached = cachedAccount;
|
return getCachedAccount(txn).getLocalAuthor();
|
||||||
if (cached == null)
|
|
||||||
cachedAccount = cached = loadAccountWithKeyPair(txn);
|
|
||||||
return cached.getLocalAuthor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[][] getHandshakeKeys(Transaction txn) throws DbException {
|
public byte[][] getHandshakeKeys(Transaction txn) throws DbException {
|
||||||
Account cached = cachedAccount;
|
Account cached = getCachedAccount(txn);
|
||||||
if (cached == null)
|
|
||||||
cachedAccount = cached = loadAccountWithKeyPair(txn);
|
|
||||||
return new byte[][] {
|
return new byte[][] {
|
||||||
cached.getHandshakePublicKey(),
|
cached.getHandshakePublicKey(),
|
||||||
cached.getHandshakePrivateKey()
|
cached.getHandshakePrivateKey()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Account getCachedAccount(Transaction txn) throws DbException {
|
||||||
|
Account cached = cachedAccount;
|
||||||
|
if (cached == null)
|
||||||
|
cachedAccount = cached = loadAccountWithKeyPair(txn);
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
private Account loadAccountWithKeyPair(Transaction txn) throws DbException {
|
private Account loadAccountWithKeyPair(Transaction txn) throws DbException {
|
||||||
Account a = loadAccount(txn);
|
Account a = loadAccount(txn);
|
||||||
LOG.info("Account loaded");
|
LOG.info("Account loaded");
|
||||||
|
|||||||
Reference in New Issue
Block a user