mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
When cancelling, assume nothing is instantiated
This commit is contained in:
@@ -9,8 +9,8 @@ import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
||||
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -60,16 +60,20 @@ public class CustodianTaskImpl extends ReturnShardTaskImpl
|
||||
@Override
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// The reason here is OTHER rather than NO_CONNECTION because
|
||||
// the socket could fail to close because it is already closed
|
||||
observer.onStateChanged(new CustodianTask.State.Failure(
|
||||
State.Failure.Reason.OTHER));
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
// The reason here is OTHER rather than NO_CONNECTION because
|
||||
// the socket could fail to close because it is already closed
|
||||
observer.onStateChanged(new CustodianTask.State.Failure(
|
||||
State.Failure.Reason.OTHER));
|
||||
}
|
||||
}
|
||||
if (observer != null) {
|
||||
observer.onStateChanged(
|
||||
new CustodianTask.State.Failure(State.Failure.Reason.OTHER));
|
||||
}
|
||||
observer.onStateChanged(
|
||||
new CustodianTask.State.Failure(State.Failure.Reason.OTHER));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +150,7 @@ public class CustodianTaskImpl extends ReturnShardTaskImpl
|
||||
|
||||
private void receiveAck() {
|
||||
try {
|
||||
InputStream inputStream = socket.getInputStream();
|
||||
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
|
||||
// InputStream inputStream = streamReaderFactory
|
||||
// .createContactExchangeStreamReader(socket.getInputStream(),
|
||||
// sharedSecret);
|
||||
|
||||
@@ -60,9 +60,8 @@ public class ReturnShardTaskImpl {
|
||||
return message;
|
||||
}
|
||||
|
||||
byte[] read(InputStream inputStream, int length)
|
||||
byte[] read(DataInputStream dis, int length)
|
||||
throws IOException {
|
||||
DataInputStream dis = new DataInputStream(inputStream);
|
||||
byte[] output = new byte[length];
|
||||
dis.readFully(output);
|
||||
return output;
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -28,7 +29,6 @@ import static java.util.logging.Logger.getLogger;
|
||||
public class SecretOwnerTaskImpl extends ReturnShardTaskImpl
|
||||
implements SecretOwnerTask {
|
||||
|
||||
// private final Executor ioExecutor;
|
||||
private boolean cancelled = false;
|
||||
private InetSocketAddress socketAddress;
|
||||
private ClientHelper clientHelper;
|
||||
@@ -43,9 +43,8 @@ public class SecretOwnerTaskImpl extends ReturnShardTaskImpl
|
||||
|
||||
@Inject
|
||||
SecretOwnerTaskImpl(AuthenticatedCipher cipher, CryptoComponent crypto,
|
||||
@IoExecutor Executor ioExecutor, ClientHelper clientHelper) {
|
||||
ClientHelper clientHelper) {
|
||||
super(cipher, crypto);
|
||||
// this.ioExecutor = ioExecutor;
|
||||
this.clientHelper = clientHelper;
|
||||
// this.streamReaderFactory = streamReaderFactory;
|
||||
// this.streamWriterFactory = streamWriterFactory;
|
||||
@@ -101,7 +100,7 @@ public class SecretOwnerTaskImpl extends ReturnShardTaskImpl
|
||||
LOG.info("Client connected");
|
||||
observer.onStateChanged(new State.ReceivingShard());
|
||||
|
||||
InputStream inputStream = socket.getInputStream();
|
||||
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
|
||||
|
||||
AgreementPublicKey remotePublicKey =
|
||||
new AgreementPublicKey(
|
||||
@@ -156,11 +155,16 @@ public class SecretOwnerTaskImpl extends ReturnShardTaskImpl
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
LOG.info("Cancel called, failing...");
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
if (serverSocket != null) {
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
observer.onStateChanged(new State.Failure());
|
||||
}
|
||||
}
|
||||
|
||||
if (observer != null) {
|
||||
observer.onStateChanged(new State.Failure());
|
||||
}
|
||||
observer.onStateChanged(new State.Failure());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user