Skip to content

Commit

Permalink
Switch to official Corona-Warn-App servers
Browse files Browse the repository at this point in the history
Adds a number of changes needed to support and perform the switch to teh
offficial Corona-Warn-App servers:

1. Switches from using the S3 protocol used by the test download servers
to the REST protocol used by the official download servers. Info about
the REST API can be found here:

https://raw.githubusercontent.com/corona-warn-app/cwa-server/master/services/distribution/api_v1.json

2. Adds a settings file upgrade process and upgrades the file to use the
new server locations.

A number of other changes have been included to make things work better
generally:

3. The upload and download error label can now be cleared by clicking on
it. Without this, errors would be left there indefinitely.

4. The info banner on the main app page warning about the fact that test
servers are being used has been removed.

5. Some small change to the upload and verification code to ensure it
doesn't assume an http connection.

6. All of the S3 access code files have been removed since they're not
needed anymore.
  • Loading branch information
llewelld committed Sep 20, 2020
1 parent 0b960fd commit 684be27
Show file tree
Hide file tree
Showing 27 changed files with 556 additions and 1,382 deletions.
12 changes: 2 additions & 10 deletions contrac.pro
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,12 @@ HEADERS += \
src/download.h \
src/downloadconfig.h \
src/imageprovider.h \
src/s3access.h \
src/s3/s3.h \
src/s3/s3internal.h \
src/s3/s3xml.h \
contracd/src/exposuresummary.h \
contracd/src/exposureinformation.h \
contracd/src/temporaryexposurekey.h \
contracd/src/exposureconfiguration.h \
contracd/src/zipistreambuffer.h \
src/serveraccess.h \
src/settings.h \
src/upload.h

Expand All @@ -70,17 +67,12 @@ SOURCES += \
src/contactmodel.cpp \
src/download.cpp \
src/imageprovider.cpp \
src/s3access.cpp \
src/s3/s3bucket.c \
src/s3/s3digest.c \
src/s3/s3ops.c \
src/s3/s3string.c \
src/s3/s3xml.c \
contracd/src/exposuresummary.cpp \
contracd/src/exposureinformation.cpp \
contracd/src/temporaryexposurekey.cpp \
contracd/src/exposureconfiguration.cpp \
contracd/src/zipistreambuffer.cpp \
src/serveraccess.cpp \
src/settings.cpp \
src/upload.cpp

Expand Down
63 changes: 49 additions & 14 deletions contracd/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@

#include "settings.h"

#define SETTINGS_MAX_VERSION (0)

Settings * Settings::instance = nullptr;

Settings::Settings(QObject *parent) : QObject(parent),
settings(this)
m_settings(this)
{
m_tracingKey = settings.value(QStringLiteral("keys/tracingKey"), QVariant(QByteArray())).toByteArray();
m_enabled = settings.value(QStringLiteral("state/enabled"), false).toBool();
m_sent = settings.value(QStringLiteral("state/sent"), 0).toUInt();
m_received = settings.value(QStringLiteral("state/received"), 0).toUInt();
m_txPower = static_cast<qint8>(settings.value(QStringLiteral("configuration/txPower"), -30).toInt());
m_rssiCorrection = static_cast<qint8>(settings.value(QStringLiteral("configuration/rssiCorretion"), 5).toInt());
m_tracingKey = m_settings.value(QStringLiteral("keys/tracingKey"), QVariant(QByteArray())).toByteArray();
m_enabled = m_settings.value(QStringLiteral("state/enabled"), false).toBool();
m_sent = m_settings.value(QStringLiteral("state/sent"), 0).toUInt();
m_received = m_settings.value(QStringLiteral("state/received"), 0).toUInt();
m_txPower = static_cast<qint8>(m_settings.value(QStringLiteral("configuration/txPower"), -30).toInt());
m_rssiCorrection = static_cast<qint8>(m_settings.value(QStringLiteral("configuration/rssiCorretion"), 5).toInt());

qDebug() << "Settings created: " << m_settings.fileName();

qDebug() << "Settings created: " << settings.fileName();
upgrade();
}

Settings::~Settings()
{
settings.setValue(QStringLiteral("keys/tracingKey"), m_tracingKey);
settings.setValue(QStringLiteral("state/enabled"), m_enabled);
settings.setValue(QStringLiteral("state/sent"), m_sent);
settings.setValue(QStringLiteral("state/received"), m_received);
settings.setValue(QStringLiteral("configuration/txPower"), m_txPower);
settings.setValue(QStringLiteral("configuration/rssiCorrection"), m_rssiCorrection);
m_settings.setValue(QStringLiteral("keys/tracingKey"), m_tracingKey);
m_settings.setValue(QStringLiteral("state/enabled"), m_enabled);
m_settings.setValue(QStringLiteral("state/sent"), m_sent);
m_settings.setValue(QStringLiteral("state/received"), m_received);
m_settings.setValue(QStringLiteral("configuration/txPower"), m_txPower);
m_settings.setValue(QStringLiteral("configuration/rssiCorrection"), m_rssiCorrection);

instance = nullptr;
qDebug() << "Deleted settings";
Expand Down Expand Up @@ -129,3 +133,34 @@ void Settings::setRssiCorrection(qint8 rssiCorrection)
emit rssiCorrectionChanged();
}
}

bool Settings::upgrade()
{
quint32 version;
bool success = true;

if (m_settings.allKeys().size() == 0) {
version = SETTINGS_MAX_VERSION;
qDebug() << "Creating new settings file with version: " << SETTINGS_MAX_VERSION;
}
else {
version = m_settings.value(QStringLiteral("application/settingsVersion"), 0).toUInt();
qDebug() << "Existing settings file version: " << version;
}

switch (version) {
default:
case SETTINGS_MAX_VERSION:
// File upgraded
// Do nothing
break;
}

if (success) {
m_settings.setValue(QStringLiteral("application/version"), VERSION);
m_settings.setValue(QStringLiteral("application/settingsVersion"), SETTINGS_MAX_VERSION);
}

return success;
}

5 changes: 4 additions & 1 deletion contracd/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ public slots:
void setTxPower(qint8 txPower);
void setRssiCorrection(qint8 rssiCorrection);

private:
bool upgrade();

private:
static Settings * instance;
QSettings settings;
QSettings m_settings;

QByteArray m_tracingKey;
bool m_enabled;
Expand Down
17 changes: 8 additions & 9 deletions qml/pages/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ Page {
title: qsTrId("contrac-main_title")
}

Label {
width: parent.width - 2 * Theme.horizontalPageMargin
x: Theme.horizontalPageMargin
//% "Using the Google/Apple API and a Corona Warn App test server. Uploads/downloads are only for testing."
text: qsTrId("contrac-main_info")
color: Theme.highlightColor
wrapMode: Text.Wrap
}

SectionHeader {
//% "Status"
text: qsTrId("contrac-main_he_status")
Expand Down Expand Up @@ -187,6 +178,14 @@ Page {
}
}
color: Theme.highlightColor

MouseArea {
anchors.fill: parent
onClicked: {
download.clearError()
upload.clearError()
}
}
}
}

Expand Down
38 changes: 25 additions & 13 deletions src/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <QStandardPaths>

#include "settings.h"
#include "s3access.h"
#include "serveraccess.h"
#include "downloadconfig.h"

#include "download.h"

Download::Download(QObject *parent) : QObject(parent)
, m_s3Access(new S3Access(this))
, m_serverAccess(new ServerAccess(this))
, m_fileQueue()
, m_latest()
, m_downloading(false)
Expand All @@ -19,10 +19,10 @@ Download::Download(QObject *parent) : QObject(parent)
, m_status(StatusIdle)
, m_downloadConfig(new DownloadConfig(this))
{
m_s3Access->setId("accessKey1");
m_s3Access->setSecret("verySecretKey1");
m_s3Access->setBaseUrl(Settings::getInstance().downloadServer());
m_s3Access->setBucket("cwa");
m_serverAccess->setId("accessKey1");
m_serverAccess->setSecret("verySecretKey1");
m_serverAccess->setBaseUrl(Settings::getInstance().downloadServer());
m_serverAccess->setBucket("cwa");

m_latest = Settings::getInstance().summaryUpdated().date();

Expand Down Expand Up @@ -55,14 +55,13 @@ Q_INVOKABLE void Download::downloadLatest()
}
}


void Download::configDownloadComplete(QString const &)
{
switch (m_downloadConfig->error()) {
case DownloadConfig::ErrorNone:
qDebug() << "Requesting keys";
setStatus(StatusDownloadingKeys);
m_s3Access->setBaseUrl(Settings::getInstance().downloadServer());
m_serverAccess->setBaseUrl(Settings::getInstance().downloadServer());
startNextDateDownload();
break;
default:
Expand Down Expand Up @@ -133,8 +132,8 @@ void Download::startNextFileDownload() {

QString filename = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/download/" + file;
qDebug() << "Saving to:" << filename;
S3GetFileResult *result = m_s3Access->getFile(key, filename);
connect(result, &S3Result::finished, this, [this, result, date, filename]() {
ServerGetFileResult *result = m_serverAccess->getFile(key, filename);
connect(result, &ServerResult::finished, this, [this, result, date, filename]() {
qDebug() << "Finished downloading:" << m_fileQueue[date].first();

++m_filesReceived;
Expand Down Expand Up @@ -187,9 +186,9 @@ void Download::startDateDownload(QDate const &date)
{
qDebug() << "Starting date download:" << date;

QString url = "version/v1/diagnosis-keys/country/DE/date/" + date.toString("yyyy-MM-dd") + "/hour/";
S3ListResult *result = m_s3Access->list(url);
connect(result, &S3ListResult::finished, this, [this, result, date]() {
QString url = "version/v1/diagnosis-keys/country/DE/date/" + date.toString("yyyy-MM-dd") + "/hour";
ServerListResult *result = m_serverAccess->list(url);
connect(result, &ServerListResult::finished, this, [this, result, date]() {
QStringList keys;

switch (result->error()) {
Expand Down Expand Up @@ -333,3 +332,16 @@ QStringList Download::fileList() const
return result;
}

Q_INVOKABLE void Download::clearError()
{
if (m_error != ErrorNone) {
qDebug() << "Clearing download error status";
m_error = ErrorNone;

if (m_status == StatusError) {
m_status = StatusIdle;
emit statusChanged();
}
emit errorChanged();
}
}
5 changes: 3 additions & 2 deletions src/download.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "../contracd/src/exposureconfiguration.h"

class S3Access;
class ServerAccess;
class DownloadConfig;

class Download : public QObject
Expand Down Expand Up @@ -45,6 +45,7 @@ class Download : public QObject
float progress() const;
Status status() const;
ErrorType error() const;
Q_INVOKABLE void clearError();
ExposureConfiguration const *config() const;

signals:
Expand Down Expand Up @@ -73,7 +74,7 @@ private slots:
void setStatusError(ErrorType error);

private:
S3Access *m_s3Access;
ServerAccess *m_serverAccess;
QMap<QDate, QStringList> m_fileQueue;
QDate m_latest;
bool m_downloading;
Expand Down
31 changes: 19 additions & 12 deletions src/downloadconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#include <QStandardPaths>
#include <QDir>

#include "../contracd/src/exposureconfiguration.h"
#include "../contracd/src/zipistreambuffer.h"

#include "settings.h"
#include "s3access.h"
#include "serveraccess.h"
#include "proto/applicationConfiguration.pb.h"

#include "downloadconfig.h"

#define CONFIG_FILENAME QStringLiteral("/download/file.config")
#define CONFIG_DIRECTORY QStringLiteral("/download/")
#define CONFIG_LEAFNAME QStringLiteral("file.config")

DownloadConfig::DownloadConfig(QObject *parent) : QObject(parent)
, m_s3Access(new S3Access(this))
, m_serverAccess(new ServerAccess(this))
, m_downloading(false)
, m_status(StatusIdle)
, m_configuration(new ExposureConfiguration(this))
{
m_s3Access->setId("accessKey1");
m_s3Access->setSecret("verySecretKey1");
m_s3Access->setBaseUrl(Settings::getInstance().downloadServer());
m_s3Access->setBucket("cwa");
m_serverAccess->setId("accessKey1");
m_serverAccess->setSecret("verySecretKey1");
m_serverAccess->setBaseUrl(Settings::getInstance().downloadServer());
m_serverAccess->setBucket("cwa");

connect(m_configuration, &ExposureConfiguration::minimumRiskScoreChanged, this, &DownloadConfig::configChanged);
connect(m_configuration, &ExposureConfiguration::attenuationScoresChanged, this, &DownloadConfig::configChanged);
Expand All @@ -41,14 +43,19 @@ Q_INVOKABLE void DownloadConfig::downloadLatest()
qDebug() << "Requesting configuration";

if (!m_downloading) {
m_s3Access->setBaseUrl(Settings::getInstance().downloadServer());
m_serverAccess->setBaseUrl(Settings::getInstance().downloadServer());
setStatus(StatusDownloading);

QString key = "version/v1/configuration/country/DE/app_config";
QString filename = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + CONFIG_FILENAME;
QString filename = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + CONFIG_DIRECTORY;
QDir dir;
qDebug() << "Creating directory:" << filename;
dir.mkpath(filename);
filename += CONFIG_LEAFNAME;
qDebug() << "Saving to:" << filename;
S3GetFileResult *result = m_s3Access->getFile(key, filename);
connect(result, &S3Result::finished, this, [this, result, filename]() {

ServerGetFileResult *result = m_serverAccess->getFile(key, filename);
connect(result, &ServerResult::finished, this, [this, result, filename]() {
qDebug() << "Finished downloading configuration";
finalise();
switch (result->error()) {
Expand Down Expand Up @@ -127,7 +134,7 @@ bool DownloadConfig::downloading() const

bool DownloadConfig::loadConfig()
{
QString filename = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + CONFIG_FILENAME;
QString filename = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + CONFIG_DIRECTORY + CONFIG_LEAFNAME;

QuaZip quazip(filename);
bool result = true;
Expand Down
4 changes: 2 additions & 2 deletions src/downloadconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <QObject>

class S3Access;
class ServerAccess;
class ExposureConfiguration;

namespace diagnosis {
Expand Down Expand Up @@ -56,7 +56,7 @@ private slots:
void applyConfiguration(diagnosis::ApplicationConfiguration const &appConfig);

private:
S3Access *m_s3Access;
ServerAccess *m_serverAccess;
bool m_downloading;
Status m_status;
ErrorType m_error;
Expand Down
8 changes: 4 additions & 4 deletions src/harbour-contrac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ int main(int argc, char *argv[])
qDebug() << "VERSION_MINOR:" << VERSION_MINOR;
qDebug() << "VERSION_BUILD:" << VERSION_BUILD;

// Needed for Settings save/load
qRegisterMetaType<ExposureSummary>();
qRegisterMetaTypeStreamOperators<ExposureSummary>("ExposureSummary");

Settings::instantiate(app);

qmlRegisterType<DBusProxy>("uk.co.flypig.contrac", 1, 0, "DBusProxy");
Expand All @@ -53,10 +57,6 @@ int main(int argc, char *argv[])

qmlRegisterSingletonType<Settings>("uk.co.flypig.contrac", 1, 0, "Settings", Settings::provider);

// Needed for Settings save/load
qRegisterMetaType<ExposureSummary>();
qRegisterMetaTypeStreamOperators<ExposureSummary>("ExposureSummary");

QQuickView *view = SailfishApp::createView();
// The engine takes ownership of the ImageProvider
view->engine()->addImageProvider(QLatin1String("contrac"), new ImageProvider(Settings::getInstance()));
Expand Down
Loading

0 comments on commit 684be27

Please sign in to comment.