mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Allow duplex connections' dispose() methods to throw IOExceptions.
This commit is contained in:
@@ -28,5 +28,5 @@ public interface DuplexTransportConnection {
|
||||
* of an exception and the second argument indicates whether the connection
|
||||
* was recognised, which may affect how resources are disposed of.
|
||||
*/
|
||||
void dispose(boolean exception, boolean recognised);
|
||||
void dispose(boolean exception, boolean recognised) throws IOException;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ public interface SimplexTransportReader {
|
||||
* argument indicates whether the reader is being closed because of an
|
||||
* exception and the second argument indicates whether the connection was
|
||||
* recognised, which may affect how resources are disposed of.
|
||||
* @throws IOException
|
||||
*/
|
||||
void dispose(boolean exception, boolean recognised) throws IOException;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public interface SimplexTransportWriter {
|
||||
* Closes the writer and disposes of any associated resources. The
|
||||
* argument indicates whether the writer is being closed because of an
|
||||
* exception, which may affect how resources are disposed of.
|
||||
* @throws IOException
|
||||
*/
|
||||
void dispose(boolean exception) throws IOException;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.sf.briar.plugins.bluetooth;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.microedition.io.StreamConnection;
|
||||
|
||||
@@ -12,9 +10,6 @@ import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
|
||||
class BluetoothTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BluetoothTransportConnection.class.getName());
|
||||
|
||||
private final StreamConnection stream;
|
||||
|
||||
BluetoothTransportConnection(StreamConnection stream) {
|
||||
@@ -33,11 +28,8 @@ class BluetoothTransportConnection implements DuplexTransportConnection {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void dispose(boolean exception, boolean recognised) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
}
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,11 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
|
||||
class SocketTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SocketTransportConnection.class.getName());
|
||||
|
||||
private final Socket socket;
|
||||
|
||||
SocketTransportConnection(Socket socket) {
|
||||
@@ -32,11 +27,8 @@ class SocketTransportConnection implements DuplexTransportConnection {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void dispose(boolean exception, boolean recognised) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
}
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.sf.briar.plugins.tor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
|
||||
@@ -12,9 +10,6 @@ import org.silvertunnel.netlib.api.NetSocket;
|
||||
|
||||
class TorTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(TorTransportConnection.class.getName());
|
||||
|
||||
private final NetSocket socket;
|
||||
|
||||
TorTransportConnection(NetSocket socket) {
|
||||
@@ -33,11 +28,8 @@ class TorTransportConnection implements DuplexTransportConnection {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void dispose(boolean exception, boolean recognised) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
}
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,11 @@ abstract class DuplexConnection implements DatabaseListener {
|
||||
private void dispose(boolean exception, boolean recognised) {
|
||||
if(disposed.getAndSet(true)) return;
|
||||
ByteUtils.erase(ctx.getSecret());
|
||||
transport.dispose(exception, recognised);
|
||||
try {
|
||||
transport.dispose(exception, recognised);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// This task runs on a database thread
|
||||
|
||||
@@ -127,21 +127,31 @@ class ConnectionDispatcherImpl implements ConnectionDispatcher {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
byte[] tag;
|
||||
try {
|
||||
byte[] tag = readTag(transport.getInputStream());
|
||||
ConnectionContext ctx = recogniser.acceptConnection(transportId,
|
||||
tag);
|
||||
if(ctx == null) {
|
||||
transport.dispose(false, false);
|
||||
} else {
|
||||
duplexConnFactory.createIncomingConnection(ctx, transport);
|
||||
}
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
transport.dispose(true, false);
|
||||
tag = readTag(transport.getInputStream());
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
dispose(true, false);
|
||||
return;
|
||||
}
|
||||
ConnectionContext ctx = null;
|
||||
try {
|
||||
ctx = recogniser.acceptConnection(transportId, tag);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
dispose(true, false);
|
||||
return;
|
||||
}
|
||||
if(ctx == null) dispose(false, false);
|
||||
else duplexConnFactory.createIncomingConnection(ctx, transport);
|
||||
}
|
||||
|
||||
private void dispose(boolean exception, boolean recognised) {
|
||||
try {
|
||||
transport.dispose(exception, recognised);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
|
||||
transport.dispose(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,11 @@ abstract class DuplexTest {
|
||||
d.dispose(false, true);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
d.dispose(true, true);
|
||||
try {
|
||||
d.dispose(true, true);
|
||||
} catch(IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +69,11 @@ abstract class DuplexTest {
|
||||
d.dispose(false, true);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
d.dispose(true, true);
|
||||
try {
|
||||
d.dispose(true, true);
|
||||
} catch(IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user