Commit 8529c976 authored by akwizgran's avatar akwizgran

Renamed a bunch of lock variables.

"synchLock" will become confusing when we have lots of objects with "sync" in the name.
parent 4f59491c
......@@ -66,7 +66,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
......
......@@ -61,9 +61,9 @@ Service, EventListener {
private final Executor dbExecutor;
private final EventBus eventBus;
private final Context appContext;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<ContactId, Integer> contactCounts =
new HashMap<ContactId, Integer>();
private final Map<GroupId, Integer> groupCounts =
......@@ -112,7 +112,7 @@ Service, EventListener {
}
public void showPrivateMessageNotification(ContactId c) {
synchLock.lock();
lock.lock();
try {
Integer count = contactCounts.get(c);
if (count == null) contactCounts.put(c, 1);
......@@ -120,23 +120,23 @@ Service, EventListener {
privateTotal++;
updatePrivateMessageNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void clearPrivateMessageNotification(ContactId c) {
synchLock.lock();
lock.lock();
try {
Integer count = contactCounts.remove(c);
if (count == null) return; // Already cleared
privateTotal -= count;
updatePrivateMessageNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Locking: synchLock
// Locking: lock
private void updatePrivateMessageNotification() {
if (privateTotal == 0) {
clearPrivateMessageNotification();
......@@ -181,7 +181,7 @@ Service, EventListener {
}
}
// Locking: synchLock
// Locking: lock
private void clearPrivateMessageNotification() {
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
......@@ -200,7 +200,7 @@ Service, EventListener {
}
public void showGroupPostNotification(GroupId g) {
synchLock.lock();
lock.lock();
try {
Integer count = groupCounts.get(g);
if (count == null) groupCounts.put(g, 1);
......@@ -208,23 +208,23 @@ Service, EventListener {
groupTotal++;
updateGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void clearGroupPostNotification(GroupId g) {
synchLock.lock();
lock.lock();
try {
Integer count = groupCounts.remove(g);
if (count == null) return; // Already cleared
groupTotal -= count;
updateGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Locking: synchLock
// Locking: lock
private void updateGroupPostNotification() {
if (groupTotal == 0) {
clearGroupPostNotification();
......@@ -269,7 +269,7 @@ Service, EventListener {
}
}
// Locking: synchLock
// Locking: lock
private void clearGroupPostNotification() {
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
......@@ -277,7 +277,7 @@ Service, EventListener {
}
public void clearNotifications() {
synchLock.lock();
lock.lock();
try {
contactCounts.clear();
groupCounts.clear();
......@@ -285,7 +285,7 @@ Service, EventListener {
clearPrivateMessageNotification();
clearGroupPostNotification();
} finally {
synchLock.unlock();
lock.unlock();
}
}
}
......@@ -15,15 +15,15 @@ class ReferenceManagerImpl implements ReferenceManager {
private static final Logger LOG =
Logger.getLogger(ReferenceManagerImpl.class.getName());
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<Class<?>, Map<Long, Object>> outerMap =
new HashMap<Class<?>, Map<Long, Object>>();
private long nextHandle = 0;
public <T> T getReference(long handle, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) {
......@@ -36,13 +36,13 @@ class ReferenceManagerImpl implements ReferenceManager {
Object o = innerMap.get(handle);
return c.cast(o);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public <T> long putReference(T reference, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) {
......@@ -57,12 +57,12 @@ class ReferenceManagerImpl implements ReferenceManager {
}
return handle;
} finally {
synchLock.unlock();
lock.unlock();
}
}
public <T> T removeReference(long handle, Class<T> c) {
synchLock.lock();
lock.lock();
try {
Map<Long, Object> innerMap = outerMap.get(c);
if (innerMap == null) return null;
......@@ -74,7 +74,7 @@ class ReferenceManagerImpl implements ReferenceManager {
}
return c.cast(o);
} finally {
synchLock.unlock();
lock.unlock();
}
}
......
......@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
......@@ -28,5 +28,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="guice-3.0-no_aop" level="project" />
<orderEntry type="library" exported="" name="javax.inject" level="project" />
<orderEntry type="library" exported="" name="briar-api.briar-api" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -13,7 +13,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
......@@ -32,5 +32,6 @@
<orderEntry type="library" exported="" name="h2small-1.4.190" level="project" />
<orderEntry type="library" exported="" name="spongy-core-1.53" level="project" />
<orderEntry type="library" exported="" name="weupnp-0.1.3-SNAPSHOT-briar" level="project" />
<orderEntry type="library" exported="" name="briar-core.briar-core" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -19,9 +19,9 @@ class FortunaGenerator {
private static final int KEY_BYTES = 32;
private static final int BLOCK_BYTES = 16;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final MessageDigest digest = new DoubleDigest(new SHA256Digest());
private final BlockCipher cipher = new AESLightEngine();
private final byte[] key = new byte[KEY_BYTES];
......@@ -34,21 +34,21 @@ class FortunaGenerator {
}
void reseed(byte[] seed) {
synchLock.lock();
lock.lock();
try {
digest.update(key);
digest.update(seed);
digest.digest(key, 0, KEY_BYTES);
incrementCounter();
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Package access for testing
void incrementCounter() {
synchLock.lock();
lock.lock();
try {
counter[0]++;
for (int i = 0; counter[i] == 0; i++) {
......@@ -57,23 +57,23 @@ class FortunaGenerator {
counter[i + 1]++;
}
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Package access for testing
byte[] getCounter() {
synchLock.lock();
lock.lock();
try {
return counter;
} finally {
synchLock.unlock();
lock.unlock();
}
}
int nextBytes(byte[] dest, int off, int len) {
synchLock.lock();
lock.lock();
try {
// Don't write more than the maximum number of bytes in one request
if (len > MAX_BYTES_PER_REQUEST) len = MAX_BYTES_PER_REQUEST;
......@@ -104,7 +104,7 @@ class FortunaGenerator {
// Return the number of bytes written
return len;
} finally {
synchLock.unlock();
lock.unlock();
}
}
}
......@@ -62,9 +62,9 @@ class ConnectorGroup extends Thread implements InvitationTask {
private final Collection<InvitationListener> listeners;
private final AtomicBoolean connected;
private final CountDownLatch localConfirmationLatch;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private int localConfirmationCode = -1, remoteConfirmationCode = -1;
private boolean connectionFailed = false;
private boolean localCompared = false, remoteCompared = false;
......@@ -103,7 +103,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
public InvitationState addListener(InvitationListener l) {
synchLock.lock();
lock.lock();
try {
listeners.add(l);
return new InvitationState(localInvitationCode,
......@@ -112,7 +112,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
localCompared, remoteCompared, localMatched, remoteMatched,
remoteName);
} finally {
synchLock.unlock();
lock.unlock();
}
}
......@@ -134,11 +134,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
localProps = db.getLocalProperties();
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
synchLock.lock();
lock.lock();
try {
connectionFailed = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.connectionFailed();
return;
......@@ -170,11 +170,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
// If none of the threads connected, inform the listeners
if (!connected.get()) {
synchLock.lock();
lock.lock();
try {
connectionFailed = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.connectionFailed();
}
......@@ -203,23 +203,23 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
public void localConfirmationSucceeded() {
synchLock.lock();
lock.lock();
try {
localCompared = true;
localMatched = true;
} finally {
synchLock.unlock();
lock.unlock();
}
localConfirmationLatch.countDown();
}
public void localConfirmationFailed() {
synchLock.lock();
lock.lock();
try {
localCompared = true;
localMatched = false;
} finally {
synchLock.unlock();
lock.unlock();
}
localConfirmationLatch.countDown();
}
......@@ -232,12 +232,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
}
void keyAgreementSucceeded(int localCode, int remoteCode) {
synchLock.lock();
lock.lock();
try {
localConfirmationCode = localCode;
remoteConfirmationCode = remoteCode;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners)
l.keyAgreementSucceeded(localCode, remoteCode);
......@@ -249,43 +249,43 @@ class ConnectorGroup extends Thread implements InvitationTask {
boolean waitForLocalConfirmationResult() throws InterruptedException {
localConfirmationLatch.await(CONFIRMATION_TIMEOUT, MILLISECONDS);
synchLock.lock();
lock.lock();
try {
return localMatched;
} finally {
synchLock.unlock();
lock.unlock();
}
}
void remoteConfirmationSucceeded() {
synchLock.lock();
lock.lock();
try {
remoteCompared = true;
remoteMatched = true;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.remoteConfirmationSucceeded();
}
void remoteConfirmationFailed() {
synchLock.lock();
lock.lock();
try {
remoteCompared = true;
remoteMatched = false;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners) l.remoteConfirmationFailed();
}
void pseudonymExchangeSucceeded(Author remoteAuthor) {
String name = remoteAuthor.getName();
synchLock.lock();
lock.lock();
try {
remoteName = name;
} finally {
synchLock.unlock();
lock.unlock();
}
for (InvitationListener l : listeners)
l.pseudonymExchangeSucceeded(name);
......
......@@ -9,9 +9,9 @@ import org.briarproject.api.lifecycle.ShutdownManager;
class ShutdownManagerImpl implements ShutdownManager {
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
protected final Map<Integer, Thread> hooks;
private int nextHandle = 0;
......@@ -20,7 +20,7 @@ class ShutdownManagerImpl implements ShutdownManager {
}
public int addShutdownHook(Runnable r) {
synchLock.lock();
lock.lock();
try {
int handle = nextHandle++;
Thread hook = createThread(r);
......@@ -28,7 +28,7 @@ class ShutdownManagerImpl implements ShutdownManager {
Runtime.getRuntime().addShutdownHook(hook);
return handle;
} finally {
synchLock.unlock();
lock.unlock();
}
}
......@@ -38,13 +38,13 @@ class ShutdownManagerImpl implements ShutdownManager {
}
public boolean removeShutdownHook(int handle) {
synchLock.lock();
lock.lock();
try {
Thread hook = hooks.remove(handle);
if (hook == null) return false;
else return Runtime.getRuntime().removeShutdownHook(hook);
} finally {
synchLock.unlock();
lock.unlock();
}
}
......
......@@ -27,9 +27,9 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
Logger.getLogger(ConnectionRegistryImpl.class.getName());
private final EventBus eventBus;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<TransportId, Map<ContactId, Integer>> connections;
private final Map<ContactId, Integer> contactCounts;
......@@ -43,7 +43,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public void registerConnection(ContactId c, TransportId t) {
LOG.info("Connection registered");
boolean firstConnection = false;
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) {
......@@ -61,7 +61,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
contactCounts.put(c, count + 1);
}
} finally {
synchLock.unlock();
lock.unlock();
}
if (firstConnection) {
......@@ -73,7 +73,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public void unregisterConnection(ContactId c, TransportId t) {
LOG.info("Connection unregistered");
boolean lastConnection = false;
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) throw new IllegalArgumentException();
......@@ -93,7 +93,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
contactCounts.put(c, count - 1);
}
} finally {
synchLock.unlock();
lock.unlock();
}
if (lastConnection) {
......@@ -104,7 +104,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
public Collection<ContactId> getConnectedContacts(
TransportId t) {
synchLock.lock();
lock.lock();
try {
Map<ContactId, Integer> m = connections.get(t);
if (m == null) return Collections.emptyList();
......@@ -112,17 +112,17 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
return Collections.unmodifiableList(ids);
} finally {
synchLock.unlock();
lock.unlock();
}
}
public boolean isConnected(ContactId c) {
synchLock.lock();
lock.lock();
try {
return contactCounts.containsKey(c);
} finally {
synchLock.unlock();
lock.unlock();
}
}
......
......@@ -50,9 +50,9 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
private final TagRecogniser tagRecogniser;
private final Clock clock;
private final Timer timer;
private final Lock synchLock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// The following are locking: synchLock
// The following are locking: lock
private final Map<TransportId, Integer> maxLatencies;
private final Map<EndpointKey, TemporarySecret> oldSecrets;
private final Map<EndpointKey, TemporarySecret> currentSecrets;
......@@ -75,7 +75,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
public boolean start() {
synchLock.lock();
lock.lock();
try {
eventBus.addListener(this);
// Load the temporary secrets and transport latencies from the DB
......@@ -116,12 +116,12 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
MS_BETWEEN_CHECKS);
return true;
} finally {
synchLock.unlock();
lock.unlock();
}
}
// Assigns secrets to the appropriate maps and returns any dead secrets
// Locking: synchLock
// Locking: lock
private Collection<TemporarySecret> assignSecretsToMaps(long now,
Collection<TemporarySecret> secrets) {
Collection<TemporarySecret> dead = new ArrayList<TemporarySecret>();
......@@ -154,7 +154,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
// Replaces the given secrets and returns any secrets created
// Locking: synchLock
// Locking: lock
private Collection<TemporarySecret> replaceDeadSecrets(long now,
Collection<TemporarySecret> dead) {
// If there are several dead secrets for an endpoint, use the newest
......@@ -213,7 +213,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
public boolean stop() {
synchLock.lock();
lock.lock();
try {
eventBus.removeListener(this);
timer.cancel();
......@@ -224,13 +224,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
newSecrets.clear();
return true;
} finally {
synchLock.unlock();
lock.unlock();
}
}
public StreamContext getStreamContext(ContactId c,
TransportId t) {
synchLock.lock();
lock.lock();
try {
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
if (s == null) {
......@@ -251,13 +251,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
byte[] secret = s.getSecret();
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
} finally {
synchLock.unlock();
lock.unlock();
}
}
public void endpointAdded(Endpoint ep, int maxLatency,
byte[] initialSecret) {
synchLock.lock();
lock.lock();
try {
maxLatencies.put(ep.getTransportId(), maxLatency);
// Work out which rotation period we're in
......@@ -291,13 +291,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
tagRecogniser.addSecret(s2);
tagRecogniser.addSecret(s3);
} finally {
synchLock.unlock();
lock.unlock();
}
}
@Override
public void run() {
synchLock.lock();
lock.lock();
try {
// Rebuild the maps because we may be running a whole period late
Collection<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
......@@ -330,7 +330,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
for (TemporarySecret s : created) tagRecogniser.addSecret(s);
}
} finally {