Code cleanup: import static.

This commit is contained in:
akwizgran
2012-10-31 00:36:48 +00:00
parent 3fa433f7fe
commit 8ed68f36e4
29 changed files with 229 additions and 203 deletions

View File

@@ -1,7 +1,9 @@
package net.sf.briar; package net.sf.briar;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.android.AndroidModule; import net.sf.briar.android.AndroidModule;
@@ -65,31 +67,31 @@ public class HelloWorldService extends Service implements Runnable {
pluginManager = i.getInstance(PluginManager.class); pluginManager = i.getInstance(PluginManager.class);
try { try {
// Start... // Start...
if(LOG.isLoggable(Level.INFO)) LOG.info("Starting"); if(LOG.isLoggable(INFO)) LOG.info("Starting");
db.open(false); db.open(false);
if(LOG.isLoggable(Level.INFO)) LOG.info("Database opened"); if(LOG.isLoggable(INFO)) LOG.info("Database opened");
keyManager.start(); keyManager.start();
if(LOG.isLoggable(Level.INFO)) LOG.info("Key manager started"); if(LOG.isLoggable(INFO)) LOG.info("Key manager started");
int pluginsStarted = pluginManager.start(this); int pluginsStarted = pluginManager.start(this);
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info(pluginsStarted + " plugins started"); LOG.info(pluginsStarted + " plugins started");
// ...sleep... // ...sleep...
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch(InterruptedException ignored) {} } catch(InterruptedException ignored) {}
// ...and stop // ...and stop
if(LOG.isLoggable(Level.INFO)) LOG.info("Shutting down"); if(LOG.isLoggable(INFO)) LOG.info("Shutting down");
int pluginsStopped = pluginManager.stop(); int pluginsStopped = pluginManager.stop();
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info(pluginsStopped + " plugins stopped"); LOG.info(pluginsStopped + " plugins stopped");
keyManager.stop(); keyManager.stop();
if(LOG.isLoggable(Level.INFO)) LOG.info("Key manager stopped"); if(LOG.isLoggable(INFO)) LOG.info("Key manager stopped");
db.close(); db.close();
if(LOG.isLoggable(Level.INFO)) LOG.info("Database closed"); if(LOG.isLoggable(INFO)) LOG.info("Database closed");
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,8 +1,10 @@
package net.sf.briar.db; package net.sf.briar.db;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.db.DbClosedException; import net.sf.briar.api.db.DbClosedException;
@@ -34,12 +36,12 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner {
callback.checkFreeSpaceAndClean(); callback.checkFreeSpaceAndClean();
} }
} catch(DbClosedException e) { } catch(DbClosedException e) {
if(LOG.isLoggable(Level.INFO)) LOG.info("Database closed, exiting"); if(LOG.isLoggable(INFO)) LOG.info("Database closed, exiting");
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
throw new Error(e); // Kill the application throw new Error(e); // Kill the application
} catch(RuntimeException e) { } catch(RuntimeException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
throw new Error(e); // Kill the application throw new Error(e); // Kill the application
} }
} }

View File

@@ -1,5 +1,6 @@
package net.sf.briar.db; package net.sf.briar.db;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP; import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP;
import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE; import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE;
import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS; import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS;
@@ -19,7 +20,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -140,11 +140,9 @@ DatabaseCleaner.Callback {
close(); close();
} }
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
LOG.warning(e.toString());
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
LOG.warning(e.toString());
} }
} }
}); });

View File

@@ -1,5 +1,7 @@
package net.sf.briar.db; package net.sf.briar.db;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.db.DatabaseConstants.EXPIRY_MODULUS; import static net.sf.briar.db.DatabaseConstants.EXPIRY_MODULUS;
import static net.sf.briar.db.DatabaseConstants.RETRANSMIT_THRESHOLD; import static net.sf.briar.db.DatabaseConstants.RETRANSMIT_THRESHOLD;
@@ -20,7 +22,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -361,7 +362,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if(s != null) try { if(s != null) try {
s.close(); s.close();
} catch(SQLException e) { } catch(SQLException e) {
if(LOG.isLoggable(Level.WARNING))LOG.warning(e.toString()); if(LOG.isLoggable(WARNING))LOG.warning(e.toString());
} }
} }
@@ -369,7 +370,7 @@ abstract class JdbcDatabase implements Database<Connection> {
if(rs != null) try { if(rs != null) try {
rs.close(); rs.close();
} catch(SQLException e) { } catch(SQLException e) {
if(LOG.isLoggable(Level.WARNING))LOG.warning(e.toString()); if(LOG.isLoggable(WARNING))LOG.warning(e.toString());
} }
} }
@@ -405,11 +406,11 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} catch(SQLException e) { } catch(SQLException e) {
// Try to close the connection // Try to close the connection
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
try { try {
txn.close(); txn.close();
} catch(SQLException e1) { } catch(SQLException e1) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e1.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e1.toString());
} }
// Whatever happens, allow the database to close // Whatever happens, allow the database to close
synchronized(connections) { synchronized(connections) {
@@ -443,7 +444,7 @@ abstract class JdbcDatabase implements Database<Connection> {
try { try {
connections.wait(); connections.wait();
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while closing connections"); LOG.info("Interrupted while closing connections");
interrupted = true; interrupted = true;
} }

View File

@@ -1,10 +1,12 @@
package net.sf.briar.lifecycle; package net.sf.briar.lifecycle;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.util.OsUtils; import net.sf.briar.util.OsUtils;
@@ -62,7 +64,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
if(OsUtils.isWindows()) { if(OsUtils.isWindows()) {
new EventLoop().start(); new EventLoop().start();
} else { } else {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Windows shutdown manager used on non-Windows OS"); LOG.warning("Windows shutdown manager used on non-Windows OS");
} }
initialised = true; initialised = true;
@@ -78,7 +80,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
try { try {
hook.join(); hook.join();
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while running shutdown hooks"); LOG.info("Interrupted while running shutdown hooks");
interrupted = true; interrupted = true;
} }
@@ -113,12 +115,12 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
try { try {
// Use SetWindowLongPtr if available (64-bit safe) // Use SetWindowLongPtr if available (64-bit safe)
user32.SetWindowLongPtr(hwnd, GWL_WNDPROC, proc); user32.SetWindowLongPtr(hwnd, GWL_WNDPROC, proc);
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Registered 64-bit callback"); LOG.info("Registered 64-bit callback");
} catch(UnsatisfiedLinkError e) { } catch(UnsatisfiedLinkError e) {
// Use SetWindowLong if SetWindowLongPtr isn't available // Use SetWindowLong if SetWindowLongPtr isn't available
user32.SetWindowLong(hwnd, GWL_WNDPROC, proc); user32.SetWindowLong(hwnd, GWL_WNDPROC, proc);
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Registered 32-bit callback"); LOG.info("Registered 32-bit callback");
} }
// Handle events until the window is destroyed // Handle events until the window is destroyed
@@ -128,7 +130,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
user32.DispatchMessage(msg); user32.DispatchMessage(msg);
} }
} catch(UnsatisfiedLinkError e) { } catch(UnsatisfiedLinkError e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,5 +1,8 @@
package net.sf.briar.plugins; package net.sf.briar.plugins;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -9,7 +12,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -97,7 +99,7 @@ class PluginManagerImpl implements PluginManager {
SimplexPlugin plugin = factory.createPlugin(pluginExecutor, SimplexPlugin plugin = factory.createPlugin(pluginExecutor,
androidExecutor, appContext, callback); androidExecutor, appContext, callback);
if(plugin == null) { if(plugin == null) {
if(LOG.isLoggable(Level.INFO)) { if(LOG.isLoggable(INFO)) {
LOG.info(factory.getClass().getSimpleName() LOG.info(factory.getClass().getSimpleName()
+ " did not create a plugin"); + " did not create a plugin");
} }
@@ -105,7 +107,7 @@ class PluginManagerImpl implements PluginManager {
} }
TransportId id = plugin.getId(); TransportId id = plugin.getId();
if(!ids.add(id)) { if(!ids.add(id)) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Duplicate transport ID: " + id); LOG.warning("Duplicate transport ID: " + id);
continue; continue;
} }
@@ -113,10 +115,10 @@ class PluginManagerImpl implements PluginManager {
plugin.start(); plugin.start();
simplexPlugins.add(plugin); simplexPlugins.add(plugin);
} catch(ClassCastException e) { } catch(ClassCastException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
continue; continue;
} catch(Exception e) { } catch(Exception e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
continue; continue;
} }
} }
@@ -130,7 +132,7 @@ class PluginManagerImpl implements PluginManager {
DuplexPlugin plugin = factory.createPlugin(pluginExecutor, DuplexPlugin plugin = factory.createPlugin(pluginExecutor,
androidExecutor, appContext, callback); androidExecutor, appContext, callback);
if(plugin == null) { if(plugin == null) {
if(LOG.isLoggable(Level.INFO)) { if(LOG.isLoggable(INFO)) {
LOG.info(factory.getClass().getSimpleName() LOG.info(factory.getClass().getSimpleName()
+ " did not create a plugin"); + " did not create a plugin");
} }
@@ -138,7 +140,7 @@ class PluginManagerImpl implements PluginManager {
} }
TransportId id = plugin.getId(); TransportId id = plugin.getId();
if(!ids.add(id)) { if(!ids.add(id)) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Duplicate transport ID: " + id); LOG.warning("Duplicate transport ID: " + id);
continue; continue;
} }
@@ -146,10 +148,10 @@ class PluginManagerImpl implements PluginManager {
plugin.start(); plugin.start();
duplexPlugins.add(plugin); duplexPlugins.add(plugin);
} catch(ClassCastException e) { } catch(ClassCastException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
continue; continue;
} catch(Exception e) { } catch(Exception e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
continue; continue;
} }
} }
@@ -182,7 +184,7 @@ class PluginManagerImpl implements PluginManager {
plugin.stop(); plugin.stop();
stopped++; stopped++;
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
// Stop the duplex plugins // Stop the duplex plugins
@@ -191,7 +193,7 @@ class PluginManagerImpl implements PluginManager {
plugin.stop(); plugin.stop();
stopped++; stopped++;
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
// Shut down the executors // Shut down the executors
@@ -225,7 +227,7 @@ class PluginManagerImpl implements PluginManager {
try { try {
return db.getConfig(id); return db.getConfig(id);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return new TransportConfig(); return new TransportConfig();
} }
} }
@@ -236,7 +238,7 @@ class PluginManagerImpl implements PluginManager {
TransportProperties p = db.getLocalProperties(id); TransportProperties p = db.getLocalProperties(id);
return p == null ? new TransportProperties() : p; return p == null ? new TransportProperties() : p;
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return new TransportProperties(); return new TransportProperties();
} }
} }
@@ -246,7 +248,7 @@ class PluginManagerImpl implements PluginManager {
try { try {
return db.getRemoteProperties(id); return db.getRemoteProperties(id);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return Collections.emptyMap(); return Collections.emptyMap();
} }
} }
@@ -256,7 +258,7 @@ class PluginManagerImpl implements PluginManager {
try { try {
db.mergeConfig(id, c); db.mergeConfig(id, c);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -265,7 +267,7 @@ class PluginManagerImpl implements PluginManager {
try { try {
db.mergeLocalProperties(id, p); db.mergeLocalProperties(id, p);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }

View File

@@ -1,9 +1,11 @@
package net.sf.briar.plugins; package net.sf.briar.plugins;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.util.Collection; import java.util.Collection;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -57,7 +59,7 @@ class PollerImpl implements Poller, Runnable {
try { try {
p.plugin.poll(connected); p.plugin.poll(connected);
} catch(RuntimeException e) { } catch(RuntimeException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Plugin " + p.plugin.getId() + " " + e); LOG.warning("Plugin " + p.plugin.getId() + " " + e);
} }
schedule(p.plugin); schedule(p.plugin);
@@ -65,7 +67,7 @@ class PollerImpl implements Poller, Runnable {
try { try {
wait(p.time - now); wait(p.time - now);
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting to poll"); LOG.info("Interrupted while waiting to poll");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return; return;

View File

@@ -1,6 +1,8 @@
package net.sf.briar.plugins.bluetooth; package net.sf.briar.plugins.bluetooth;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static javax.bluetooth.DiscoveryAgent.GIAC; import static javax.bluetooth.DiscoveryAgent.GIAC;
import java.io.IOException; import java.io.IOException;
@@ -12,7 +14,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.bluetooth.BluetoothStateException; import javax.bluetooth.BluetoothStateException;
@@ -82,7 +83,7 @@ class BluetoothPlugin implements DuplexPlugin {
callback.showMessage("BLUETOOTH_INSTALL_LIBS"); callback.showMessage("BLUETOOTH_INSTALL_LIBS");
throw new IOException(e.toString()); throw new IOException(e.toString());
} }
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Local address " + localDevice.getBluetoothAddress()); LOG.info("Local address " + localDevice.getBluetoothAddress());
synchronized(this) { synchronized(this) {
running = true; running = true;
@@ -107,7 +108,7 @@ class BluetoothPlugin implements DuplexPlugin {
try { try {
scn = (StreamConnectionNotifier) Connector.open(url); scn = (StreamConnectionNotifier) Connector.open(url);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return; return;
} }
synchronized(this) { synchronized(this) {
@@ -133,7 +134,7 @@ class BluetoothPlugin implements DuplexPlugin {
try { try {
scn.close(); scn.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -144,7 +145,7 @@ class BluetoothPlugin implements DuplexPlugin {
s = scn.acceptAndOpen(); s = scn.acceptAndOpen();
} catch(IOException e) { } catch(IOException e) {
// This is expected when the socket is closed // This is expected when the socket is closed
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(scn); tryToClose(scn);
return; return;
} }
@@ -209,7 +210,7 @@ class BluetoothPlugin implements DuplexPlugin {
StreamConnection s = (StreamConnection) Connector.open(url); StreamConnection s = (StreamConnection) Connector.open(url);
return new BluetoothTransportConnection(s); return new BluetoothTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
} }
@@ -251,11 +252,11 @@ class BluetoothPlugin implements DuplexPlugin {
discoveryAgent.startInquiry(GIAC, listener); discoveryAgent.startInquiry(GIAC, listener);
url = listener.waitForUrl(); url = listener.waitForUrl();
} catch(BluetoothStateException e) { } catch(BluetoothStateException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning(e.toString()); LOG.warning(e.toString());
return null; return null;
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting for URL"); LOG.info("Interrupted while waiting for URL");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return null; return null;
@@ -289,7 +290,7 @@ class BluetoothPlugin implements DuplexPlugin {
try { try {
scn = (StreamConnectionNotifier) Connector.open(url); scn = (StreamConnectionNotifier) Connector.open(url);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
synchronized(this) { synchronized(this) {
@@ -311,7 +312,7 @@ class BluetoothPlugin implements DuplexPlugin {
return new BluetoothTransportConnection(s); return new BluetoothTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
// This is expected when the socket is closed // This is expected when the socket is closed
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
return null; return null;
} finally { } finally {
if(f.cancel(false)) tryToClose(scn); if(f.cancel(false)) tryToClose(scn);
@@ -326,7 +327,7 @@ class BluetoothPlugin implements DuplexPlugin {
try { try {
localDevice.setDiscoverable(GIAC); localDevice.setDiscoverable(GIAC);
} catch(BluetoothStateException e) { } catch(BluetoothStateException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,12 +1,13 @@
package net.sf.briar.plugins.bluetooth; package net.sf.briar.plugins.bluetooth;
import static java.util.logging.Level.WARNING;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.bluetooth.BluetoothStateException; import javax.bluetooth.BluetoothStateException;
@@ -47,7 +48,7 @@ class InvitationListener implements DiscoveryListener {
discoveryAgent.searchServices(null, uuids, device, this); discoveryAgent.searchServices(null, uuids, device, this);
searches.incrementAndGet(); searches.incrementAndGet();
} catch(BluetoothStateException e) { } catch(BluetoothStateException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }

View File

@@ -10,6 +10,8 @@ import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE; import static android.bluetooth.BluetoothDevice.EXTRA_DEVICE;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
@@ -22,7 +24,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -117,11 +118,10 @@ class DroidtoothPlugin implements DuplexPlugin {
if(!running) return; if(!running) return;
} }
if(!enableBluetooth()) { if(!enableBluetooth()) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Could not enable Bluetooth");
LOG.info("Could not enable Bluetooth");
return; return;
} }
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Local address " + adapter.getAddress()); LOG.info("Local address " + adapter.getAddress());
// Advertise the Bluetooth address to contacts // Advertise the Bluetooth address to contacts
TransportProperties p = new TransportProperties(); TransportProperties p = new TransportProperties();
@@ -132,7 +132,7 @@ class DroidtoothPlugin implements DuplexPlugin {
try { try {
ss = InsecureBluetooth.listen(adapter, "RFCOMM", getUuid(), false); ss = InsecureBluetooth.listen(adapter, "RFCOMM", getUuid(), false);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return; return;
} }
synchronized(this) { synchronized(this) {
@@ -158,7 +158,7 @@ class DroidtoothPlugin implements DuplexPlugin {
if(!adapter.enable()) return false; if(!adapter.enable()) return false;
return receiver.waitForStateChange(); return receiver.waitForStateChange();
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while enabling Bluetooth"); LOG.info("Interrupted while enabling Bluetooth");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return false; return false;
@@ -174,7 +174,7 @@ class DroidtoothPlugin implements DuplexPlugin {
try { try {
ss.close(); ss.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -185,7 +185,7 @@ class DroidtoothPlugin implements DuplexPlugin {
s = ss.accept(); s = ss.accept();
} catch(IOException e) { } catch(IOException e) {
// This is expected when the socket is closed // This is expected when the socket is closed
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(ss); tryToClose(ss);
return; return;
} }
@@ -246,7 +246,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private DuplexTransportConnection connect(String address, String uuid) { private DuplexTransportConnection connect(String address, String uuid) {
// Validate the address // Validate the address
if(!BluetoothAdapter.checkBluetoothAddress(address)) { if(!BluetoothAdapter.checkBluetoothAddress(address)) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Invalid address " + address); LOG.warning("Invalid address " + address);
return null; return null;
} }
@@ -256,7 +256,7 @@ class DroidtoothPlugin implements DuplexPlugin {
try { try {
u = UUID.fromString(uuid); u = UUID.fromString(uuid);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Invalid UUID " + uuid); LOG.warning("Invalid UUID " + uuid);
return null; return null;
} }
@@ -265,7 +265,7 @@ class DroidtoothPlugin implements DuplexPlugin {
BluetoothSocket s = InsecureBluetooth.createSocket(d, u, false); BluetoothSocket s = InsecureBluetooth.createSocket(d, u, false);
return new DroidtoothTransportConnection(s); return new DroidtoothTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
} }
@@ -304,7 +304,7 @@ class DroidtoothPlugin implements DuplexPlugin {
try { try {
return receiver.waitForConnection(timeout); return receiver.waitForConnection(timeout);
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while sending invitation"); LOG.info("Interrupted while sending invitation");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return null; return null;
@@ -325,17 +325,17 @@ class DroidtoothPlugin implements DuplexPlugin {
try { try {
ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid, false); ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid, false);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
// Return the first connection received by the socket, if any // Return the first connection received by the socket, if any
try { try {
return new DroidtoothTransportConnection(ss.accept((int) timeout)); return new DroidtoothTransportConnection(ss.accept((int) timeout));
} catch(SocketTimeoutException e) { } catch(SocketTimeoutException e) {
if(LOG.isLoggable(Level.INFO)) LOG.info("Invitation timed out"); if(LOG.isLoggable(INFO)) LOG.info("Invitation timed out");
return null; return null;
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} finally { } finally {
tryToClose(ss); tryToClose(ss);

View File

@@ -1,5 +1,7 @@
package net.sf.briar.plugins.email; package net.sf.briar.plugins.email;
import static java.util.logging.Level.WARNING;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -9,7 +11,6 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.activation.DataHandler; import javax.activation.DataHandler;
@@ -84,7 +85,7 @@ class GmailPlugin implements SimplexPlugin {
try { try {
return message.getInputStream(); return message.getInputStream();
} catch(MessagingException e) { } catch(MessagingException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning(e.toString()); LOG.warning(e.toString());
} }
return null; return null;
@@ -96,14 +97,14 @@ class GmailPlugin implements SimplexPlugin {
message.setFlag(Flag.DELETED, recognised); message.setFlag(Flag.DELETED, recognised);
message.setFlag(Flag.SEEN, recognised); message.setFlag(Flag.SEEN, recognised);
} catch(MessagingException e) { } catch(MessagingException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning(e.toString()); LOG.warning(e.toString());
} }
} }
}); });
} }
} catch(MessagingException e) { } catch(MessagingException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -122,9 +123,9 @@ class GmailPlugin implements SimplexPlugin {
inbox.open(Folder.READ_ONLY); inbox.open(Folder.READ_ONLY);
checkUnreadEmails(inbox); checkUnreadEmails(inbox);
} catch(NoSuchProviderException e) { } catch(NoSuchProviderException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} catch(MessagingException e) { } catch(MessagingException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -214,7 +215,7 @@ class GmailPlugin implements SimplexPlugin {
outputStream.close(); outputStream.close();
outputStream = null; outputStream = null;
} catch(Exception e) { } catch(Exception e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,8 +1,9 @@
package net.sf.briar.plugins.email; package net.sf.briar.plugins.email;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.microedition.io.StreamConnection; import javax.microedition.io.StreamConnection;
@@ -36,7 +37,7 @@ class GmailTransportConnectionWriter implements SimplexTransportWriter {
try { try {
stream.close(); stream.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,5 +1,6 @@
package net.sf.briar.plugins.file; package net.sf.briar.plugins.file;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH; import static net.sf.briar.api.transport.TransportConstants.MIN_CONNECTION_LENGTH;
import java.io.File; import java.io.File;
@@ -9,7 +10,6 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -74,7 +74,7 @@ public abstract class FilePlugin implements SimplexPlugin {
OutputStream out = new FileOutputStream(f); OutputStream out = new FileOutputStream(f);
return new FileTransportWriter(f, out, capacity, this); return new FileTransportWriter(f, out, capacity, this);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
f.delete(); f.delete();
return null; return null;
} }
@@ -104,8 +104,7 @@ public abstract class FilePlugin implements SimplexPlugin {
callback.readerCreated(new FileTransportReader(file, in, callback.readerCreated(new FileTransportReader(file, in,
FilePlugin.this)); FilePlugin.this));
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,9 +1,10 @@
package net.sf.briar.plugins.file; package net.sf.briar.plugins.file;
import static java.util.logging.Level.WARNING;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader; import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
@@ -31,7 +32,7 @@ class FileTransportReader implements SimplexTransportReader {
try { try {
in.close(); in.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
if(recognised) { if(recognised) {
file.delete(); file.delete();

View File

@@ -1,9 +1,10 @@
package net.sf.briar.plugins.file; package net.sf.briar.plugins.file;
import static java.util.logging.Level.WARNING;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter; import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
@@ -42,7 +43,7 @@ class FileTransportWriter implements SimplexTransportWriter {
try { try {
out.close(); out.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
if(exception) file.delete(); if(exception) file.delete();
else plugin.writerFinished(file); else plugin.writerFinished(file);

View File

@@ -1,10 +1,11 @@
package net.sf.briar.plugins.file; package net.sf.briar.plugins.file;
import static java.util.logging.Level.INFO;
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.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.plugins.PluginExecutor; import net.sf.briar.api.plugins.PluginExecutor;
@@ -66,7 +67,7 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
drives = newDrives; drives = newDrives;
} }
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting to poll"); LOG.info("Interrupted while waiting to poll");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} catch(IOException e) { } catch(IOException e) {

View File

@@ -1,5 +1,7 @@
package net.sf.briar.plugins.file; package net.sf.briar.plugins.file;
import static java.util.logging.Level.WARNING;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -7,7 +9,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -79,7 +80,7 @@ implements RemovableDriveMonitor.Callback {
if(i == -1) return null; if(i == -1) return null;
return drives.get(i); return drives.get(i);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
} }
@@ -108,7 +109,7 @@ implements RemovableDriveMonitor.Callback {
} }
} }
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
return Collections.unmodifiableList(matches); return Collections.unmodifiableList(matches);
} }
@@ -121,6 +122,6 @@ implements RemovableDriveMonitor.Callback {
} }
public void exceptionThrown(IOException e) { public void exceptionThrown(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }

View File

@@ -1,5 +1,8 @@
package net.sf.briar.plugins.socket; package net.sf.briar.plugins.socket;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.InetAddress; import java.net.InetAddress;
@@ -10,7 +13,6 @@ import java.net.Socket;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.crypto.PseudoRandom; import net.sf.briar.api.crypto.PseudoRandom;
@@ -51,7 +53,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
ms.setInterface(iface); ms.setInterface(iface);
ms.joinGroup(mcast.getAddress()); ms.joinGroup(mcast.getAddress());
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
if(ms != null) tryToClose(ms, mcast.getAddress()); if(ms != null) tryToClose(ms, mcast.getAddress());
return null; return null;
} }
@@ -75,7 +77,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
Socket s = new Socket(packet.getAddress(), port); Socket s = new Socket(packet.getAddress(), port);
return new SocketTransportConnection(s); return new SocketTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning(e.toString()); LOG.warning(e.toString());
} }
} }
@@ -87,10 +89,10 @@ class LanSocketPlugin extends SimpleSocketPlugin {
if(!running) return null; if(!running) return null;
} }
} }
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Timeout while sending invitation"); LOG.info("Timeout while sending invitation");
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} finally { } finally {
tryToClose(ms, mcast.getAddress()); tryToClose(ms, mcast.getAddress());
} }
@@ -101,7 +103,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
try { try {
ms.leaveGroup(addr); ms.leaveGroup(addr);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
ms.close(); ms.close();
} }
@@ -152,7 +154,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
ss = new ServerSocket(); ss = new ServerSocket();
ss.bind(new InetSocketAddress(iface, 0)); ss.bind(new InetSocketAddress(iface, 0));
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
if(ss != null) tryToClose(ss); if(ss != null) tryToClose(ss);
return null; return null;
} }
@@ -163,7 +165,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
ms = new MulticastSocket(); ms = new MulticastSocket();
ms.setInterface(iface); ms.setInterface(iface);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
if(ms != null) ms.close(); if(ms != null) ms.close();
tryToClose(ss); tryToClose(ss);
return null; return null;
@@ -197,10 +199,10 @@ class LanSocketPlugin extends SimpleSocketPlugin {
if(!running) return null; if(!running) return null;
} }
} }
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Timeout while accepting invitation"); LOG.info("Timeout while accepting invitation");
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} finally { } finally {
ms.close(); ms.close();
tryToClose(ss); tryToClose(ss);
@@ -212,7 +214,7 @@ class LanSocketPlugin extends SimpleSocketPlugin {
try { try {
ss.close(); ss.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,5 +1,8 @@
package net.sf.briar.plugins.socket; package net.sf.briar.plugins.socket;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@@ -10,7 +13,6 @@ import java.net.SocketAddress;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -61,7 +63,7 @@ class SimpleSocketPlugin extends SocketPlugin {
try { try {
return new InetSocketAddress(chooseInterface(false), 0); return new InetSocketAddress(chooseInterface(false), 0);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
return addr; return addr;
@@ -77,7 +79,7 @@ class SimpleSocketPlugin extends SocketPlugin {
boolean link = addr.isLinkLocalAddress(); boolean link = addr.isLinkLocalAddress();
boolean site = addr.isSiteLocalAddress(); boolean site = addr.isSiteLocalAddress();
if(lan == (link || site)) { if(lan == (link || site)) {
if(LOG.isLoggable(Level.INFO)) { if(LOG.isLoggable(INFO)) {
LOG.info("Choosing interface " LOG.info("Choosing interface "
+ addr.getHostAddress()); + addr.getHostAddress());
} }
@@ -90,7 +92,7 @@ class SimpleSocketPlugin extends SocketPlugin {
for(NetworkInterface iface : ifaces) { for(NetworkInterface iface : ifaces) {
for(InetAddress addr : Collections.list(iface.getInetAddresses())) { for(InetAddress addr : Collections.list(iface.getInetAddresses())) {
if(!addr.isLoopbackAddress()) { if(!addr.isLoopbackAddress()) {
if(LOG.isLoggable(Level.INFO)) { if(LOG.isLoggable(INFO)) {
LOG.info("Accepting interface " LOG.info("Accepting interface "
+ addr.getHostAddress()); + addr.getHostAddress());
} }

View File

@@ -1,5 +1,8 @@
package net.sf.briar.plugins.socket; package net.sf.briar.plugins.socket;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@@ -7,7 +10,6 @@ import java.net.SocketAddress;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -62,14 +64,14 @@ abstract class SocketPlugin implements DuplexPlugin {
addr = getLocalSocketAddress(); addr = getLocalSocketAddress();
ss = createServerSocket(); ss = createServerSocket();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return; return;
} }
if(addr == null || ss == null) return; if(addr == null || ss == null) return;
try { try {
ss.bind(addr); ss.bind(addr);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
tryToClose(ss); tryToClose(ss);
return; return;
} }
@@ -80,7 +82,7 @@ abstract class SocketPlugin implements DuplexPlugin {
} }
socket = ss; socket = ss;
} }
if(LOG.isLoggable(Level.INFO)) { if(LOG.isLoggable(INFO)) {
LOG.info("Listening on " + ss.getInetAddress().getHostAddress() LOG.info("Listening on " + ss.getInetAddress().getHostAddress()
+ ":" + ss.getLocalPort()); + ":" + ss.getLocalPort());
} }
@@ -92,7 +94,7 @@ abstract class SocketPlugin implements DuplexPlugin {
try { try {
ss.close(); ss.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -103,7 +105,7 @@ abstract class SocketPlugin implements DuplexPlugin {
s = ss.accept(); s = ss.accept();
} catch(IOException e) { } catch(IOException e) {
// This is expected when the socket is closed // This is expected when the socket is closed
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(ss); tryToClose(ss);
return; return;
} }
@@ -163,7 +165,7 @@ abstract class SocketPlugin implements DuplexPlugin {
s.connect(addr); s.connect(addr);
return new SocketTransportConnection(s); return new SocketTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
return null; return null;
} }
} }

View File

@@ -1,10 +1,12 @@
package net.sf.briar.plugins.tor; package net.sf.briar.plugins.tor;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -76,11 +78,9 @@ class TorPlugin implements DuplexPlugin {
// Connect to Tor // Connect to Tor
NetFactory netFactory = NetFactory.getInstance(); NetFactory netFactory = NetFactory.getInstance();
NetLayer nl = netFactory.getNetLayerById(NetLayerIDs.TOR); NetLayer nl = netFactory.getNetLayerById(NetLayerIDs.TOR);
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Waiting for net layer to be ready");
LOG.info("Waiting for net layer to be ready");
nl.waitUntilReady(); nl.waitUntilReady();
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Net layer is ready");
LOG.info("Net layer is ready");
synchronized(this) { synchronized(this) {
if(!running) { if(!running) {
tryToClear(nl); tryToClear(nl);
@@ -93,8 +93,7 @@ class TorPlugin implements DuplexPlugin {
// If we're configure not to create a hidden service, return // If we're configure not to create a hidden service, return
TransportConfig c = callback.getConfig(); TransportConfig c = callback.getConfig();
if(c.containsKey("noHiddenService")) { if(c.containsKey("noHiddenService")) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Not creating hidden service");
LOG.info("Not creating hidden service");
TransportProperties p = new TransportProperties(); TransportProperties p = new TransportProperties();
p.put("onion", null); p.put("onion", null);
callback.mergeLocalProperties(p); callback.mergeLocalProperties(p);
@@ -105,17 +104,17 @@ class TorPlugin implements DuplexPlugin {
TorNetLayerUtil util = TorNetLayerUtil.getInstance(); TorNetLayerUtil util = TorNetLayerUtil.getInstance();
String privateKey = c.get("privateKey"); String privateKey = c.get("privateKey");
if(privateKey == null) { if(privateKey == null) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Creating hidden service address"); LOG.info("Creating hidden service address");
addr = createHiddenServiceAddress(util); addr = createHiddenServiceAddress(util);
} else { } else {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Parsing hidden service address"); LOG.info("Parsing hidden service address");
try { try {
addr = util.parseTorHiddenServicePrivateNetAddressFromStrings( addr = util.parseTorHiddenServicePrivateNetAddressFromStrings(
privateKey, "", false); privateKey, "", false);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
addr = createHiddenServiceAddress(util); addr = createHiddenServiceAddress(util);
} }
} }
@@ -123,11 +122,11 @@ class TorPlugin implements DuplexPlugin {
new TorHiddenServicePortPrivateNetAddress(addr, 80); new TorHiddenServicePortPrivateNetAddress(addr, 80);
// Publish the hidden service // Publish the hidden service
NetServerSocket ss; NetServerSocket ss;
if(LOG.isLoggable(Level.INFO)) LOG.info("Publishing hidden service"); if(LOG.isLoggable(INFO)) LOG.info("Publishing hidden service");
try { try {
ss = nl.createNetServerSocket(null, addrPort); ss = nl.createNetServerSocket(null, addrPort);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return; return;
} }
synchronized(this) { synchronized(this) {
@@ -138,7 +137,7 @@ class TorPlugin implements DuplexPlugin {
socket = ss; socket = ss;
} }
String onion = addr.getPublicOnionHostname(); String onion = addr.getPublicOnionHostname();
if(LOG.isLoggable(Level.INFO)) LOG.info("Listening on " + onion); if(LOG.isLoggable(INFO)) LOG.info("Listening on " + onion);
TransportProperties p = callback.getLocalProperties(); TransportProperties p = callback.getLocalProperties();
p.put("onion", onion); p.put("onion", onion);
callback.mergeLocalProperties(p); callback.mergeLocalProperties(p);
@@ -161,7 +160,7 @@ class TorPlugin implements DuplexPlugin {
try { try {
nl.clear(); nl.clear();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -169,7 +168,7 @@ class TorPlugin implements DuplexPlugin {
try { try {
ss.close(); ss.close();
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -180,7 +179,7 @@ class TorPlugin implements DuplexPlugin {
s = ss.accept(); s = ss.accept();
} catch(IOException e) { } catch(IOException e) {
// This is expected when the socket is closed // This is expected when the socket is closed
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
tryToClose(ss); tryToClose(ss);
return; return;
} }
@@ -244,12 +243,12 @@ class TorPlugin implements DuplexPlugin {
synchronized(this) { synchronized(this) {
while(!connected) { while(!connected) {
if(!running) return null; if(!running) return null;
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Waiting for net layer before connecting"); LOG.info("Waiting for net layer before connecting");
try { try {
wait(); wait();
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting to connect"); LOG.info("Interrupted while waiting to connect");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return null; return null;
@@ -263,14 +262,12 @@ class TorPlugin implements DuplexPlugin {
if(onion == null) return null; if(onion == null) return null;
NetAddress addr = new TcpipNetAddress(onion, 80); NetAddress addr = new TcpipNetAddress(onion, 80);
try { try {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Connecting to hidden service");
LOG.info("Connecting to hidden service");
NetSocket s = nl.createNetSocket(null, null, addr); NetSocket s = nl.createNetSocket(null, null, addr);
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO)) LOG.info("Connected to hidden service");
LOG.info("Connected to hidden service");
return new TorTransportConnection(s); return new TorTransportConnection(s);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.INFO)) LOG.info(e.toString()); if(LOG.isLoggable(INFO)) LOG.info(e.toString());
return null; return null;
} }
} }

View File

@@ -1,5 +1,8 @@
package net.sf.briar.protocol.duplex; package net.sf.briar.protocol.duplex;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@@ -14,7 +17,6 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -179,7 +181,7 @@ abstract class DuplexConnection implements DatabaseListener {
// The writer will dispose of the transport if no exceptions occur // The writer will dispose of the transport if no exceptions occur
writerTasks.add(CLOSE); writerTasks.add(CLOSE);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -217,11 +219,11 @@ abstract class DuplexConnection implements DatabaseListener {
writer.close(); writer.close();
dispose(false, true); dispose(false, true);
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting for task"); LOG.info("Interrupted while waiting for task");
dispose(true, true); dispose(true, true);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} finally { } finally {
connRegistry.unregisterConnection(contactId, transportId); connRegistry.unregisterConnection(contactId, transportId);
@@ -235,7 +237,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
transport.dispose(exception, recognised); transport.dispose(exception, recognised);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -252,7 +254,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
db.receiveAck(contactId, ack); db.receiveAck(contactId, ack);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -271,7 +273,7 @@ abstract class DuplexConnection implements DatabaseListener {
Batch b = batch.verify(); Batch b = batch.verify();
dbExecutor.execute(new ReceiveBatch(b)); dbExecutor.execute(new ReceiveBatch(b));
} catch(GeneralSecurityException e) { } catch(GeneralSecurityException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -289,7 +291,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
db.receiveBatch(contactId, batch); db.receiveBatch(contactId, batch);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -308,7 +310,7 @@ abstract class DuplexConnection implements DatabaseListener {
Request r = db.receiveOffer(contactId, offer); Request r = db.receiveOffer(contactId, offer);
writerTasks.add(new WriteRequest(r)); writerTasks.add(new WriteRequest(r));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -327,7 +329,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
writer.writeRequest(request); writer.writeRequest(request);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -346,7 +348,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
db.setSeen(contactId, seen); db.setSeen(contactId, seen);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -364,7 +366,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
db.receiveSubscriptionUpdate(contactId, update); db.receiveSubscriptionUpdate(contactId, update);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -382,7 +384,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
db.receiveTransportUpdate(contactId, update); db.receiveTransportUpdate(contactId, update);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -397,7 +399,7 @@ abstract class DuplexConnection implements DatabaseListener {
Ack a = db.generateAck(contactId, maxBatches); Ack a = db.generateAck(contactId, maxBatches);
if(a != null) writerTasks.add(new WriteAck(a)); if(a != null) writerTasks.add(new WriteAck(a));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -417,7 +419,7 @@ abstract class DuplexConnection implements DatabaseListener {
writer.writeAck(ack); writer.writeAck(ack);
dbExecutor.execute(new GenerateAcks()); dbExecutor.execute(new GenerateAcks());
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -440,7 +442,7 @@ abstract class DuplexConnection implements DatabaseListener {
if(b == null) new GenerateOffer().run(); if(b == null) new GenerateOffer().run();
else writerTasks.add(new WriteBatch(b, requested)); else writerTasks.add(new WriteBatch(b, requested));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -463,7 +465,7 @@ abstract class DuplexConnection implements DatabaseListener {
if(requested.isEmpty()) dbExecutor.execute(new GenerateOffer()); if(requested.isEmpty()) dbExecutor.execute(new GenerateOffer());
else dbExecutor.execute(new GenerateBatches(requested)); else dbExecutor.execute(new GenerateBatches(requested));
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -487,7 +489,7 @@ abstract class DuplexConnection implements DatabaseListener {
writerTasks.add(new WriteOffer(o)); writerTasks.add(new WriteOffer(o));
} }
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -506,7 +508,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
writer.writeOffer(offer); writer.writeOffer(offer);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -520,7 +522,7 @@ abstract class DuplexConnection implements DatabaseListener {
SubscriptionUpdate s = db.generateSubscriptionUpdate(contactId); SubscriptionUpdate s = db.generateSubscriptionUpdate(contactId);
if(s != null) writerTasks.add(new WriteSubscriptionUpdate(s)); if(s != null) writerTasks.add(new WriteSubscriptionUpdate(s));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -539,7 +541,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
writer.writeSubscriptionUpdate(update); writer.writeSubscriptionUpdate(update);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }
@@ -553,7 +555,7 @@ abstract class DuplexConnection implements DatabaseListener {
TransportUpdate t = db.generateTransportUpdate(contactId); TransportUpdate t = db.generateTransportUpdate(contactId);
if(t != null) writerTasks.add(new WriteTransportUpdate(t)); if(t != null) writerTasks.add(new WriteTransportUpdate(t));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -572,7 +574,7 @@ abstract class DuplexConnection implements DatabaseListener {
try { try {
writer.writeTransportUpdate(update); writer.writeTransportUpdate(update);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} }
} }

View File

@@ -1,7 +1,8 @@
package net.sf.briar.protocol.duplex; package net.sf.briar.protocol.duplex;
import static java.util.logging.Level.WARNING;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -78,7 +79,7 @@ class DuplexConnectionFactoryImpl implements DuplexConnectionFactory {
DuplexTransportConnection transport) { DuplexTransportConnection transport) {
ConnectionContext ctx = keyManager.getConnectionContext(c, t); ConnectionContext ctx = keyManager.getConnectionContext(c, t);
if(ctx == null) { if(ctx == null) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Could not create outgoing connection context"); LOG.warning("Could not create outgoing connection context");
return; return;
} }

View File

@@ -1,10 +1,11 @@
package net.sf.briar.protocol.simplex; package net.sf.briar.protocol.simplex;
import static java.util.logging.Level.WARNING;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -88,7 +89,7 @@ class IncomingSimplexConnection {
} }
dispose(false, true); dispose(false, true);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, true); dispose(true, true);
} finally { } finally {
connRegistry.unregisterConnection(contactId, transportId); connRegistry.unregisterConnection(contactId, transportId);
@@ -100,7 +101,7 @@ class IncomingSimplexConnection {
try { try {
transport.dispose(exception, recognised); transport.dispose(exception, recognised);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
@@ -116,7 +117,7 @@ class IncomingSimplexConnection {
try { try {
db.receiveAck(contactId, ack); db.receiveAck(contactId, ack);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -134,7 +135,7 @@ class IncomingSimplexConnection {
Batch b = batch.verify(); Batch b = batch.verify();
dbExecutor.execute(new ReceiveBatch(b)); dbExecutor.execute(new ReceiveBatch(b));
} catch(GeneralSecurityException e) { } catch(GeneralSecurityException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -151,7 +152,7 @@ class IncomingSimplexConnection {
try { try {
db.receiveBatch(contactId, batch); db.receiveBatch(contactId, batch);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -168,7 +169,7 @@ class IncomingSimplexConnection {
try { try {
db.receiveSubscriptionUpdate(contactId, update); db.receiveSubscriptionUpdate(contactId, update);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -185,7 +186,7 @@ class IncomingSimplexConnection {
try { try {
db.receiveTransportUpdate(contactId, update); db.receiveTransportUpdate(contactId, update);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,11 +1,11 @@
package net.sf.briar.protocol.simplex; package net.sf.briar.protocol.simplex;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH; import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -99,10 +99,10 @@ class OutgoingSimplexConnection {
writer.close(); writer.close();
dispose(false); dispose(false);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true); dispose(true);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true); dispose(true);
} finally { } finally {
connRegistry.unregisterConnection(contactId, transportId); connRegistry.unregisterConnection(contactId, transportId);
@@ -114,7 +114,7 @@ class OutgoingSimplexConnection {
try { try {
transport.dispose(exception); transport.dispose(exception);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,7 +1,8 @@
package net.sf.briar.protocol.simplex; package net.sf.briar.protocol.simplex;
import static java.util.logging.Level.WARNING;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -72,7 +73,7 @@ class SimplexConnectionFactoryImpl implements SimplexConnectionFactory {
SimplexTransportWriter w) { SimplexTransportWriter w) {
ConnectionContext ctx = keyManager.getConnectionContext(c, t); ConnectionContext ctx = keyManager.getConnectionContext(c, t);
if(ctx == null) { if(ctx == null) {
if(LOG.isLoggable(Level.WARNING)) if(LOG.isLoggable(WARNING))
LOG.warning("Could not create outgoing connection context"); LOG.warning("Could not create outgoing connection context");
return; return;
} }

View File

@@ -1,12 +1,12 @@
package net.sf.briar.transport; package net.sf.briar.transport;
import static java.util.logging.Level.WARNING;
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH; import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -98,18 +98,18 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
transport); transport);
} }
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
try { try {
transport.dispose(true, false); transport.dispose(true, false);
} catch(IOException e1) { } catch(IOException e1) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
try { try {
transport.dispose(true, false); transport.dispose(true, false);
} catch(IOException e1) { } catch(IOException e1) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }
@@ -131,7 +131,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
try { try {
tag = readTag(transport.getInputStream()); tag = readTag(transport.getInputStream());
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, false); dispose(true, false);
return; return;
} }
@@ -139,7 +139,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
try { try {
ctx = recogniser.acceptConnection(transportId, tag); ctx = recogniser.acceptConnection(transportId, tag);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
dispose(true, false); dispose(true, false);
return; return;
} }
@@ -151,7 +151,7 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
try { try {
transport.dispose(exception, recognised); transport.dispose(exception, recognised);
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
} }
} }

View File

@@ -1,5 +1,7 @@
package net.sf.briar.transport; package net.sf.briar.transport;
import static java.util.logging.Level.WARNING;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@@ -8,7 +10,6 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -63,7 +64,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
try { try {
secrets = db.getSecrets(); secrets = db.getSecrets();
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return false; return false;
} }
// Work out what phase of its lifecycle each secret is in // Work out what phase of its lifecycle each secret is in
@@ -76,7 +77,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
try { try {
db.addSecrets(created); db.addSecrets(created);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return false; return false;
} }
} }
@@ -223,7 +224,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
try { try {
connection = db.incrementConnectionCounter(c, t, s.getPeriod()); connection = db.incrementConnectionCounter(c, t, s.getPeriod());
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
return null; return null;
} }
byte[] secret = s.getSecret().clone(); byte[] secret = s.getSecret().clone();
@@ -268,7 +269,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
try { try {
db.addSecrets(Arrays.asList(s1, s2)); db.addSecrets(Arrays.asList(s1, s2));
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
// Pass the new secrets to the recogniser // Pass the new secrets to the recogniser
recogniser.addSecret(s1); recogniser.addSecret(s1);
@@ -303,7 +304,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, DatabaseListener {
try { try {
db.addSecrets(created); db.addSecrets(created);
} catch(DbException e) { } catch(DbException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
} }
// Pass any secrets that have been created to the recogniser // Pass any secrets that have been created to the recogniser
for(TemporarySecret s : created) recogniser.addSecret(s); for(TemporarySecret s : created) recogniser.addSecret(s);

View File

@@ -1,6 +1,8 @@
package net.sf.briar.util; package net.sf.briar.util;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -8,7 +10,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@@ -44,12 +45,12 @@ public class BoundedExecutor implements Executor {
} }
}); });
} catch(InterruptedException e) { } catch(InterruptedException e) {
if(LOG.isLoggable(Level.INFO)) if(LOG.isLoggable(INFO))
LOG.info("Interrupted while queueing task"); LOG.info("Interrupted while queueing task");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
throw new RejectedExecutionException(); throw new RejectedExecutionException();
} catch(RejectedExecutionException e) { } catch(RejectedExecutionException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString()); if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
semaphore.release(); semaphore.release();
throw e; throw e;
} }