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