mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Renamed a bunch of lock variables.
"synchLock" will become confusing when we have lots of objects with "sync" in the name.
This commit is contained in:
@@ -66,7 +66,6 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
<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/pre-dexed" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ Service, EventListener {
|
|||||||
private final Executor dbExecutor;
|
private final Executor dbExecutor;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final Context appContext;
|
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 =
|
private final Map<ContactId, Integer> contactCounts =
|
||||||
new HashMap<ContactId, Integer>();
|
new HashMap<ContactId, Integer>();
|
||||||
private final Map<GroupId, Integer> groupCounts =
|
private final Map<GroupId, Integer> groupCounts =
|
||||||
@@ -112,7 +112,7 @@ Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showPrivateMessageNotification(ContactId c) {
|
public void showPrivateMessageNotification(ContactId c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Integer count = contactCounts.get(c);
|
Integer count = contactCounts.get(c);
|
||||||
if (count == null) contactCounts.put(c, 1);
|
if (count == null) contactCounts.put(c, 1);
|
||||||
@@ -120,23 +120,23 @@ Service, EventListener {
|
|||||||
privateTotal++;
|
privateTotal++;
|
||||||
updatePrivateMessageNotification();
|
updatePrivateMessageNotification();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearPrivateMessageNotification(ContactId c) {
|
public void clearPrivateMessageNotification(ContactId c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Integer count = contactCounts.remove(c);
|
Integer count = contactCounts.remove(c);
|
||||||
if (count == null) return; // Already cleared
|
if (count == null) return; // Already cleared
|
||||||
privateTotal -= count;
|
privateTotal -= count;
|
||||||
updatePrivateMessageNotification();
|
updatePrivateMessageNotification();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void updatePrivateMessageNotification() {
|
private void updatePrivateMessageNotification() {
|
||||||
if (privateTotal == 0) {
|
if (privateTotal == 0) {
|
||||||
clearPrivateMessageNotification();
|
clearPrivateMessageNotification();
|
||||||
@@ -181,7 +181,7 @@ Service, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void clearPrivateMessageNotification() {
|
private void clearPrivateMessageNotification() {
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationManager nm = (NotificationManager) o;
|
NotificationManager nm = (NotificationManager) o;
|
||||||
@@ -200,7 +200,7 @@ Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showGroupPostNotification(GroupId g) {
|
public void showGroupPostNotification(GroupId g) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Integer count = groupCounts.get(g);
|
Integer count = groupCounts.get(g);
|
||||||
if (count == null) groupCounts.put(g, 1);
|
if (count == null) groupCounts.put(g, 1);
|
||||||
@@ -208,23 +208,23 @@ Service, EventListener {
|
|||||||
groupTotal++;
|
groupTotal++;
|
||||||
updateGroupPostNotification();
|
updateGroupPostNotification();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearGroupPostNotification(GroupId g) {
|
public void clearGroupPostNotification(GroupId g) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Integer count = groupCounts.remove(g);
|
Integer count = groupCounts.remove(g);
|
||||||
if (count == null) return; // Already cleared
|
if (count == null) return; // Already cleared
|
||||||
groupTotal -= count;
|
groupTotal -= count;
|
||||||
updateGroupPostNotification();
|
updateGroupPostNotification();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void updateGroupPostNotification() {
|
private void updateGroupPostNotification() {
|
||||||
if (groupTotal == 0) {
|
if (groupTotal == 0) {
|
||||||
clearGroupPostNotification();
|
clearGroupPostNotification();
|
||||||
@@ -269,7 +269,7 @@ Service, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void clearGroupPostNotification() {
|
private void clearGroupPostNotification() {
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationManager nm = (NotificationManager) o;
|
NotificationManager nm = (NotificationManager) o;
|
||||||
@@ -277,7 +277,7 @@ Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearNotifications() {
|
public void clearNotifications() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
contactCounts.clear();
|
contactCounts.clear();
|
||||||
groupCounts.clear();
|
groupCounts.clear();
|
||||||
@@ -285,7 +285,7 @@ Service, EventListener {
|
|||||||
clearPrivateMessageNotification();
|
clearPrivateMessageNotification();
|
||||||
clearGroupPostNotification();
|
clearGroupPostNotification();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,15 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ReferenceManagerImpl.class.getName());
|
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 =
|
private final Map<Class<?>, Map<Long, Object>> outerMap =
|
||||||
new HashMap<Class<?>, Map<Long, Object>>();
|
new HashMap<Class<?>, Map<Long, Object>>();
|
||||||
private long nextHandle = 0;
|
private long nextHandle = 0;
|
||||||
|
|
||||||
public <T> T getReference(long handle, Class<T> c) {
|
public <T> T getReference(long handle, Class<T> c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<Long, Object> innerMap = outerMap.get(c);
|
Map<Long, Object> innerMap = outerMap.get(c);
|
||||||
if (innerMap == null) {
|
if (innerMap == null) {
|
||||||
@@ -36,13 +36,13 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
Object o = innerMap.get(handle);
|
Object o = innerMap.get(handle);
|
||||||
return c.cast(o);
|
return c.cast(o);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> long putReference(T reference, Class<T> c) {
|
public <T> long putReference(T reference, Class<T> c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<Long, Object> innerMap = outerMap.get(c);
|
Map<Long, Object> innerMap = outerMap.get(c);
|
||||||
if (innerMap == null) {
|
if (innerMap == null) {
|
||||||
@@ -57,12 +57,12 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T removeReference(long handle, Class<T> c) {
|
public <T> T removeReference(long handle, Class<T> c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<Long, Object> innerMap = outerMap.get(c);
|
Map<Long, Object> innerMap = outerMap.get(c);
|
||||||
if (innerMap == null) return null;
|
if (innerMap == null) return null;
|
||||||
@@ -74,7 +74,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
}
|
}
|
||||||
return c.cast(o);
|
return c.cast(o);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
</component>
|
</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 url="file://$MODULE_DIR$/build/classes/main" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
@@ -28,5 +28,6 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" name="guice-3.0-no_aop" level="project" />
|
<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="javax.inject" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="briar-api.briar-api" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
</component>
|
</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 url="file://$MODULE_DIR$/build/classes/main" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
@@ -32,5 +32,6 @@
|
|||||||
<orderEntry type="library" exported="" name="h2small-1.4.190" level="project" />
|
<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="spongy-core-1.53" level="project" />
|
||||||
<orderEntry type="library" exported="" name="weupnp-0.1.3-SNAPSHOT-briar" 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>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -19,9 +19,9 @@ class FortunaGenerator {
|
|||||||
private static final int KEY_BYTES = 32;
|
private static final int KEY_BYTES = 32;
|
||||||
private static final int BLOCK_BYTES = 16;
|
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 MessageDigest digest = new DoubleDigest(new SHA256Digest());
|
||||||
private final BlockCipher cipher = new AESLightEngine();
|
private final BlockCipher cipher = new AESLightEngine();
|
||||||
private final byte[] key = new byte[KEY_BYTES];
|
private final byte[] key = new byte[KEY_BYTES];
|
||||||
@@ -34,21 +34,21 @@ class FortunaGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reseed(byte[] seed) {
|
void reseed(byte[] seed) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
digest.update(key);
|
digest.update(key);
|
||||||
digest.update(seed);
|
digest.update(seed);
|
||||||
digest.digest(key, 0, KEY_BYTES);
|
digest.digest(key, 0, KEY_BYTES);
|
||||||
incrementCounter();
|
incrementCounter();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
void incrementCounter() {
|
void incrementCounter() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
counter[0]++;
|
counter[0]++;
|
||||||
for (int i = 0; counter[i] == 0; i++) {
|
for (int i = 0; counter[i] == 0; i++) {
|
||||||
@@ -57,23 +57,23 @@ class FortunaGenerator {
|
|||||||
counter[i + 1]++;
|
counter[i + 1]++;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
byte[] getCounter() {
|
byte[] getCounter() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
return counter;
|
return counter;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextBytes(byte[] dest, int off, int len) {
|
int nextBytes(byte[] dest, int off, int len) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Don't write more than the maximum number of bytes in one request
|
// Don't write more than the maximum number of bytes in one request
|
||||||
if (len > MAX_BYTES_PER_REQUEST) len = MAX_BYTES_PER_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 the number of bytes written
|
||||||
return len;
|
return len;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
private final Collection<InvitationListener> listeners;
|
private final Collection<InvitationListener> listeners;
|
||||||
private final AtomicBoolean connected;
|
private final AtomicBoolean connected;
|
||||||
private final CountDownLatch localConfirmationLatch;
|
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 int localConfirmationCode = -1, remoteConfirmationCode = -1;
|
||||||
private boolean connectionFailed = false;
|
private boolean connectionFailed = false;
|
||||||
private boolean localCompared = false, remoteCompared = false;
|
private boolean localCompared = false, remoteCompared = false;
|
||||||
@@ -103,7 +103,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InvitationState addListener(InvitationListener l) {
|
public InvitationState addListener(InvitationListener l) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
listeners.add(l);
|
listeners.add(l);
|
||||||
return new InvitationState(localInvitationCode,
|
return new InvitationState(localInvitationCode,
|
||||||
@@ -112,7 +112,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
localCompared, remoteCompared, localMatched, remoteMatched,
|
localCompared, remoteCompared, localMatched, remoteMatched,
|
||||||
remoteName);
|
remoteName);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,11 +134,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
localProps = db.getLocalProperties();
|
localProps = db.getLocalProperties();
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
connectionFailed = true;
|
connectionFailed = true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners) l.connectionFailed();
|
for (InvitationListener l : listeners) l.connectionFailed();
|
||||||
return;
|
return;
|
||||||
@@ -170,11 +170,11 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
}
|
}
|
||||||
// If none of the threads connected, inform the listeners
|
// If none of the threads connected, inform the listeners
|
||||||
if (!connected.get()) {
|
if (!connected.get()) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
connectionFailed = true;
|
connectionFailed = true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners) l.connectionFailed();
|
for (InvitationListener l : listeners) l.connectionFailed();
|
||||||
}
|
}
|
||||||
@@ -203,23 +203,23 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void localConfirmationSucceeded() {
|
public void localConfirmationSucceeded() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
localCompared = true;
|
localCompared = true;
|
||||||
localMatched = true;
|
localMatched = true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
localConfirmationLatch.countDown();
|
localConfirmationLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void localConfirmationFailed() {
|
public void localConfirmationFailed() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
localCompared = true;
|
localCompared = true;
|
||||||
localMatched = false;
|
localMatched = false;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
localConfirmationLatch.countDown();
|
localConfirmationLatch.countDown();
|
||||||
}
|
}
|
||||||
@@ -232,12 +232,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void keyAgreementSucceeded(int localCode, int remoteCode) {
|
void keyAgreementSucceeded(int localCode, int remoteCode) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
localConfirmationCode = localCode;
|
localConfirmationCode = localCode;
|
||||||
remoteConfirmationCode = remoteCode;
|
remoteConfirmationCode = remoteCode;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners)
|
for (InvitationListener l : listeners)
|
||||||
l.keyAgreementSucceeded(localCode, remoteCode);
|
l.keyAgreementSucceeded(localCode, remoteCode);
|
||||||
@@ -249,43 +249,43 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
|
|
||||||
boolean waitForLocalConfirmationResult() throws InterruptedException {
|
boolean waitForLocalConfirmationResult() throws InterruptedException {
|
||||||
localConfirmationLatch.await(CONFIRMATION_TIMEOUT, MILLISECONDS);
|
localConfirmationLatch.await(CONFIRMATION_TIMEOUT, MILLISECONDS);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
return localMatched;
|
return localMatched;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remoteConfirmationSucceeded() {
|
void remoteConfirmationSucceeded() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
remoteCompared = true;
|
remoteCompared = true;
|
||||||
remoteMatched = true;
|
remoteMatched = true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners) l.remoteConfirmationSucceeded();
|
for (InvitationListener l : listeners) l.remoteConfirmationSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void remoteConfirmationFailed() {
|
void remoteConfirmationFailed() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
remoteCompared = true;
|
remoteCompared = true;
|
||||||
remoteMatched = false;
|
remoteMatched = false;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners) l.remoteConfirmationFailed();
|
for (InvitationListener l : listeners) l.remoteConfirmationFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pseudonymExchangeSucceeded(Author remoteAuthor) {
|
void pseudonymExchangeSucceeded(Author remoteAuthor) {
|
||||||
String name = remoteAuthor.getName();
|
String name = remoteAuthor.getName();
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
remoteName = name;
|
remoteName = name;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (InvitationListener l : listeners)
|
for (InvitationListener l : listeners)
|
||||||
l.pseudonymExchangeSucceeded(name);
|
l.pseudonymExchangeSucceeded(name);
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import org.briarproject.api.lifecycle.ShutdownManager;
|
|||||||
|
|
||||||
class ShutdownManagerImpl implements 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;
|
protected final Map<Integer, Thread> hooks;
|
||||||
private int nextHandle = 0;
|
private int nextHandle = 0;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ class ShutdownManagerImpl implements ShutdownManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int addShutdownHook(Runnable r) {
|
public int addShutdownHook(Runnable r) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
int handle = nextHandle++;
|
int handle = nextHandle++;
|
||||||
Thread hook = createThread(r);
|
Thread hook = createThread(r);
|
||||||
@@ -28,7 +28,7 @@ class ShutdownManagerImpl implements ShutdownManager {
|
|||||||
Runtime.getRuntime().addShutdownHook(hook);
|
Runtime.getRuntime().addShutdownHook(hook);
|
||||||
return handle;
|
return handle;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -38,13 +38,13 @@ class ShutdownManagerImpl implements ShutdownManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeShutdownHook(int handle) {
|
public boolean removeShutdownHook(int handle) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Thread hook = hooks.remove(handle);
|
Thread hook = hooks.remove(handle);
|
||||||
if (hook == null) return false;
|
if (hook == null) return false;
|
||||||
else return Runtime.getRuntime().removeShutdownHook(hook);
|
else return Runtime.getRuntime().removeShutdownHook(hook);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
Logger.getLogger(ConnectionRegistryImpl.class.getName());
|
Logger.getLogger(ConnectionRegistryImpl.class.getName());
|
||||||
|
|
||||||
private final EventBus eventBus;
|
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<TransportId, Map<ContactId, Integer>> connections;
|
||||||
private final Map<ContactId, Integer> contactCounts;
|
private final Map<ContactId, Integer> contactCounts;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
public void registerConnection(ContactId c, TransportId t) {
|
public void registerConnection(ContactId c, TransportId t) {
|
||||||
LOG.info("Connection registered");
|
LOG.info("Connection registered");
|
||||||
boolean firstConnection = false;
|
boolean firstConnection = false;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<ContactId, Integer> m = connections.get(t);
|
Map<ContactId, Integer> m = connections.get(t);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
@@ -61,7 +61,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
contactCounts.put(c, count + 1);
|
contactCounts.put(c, count + 1);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstConnection) {
|
if (firstConnection) {
|
||||||
@@ -73,7 +73,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
public void unregisterConnection(ContactId c, TransportId t) {
|
public void unregisterConnection(ContactId c, TransportId t) {
|
||||||
LOG.info("Connection unregistered");
|
LOG.info("Connection unregistered");
|
||||||
boolean lastConnection = false;
|
boolean lastConnection = false;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<ContactId, Integer> m = connections.get(t);
|
Map<ContactId, Integer> m = connections.get(t);
|
||||||
if (m == null) throw new IllegalArgumentException();
|
if (m == null) throw new IllegalArgumentException();
|
||||||
@@ -93,7 +93,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
contactCounts.put(c, count - 1);
|
contactCounts.put(c, count - 1);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastConnection) {
|
if (lastConnection) {
|
||||||
@@ -104,7 +104,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
|
|
||||||
public Collection<ContactId> getConnectedContacts(
|
public Collection<ContactId> getConnectedContacts(
|
||||||
TransportId t) {
|
TransportId t) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Map<ContactId, Integer> m = connections.get(t);
|
Map<ContactId, Integer> m = connections.get(t);
|
||||||
if (m == null) return Collections.emptyList();
|
if (m == null) return Collections.emptyList();
|
||||||
@@ -112,17 +112,17 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
|
if (LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
|
||||||
return Collections.unmodifiableList(ids);
|
return Collections.unmodifiableList(ids);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected(ContactId c) {
|
public boolean isConnected(ContactId c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
return contactCounts.containsKey(c);
|
return contactCounts.containsKey(c);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
private final TagRecogniser tagRecogniser;
|
private final TagRecogniser tagRecogniser;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final Timer timer;
|
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<TransportId, Integer> maxLatencies;
|
||||||
private final Map<EndpointKey, TemporarySecret> oldSecrets;
|
private final Map<EndpointKey, TemporarySecret> oldSecrets;
|
||||||
private final Map<EndpointKey, TemporarySecret> currentSecrets;
|
private final Map<EndpointKey, TemporarySecret> currentSecrets;
|
||||||
@@ -75,7 +75,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
// Load the temporary secrets and transport latencies from the DB
|
// Load the temporary secrets and transport latencies from the DB
|
||||||
@@ -116,12 +116,12 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
MS_BETWEEN_CHECKS);
|
MS_BETWEEN_CHECKS);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assigns secrets to the appropriate maps and returns any dead secrets
|
// Assigns secrets to the appropriate maps and returns any dead secrets
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private Collection<TemporarySecret> assignSecretsToMaps(long now,
|
private Collection<TemporarySecret> assignSecretsToMaps(long now,
|
||||||
Collection<TemporarySecret> secrets) {
|
Collection<TemporarySecret> secrets) {
|
||||||
Collection<TemporarySecret> dead = new ArrayList<TemporarySecret>();
|
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
|
// Replaces the given secrets and returns any secrets created
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private Collection<TemporarySecret> replaceDeadSecrets(long now,
|
private Collection<TemporarySecret> replaceDeadSecrets(long now,
|
||||||
Collection<TemporarySecret> dead) {
|
Collection<TemporarySecret> dead) {
|
||||||
// If there are several dead secrets for an endpoint, use the newest
|
// 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() {
|
public boolean stop() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
@@ -224,13 +224,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
newSecrets.clear();
|
newSecrets.clear();
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamContext getStreamContext(ContactId c,
|
public StreamContext getStreamContext(ContactId c,
|
||||||
TransportId t) {
|
TransportId t) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
|
TemporarySecret s = currentSecrets.get(new EndpointKey(c, t));
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
@@ -251,13 +251,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
byte[] secret = s.getSecret();
|
byte[] secret = s.getSecret();
|
||||||
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
|
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endpointAdded(Endpoint ep, int maxLatency,
|
public void endpointAdded(Endpoint ep, int maxLatency,
|
||||||
byte[] initialSecret) {
|
byte[] initialSecret) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
maxLatencies.put(ep.getTransportId(), maxLatency);
|
maxLatencies.put(ep.getTransportId(), maxLatency);
|
||||||
// Work out which rotation period we're in
|
// Work out which rotation period we're in
|
||||||
@@ -291,13 +291,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
tagRecogniser.addSecret(s2);
|
tagRecogniser.addSecret(s2);
|
||||||
tagRecogniser.addSecret(s3);
|
tagRecogniser.addSecret(s3);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Rebuild the maps because we may be running a whole period late
|
// Rebuild the maps because we may be running a whole period late
|
||||||
Collection<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
|
Collection<TemporarySecret> secrets = new ArrayList<TemporarySecret>();
|
||||||
@@ -330,7 +330,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
for (TemporarySecret s : created) tagRecogniser.addSecret(s);
|
for (TemporarySecret s : created) tagRecogniser.addSecret(s);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,14 +347,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void removeSecrets(ContactId c, Map<?, TemporarySecret> m) {
|
private void removeSecrets(ContactId c, Map<?, TemporarySecret> m) {
|
||||||
Iterator<TemporarySecret> it = m.values().iterator();
|
Iterator<TemporarySecret> it = m.values().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
if (it.next().getContactId().equals(c)) it.remove();
|
if (it.next().getContactId().equals(c)) it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void removeSecrets(TransportId t, Map<?, TemporarySecret> m) {
|
private void removeSecrets(TransportId t, Map<?, TemporarySecret> m) {
|
||||||
Iterator<TemporarySecret> it = m.values().iterator();
|
Iterator<TemporarySecret> it = m.values().iterator();
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
@@ -403,13 +403,13 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
ContactId c = event.getContactId();
|
ContactId c = event.getContactId();
|
||||||
tagRecogniser.removeSecrets(c);
|
tagRecogniser.removeSecrets(c);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
removeSecrets(c, oldSecrets);
|
removeSecrets(c, oldSecrets);
|
||||||
removeSecrets(c, currentSecrets);
|
removeSecrets(c, currentSecrets);
|
||||||
removeSecrets(c, newSecrets);
|
removeSecrets(c, newSecrets);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,11 +424,11 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
|
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,14 +445,14 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
TransportId t = event.getTransportId();
|
TransportId t = event.getTransportId();
|
||||||
tagRecogniser.removeSecrets(t);
|
tagRecogniser.removeSecrets(t);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
maxLatencies.remove(t);
|
maxLatencies.remove(t);
|
||||||
removeSecrets(t, oldSecrets);
|
removeSecrets(t, oldSecrets);
|
||||||
removeSecrets(t, currentSecrets);
|
removeSecrets(t, currentSecrets);
|
||||||
removeSecrets(t, newSecrets);
|
removeSecrets(t, newSecrets);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
|
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final Lock synchLock = new ReentrantLock();
|
private final Lock lock = new ReentrantLock();
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private final Map<TransportId, TransportTagRecogniser> recognisers;
|
private final Map<TransportId, TransportTagRecogniser> recognisers;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -35,11 +35,11 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
public StreamContext recogniseTag(TransportId t, byte[] tag)
|
public StreamContext recogniseTag(TransportId t, byte[] tag)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
TransportTagRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (r == null) return null;
|
if (r == null) return null;
|
||||||
return r.recogniseTag(tag);
|
return r.recogniseTag(tag);
|
||||||
@@ -48,7 +48,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
public void addSecret(TemporarySecret s) {
|
public void addSecret(TemporarySecret s) {
|
||||||
TransportId t = s.getTransportId();
|
TransportId t = s.getTransportId();
|
||||||
TransportTagRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
@@ -56,49 +56,49 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
recognisers.put(t, r);
|
recognisers.put(t, r);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
r.addSecret(s);
|
r.addSecret(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSecret(ContactId c, TransportId t, long period) {
|
public void removeSecret(ContactId c, TransportId t, long period) {
|
||||||
TransportTagRecogniser r;
|
TransportTagRecogniser r;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (r != null) r.removeSecret(c, period);
|
if (r != null) r.removeSecret(c, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSecrets(ContactId c) {
|
public void removeSecrets(ContactId c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
for (TransportTagRecogniser r : recognisers.values())
|
for (TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets(c);
|
r.removeSecrets(c);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSecrets(TransportId t) {
|
public void removeSecrets(TransportId t) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
recognisers.remove(t);
|
recognisers.remove(t);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSecrets() {
|
public void removeSecrets() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
for (TransportTagRecogniser r : recognisers.values())
|
for (TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets();
|
r.removeSecrets();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ class TransportTagRecogniser {
|
|||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
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<Bytes, TagContext> tagMap;
|
private final Map<Bytes, TagContext> tagMap;
|
||||||
private final Map<RemovalKey, RemovalContext> removalMap;
|
private final Map<RemovalKey, RemovalContext> removalMap;
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ class TransportTagRecogniser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StreamContext recogniseTag(byte[] tag) throws DbException {
|
StreamContext recogniseTag(byte[] tag) throws DbException {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
TagContext t = tagMap.remove(new Bytes(tag));
|
TagContext t = tagMap.remove(new Bytes(tag));
|
||||||
if (t == null) return null; // The tag was not expected
|
if (t == null) return null; // The tag was not expected
|
||||||
@@ -69,12 +69,12 @@ class TransportTagRecogniser {
|
|||||||
return new StreamContext(t.contactId, transportId, t.secret,
|
return new StreamContext(t.contactId, transportId, t.secret,
|
||||||
t.streamNumber, t.alice);
|
t.streamNumber, t.alice);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSecret(TemporarySecret s) {
|
void addSecret(TemporarySecret s) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
ContactId contactId = s.getContactId();
|
ContactId contactId = s.getContactId();
|
||||||
boolean alice = s.getAlice();
|
boolean alice = s.getAlice();
|
||||||
@@ -97,23 +97,23 @@ class TransportTagRecogniser {
|
|||||||
RemovalContext r = new RemovalContext(window, secret, alice);
|
RemovalContext r = new RemovalContext(window, secret, alice);
|
||||||
removalMap.put(new RemovalKey(contactId, period), r);
|
removalMap.put(new RemovalKey(contactId, period), r);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeSecret(ContactId contactId, long period) {
|
void removeSecret(ContactId contactId, long period) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
RemovalKey k = new RemovalKey(contactId, period);
|
RemovalKey k = new RemovalKey(contactId, period);
|
||||||
RemovalContext removed = removalMap.remove(k);
|
RemovalContext removed = removalMap.remove(k);
|
||||||
if (removed == null) throw new IllegalArgumentException();
|
if (removed == null) throw new IllegalArgumentException();
|
||||||
removeSecret(removed);
|
removeSecret(removed);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void removeSecret(RemovalContext r) {
|
private void removeSecret(RemovalContext r) {
|
||||||
// Remove the expected tags
|
// Remove the expected tags
|
||||||
SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
|
SecretKey key = crypto.deriveTagKey(r.secret, !r.alice);
|
||||||
@@ -126,7 +126,7 @@ class TransportTagRecogniser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void removeSecrets(ContactId c) {
|
void removeSecrets(ContactId c) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
|
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
|
||||||
for (RemovalKey k : removalMap.keySet())
|
for (RemovalKey k : removalMap.keySet())
|
||||||
@@ -134,18 +134,18 @@ class TransportTagRecogniser {
|
|||||||
for (RemovalKey k : keysToRemove)
|
for (RemovalKey k : keysToRemove)
|
||||||
removeSecret(k.contactId, k.period);
|
removeSecret(k.contactId, k.period);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeSecrets() {
|
void removeSecrets() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
for (RemovalContext r : removalMap.values()) removeSecret(r);
|
for (RemovalContext r : removalMap.values()) removeSecret(r);
|
||||||
assert tagMap.isEmpty();
|
assert tagMap.isEmpty();
|
||||||
removalMap.clear();
|
removalMap.clear();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
</component>
|
</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 url="file://$MODULE_DIR$/build/classes/main" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
private static final int WS_MINIMIZE = 0x20000000;
|
private static final int WS_MINIMIZE = 0x20000000;
|
||||||
|
|
||||||
private final Map<String, Object> options;
|
private final Map<String, Object> options;
|
||||||
private final Lock synchLock = new ReentrantLock();
|
private final Lock lock = new ReentrantLock();
|
||||||
|
|
||||||
private boolean initialised = false; // Locking: synchLock
|
private boolean initialised = false; // Locking: lock
|
||||||
|
|
||||||
WindowsShutdownManagerImpl() {
|
WindowsShutdownManagerImpl() {
|
||||||
// Use the Unicode versions of Win32 API calls
|
// Use the Unicode versions of Win32 API calls
|
||||||
@@ -52,12 +52,12 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addShutdownHook(Runnable r) {
|
public int addShutdownHook(Runnable r) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
if (!initialised) initialise();
|
if (!initialised) initialise();
|
||||||
return super.addShutdownHook(r);
|
return super.addShutdownHook(r);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
return new StartOnce(r);
|
return new StartOnce(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: synchLock
|
// Locking: lock
|
||||||
private void initialise() {
|
private void initialise() {
|
||||||
if (OsUtils.isWindows()) {
|
if (OsUtils.isWindows()) {
|
||||||
new EventLoop().start();
|
new EventLoop().start();
|
||||||
@@ -78,7 +78,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
void runShutdownHooks() {
|
void runShutdownHooks() {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
boolean interrupted = false;
|
boolean interrupted = false;
|
||||||
// Start each hook in its own thread
|
// Start each hook in its own thread
|
||||||
@@ -94,7 +94,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
}
|
}
|
||||||
if (interrupted) Thread.currentThread().interrupt();
|
if (interrupted) Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface User32 extends StdCallLibrary {
|
private interface User32 extends StdCallLibrary {
|
||||||
|
|
||||||
HWND CreateWindowEx(int styleEx, String className, String windowName,
|
HWND CreateWindowEx(int styleEx, String className, String windowName,
|
||||||
int style, int x, int y, int width, int height, HWND parent,
|
int style, int x, int y, int width, int height, HWND parent,
|
||||||
@@ -177,8 +177,8 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
LRESULT DispatchMessage(MSG msg);
|
LRESULT DispatchMessage(MSG msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface WindowProc extends StdCallCallback {
|
private interface WindowProc extends StdCallCallback {
|
||||||
|
|
||||||
public LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,15 +14,15 @@ abstract class UnixRemovableDriveMonitor implements RemovableDriveMonitor,
|
|||||||
JNotifyListener {
|
JNotifyListener {
|
||||||
|
|
||||||
//TODO: rationalise this in a further refactor
|
//TODO: rationalise this in a further refactor
|
||||||
private static final Lock staticSynchLock = new ReentrantLock();
|
private static final Lock staticLock = new ReentrantLock();
|
||||||
|
|
||||||
// The following are locking: staticSynchLock
|
// The following are locking: staticLock
|
||||||
private static boolean triedLoad = false;
|
private static boolean triedLoad = false;
|
||||||
private static Throwable loadError = null;
|
private static Throwable loadError = null;
|
||||||
|
|
||||||
private final Lock synchLock = new ReentrantLock();
|
private final Lock lock = new ReentrantLock();
|
||||||
|
|
||||||
// The following are locking: synchLock
|
// The following are locking: lock
|
||||||
private final List<Integer> watches = new ArrayList<Integer>();
|
private final List<Integer> watches = new ArrayList<Integer>();
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private Callback callback = null;
|
private Callback callback = null;
|
||||||
@@ -41,7 +41,7 @@ JNotifyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void checkEnabled() throws IOException {
|
public static void checkEnabled() throws IOException {
|
||||||
staticSynchLock.lock();
|
staticLock.lock();
|
||||||
try {
|
try {
|
||||||
if (!triedLoad) {
|
if (!triedLoad) {
|
||||||
loadError = tryLoad();
|
loadError = tryLoad();
|
||||||
@@ -49,7 +49,7 @@ JNotifyListener {
|
|||||||
}
|
}
|
||||||
if (loadError != null) throw new IOException(loadError.toString());
|
if (loadError != null) throw new IOException(loadError.toString());
|
||||||
} finally {
|
} finally {
|
||||||
staticSynchLock.unlock();
|
staticLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ JNotifyListener {
|
|||||||
if (new File(path).exists())
|
if (new File(path).exists())
|
||||||
watches.add(JNotify.addWatch(path, mask, false, this));
|
watches.add(JNotify.addWatch(path, mask, false, this));
|
||||||
}
|
}
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
assert !started;
|
assert !started;
|
||||||
assert this.callback == null;
|
assert this.callback == null;
|
||||||
@@ -69,14 +69,14 @@ JNotifyListener {
|
|||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.watches.addAll(watches);
|
this.watches.addAll(watches);
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws IOException {
|
public void stop() throws IOException {
|
||||||
checkEnabled();
|
checkEnabled();
|
||||||
List<Integer> watches;
|
List<Integer> watches;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
assert started;
|
assert started;
|
||||||
assert callback != null;
|
assert callback != null;
|
||||||
@@ -85,18 +85,18 @@ JNotifyListener {
|
|||||||
watches = new ArrayList<Integer>(this.watches);
|
watches = new ArrayList<Integer>(this.watches);
|
||||||
this.watches.clear();
|
this.watches.clear();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
for (Integer w : watches) JNotify.removeWatch(w);
|
for (Integer w : watches) JNotify.removeWatch(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fileCreated(int wd, String rootPath, String name) {
|
public void fileCreated(int wd, String rootPath, String name) {
|
||||||
Callback callback;
|
Callback callback;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
callback = this.callback;
|
callback = this.callback;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.driveInserted(new File(rootPath + "/" + name));
|
callback.driveInserted(new File(rootPath + "/" + name));
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
private final Semaphore stateChange;
|
private final Semaphore stateChange;
|
||||||
private final byte[] line;
|
private final byte[] line;
|
||||||
|
|
||||||
private final Lock synchLock = new ReentrantLock();
|
private final Lock lock = new ReentrantLock();
|
||||||
private final Condition connectedStateChanged = synchLock.newCondition();
|
private final Condition connectedStateChanged = lock.newCondition();
|
||||||
private final Condition initialisedStateChanged = synchLock.newCondition();
|
private final Condition initialisedStateChanged = lock.newCondition();
|
||||||
|
|
||||||
// The following are locking: synchLock
|
// The following are locking: lock
|
||||||
private ReliabilityLayer reliability = null;
|
private ReliabilityLayer reliability = null;
|
||||||
private boolean initialised = false, connected = false;
|
private boolean initialised = false, connected = false;
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
// Wait for the event thread to receive "OK"
|
// Wait for the event thread to receive "OK"
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + OK_TIMEOUT;
|
long end = now + OK_TIMEOUT;
|
||||||
@@ -110,7 +110,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
success = initialised;
|
success = initialised;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
@@ -135,7 +135,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
|
|
||||||
public void stop() throws IOException {
|
public void stop() throws IOException {
|
||||||
LOG.info("Stopping");
|
LOG.info("Stopping");
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
// Wake any threads that are waiting to connect
|
// Wake any threads that are waiting to connect
|
||||||
initialised = false;
|
initialised = false;
|
||||||
@@ -143,7 +143,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
initialisedStateChanged.signalAll();
|
initialisedStateChanged.signalAll();
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
// Hang up if necessary and close the port
|
// Hang up if necessary and close the port
|
||||||
try {
|
try {
|
||||||
@@ -164,7 +164,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
// Locking: stateChange
|
// Locking: stateChange
|
||||||
private void hangUpInner() throws IOException {
|
private void hangUpInner() throws IOException {
|
||||||
ReliabilityLayer reliability;
|
ReliabilityLayer reliability;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
if (this.reliability == null) {
|
if (this.reliability == null) {
|
||||||
LOG.info("Not hanging up - already on the hook");
|
LOG.info("Not hanging up - already on the hook");
|
||||||
@@ -174,7 +174,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
this.reliability = null;
|
this.reliability = null;
|
||||||
connected = false;
|
connected = false;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
reliability.stop();
|
reliability.stop();
|
||||||
LOG.info("Hanging up");
|
LOG.info("Hanging up");
|
||||||
@@ -201,7 +201,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
ReliabilityLayer reliability =
|
ReliabilityLayer reliability =
|
||||||
reliabilityFactory.createReliabilityLayer(this);
|
reliabilityFactory.createReliabilityLayer(this);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
if (!initialised) {
|
if (!initialised) {
|
||||||
LOG.info("Not dialling - modem not initialised");
|
LOG.info("Not dialling - modem not initialised");
|
||||||
@@ -213,7 +213,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
this.reliability = reliability;
|
this.reliability = reliability;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
reliability.start();
|
reliability.start();
|
||||||
LOG.info("Dialling");
|
LOG.info("Dialling");
|
||||||
@@ -226,7 +226,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
// Wait for the event thread to receive "CONNECT"
|
// Wait for the event thread to receive "CONNECT"
|
||||||
try {
|
try {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + CONNECT_TIMEOUT;
|
long end = now + CONNECT_TIMEOUT;
|
||||||
@@ -236,7 +236,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
if (connected) return true;
|
if (connected) return true;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
@@ -252,11 +252,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
ReliabilityLayer reliability;
|
ReliabilityLayer reliability;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (reliability == null) throw new IOException("Not connected");
|
if (reliability == null) throw new IOException("Not connected");
|
||||||
return reliability.getInputStream();
|
return reliability.getInputStream();
|
||||||
@@ -264,11 +264,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
|
|
||||||
public OutputStream getOutputStream() throws IOException {
|
public OutputStream getOutputStream() throws IOException {
|
||||||
ReliabilityLayer reliability;
|
ReliabilityLayer reliability;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (reliability == null) throw new IOException("Not connected");
|
if (reliability == null) throw new IOException("Not connected");
|
||||||
return reliability.getOutputStream();
|
return reliability.getOutputStream();
|
||||||
@@ -319,11 +319,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
|
|
||||||
private boolean handleData(byte[] b) throws IOException {
|
private boolean handleData(byte[] b) throws IOException {
|
||||||
ReliabilityLayer reliability;
|
ReliabilityLayer reliability;
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
if (reliability == null) return false;
|
if (reliability == null) return false;
|
||||||
reliability.handleRead(b);
|
reliability.handleRead(b);
|
||||||
@@ -343,12 +343,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
lineLen = 0;
|
lineLen = 0;
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Modem status: " + s);
|
if (LOG.isLoggable(INFO)) LOG.info("Modem status: " + s);
|
||||||
if (s.startsWith("CONNECT")) {
|
if (s.startsWith("CONNECT")) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
connected = true;
|
connected = true;
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
// There might be data in the buffer as well as text
|
// There might be data in the buffer as well as text
|
||||||
int off = i + 1;
|
int off = i + 1;
|
||||||
@@ -360,20 +360,20 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
return;
|
return;
|
||||||
} else if (s.equals("BUSY") || s.equals("NO DIALTONE")
|
} else if (s.equals("BUSY") || s.equals("NO DIALTONE")
|
||||||
|| s.equals("NO CARRIER")) {
|
|| s.equals("NO CARRIER")) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
connected = false;
|
connected = false;
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} else if (s.equals("OK")) {
|
} else if (s.equals("OK")) {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
initialised = true;
|
initialised = true;
|
||||||
initialisedStateChanged.signalAll();
|
initialisedStateChanged.signalAll();
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} else if (s.equals("RING")) {
|
} else if (s.equals("RING")) {
|
||||||
ioExecutor.execute(new Runnable() {
|
ioExecutor.execute(new Runnable() {
|
||||||
@@ -401,7 +401,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
ReliabilityLayer reliability =
|
ReliabilityLayer reliability =
|
||||||
reliabilityFactory.createReliabilityLayer(this);
|
reliabilityFactory.createReliabilityLayer(this);
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
if (!initialised) {
|
if (!initialised) {
|
||||||
LOG.info("Not answering - modem not initialised");
|
LOG.info("Not answering - modem not initialised");
|
||||||
@@ -413,7 +413,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
this.reliability = reliability;
|
this.reliability = reliability;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
reliability.start();
|
reliability.start();
|
||||||
LOG.info("Answering");
|
LOG.info("Answering");
|
||||||
@@ -426,7 +426,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
// Wait for the event thread to receive "CONNECT"
|
// Wait for the event thread to receive "CONNECT"
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
synchLock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + CONNECT_TIMEOUT;
|
long end = now + CONNECT_TIMEOUT;
|
||||||
@@ -436,7 +436,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
}
|
}
|
||||||
success = connected;
|
success = connected;
|
||||||
} finally {
|
} finally {
|
||||||
synchLock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
tryToClose(port);
|
tryToClose(port);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
</facet>
|
</facet>
|
||||||
</component>
|
</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 url="file://$MODULE_DIR$/build/classes/main" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module external.linked.project.id="briar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" version="4">
|
<module external.linked.project.id="briar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||||
<component name="FacetManager">
|
<component name="FacetManager">
|
||||||
<facet type="java-gradle" name="Java-Gradle">
|
<facet type="java-gradle" name="Java-Gradle">
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user