mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
@GuardedBy annotations.
This commit is contained in:
@@ -17,6 +17,7 @@ import java.io.InputStreamReader;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -67,7 +68,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
return databaseKey;
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
@Nullable
|
||||
protected String loadEncryptedDatabaseKey() {
|
||||
String key = readDbKeyFromFile(dbKeyFile);
|
||||
@@ -82,7 +83,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
return key;
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
@Nullable
|
||||
private String readDbKeyFromFile(File f) {
|
||||
if (!f.exists()) {
|
||||
@@ -101,7 +102,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
boolean storeEncryptedDatabaseKey(String hex) {
|
||||
LOG.info("Storing database key in file");
|
||||
// Create the directory if necessary
|
||||
@@ -139,7 +140,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
private void writeDbKeyToFile(String key, File f) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
out.write(key.getBytes("UTF-8"));
|
||||
@@ -169,7 +170,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
private boolean encryptAndStoreDatabaseKey(SecretKey key, String password) {
|
||||
byte[] plaintext = key.getBytes();
|
||||
byte[] ciphertext = crypto.encryptWithPassword(plaintext, password);
|
||||
@@ -196,7 +197,7 @@ class AccountManagerImpl implements AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: stateChangeLock
|
||||
@GuardedBy("stateChangeLock")
|
||||
@Nullable
|
||||
private SecretKey loadAndDecryptDatabaseKey(String password) {
|
||||
String hex = loadEncryptedDatabaseKey();
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
import static java.sql.Types.INTEGER;
|
||||
@@ -319,11 +320,13 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
private final Clock clock;
|
||||
private final DatabaseTypes dbTypes;
|
||||
|
||||
// Locking: connectionsLock
|
||||
@GuardedBy("connectionsLock")
|
||||
private final LinkedList<Connection> connections = new LinkedList<>();
|
||||
|
||||
private int openConnections = 0; // Locking: connectionsLock
|
||||
private boolean closed = false; // Locking: connectionsLock
|
||||
@GuardedBy("connectionsLock")
|
||||
private int openConnections = 0;
|
||||
@GuardedBy("connectionsLock")
|
||||
private boolean closed = false;
|
||||
|
||||
protected abstract Connection createConnection() throws SQLException;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
@@ -59,7 +60,8 @@ class Poller implements EventListener {
|
||||
private final SecureRandom random;
|
||||
private final Clock clock;
|
||||
private final Lock lock;
|
||||
private final Map<TransportId, ScheduledPollTask> tasks; // Locking: lock
|
||||
@GuardedBy("lock")
|
||||
private final Map<TransportId, ScheduledPollTask> tasks;
|
||||
|
||||
Poller(@IoExecutor Executor ioExecutor,
|
||||
@Scheduler ScheduledExecutorService scheduler,
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
@@ -111,7 +112,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
return rotationResult;
|
||||
}
|
||||
|
||||
// Locking: lock
|
||||
@GuardedBy("lock")
|
||||
private void addKeys(Collection<KeySet> keys) {
|
||||
for (KeySet ks : keys) {
|
||||
addKeys(ks.getKeySetId(), ks.getContactId(),
|
||||
@@ -119,7 +120,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: lock
|
||||
@GuardedBy("lock")
|
||||
private void addKeys(KeySetId keySetId, ContactId contactId,
|
||||
MutableTransportKeys m) {
|
||||
MutableKeySet ks = new MutableKeySet(keySetId, contactId, m);
|
||||
@@ -130,7 +131,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
considerReplacingOutgoingKeys(ks);
|
||||
}
|
||||
|
||||
// Locking: lock
|
||||
@GuardedBy("lock")
|
||||
private void encodeTags(KeySetId keySetId, ContactId contactId,
|
||||
MutableIncomingKeys inKeys) {
|
||||
for (long streamNumber : inKeys.getWindow().getUnseen()) {
|
||||
@@ -143,7 +144,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Locking: lock
|
||||
@GuardedBy("lock")
|
||||
private void considerReplacingOutgoingKeys(MutableKeySet ks) {
|
||||
// Use the active outgoing keys with the highest key set ID
|
||||
if (ks.getTransportKeys().getCurrentOutgoingKeys().isActive()) {
|
||||
|
||||
Reference in New Issue
Block a user