From d5bf7194f6c2e9fbc924b5e5b92a3ae345f9426f Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 6 Apr 2016 09:51:57 +0100 Subject: [PATCH] Register outgoing duplex connection after reading tag. This prevents the connection from being registered until the contact responds, which ensures we're actually connected to the contact. --- .../plugins/ConnectionManagerImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java index 2eb502cf1e..3c9f5fb48e 100644 --- a/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java +++ b/briar-core/src/org/briarproject/plugins/ConnectionManagerImpl.java @@ -191,7 +191,7 @@ class ConnectionManagerImpl implements ConnectionManager { } if (ctx == null) { LOG.warning("Could not allocate stream context"); - disposeWriter(false); + disposeWriter(true); return; } connectionRegistry.registerConnection(contactId, transportId); @@ -286,7 +286,7 @@ class ConnectionManagerImpl implements ConnectionManager { } if (ctx == null) { LOG.warning("Could not allocate stream context"); - disposeWriter(false); + disposeWriter(true); return; } try { @@ -351,10 +351,9 @@ class ConnectionManagerImpl implements ConnectionManager { } if (ctx == null) { LOG.warning("Could not allocate stream context"); - disposeWriter(false); + disposeWriter(true); return; } - connectionRegistry.registerConnection(contactId, transportId); // Start the incoming session on another thread ioExecutor.execute(new Runnable() { public void run() { @@ -369,8 +368,6 @@ class ConnectionManagerImpl implements ConnectionManager { } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); disposeWriter(true); - } finally { - connectionRegistry.unregisterConnection(contactId, transportId); } } @@ -382,17 +379,17 @@ class ConnectionManagerImpl implements ConnectionManager { ctx = keyManager.getStreamContext(transportId, tag); } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); - disposeReader(true, true); + disposeReader(true, false); return; } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); - disposeReader(true, true); + disposeReader(true, false); return; } // Unrecognised tags are suspicious in this case if (ctx == null) { LOG.warning("Unrecognised tag for returning stream"); - disposeReader(true, true); + disposeReader(true, false); return; } // Check that the stream comes from the expected contact @@ -401,6 +398,7 @@ class ConnectionManagerImpl implements ConnectionManager { disposeReader(true, true); return; } + connectionRegistry.registerConnection(contactId, transportId); try { // Create and run the incoming session incomingSession = createIncomingSession(ctx, reader); @@ -409,6 +407,8 @@ class ConnectionManagerImpl implements ConnectionManager { } catch (IOException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); disposeReader(true, true); + } finally { + connectionRegistry.unregisterConnection(contactId, transportId); } } -- GitLab