mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Split onError() into two methods.
This commit is contained in:
@@ -20,7 +20,6 @@ import java.io.IOException;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -51,7 +50,7 @@ class IncomingSimplexSyncConnection extends SyncConnection implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Read and recognise the tag
|
// Read and recognise the tag
|
||||||
byte[] tag = null;
|
byte[] tag;
|
||||||
StreamContext ctx;
|
StreamContext ctx;
|
||||||
try {
|
try {
|
||||||
tag = readTag(reader.getInputStream());
|
tag = readTag(reader.getInputStream());
|
||||||
@@ -63,24 +62,24 @@ class IncomingSimplexSyncConnection extends SyncConnection implements Runnable {
|
|||||||
}
|
}
|
||||||
} catch (IOException | DbException e) {
|
} catch (IOException | DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
onError(false, tag);
|
onError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctx == null) {
|
if (ctx == null) {
|
||||||
LOG.info("Unrecognised tag");
|
LOG.info("Unrecognised tag");
|
||||||
onError(false, tag);
|
onError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ContactId contactId = ctx.getContactId();
|
ContactId contactId = ctx.getContactId();
|
||||||
if (contactId == null) {
|
if (contactId == null) {
|
||||||
LOG.warning("Received rendezvous stream, expected contact");
|
LOG.warning("Received rendezvous stream, expected contact");
|
||||||
onError(true, tag);
|
onError(tag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctx.isHandshakeMode()) {
|
if (ctx.isHandshakeMode()) {
|
||||||
// TODO: Support handshake mode for contacts
|
// TODO: Support handshake mode for contacts
|
||||||
LOG.warning("Received handshake tag, expected rotation mode");
|
LOG.warning("Received handshake tag, expected rotation mode");
|
||||||
onError(true, tag);
|
onError(tag);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -94,15 +93,17 @@ class IncomingSimplexSyncConnection extends SyncConnection implements Runnable {
|
|||||||
reader.dispose(false, true);
|
reader.dispose(false, true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
onError(true, tag);
|
onError(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onError(boolean recognised, @Nullable byte[] tag) {
|
private void onError() {
|
||||||
if (recognised) {
|
disposeOnError(reader, false);
|
||||||
markTagAsRecognisedIfRequired(true, requireNonNull(tag));
|
}
|
||||||
}
|
|
||||||
disposeOnError(reader, recognised);
|
private void onError(byte[] tag) {
|
||||||
|
markTagAsRecognisedIfRequired(true, tag);
|
||||||
|
disposeOnError(reader, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markTagAsRecognisedIfRequired(boolean exception, byte[] tag) {
|
private void markTagAsRecognisedIfRequired(boolean exception, byte[] tag) {
|
||||||
|
|||||||
Reference in New Issue
Block a user