mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 08:09:54 +01:00
Code formatting and small cleanups.
This commit is contained in:
@@ -49,6 +49,10 @@ Service, EventListener {
|
|||||||
|
|
||||||
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
|
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
|
||||||
private static final int GROUP_POST_NOTIFICATION_ID = 4;
|
private static final int GROUP_POST_NOTIFICATION_ID = 4;
|
||||||
|
private static final String CONTACT_URI =
|
||||||
|
"content://org.briarproject/contact";
|
||||||
|
private static final String GROUP_URI =
|
||||||
|
"content://org.briarproject/group";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
|
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
|
||||||
@@ -115,8 +119,7 @@ Service, EventListener {
|
|||||||
else contactCounts.put(c, count + 1);
|
else contactCounts.put(c, count + 1);
|
||||||
privateTotal++;
|
privateTotal++;
|
||||||
updatePrivateMessageNotification();
|
updatePrivateMessageNotification();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,8 +131,7 @@ Service, EventListener {
|
|||||||
if(count == null) return; // Already cleared
|
if(count == null) return; // Already cleared
|
||||||
privateTotal -= count;
|
privateTotal -= count;
|
||||||
updatePrivateMessageNotification();
|
updatePrivateMessageNotification();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,7 +160,7 @@ Service, EventListener {
|
|||||||
Intent i = new Intent(appContext, ConversationActivity.class);
|
Intent i = new Intent(appContext, ConversationActivity.class);
|
||||||
ContactId c = contactCounts.keySet().iterator().next();
|
ContactId c = contactCounts.keySet().iterator().next();
|
||||||
i.putExtra("briar.CONTACT_ID", c.getInt());
|
i.putExtra("briar.CONTACT_ID", c.getInt());
|
||||||
i.setData(Uri.parse(String.format("content://contact/%s", c.getInt())));
|
i.setData(Uri.parse(CONTACT_URI + "/" + c.getInt()));
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
t.addParentStack(ConversationActivity.class);
|
t.addParentStack(ConversationActivity.class);
|
||||||
@@ -203,8 +205,7 @@ Service, EventListener {
|
|||||||
else groupCounts.put(g, count + 1);
|
else groupCounts.put(g, count + 1);
|
||||||
groupTotal++;
|
groupTotal++;
|
||||||
updateGroupPostNotification();
|
updateGroupPostNotification();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,8 +217,7 @@ Service, EventListener {
|
|||||||
if(count == null) return; // Already cleared
|
if(count == null) return; // Already cleared
|
||||||
groupTotal -= count;
|
groupTotal -= count;
|
||||||
updateGroupPostNotification();
|
updateGroupPostNotification();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,8 +245,8 @@ Service, EventListener {
|
|||||||
Intent i = new Intent(appContext, GroupActivity.class);
|
Intent i = new Intent(appContext, GroupActivity.class);
|
||||||
GroupId g = groupCounts.keySet().iterator().next();
|
GroupId g = groupCounts.keySet().iterator().next();
|
||||||
i.putExtra("briar.GROUP_ID", g.getBytes());
|
i.putExtra("briar.GROUP_ID", g.getBytes());
|
||||||
String groupIdString = new String(g.getBytes());
|
String idHex = StringUtils.toHexString(g.getBytes());
|
||||||
i.setData(Uri.parse(String.format("content://org.brairproject.group/%s", groupIdString)));
|
i.setData(Uri.parse(GROUP_URI + "/" + idHex));
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
t.addParentStack(GroupActivity.class);
|
t.addParentStack(GroupActivity.class);
|
||||||
@@ -280,8 +280,7 @@ Service, EventListener {
|
|||||||
privateTotal = groupTotal = 0;
|
privateTotal = groupTotal = 0;
|
||||||
clearPrivateMessageNotification();
|
clearPrivateMessageNotification();
|
||||||
clearGroupPostNotification();
|
clearGroupPostNotification();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
LOG.info(innerMap.size() + " handles for " + c.getName());
|
LOG.info(innerMap.size() + " handles for " + c.getName());
|
||||||
Object o = innerMap.get(handle);
|
Object o = innerMap.get(handle);
|
||||||
return c.cast(o);
|
return c.cast(o);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +56,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
" after put");
|
" after put");
|
||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,8 +73,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
|||||||
" after remove");
|
" after remove");
|
||||||
}
|
}
|
||||||
return c.cast(o);
|
return c.cast(o);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>Phone network. This works even when no SIM card is inserted, or a
|
* <li>Phone network. This works even when no SIM card is inserted, or a
|
||||||
* foreign SIM card is inserted.</li>
|
* foreign SIM card is inserted.</li>
|
||||||
* <li><del>Location service (GPS/WiFi/etc).</del> <em>This is disabled for
|
|
||||||
* now, until we figure out an offline method of converting a long/lat
|
|
||||||
* into a country code, that doesn't involve a network call.</em>
|
|
||||||
* <li>SIM card. This is only an heuristic and assumes the user is not
|
* <li>SIM card. This is only an heuristic and assumes the user is not
|
||||||
* roaming.</li>
|
* roaming.</li>
|
||||||
* <li>User locale. This is an even worse heuristic.</li>
|
* <li>User locale. This is an even worse heuristic.</li>
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ class FortunaGenerator {
|
|||||||
digest.update(seed);
|
digest.update(seed);
|
||||||
digest.digest(key, 0, KEY_BYTES);
|
digest.digest(key, 0, KEY_BYTES);
|
||||||
incrementCounter();
|
incrementCounter();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +55,7 @@ class FortunaGenerator {
|
|||||||
throw new RuntimeException("Counter exhausted");
|
throw new RuntimeException("Counter exhausted");
|
||||||
counter[i + 1]++;
|
counter[i + 1]++;
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +65,7 @@ class FortunaGenerator {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
return counter;
|
return counter;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +102,7 @@ class FortunaGenerator {
|
|||||||
for(int i = 0; i < KEY_BYTES; i++) newKey[i] = 0;
|
for(int i = 0; i < KEY_BYTES; i++) newKey[i] = 0;
|
||||||
// Return the number of bytes written
|
// Return the number of bytes written
|
||||||
return len;
|
return len;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ class PseudoRandomImpl implements PseudoRandom {
|
|||||||
System.arraycopy(state, offset, b, off, len);
|
System.arraycopy(state, offset, b, off, len);
|
||||||
offset += len;
|
offset += len;
|
||||||
return b;
|
return b;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -441,8 +441,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
try {
|
try {
|
||||||
if(closed) throw new DbClosedException();
|
if(closed) throw new DbClosedException();
|
||||||
txn = connections.poll();
|
txn = connections.poll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,8 +454,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
connectionsLock.lock();
|
connectionsLock.lock();
|
||||||
try {
|
try {
|
||||||
openConnections++;
|
openConnections++;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -474,8 +472,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
try {
|
try {
|
||||||
connections.add(txn);
|
connections.add(txn);
|
||||||
connectionsChanged.signalAll();
|
connectionsChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
}
|
}
|
||||||
} catch(SQLException e) {
|
} catch(SQLException e) {
|
||||||
@@ -491,10 +488,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
try {
|
try {
|
||||||
openConnections--;
|
openConnections--;
|
||||||
connectionsChanged.signalAll();
|
connectionsChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commitTransaction(Connection txn) throws DbException {
|
public void commitTransaction(Connection txn) throws DbException {
|
||||||
@@ -512,8 +509,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
try {
|
try {
|
||||||
connections.add(txn);
|
connections.add(txn);
|
||||||
connectionsChanged.signalAll();
|
connectionsChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -545,8 +541,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
openConnections -= connections.size();
|
openConnections -= connections.size();
|
||||||
connections.clear();
|
connections.clear();
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
connectionsLock.unlock();
|
connectionsLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,12 +109,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
listeners.add(l);
|
listeners.add(l);
|
||||||
return new InvitationState(localInvitationCode, remoteInvitationCode,
|
return new InvitationState(localInvitationCode,
|
||||||
localConfirmationCode, remoteConfirmationCode, connected.get(),
|
remoteInvitationCode, localConfirmationCode,
|
||||||
connectionFailed, localCompared, remoteCompared, localMatched,
|
remoteConfirmationCode, connected.get(), connectionFailed,
|
||||||
remoteMatched, remoteName);
|
localCompared, remoteCompared, localMatched, remoteMatched,
|
||||||
}
|
remoteName);
|
||||||
finally{
|
} finally {
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,8 +140,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
connectionFailed = true;
|
connectionFailed = true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners) l.connectionFailed();
|
for(InvitationListener l : listeners) l.connectionFailed();
|
||||||
@@ -177,8 +176,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
connectionFailed = true;
|
connectionFailed = true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners) l.connectionFailed();
|
for(InvitationListener l : listeners) l.connectionFailed();
|
||||||
@@ -212,8 +210,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
try {
|
try {
|
||||||
localCompared = true;
|
localCompared = true;
|
||||||
localMatched = true;
|
localMatched = true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
localConfirmationLatch.countDown();
|
localConfirmationLatch.countDown();
|
||||||
@@ -224,8 +221,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
try {
|
try {
|
||||||
localCompared = true;
|
localCompared = true;
|
||||||
localMatched = false;
|
localMatched = false;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
localConfirmationLatch.countDown();
|
localConfirmationLatch.countDown();
|
||||||
@@ -243,8 +239,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
try {
|
try {
|
||||||
localConfirmationCode = localCode;
|
localConfirmationCode = localCode;
|
||||||
remoteConfirmationCode = remoteCode;
|
remoteConfirmationCode = remoteCode;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners)
|
for(InvitationListener l : listeners)
|
||||||
@@ -260,8 +255,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
return localMatched;
|
return localMatched;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,8 +265,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
try {
|
try {
|
||||||
remoteCompared = true;
|
remoteCompared = true;
|
||||||
remoteMatched = true;
|
remoteMatched = true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners) l.remoteConfirmationSucceeded();
|
for(InvitationListener l : listeners) l.remoteConfirmationSucceeded();
|
||||||
@@ -283,8 +276,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
try {
|
try {
|
||||||
remoteCompared = true;
|
remoteCompared = true;
|
||||||
remoteMatched = false;
|
remoteMatched = false;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners) l.remoteConfirmationFailed();
|
for(InvitationListener l : listeners) l.remoteConfirmationFailed();
|
||||||
@@ -295,8 +287,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
remoteName = name;
|
remoteName = name;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(InvitationListener l : listeners)
|
for(InvitationListener l : listeners)
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ class ShutdownManagerImpl implements ShutdownManager {
|
|||||||
hooks.put(handle, hook);
|
hooks.put(handle, hook);
|
||||||
Runtime.getRuntime().addShutdownHook(hook);
|
Runtime.getRuntime().addShutdownHook(hook);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +43,7 @@ class ShutdownManagerImpl implements ShutdownManager {
|
|||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import org.briarproject.api.messaging.Group;
|
|||||||
import org.briarproject.api.messaging.GroupFactory;
|
import org.briarproject.api.messaging.GroupFactory;
|
||||||
import org.briarproject.api.messaging.MessageFactory;
|
import org.briarproject.api.messaging.MessageFactory;
|
||||||
import org.briarproject.api.messaging.MessageVerifier;
|
import org.briarproject.api.messaging.MessageVerifier;
|
||||||
|
import org.briarproject.api.messaging.MessagingSessionFactory;
|
||||||
import org.briarproject.api.messaging.PacketReaderFactory;
|
import org.briarproject.api.messaging.PacketReaderFactory;
|
||||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||||
import org.briarproject.api.messaging.MessagingSessionFactory;
|
|
||||||
import org.briarproject.api.messaging.SubscriptionUpdate;
|
import org.briarproject.api.messaging.SubscriptionUpdate;
|
||||||
import org.briarproject.api.messaging.UnverifiedMessage;
|
import org.briarproject.api.messaging.UnverifiedMessage;
|
||||||
import org.briarproject.api.serial.StructReader;
|
import org.briarproject.api.serial.StructReader;
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
} else {
|
} else {
|
||||||
contactCounts.put(c, count + 1);
|
contactCounts.put(c, count + 1);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +93,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
} else {
|
} else {
|
||||||
contactCounts.put(c, count - 1);
|
contactCounts.put(c, count - 1);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +112,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
|
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
|
||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,8 +122,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
return contactCounts.containsKey(c);
|
return contactCounts.containsKey(c);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package org.briarproject.reliability;
|
package org.briarproject.reliability;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -43,7 +44,7 @@ class Receiver implements ReadHandler {
|
|||||||
while(now < end && valid) {
|
while(now < end && valid) {
|
||||||
if(dataFrames.isEmpty()) {
|
if(dataFrames.isEmpty()) {
|
||||||
// Wait for a data frame
|
// Wait for a data frame
|
||||||
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
dataFrameAvailable.await(end - now, MILLISECONDS);
|
||||||
} else {
|
} else {
|
||||||
Data d = dataFrames.first();
|
Data d = dataFrames.first();
|
||||||
if(d.getSequenceNumber() == nextSequenceNumber) {
|
if(d.getSequenceNumber() == nextSequenceNumber) {
|
||||||
@@ -55,15 +56,14 @@ class Receiver implements ReadHandler {
|
|||||||
return d;
|
return d;
|
||||||
} else {
|
} else {
|
||||||
// Wait for the next in-order data frame
|
// Wait for the next in-order data frame
|
||||||
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
dataFrameAvailable.await(end - now, MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(valid) throw new IOException("Read timed out");
|
if(valid) throw new IOException("Read timed out");
|
||||||
throw new IOException("Connection closed");
|
throw new IOException("Connection closed");
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,8 +73,7 @@ class Receiver implements ReadHandler {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
dataFrameAvailable.signalAll();
|
dataFrameAvailable.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,8 +133,7 @@ class Receiver implements ReadHandler {
|
|||||||
}
|
}
|
||||||
// Acknowledge the data frame even if it's a duplicate
|
// Acknowledge the data frame even if it's a duplicate
|
||||||
sender.sendAck(sequenceNumber, windowSize);
|
sender.sendAck(sequenceNumber, windowSize);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package org.briarproject.reliability;
|
package org.briarproject.reliability;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -101,9 +102,9 @@ class Sender {
|
|||||||
// Don't accept an unreasonably large window size
|
// Don't accept an unreasonably large window size
|
||||||
windowSize = Math.min(a.getWindowSize(), MAX_WINDOW_SIZE);
|
windowSize = Math.min(a.getWindowSize(), MAX_WINDOW_SIZE);
|
||||||
// If space has become available, notify any waiting writers
|
// If space has become available, notify any waiting writers
|
||||||
if(windowSize > oldWindowSize || foundIndex != -1) sendWindowAvailable.signalAll();
|
if(windowSize > oldWindowSize || foundIndex != -1)
|
||||||
}
|
sendWindowAvailable.signalAll();
|
||||||
finally{
|
} finally {
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
// Fast retransmission
|
// Fast retransmission
|
||||||
@@ -145,8 +146,7 @@ class Sender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
// Send a window probe if necessary
|
// Send a window probe if necessary
|
||||||
@@ -171,7 +171,7 @@ class Sender {
|
|||||||
long now = clock.currentTimeMillis(), end = now + WRITE_TIMEOUT;
|
long now = clock.currentTimeMillis(), end = now + WRITE_TIMEOUT;
|
||||||
while(now < end && outstandingBytes + payloadLength >= windowSize) {
|
while(now < end && outstandingBytes + payloadLength >= windowSize) {
|
||||||
dataWaiting = true;
|
dataWaiting = true;
|
||||||
sendWindowAvailable.await(end - now, TimeUnit.MILLISECONDS);
|
sendWindowAvailable.await(end - now, MILLISECONDS);
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(outstandingBytes + payloadLength >= windowSize)
|
if(outstandingBytes + payloadLength >= windowSize)
|
||||||
@@ -179,8 +179,7 @@ class Sender {
|
|||||||
outstanding.add(new Outstanding(d, now));
|
outstanding.add(new Outstanding(d, now));
|
||||||
outstandingBytes += payloadLength;
|
outstandingBytes += payloadLength;
|
||||||
dataWaiting = false;
|
dataWaiting = false;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
writeHandler.handleWrite(d.getBuffer());
|
writeHandler.handleWrite(d.getBuffer());
|
||||||
@@ -189,9 +188,9 @@ class Sender {
|
|||||||
void flush() throws IOException, InterruptedException {
|
void flush() throws IOException, InterruptedException {
|
||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
while(dataWaiting || !outstanding.isEmpty()) sendWindowAvailable.await();
|
while(dataWaiting || !outstanding.isEmpty())
|
||||||
}
|
sendWindowAvailable.await();
|
||||||
finally{
|
} finally {
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
// Load the temporary secrets and transport latencies from the database
|
// Load the temporary secrets and transport latencies from the DB
|
||||||
Collection<TemporarySecret> secrets;
|
Collection<TemporarySecret> secrets;
|
||||||
try {
|
try {
|
||||||
secrets = db.getSecrets();
|
secrets = db.getSecrets();
|
||||||
@@ -89,15 +89,18 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
}
|
}
|
||||||
// Work out what phase of its lifecycle each secret is in
|
// Work out what phase of its lifecycle each secret is in
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
Collection<TemporarySecret> dead = assignSecretsToMaps(now, secrets);
|
Collection<TemporarySecret> dead =
|
||||||
|
assignSecretsToMaps(now, secrets);
|
||||||
// Replace any dead secrets
|
// Replace any dead secrets
|
||||||
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
|
||||||
if(!created.isEmpty()) {
|
if(!created.isEmpty()) {
|
||||||
// Store any secrets that have been created, removing any dead ones
|
// Store any secrets that have been created,
|
||||||
|
// removing any dead ones
|
||||||
try {
|
try {
|
||||||
db.addSecrets(created);
|
db.addSecrets(created);
|
||||||
} 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);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,10 +112,10 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
for(TemporarySecret s : newSecrets.values())
|
for(TemporarySecret s : newSecrets.values())
|
||||||
tagRecogniser.addSecret(s);
|
tagRecogniser.addSecret(s);
|
||||||
// Schedule periodic key rotation
|
// Schedule periodic key rotation
|
||||||
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS, MS_BETWEEN_CHECKS);
|
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS,
|
||||||
|
MS_BETWEEN_CHECKS);
|
||||||
return true;
|
return true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,8 +221,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
currentSecrets.clear();
|
currentSecrets.clear();
|
||||||
newSecrets.clear();
|
newSecrets.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,8 +248,7 @@ 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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,8 +288,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
tagRecogniser.addSecret(s1);
|
tagRecogniser.addSecret(s1);
|
||||||
tagRecogniser.addSecret(s2);
|
tagRecogniser.addSecret(s2);
|
||||||
tagRecogniser.addSecret(s3);
|
tagRecogniser.addSecret(s3);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,8 +327,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
// Pass any secrets that have been created to the recogniser
|
// Pass any secrets that have been created to the recogniser
|
||||||
for(TemporarySecret s : created) tagRecogniser.addSecret(s);
|
for(TemporarySecret s : created) tagRecogniser.addSecret(s);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,8 +404,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
removeSecrets(c, oldSecrets);
|
removeSecrets(c, oldSecrets);
|
||||||
removeSecrets(c, currentSecrets);
|
removeSecrets(c, currentSecrets);
|
||||||
removeSecrets(c, newSecrets);
|
removeSecrets(c, newSecrets);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,8 +423,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
|
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,8 +447,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
|
|||||||
removeSecrets(t, oldSecrets);
|
removeSecrets(t, oldSecrets);
|
||||||
removeSecrets(t, currentSecrets);
|
removeSecrets(t, currentSecrets);
|
||||||
removeSecrets(t, newSecrets);
|
removeSecrets(t, newSecrets);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(r == null) return null;
|
if(r == null) return null;
|
||||||
@@ -57,8 +56,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
r = new TransportTagRecogniser(crypto, db, t);
|
r = new TransportTagRecogniser(crypto, db, t);
|
||||||
recognisers.put(t, r);
|
recognisers.put(t, r);
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
r.addSecret(s);
|
r.addSecret(s);
|
||||||
@@ -69,8 +67,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
r = recognisers.get(t);
|
r = recognisers.get(t);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(r != null) r.removeSecret(c, period);
|
if(r != null) r.removeSecret(c, period);
|
||||||
@@ -81,8 +78,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
try {
|
try {
|
||||||
for(TransportTagRecogniser r : recognisers.values())
|
for(TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets(c);
|
r.removeSecrets(c);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,8 +87,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
recognisers.remove(t);
|
recognisers.remove(t);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +98,7 @@ class TagRecogniserImpl implements TagRecogniser {
|
|||||||
try {
|
try {
|
||||||
for(TransportTagRecogniser r : recognisers.values())
|
for(TransportTagRecogniser r : recognisers.values())
|
||||||
r.removeSecrets();
|
r.removeSecrets();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ class TransportTagRecogniser {
|
|||||||
t.window.getCentre(), t.window.getBitmap());
|
t.window.getCentre(), t.window.getBitmap());
|
||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,8 +95,7 @@ class TransportTagRecogniser {
|
|||||||
// Create a removal context to remove the window and the tags later
|
// Create a removal context to remove the window and the tags later
|
||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,8 +107,7 @@ class TransportTagRecogniser {
|
|||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,9 +129,9 @@ class TransportTagRecogniser {
|
|||||||
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
|
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
|
||||||
for(RemovalKey k : removalMap.keySet())
|
for(RemovalKey k : removalMap.keySet())
|
||||||
if(k.contactId.equals(c)) keysToRemove.add(k);
|
if(k.contactId.equals(c)) keysToRemove.add(k);
|
||||||
for(RemovalKey k : keysToRemove) removeSecret(k.contactId, k.period);
|
for(RemovalKey k : keysToRemove)
|
||||||
}
|
removeSecret(k.contactId, k.period);
|
||||||
finally{
|
} finally {
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,8 +142,7 @@ class TransportTagRecogniser {
|
|||||||
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();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package org.briarproject.util;
|
package org.briarproject.util;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class LatchedReference<T> {
|
public class LatchedReference<T> {
|
||||||
@@ -23,7 +24,7 @@ public class LatchedReference<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public T waitForReference(long timeout) throws InterruptedException {
|
public T waitForReference(long timeout) throws InterruptedException {
|
||||||
latch.await(timeout, TimeUnit.MILLISECONDS);
|
latch.await(timeout, MILLISECONDS);
|
||||||
return reference.get();
|
return reference.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
try {
|
try {
|
||||||
if(!initialised) initialise();
|
if(!initialised) initialise();
|
||||||
return super.addShutdownHook(r);
|
return super.addShutdownHook(r);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,8 +94,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(interrupted) Thread.currentThread().interrupt();
|
if(interrupted) Thread.currentThread().interrupt();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -56,9 +57,8 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
|
|||||||
while(running) {
|
while(running) {
|
||||||
pollingLock.lock();
|
pollingLock.lock();
|
||||||
try {
|
try {
|
||||||
stopPolling.await(pollingInterval, TimeUnit.MILLISECONDS);
|
stopPolling.await(pollingInterval, MILLISECONDS);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
pollingLock.unlock();
|
pollingLock.unlock();
|
||||||
}
|
}
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.locks.Condition;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@@ -47,8 +46,7 @@ JNotifyListener {
|
|||||||
triedLoad = true;
|
triedLoad = true;
|
||||||
}
|
}
|
||||||
if(loadError != null) throw new IOException(loadError.toString());
|
if(loadError != null) throw new IOException(loadError.toString());
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
staticSynchLock.unlock();
|
staticSynchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,8 +66,7 @@ JNotifyListener {
|
|||||||
started = true;
|
started = true;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.watches.addAll(watches);
|
this.watches.addAll(watches);
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,8 +82,7 @@ JNotifyListener {
|
|||||||
callback = null;
|
callback = null;
|
||||||
watches = new ArrayList<Integer>(this.watches);
|
watches = new ArrayList<Integer>(this.watches);
|
||||||
this.watches.clear();
|
this.watches.clear();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
for(Integer w : watches) JNotify.removeWatch(w);
|
for(Integer w : watches) JNotify.removeWatch(w);
|
||||||
@@ -97,8 +93,7 @@ JNotifyListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
callback = this.callback;
|
callback = this.callback;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(callback != null)
|
if(callback != null)
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ class CountryCodes {
|
|||||||
new Country("GP", "Guadeloupe", "590", "00", ""),
|
new Country("GP", "Guadeloupe", "590", "00", ""),
|
||||||
new Country("GQ", "Equatorial Guinea", "240", "00", ""),
|
new Country("GQ", "Equatorial Guinea", "240", "00", ""),
|
||||||
new Country("GR", "Greece", "30", "00", ""),
|
new Country("GR", "Greece", "30", "00", ""),
|
||||||
new Country("GS", "South Georgia and the South Sandwich Islands", "995", "8**10", "8"),
|
new Country("GS", "South Georgia and the South Sandwich Islands",
|
||||||
|
"995", "8**10", "8"),
|
||||||
new Country("GT", "Guatemala", "502", "00", ""),
|
new Country("GT", "Guatemala", "502", "00", ""),
|
||||||
new Country("GU", "Guam", "1", "011", "1"),
|
new Country("GU", "Guam", "1", "011", "1"),
|
||||||
new Country("GW", "Guinea-Bissau", "245", "00", ""),
|
new Country("GW", "Guinea-Bissau", "245", "00", ""),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.plugins.modem;
|
package org.briarproject.plugins.modem;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static jssc.SerialPort.PURGE_RXCLEAR;
|
import static jssc.SerialPort.PURGE_RXCLEAR;
|
||||||
@@ -10,7 +11,6 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
import java.util.concurrent.locks.Condition;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
@@ -105,12 +105,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + OK_TIMEOUT;
|
long end = now + OK_TIMEOUT;
|
||||||
while(now < end && !initialised) {
|
while(now < end && !initialised) {
|
||||||
initialisedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
|
initialisedStateChanged.await(end - now, MILLISECONDS);
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
}
|
}
|
||||||
success = initialised;
|
success = initialised;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@@ -143,8 +142,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
connected = false;
|
connected = false;
|
||||||
initialisedStateChanged.signalAll();
|
initialisedStateChanged.signalAll();
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
// Hang up if necessary and close the port
|
// Hang up if necessary and close the port
|
||||||
@@ -174,8 +172,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
this.reliability = null;
|
this.reliability = null;
|
||||||
connected = false;
|
connected = false;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
reliability.stop();
|
reliability.stop();
|
||||||
@@ -214,8 +211,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.reliability = reliability;
|
this.reliability = reliability;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
reliability.start();
|
reliability.start();
|
||||||
@@ -234,12 +230,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + CONNECT_TIMEOUT;
|
long end = now + CONNECT_TIMEOUT;
|
||||||
while(now < end && initialised && !connected) {
|
while(now < end && initialised && !connected) {
|
||||||
connectedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
|
connectedStateChanged.await(end - now, MILLISECONDS);
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if(connected) return true;
|
if(connected) return true;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
@@ -259,8 +254,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(reliability == null) throw new IOException("Not connected");
|
if(reliability == null) throw new IOException("Not connected");
|
||||||
@@ -272,8 +266,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(reliability == null) throw new IOException("Not connected");
|
if(reliability == null) throw new IOException("Not connected");
|
||||||
@@ -328,8 +321,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
synchLock.lock();
|
synchLock.lock();
|
||||||
try {
|
try {
|
||||||
reliability = this.reliability;
|
reliability = this.reliability;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
if(reliability == null) return false;
|
if(reliability == null) return false;
|
||||||
@@ -354,8 +346,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
connected = true;
|
connected = true;
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
// There might be data in the buffer as well as text
|
// There might be data in the buffer as well as text
|
||||||
@@ -372,8 +363,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
connected = false;
|
connected = false;
|
||||||
connectedStateChanged.signalAll();
|
connectedStateChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
} else if(s.equals("OK")) {
|
} else if(s.equals("OK")) {
|
||||||
@@ -381,8 +371,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
try {
|
try {
|
||||||
initialised = true;
|
initialised = true;
|
||||||
initialisedStateChanged.signalAll();
|
initialisedStateChanged.signalAll();
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
} else if(s.equals("RING")) {
|
} else if(s.equals("RING")) {
|
||||||
@@ -422,8 +411,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.reliability = reliability;
|
this.reliability = reliability;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
reliability.start();
|
reliability.start();
|
||||||
@@ -442,12 +430,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
long end = now + CONNECT_TIMEOUT;
|
long end = now + CONNECT_TIMEOUT;
|
||||||
while(now < end && initialised && !connected) {
|
while(now < end && initialised && !connected) {
|
||||||
connectedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
|
connectedStateChanged.await(end - now, MILLISECONDS);
|
||||||
now = clock.currentTimeMillis();
|
now = clock.currentTimeMillis();
|
||||||
}
|
}
|
||||||
success = connected;
|
success = connected;
|
||||||
}
|
} finally {
|
||||||
finally{
|
|
||||||
synchLock.unlock();
|
synchLock.unlock();
|
||||||
}
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.briarproject.api.event.ContactConnectedEvent;
|
|||||||
import org.briarproject.api.event.ContactDisconnectedEvent;
|
import org.briarproject.api.event.ContactDisconnectedEvent;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.api.event.EventBus;
|
||||||
import org.briarproject.api.plugins.ConnectionRegistry;
|
import org.briarproject.api.plugins.ConnectionRegistry;
|
||||||
import org.briarproject.plugins.ConnectionRegistryImpl;
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|||||||
Reference in New Issue
Block a user