Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

more server interaction debug output #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class NetworkHelper {

private static final String LOG_TAG = "ITOInfectedUUIDRepository";
private static final String LOG_TAG = "ITONetworkHelper";
public static final String BASE_URL = "https://tcn.ito-app.org/tcnreport";

private static final int SIGNATURELENGTH = 64;
Expand All @@ -44,6 +44,7 @@ public static List<byte[]> refreshInfectedUUIDs() {
url = new URL(BASE_URL);
else
url = new URL(BASE_URL + "?from=" + lastReportHashForServer.lastReportHash);
Log.d(LOG_TAG, "Query using: " + url.toString());
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.addRequestProperty("Accept", "application/octet-stream");
InputStream in = new BlockingInputStream(urlConnection.getInputStream());
Expand Down Expand Up @@ -79,6 +80,7 @@ public static List<byte[]> refreshInfectedUUIDs() {
urlConnection.disconnect();
}
}
Log.d(LOG_TAG, "Found " + reports.size() + " new Reports");
if (reports.size() > 0) {
byte[] lastreport = reports.get(reports.size() - 1);

Expand All @@ -92,9 +94,9 @@ public static List<byte[]> refreshInfectedUUIDs() {


public static void publishReports(List<byte[]> reports) throws IOException {

HttpURLConnection urlConnection = null;
for (byte[] report : reports) // FIXME: validate return code
for (byte[] report : reports) { // FIXME: validate return code
Log.d(LOG_TAG, "Publishing " + byte2Hex(report));
try {
URL url = new URL(BASE_URL);
urlConnection = (HttpURLConnection) url.openConnection();
Expand All @@ -103,7 +105,9 @@ public static void publishReports(List<byte[]> reports) throws IOException {
OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
outputStream.write(report);
outputStream.close();

if (urlConnection.getResponseCode() != 200) {
throw new RuntimeException("Response Code was " + urlConnection.getResponseCode());
}
InputStream inputStream = urlConnection.getInputStream();
inputStream.read();
inputStream.close();
Expand All @@ -114,5 +118,6 @@ public static void publishReports(List<byte[]> reports) throws IOException {
if (urlConnection != null)
urlConnection.disconnect();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public CheckServerTask(ItoDBHelper itoDBHelper) {
@RequiresApi(api = 24)
@Override
protected Void doInBackground(Void... voids) {
Log.d(LOG_TAG, "Check Server Task started");
try {
List<byte[]> reports = NetworkHelper.refreshInfectedUUIDs();
reports.stream().filter(x -> TCNProtoUtil.verifySignatureOfReportCorrect(x)).forEach(x -> TCNProtoUtil.generateAllTCNsFromReport(x, tcn -> this.checkInfection(tcn)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

class PublishBeaconsTask extends AsyncTask<Void, Void, Void> {
private static final String LOG_TAG = "PublishBeaconsTask";
private static final String LOG_TAG = "ITOPublishTask";
private List<byte[]> report;
private long from;
private long to;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void setDistanceCallback(DistanceCallback distanceCallback) {
@Override
public void publishBeaconUUIDs(long from, long to, PublishUUIDsCallback callback) {
// todo use from & to ?
Log.d(LOG_TAG, "Publishing Reports...");
List<byte[]> reports = TCNProtoUtil.loadAllRatchets().stream().map(ratchet -> ratchet.generateReport(ratchet.getRatchetTickCount())).collect(Collectors.toList());

new PublishBeaconsTask(reports, callback).execute();
Expand Down