mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Whitespace-only code formatting changes.
This commit is contained in:
@@ -84,9 +84,9 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
InputStream in = r.getInputStream();
|
||||
int offset = 0;
|
||||
while(offset < tag.length) {
|
||||
while (offset < tag.length) {
|
||||
int read = in.read(tag, offset, tag.length - offset);
|
||||
if(read == -1) throw new EOFException();
|
||||
if (read == -1) throw new EOFException();
|
||||
offset += read;
|
||||
}
|
||||
return tag;
|
||||
@@ -135,16 +135,16 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
try {
|
||||
byte[] tag = readTag(transportId, reader);
|
||||
ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
}
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.info("Unrecognised tag");
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
@@ -155,8 +155,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
// Create and run the incoming session
|
||||
createIncomingSession(ctx, reader).run();
|
||||
disposeReader(false, true);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, true);
|
||||
} finally {
|
||||
connectionRegistry.unregisterConnection(contactId, transportId);
|
||||
@@ -166,8 +166,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
private void disposeReader(boolean exception, boolean recognised) {
|
||||
try {
|
||||
reader.dispose(exception, recognised);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
// Allocate a stream context
|
||||
StreamContext ctx = keyManager.getStreamContext(contactId,
|
||||
transportId);
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.warning("Could not allocate stream context");
|
||||
disposeWriter(true);
|
||||
return;
|
||||
@@ -199,8 +199,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
// Create and run the outgoing session
|
||||
createSimplexOutgoingSession(ctx, writer).run();
|
||||
disposeWriter(false);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeWriter(true);
|
||||
} finally {
|
||||
connectionRegistry.unregisterConnection(contactId, transportId);
|
||||
@@ -210,8 +210,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
private void disposeWriter(boolean exception) {
|
||||
try {
|
||||
writer.dispose(exception);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,16 +239,16 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
try {
|
||||
byte[] tag = readTag(transportId, reader);
|
||||
ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
}
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.info("Unrecognised tag");
|
||||
disposeReader(true, false);
|
||||
return;
|
||||
@@ -266,8 +266,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
incomingSession = createIncomingSession(ctx, reader);
|
||||
incomingSession.run();
|
||||
disposeReader(false, true);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, true);
|
||||
} finally {
|
||||
connectionRegistry.unregisterConnection(contactId, transportId);
|
||||
@@ -278,7 +278,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
// Allocate a stream context
|
||||
StreamContext ctx = keyManager.getStreamContext(contactId,
|
||||
transportId);
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.warning("Could not allocate stream context");
|
||||
disposeWriter(true);
|
||||
return;
|
||||
@@ -288,29 +288,29 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
outgoingSession = createDuplexOutgoingSession(ctx, writer);
|
||||
outgoingSession.run();
|
||||
disposeWriter(false);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeWriter(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void disposeReader(boolean exception, boolean recognised) {
|
||||
if(exception && outgoingSession != null)
|
||||
if (exception && outgoingSession != null)
|
||||
outgoingSession.interrupt();
|
||||
try {
|
||||
reader.dispose(exception, recognised);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void disposeWriter(boolean exception) {
|
||||
if(exception && incomingSession != null)
|
||||
if (exception && incomingSession != null)
|
||||
incomingSession.interrupt();
|
||||
try {
|
||||
writer.dispose(exception);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,7 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
// Allocate a stream context
|
||||
StreamContext ctx = keyManager.getStreamContext(contactId,
|
||||
transportId);
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.warning("Could not allocate stream context");
|
||||
disposeWriter(true);
|
||||
return;
|
||||
@@ -354,8 +354,8 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
outgoingSession = createDuplexOutgoingSession(ctx, writer);
|
||||
outgoingSession.run();
|
||||
disposeWriter(false);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeWriter(true);
|
||||
} finally {
|
||||
connectionRegistry.unregisterConnection(contactId, transportId);
|
||||
@@ -368,23 +368,23 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
try {
|
||||
byte[] tag = readTag(transportId, reader);
|
||||
ctx = tagRecogniser.recogniseTag(transportId, tag);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, true);
|
||||
return;
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, true);
|
||||
return;
|
||||
}
|
||||
// Unrecognised tags are suspicious in this case
|
||||
if(ctx == null) {
|
||||
if (ctx == null) {
|
||||
LOG.warning("Unrecognised tag for returning stream");
|
||||
disposeReader(true, true);
|
||||
return;
|
||||
}
|
||||
// Check that the stream comes from the expected contact
|
||||
if(!ctx.getContactId().equals(contactId)) {
|
||||
if (!ctx.getContactId().equals(contactId)) {
|
||||
LOG.warning("Wrong contact ID for returning stream");
|
||||
disposeReader(true, true);
|
||||
return;
|
||||
@@ -394,29 +394,29 @@ class ConnectionManagerImpl implements ConnectionManager {
|
||||
incomingSession = createIncomingSession(ctx, reader);
|
||||
incomingSession.run();
|
||||
disposeReader(false, true);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
disposeReader(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void disposeReader(boolean exception, boolean recognised) {
|
||||
if(exception && outgoingSession != null)
|
||||
if (exception && outgoingSession != null)
|
||||
outgoingSession.interrupt();
|
||||
try {
|
||||
reader.dispose(exception, recognised);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void disposeWriter(boolean exception) {
|
||||
if(exception && incomingSession != null)
|
||||
if (exception && incomingSession != null)
|
||||
incomingSession.interrupt();
|
||||
try {
|
||||
writer.dispose(exception);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<ContactId, Integer> m = connections.get(t);
|
||||
if(m == null) {
|
||||
if (m == null) {
|
||||
m = new HashMap<ContactId, Integer>();
|
||||
connections.put(t, m);
|
||||
}
|
||||
Integer count = m.get(c);
|
||||
if(count == null) m.put(c, 1);
|
||||
if (count == null) m.put(c, 1);
|
||||
else m.put(c, count + 1);
|
||||
count = contactCounts.get(c);
|
||||
if(count == null) {
|
||||
if (count == null) {
|
||||
firstConnection = true;
|
||||
contactCounts.put(c, 1);
|
||||
} else {
|
||||
@@ -64,7 +64,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
synchLock.unlock();
|
||||
}
|
||||
|
||||
if(firstConnection) {
|
||||
if (firstConnection) {
|
||||
LOG.info("Contact connected");
|
||||
eventBus.broadcast(new ContactConnectedEvent(c));
|
||||
}
|
||||
@@ -76,17 +76,17 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<ContactId, Integer> m = connections.get(t);
|
||||
if(m == null) throw new IllegalArgumentException();
|
||||
if (m == null) throw new IllegalArgumentException();
|
||||
Integer count = m.remove(c);
|
||||
if(count == null) throw new IllegalArgumentException();
|
||||
if(count == 1) {
|
||||
if(m.isEmpty()) connections.remove(t);
|
||||
if (count == null) throw new IllegalArgumentException();
|
||||
if (count == 1) {
|
||||
if (m.isEmpty()) connections.remove(t);
|
||||
} else {
|
||||
m.put(c, count - 1);
|
||||
}
|
||||
count = contactCounts.get(c);
|
||||
if(count == null) throw new IllegalArgumentException();
|
||||
if(count == 1) {
|
||||
if (count == null) throw new IllegalArgumentException();
|
||||
if (count == 1) {
|
||||
lastConnection = true;
|
||||
contactCounts.remove(c);
|
||||
} else {
|
||||
@@ -96,7 +96,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
synchLock.unlock();
|
||||
}
|
||||
|
||||
if(lastConnection) {
|
||||
if (lastConnection) {
|
||||
LOG.info("Contact disconnected");
|
||||
eventBus.broadcast(new ContactDisconnectedEvent(c));
|
||||
}
|
||||
@@ -107,9 +107,9 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<ContactId, Integer> m = connections.get(t);
|
||||
if(m == null) return Collections.emptyList();
|
||||
if (m == null) return Collections.emptyList();
|
||||
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);
|
||||
} finally {
|
||||
synchLock.unlock();
|
||||
|
||||
@@ -84,20 +84,20 @@ class PluginManagerImpl implements PluginManager {
|
||||
Collection<SimplexPluginFactory> sFactories =
|
||||
simplexPluginConfig.getFactories();
|
||||
final CountDownLatch sLatch = new CountDownLatch(sFactories.size());
|
||||
for(SimplexPluginFactory factory : sFactories)
|
||||
for (SimplexPluginFactory factory : sFactories)
|
||||
ioExecutor.execute(new SimplexPluginStarter(factory, sLatch));
|
||||
// Instantiate and start the duplex plugins
|
||||
LOG.info("Starting duplex plugins");
|
||||
Collection<DuplexPluginFactory> dFactories =
|
||||
duplexPluginConfig.getFactories();
|
||||
final CountDownLatch dLatch = new CountDownLatch(dFactories.size());
|
||||
for(DuplexPluginFactory factory : dFactories)
|
||||
for (DuplexPluginFactory factory : dFactories)
|
||||
ioExecutor.execute(new DuplexPluginStarter(factory, dLatch));
|
||||
// Wait for the plugins to start
|
||||
try {
|
||||
sLatch.await();
|
||||
dLatch.await();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while starting plugins");
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
@@ -112,11 +112,11 @@ class PluginManagerImpl implements PluginManager {
|
||||
final CountDownLatch latch = new CountDownLatch(plugins.size());
|
||||
// Stop the simplex plugins
|
||||
LOG.info("Stopping simplex plugins");
|
||||
for(SimplexPlugin plugin : simplexPlugins)
|
||||
for (SimplexPlugin plugin : simplexPlugins)
|
||||
ioExecutor.execute(new PluginStopper(plugin, latch));
|
||||
// Stop the duplex plugins
|
||||
LOG.info("Stopping duplex plugins");
|
||||
for(DuplexPlugin plugin : duplexPlugins)
|
||||
for (DuplexPlugin plugin : duplexPlugins)
|
||||
ioExecutor.execute(new PluginStopper(plugin, latch));
|
||||
plugins.clear();
|
||||
simplexPlugins.clear();
|
||||
@@ -124,7 +124,7 @@ class PluginManagerImpl implements PluginManager {
|
||||
// Wait for all the plugins to stop
|
||||
try {
|
||||
latch.await();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while stopping plugins");
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
@@ -138,8 +138,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
|
||||
public Collection<DuplexPlugin> getInvitationPlugins() {
|
||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||
for(DuplexPlugin d : duplexPlugins)
|
||||
if(d.supportsInvitations()) supported.add(d);
|
||||
for (DuplexPlugin d : duplexPlugins)
|
||||
if (d.supportsInvitations()) supported.add(d);
|
||||
return Collections.unmodifiableList(supported);
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
TransportId id = factory.getId();
|
||||
SimplexCallback callback = new SimplexCallback(id);
|
||||
SimplexPlugin plugin = factory.createPlugin(callback);
|
||||
if(plugin == null) {
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (plugin == null) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = factory.getClass().getSimpleName();
|
||||
LOG.info(name + " did not create a plugin");
|
||||
}
|
||||
@@ -170,10 +170,10 @@ class PluginManagerImpl implements PluginManager {
|
||||
long start = clock.currentTimeMillis();
|
||||
db.addTransport(id, plugin.getMaxLatency());
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Adding transport took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
return;
|
||||
}
|
||||
@@ -181,23 +181,23 @@ class PluginManagerImpl implements PluginManager {
|
||||
long start = clock.currentTimeMillis();
|
||||
boolean started = plugin.start();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(started) {
|
||||
if (started) {
|
||||
plugins.put(id, plugin);
|
||||
simplexPlugins.add(plugin);
|
||||
if(plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Starting " + name + " took " +
|
||||
duration + " ms");
|
||||
}
|
||||
} else {
|
||||
if(LOG.isLoggable(WARNING)) {
|
||||
if (LOG.isLoggable(WARNING)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.warning(name + " did not start");
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
} finally {
|
||||
@@ -222,8 +222,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
TransportId id = factory.getId();
|
||||
DuplexCallback callback = new DuplexCallback(id);
|
||||
DuplexPlugin plugin = factory.createPlugin(callback);
|
||||
if(plugin == null) {
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (plugin == null) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = factory.getClass().getSimpleName();
|
||||
LOG.info(name + " did not create a plugin");
|
||||
}
|
||||
@@ -233,10 +233,10 @@ class PluginManagerImpl implements PluginManager {
|
||||
long start = clock.currentTimeMillis();
|
||||
db.addTransport(id, plugin.getMaxLatency());
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Adding transport took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
return;
|
||||
}
|
||||
@@ -244,23 +244,23 @@ class PluginManagerImpl implements PluginManager {
|
||||
long start = clock.currentTimeMillis();
|
||||
boolean started = plugin.start();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(started) {
|
||||
if (started) {
|
||||
plugins.put(id, plugin);
|
||||
duplexPlugins.add(plugin);
|
||||
if(plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Starting " + name + " took " +
|
||||
duration + " ms");
|
||||
}
|
||||
} else {
|
||||
if(LOG.isLoggable(WARNING)) {
|
||||
if (LOG.isLoggable(WARNING)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.warning(name + " did not start");
|
||||
}
|
||||
}
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
} finally {
|
||||
@@ -284,12 +284,12 @@ class PluginManagerImpl implements PluginManager {
|
||||
long start = clock.currentTimeMillis();
|
||||
plugin.stop();
|
||||
long duration = clock.currentTimeMillis() - start;
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Stopping " + name + " took " + duration + " ms");
|
||||
}
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
@@ -307,8 +307,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
public TransportConfig getConfig() {
|
||||
try {
|
||||
return db.getConfig(id);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return new TransportConfig();
|
||||
}
|
||||
}
|
||||
@@ -317,8 +317,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
try {
|
||||
TransportProperties p = db.getLocalProperties(id);
|
||||
return p == null ? new TransportProperties() : p;
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return new TransportProperties();
|
||||
}
|
||||
}
|
||||
@@ -326,8 +326,8 @@ class PluginManagerImpl implements PluginManager {
|
||||
public Map<ContactId, TransportProperties> getRemoteProperties() {
|
||||
try {
|
||||
return db.getRemoteProperties(id);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
@@ -335,16 +335,16 @@ class PluginManagerImpl implements PluginManager {
|
||||
public void mergeConfig(TransportConfig c) {
|
||||
try {
|
||||
db.mergeConfig(id, c);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
try {
|
||||
db.mergeLocalProperties(id, p);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ class PluginManagerImpl implements PluginManager {
|
||||
|
||||
public void pollNow() {
|
||||
Plugin p = plugins.get(id);
|
||||
if(p != null) poller.pollNow(p);
|
||||
if (p != null) poller.pollNow(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,14 +41,14 @@ class PollerImpl implements Poller {
|
||||
private void schedule(Plugin plugin, boolean randomise) {
|
||||
long interval = plugin.getPollingInterval();
|
||||
// Randomise intervals at startup to spread out connection attempts
|
||||
if(randomise) interval = (long) (interval * Math.random());
|
||||
if (randomise) interval = (long) (interval * Math.random());
|
||||
timer.schedule(new PollTask(plugin), interval);
|
||||
}
|
||||
|
||||
public void pollNow(final Plugin p) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Polling " + p.getClass().getSimpleName());
|
||||
p.poll(connectionRegistry.getConnectedContacts(p.getId()));
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
}
|
||||
|
||||
public TransportConnectionWriter createWriter(ContactId c) {
|
||||
if(!running) return null;
|
||||
if (!running) return null;
|
||||
return createWriter(createConnectionFilename());
|
||||
}
|
||||
|
||||
private String createConnectionFilename() {
|
||||
StringBuilder s = new StringBuilder(12);
|
||||
for(int i = 0; i < 8; i++) s.append((char) ('a' + Math.random() * 26));
|
||||
for (int i = 0; i < 8; i++) s.append((char) ('a' + Math.random() * 26));
|
||||
s.append(".dat");
|
||||
return s.toString();
|
||||
}
|
||||
@@ -79,24 +79,24 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
}
|
||||
|
||||
private TransportConnectionWriter createWriter(String filename) {
|
||||
if(!running) return null;
|
||||
if (!running) return null;
|
||||
File dir = chooseOutputDirectory();
|
||||
if(dir == null || !dir.exists() || !dir.isDirectory()) return null;
|
||||
if (dir == null || !dir.exists() || !dir.isDirectory()) return null;
|
||||
File f = new File(dir, filename);
|
||||
try {
|
||||
long capacity = fileUtils.getFreeSpace(dir);
|
||||
if(capacity < MIN_STREAM_LENGTH) return null;
|
||||
if (capacity < MIN_STREAM_LENGTH) return null;
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
return new FileTransportWriter(f, out, capacity, this);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
f.delete();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void createReaderFromFile(final File f) {
|
||||
if(!running) return;
|
||||
if (!running) return;
|
||||
ioExecutor.execute(new ReaderCreator(f));
|
||||
}
|
||||
|
||||
@@ -109,13 +109,13 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if(isPossibleConnectionFilename(file.getName())) {
|
||||
if (isPossibleConnectionFilename(file.getName())) {
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
callback.readerCreated(new FileTransportReader(file, in,
|
||||
FilePlugin.this));
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ class FileTransportReader implements TransportConnectionReader {
|
||||
public void dispose(boolean exception, boolean recognised) {
|
||||
try {
|
||||
in.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
if(recognised) {
|
||||
if (recognised) {
|
||||
file.delete();
|
||||
plugin.readerFinished(file);
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ class FileTransportWriter implements TransportConnectionWriter {
|
||||
public void dispose(boolean exception) {
|
||||
try {
|
||||
out.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
if(exception) file.delete();
|
||||
if (exception) file.delete();
|
||||
else plugin.writerFinished(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
String oldAddress = p.get("address"), oldPort = p.get("port");
|
||||
InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
|
||||
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
||||
for(InetAddress a : getLocalIpAddresses()) {
|
||||
if(isAcceptableAddress(a)) {
|
||||
for (InetAddress a : getLocalIpAddresses()) {
|
||||
if (isAcceptableAddress(a)) {
|
||||
// If this is the old address, try to use the same port
|
||||
if(old != null && old.getAddress().equals(a))
|
||||
if (old != null && old.getAddress().equals(a))
|
||||
addrs.add(0, new InetSocketAddress(a, old.getPort()));
|
||||
addrs.add(new InetSocketAddress(a, 0));
|
||||
}
|
||||
@@ -54,10 +54,10 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
|
||||
@Override
|
||||
protected boolean isConnectable(InetSocketAddress remote) {
|
||||
if(remote.getPort() == 0) return false;
|
||||
if(!isAcceptableAddress(remote.getAddress())) return false;
|
||||
if (remote.getPort() == 0) return false;
|
||||
if (!isAcceptableAddress(remote.getAddress())) return false;
|
||||
// Try to determine whether the address is on the same LAN as us
|
||||
if(socket == null) return false;
|
||||
if (socket == null) return false;
|
||||
byte[] localIp = socket.getInetAddress().getAddress();
|
||||
byte[] remoteIp = remote.getAddress().getAddress();
|
||||
return addressesAreOnSameLan(localIp, remoteIp);
|
||||
@@ -66,12 +66,12 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
// Package access for testing
|
||||
boolean addressesAreOnSameLan(byte[] localIp, byte[] remoteIp) {
|
||||
// 10.0.0.0/8
|
||||
if(localIp[0] == 10) return remoteIp[0] == 10;
|
||||
if (localIp[0] == 10) return remoteIp[0] == 10;
|
||||
// 172.16.0.0/12
|
||||
if(localIp[0] == (byte) 172 && (localIp[1] & 0xF0) == 16)
|
||||
if (localIp[0] == (byte) 172 && (localIp[1] & 0xF0) == 16)
|
||||
return remoteIp[0] == (byte) 172 && (remoteIp[1] & 0xF0) == 16;
|
||||
// 192.168.0.0/16
|
||||
if(localIp[0] == (byte) 192 && localIp[1] == (byte) 168)
|
||||
if (localIp[0] == (byte) 192 && localIp[1] == (byte) 168)
|
||||
return remoteIp[0] == (byte) 192 && remoteIp[1] == (byte) 168;
|
||||
// Unrecognised prefix - may be compatible
|
||||
return true;
|
||||
|
||||
@@ -30,18 +30,18 @@ class PortMapperImpl implements PortMapper {
|
||||
}
|
||||
|
||||
public MappingResult map(final int port) {
|
||||
if(!started.getAndSet(true)) start();
|
||||
if(gateway == null) return null;
|
||||
if (!started.getAndSet(true)) start();
|
||||
if (gateway == null) return null;
|
||||
InetAddress internal = gateway.getLocalAddress();
|
||||
if(internal == null) return null;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (internal == null) return null;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Internal address " + getHostAddress(internal));
|
||||
boolean succeeded = false;
|
||||
InetAddress external = null;
|
||||
try {
|
||||
succeeded = gateway.addPortMapping(port, port,
|
||||
getHostAddress(internal), "TCP", "TCP");
|
||||
if(succeeded) {
|
||||
if (succeeded) {
|
||||
shutdownManager.addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
deleteMapping(port);
|
||||
@@ -49,14 +49,14 @@ class PortMapperImpl implements PortMapper {
|
||||
});
|
||||
}
|
||||
String externalString = gateway.getExternalIPAddress();
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("External address " + externalString);
|
||||
if(externalString != null)
|
||||
if (externalString != null)
|
||||
external = InetAddress.getByName(externalString);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(SAXException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (SAXException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
return new MappingResult(internal, external, port, succeeded);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class PortMapperImpl implements PortMapper {
|
||||
private String getHostAddress(InetAddress a) {
|
||||
String addr = a.getHostAddress();
|
||||
int percent = addr.indexOf('%');
|
||||
if(percent == -1) return addr;
|
||||
if (percent == -1) return addr;
|
||||
return addr.substring(0, percent);
|
||||
}
|
||||
|
||||
@@ -72,12 +72,12 @@ class PortMapperImpl implements PortMapper {
|
||||
GatewayDiscover d = new GatewayDiscover();
|
||||
try {
|
||||
d.discover();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(SAXException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(ParserConfigurationException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (SAXException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (ParserConfigurationException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
gateway = d.getValidGateway();
|
||||
}
|
||||
@@ -85,12 +85,12 @@ class PortMapperImpl implements PortMapper {
|
||||
private void deleteMapping(int port) {
|
||||
try {
|
||||
gateway.deletePortMapping(port, "TCP");
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Deleted mapping for port " + port);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(SAXException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (SAXException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.pollingInterval = pollingInterval;
|
||||
if(maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
socketTimeout = Integer.MAX_VALUE;
|
||||
else socketTimeout = maxIdleTime * 2;
|
||||
}
|
||||
@@ -80,32 +80,32 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
protected void bind() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(!running) return;
|
||||
if (!running) return;
|
||||
ServerSocket ss = null;
|
||||
for(SocketAddress addr : getLocalSocketAddresses()) {
|
||||
for (SocketAddress addr : getLocalSocketAddresses()) {
|
||||
try {
|
||||
ss = new ServerSocket();
|
||||
ss.bind(addr);
|
||||
break;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Failed to bind " + addr);
|
||||
tryToClose(ss);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(ss == null || !ss.isBound()) {
|
||||
if (ss == null || !ss.isBound()) {
|
||||
LOG.info("Could not bind server socket");
|
||||
return;
|
||||
}
|
||||
if(!running) {
|
||||
if (!running) {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
socket = ss;
|
||||
SocketAddress local = ss.getLocalSocketAddress();
|
||||
setLocalSocketAddress((InetSocketAddress) local);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Listening on " + local);
|
||||
callback.pollNow();
|
||||
acceptContactConnections();
|
||||
}
|
||||
@@ -114,9 +114,9 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
|
||||
protected void tryToClose(ServerSocket ss) {
|
||||
try {
|
||||
if(ss != null) ss.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (ss != null) ss.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,17 +134,17 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
|
||||
private void acceptContactConnections() {
|
||||
while(isRunning()) {
|
||||
while (isRunning()) {
|
||||
Socket s;
|
||||
try {
|
||||
s = socket.accept();
|
||||
s.setSoTimeout(socketTimeout);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
// This is expected when the socket is closed
|
||||
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Connection from " + s.getRemoteSocketAddress());
|
||||
TcpTransportConnection conn = new TcpTransportConnection(this, s);
|
||||
callback.incomingConnectionCreated(conn);
|
||||
@@ -169,26 +169,26 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
|
||||
public void poll(Collection<ContactId> connected) {
|
||||
if(!isRunning()) return;
|
||||
for(ContactId c : callback.getRemoteProperties().keySet())
|
||||
if(!connected.contains(c)) connectAndCallBack(c);
|
||||
if (!isRunning()) return;
|
||||
for (ContactId c : callback.getRemoteProperties().keySet())
|
||||
if (!connected.contains(c)) connectAndCallBack(c);
|
||||
}
|
||||
|
||||
private void connectAndCallBack(final ContactId c) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
DuplexTransportConnection d = createConnection(c);
|
||||
if(d != null) callback.outgoingConnectionCreated(c, d);
|
||||
if (d != null) callback.outgoingConnectionCreated(c, d);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public DuplexTransportConnection createConnection(ContactId c) {
|
||||
if(!isRunning()) return null;
|
||||
if (!isRunning()) return null;
|
||||
InetSocketAddress remote = getRemoteSocketAddress(c);
|
||||
if(remote == null) return null;
|
||||
if(!isConnectable(remote)) {
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (remote == null) return null;
|
||||
if (!isConnectable(remote)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
SocketAddress local = socket.getLocalSocketAddress();
|
||||
LOG.info(remote + " is not connectable from " + local);
|
||||
}
|
||||
@@ -196,37 +196,37 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
Socket s = new Socket();
|
||||
try {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + remote);
|
||||
s.connect(remote);
|
||||
s.setSoTimeout(socketTimeout);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + remote);
|
||||
return new TcpTransportConnection(this, s);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Could not connect to " + remote);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + remote);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private InetSocketAddress getRemoteSocketAddress(ContactId c) {
|
||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||
if(p == null) return null;
|
||||
if (p == null) return null;
|
||||
return parseSocketAddress(p.get("address"), p.get("port"));
|
||||
}
|
||||
|
||||
protected InetSocketAddress parseSocketAddress(String addr, String port) {
|
||||
if(StringUtils.isNullOrEmpty(addr)) return null;
|
||||
if(StringUtils.isNullOrEmpty(port)) return null;
|
||||
if (StringUtils.isNullOrEmpty(addr)) return null;
|
||||
if (StringUtils.isNullOrEmpty(port)) return null;
|
||||
// Ensure getByName() won't perform a DNS lookup
|
||||
if(!DOTTED_QUAD.matcher(addr).matches()) return null;
|
||||
if (!DOTTED_QUAD.matcher(addr).matches()) return null;
|
||||
try {
|
||||
InetAddress a = InetAddress.getByName(addr);
|
||||
int p = Integer.parseInt(port);
|
||||
return new InetSocketAddress(a, p);
|
||||
} catch(UnknownHostException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.warning("Invalid address: " + addr);
|
||||
} catch (UnknownHostException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.warning("Invalid address: " + addr);
|
||||
return null;
|
||||
} catch(NumberFormatException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.warning("Invalid port: " + port);
|
||||
} catch (NumberFormatException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.warning("Invalid port: " + port);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -244,12 +244,12 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
List<NetworkInterface> ifaces;
|
||||
try {
|
||||
ifaces = Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
} catch(SocketException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (SocketException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<InetAddress> addrs = new ArrayList<InetAddress>();
|
||||
for(NetworkInterface iface : ifaces)
|
||||
for (NetworkInterface iface : ifaces)
|
||||
addrs.addAll(Collections.list(iface.getInetAddresses()));
|
||||
return addrs;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class TcpTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ class TcpTransportConnection implements DuplexTransportConnection {
|
||||
}
|
||||
|
||||
public void dispose(boolean exception) throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
String oldAddress = p.get("address"), oldPort = p.get("port");
|
||||
InetSocketAddress old = parseSocketAddress(oldAddress, oldPort);
|
||||
List<SocketAddress> addrs = new LinkedList<SocketAddress>();
|
||||
for(InetAddress a : getLocalIpAddresses()) {
|
||||
if(isAcceptableAddress(a)) {
|
||||
for (InetAddress a : getLocalIpAddresses()) {
|
||||
if (isAcceptableAddress(a)) {
|
||||
// If this is the old address, try to use the same port
|
||||
if(old != null && old.getAddress().equals(a))
|
||||
if (old != null && old.getAddress().equals(a))
|
||||
addrs.add(0, new InetSocketAddress(a, old.getPort()));
|
||||
addrs.add(new InetSocketAddress(a, 0));
|
||||
}
|
||||
@@ -49,9 +49,9 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
// Accept interfaces with local addresses that can be port-mapped
|
||||
int port = old == null ? chooseEphemeralPort() : old.getPort();
|
||||
mappingResult = portMapper.map(port);
|
||||
if(mappingResult != null && mappingResult.isUsable()) {
|
||||
if (mappingResult != null && mappingResult.isUsable()) {
|
||||
InetSocketAddress a = mappingResult.getInternal();
|
||||
if(a.getAddress() instanceof Inet4Address) addrs.add(a);
|
||||
if (a.getAddress() instanceof Inet4Address) addrs.add(a);
|
||||
}
|
||||
return addrs;
|
||||
}
|
||||
@@ -71,15 +71,15 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
|
||||
@Override
|
||||
protected boolean isConnectable(InetSocketAddress remote) {
|
||||
if(remote.getPort() == 0) return false;
|
||||
if (remote.getPort() == 0) return false;
|
||||
return isAcceptableAddress(remote.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||
if(mappingResult != null && mappingResult.isUsable()) {
|
||||
if (mappingResult != null && mappingResult.isUsable()) {
|
||||
// Advertise the external address to contacts
|
||||
if(a.equals(mappingResult.getInternal()))
|
||||
if (a.equals(mappingResult.getInternal()))
|
||||
a = mappingResult.getExternal();
|
||||
}
|
||||
TransportProperties p = new TransportProperties();
|
||||
|
||||
Reference in New Issue
Block a user