diff --git a/client/core/api/apiDefs.h b/client/core/api/apiDefs.h index 12c8051f1..151746a45 100644 --- a/client/core/api/apiDefs.h +++ b/client/core/api/apiDefs.h @@ -64,6 +64,10 @@ namespace apiDefs constexpr QLatin1String id("id"); constexpr QLatin1String orderId("order_id"); constexpr QLatin1String migrationCode("migration_code"); + + constexpr QLatin1String transactionId("transaction_id"); + + constexpr QLatin1String userCountryCode("user_country_code"); } const int requestTimeoutMsecs = 12 * 1000; // 12 secs diff --git a/client/core/controllers/gatewayController.cpp b/client/core/controllers/gatewayController.cpp index 213f137d2..8bc0939cd 100644 --- a/client/core/controllers/gatewayController.cpp +++ b/client/core/controllers/gatewayController.cpp @@ -150,7 +150,9 @@ ErrorCode GatewayController::post(const QString &endpoint, const QJsonObject api return true; }; - bypassProxy(endpoint, requestFunction, replyProcessingFunction); + auto serviceType = apiPayload.value(apiDefs::key::serviceType).toString(""); + auto userCountryCode = apiPayload.value(apiDefs::key::userCountryCode).toString(""); + bypassProxy(endpoint, serviceType, userCountryCode, requestFunction, replyProcessingFunction); } auto errorCode = apiUtils::checkNetworkReplyErrors(sslErrors, replyErrorString, replyError, httpStatusCode, encryptedResponseBody); @@ -168,7 +170,7 @@ ErrorCode GatewayController::post(const QString &endpoint, const QJsonObject api } } -QStringList GatewayController::getProxyUrls() +QStringList GatewayController::getProxyUrls(const QString &serviceType, const QString &userCountryCode) { QNetworkRequest request; request.setTransferTimeout(m_requestTimeoutMsecs); @@ -178,15 +180,25 @@ QStringList GatewayController::getProxyUrls() QList sslErrors; QNetworkReply *reply; - QStringList proxyStorageUrls; + QStringList baseUrls; if (m_isDevEnvironment) { - proxyStorageUrls = QString(DEV_S3_ENDPOINT).split(", "); + baseUrls = QString(DEV_S3_ENDPOINT).split(", "); } else { - proxyStorageUrls = QString(PROD_S3_ENDPOINT).split(", "); + baseUrls = QString(PROD_S3_ENDPOINT).split(", "); } QByteArray key = m_isDevEnvironment ? DEV_AGW_PUBLIC_KEY : PROD_AGW_PUBLIC_KEY; + QStringList proxyStorageUrls; + if (!serviceType.isEmpty()) { + for (const auto &baseUrl : baseUrls) { + proxyStorageUrls.push_back(baseUrl + "-" + serviceType + "-" + userCountryCode + ".json"); + } + } + for (const auto &baseUrl : baseUrls) { + proxyStorageUrls.push_back(baseUrl + ".json"); + } + for (const auto &proxyStorageUrl : proxyStorageUrls) { request.setUrl(proxyStorageUrl); reply = amnApp->networkManager()->get(request); @@ -231,11 +243,10 @@ QStringList GatewayController::getProxyUrls() } return endpoints; } else { - QByteArray responseBody = reply->readAll(); - QString replyErrorString = reply->errorString(); auto replyError = reply->error(); int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - apiUtils::checkNetworkReplyErrors(sslErrors, replyErrorString, replyError, httpStatusCode, responseBody); + qDebug() << replyError; + qDebug() << httpStatusCode; qDebug() << "go to the next storage endpoint"; reply->deleteLater(); @@ -284,10 +295,11 @@ bool GatewayController::shouldBypassProxy(const QNetworkReply::NetworkError &rep return false; } -void GatewayController::bypassProxy(const QString &endpoint, std::function requestFunction, +void GatewayController::bypassProxy(const QString &endpoint, const QString &serviceType, const QString &userCountryCode, + std::function requestFunction, std::function &sslErrors)> replyProcessingFunction) { - QStringList proxyUrls = getProxyUrls(); + QStringList proxyUrls = getProxyUrls(serviceType, userCountryCode); std::random_device randomDevice; std::mt19937 generator(randomDevice()); std::shuffle(proxyUrls.begin(), proxyUrls.end(), generator); diff --git a/client/core/controllers/gatewayController.h b/client/core/controllers/gatewayController.h index fc32dc4ae..d4e5061f7 100644 --- a/client/core/controllers/gatewayController.h +++ b/client/core/controllers/gatewayController.h @@ -21,10 +21,11 @@ public: amnezia::ErrorCode post(const QString &endpoint, const QJsonObject apiPayload, QByteArray &responseBody); private: - QStringList getProxyUrls(); + QStringList getProxyUrls(const QString &serviceType, const QString &userCountryCode); bool shouldBypassProxy(const QNetworkReply::NetworkError &replyError, const QByteArray &responseBody, bool checkEncryption, const QByteArray &key = "", const QByteArray &iv = "", const QByteArray &salt = ""); - void bypassProxy(const QString &endpoint, std::function requestFunction, + void bypassProxy(const QString &endpoint, const QString &serviceType, const QString &userCountryCode, + std::function requestFunction, std::function &sslErrors)> replyProcessingFunction); int m_requestTimeoutMsecs; diff --git a/client/settings.cpp b/client/settings.cpp index e705615ac..a4e479d7f 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -541,12 +541,12 @@ QString Settings::getGatewayEndpoint() bool Settings::isDevGatewayEnv() { - return m_isDevGatewayEnv; + return value("Conf/devGatewayEnv", false).toBool(); } void Settings::toggleDevGatewayEnv(bool enabled) { - m_isDevGatewayEnv = enabled; + setValue("Conf/devGatewayEnv", enabled); } bool Settings::isHomeAdLabelVisible() diff --git a/client/settings.h b/client/settings.h index 5ce4fc01c..249506277 100644 --- a/client/settings.h +++ b/client/settings.h @@ -254,7 +254,6 @@ private: mutable SecureQSettings m_settings; QString m_gatewayEndpoint; - bool m_isDevGatewayEnv = true; }; #endif // SETTINGS_H diff --git a/client/ui/controllers/settingsController.cpp b/client/ui/controllers/settingsController.cpp index bfe22d41a..d1bc84b94 100644 --- a/client/ui/controllers/settingsController.cpp +++ b/client/ui/controllers/settingsController.cpp @@ -34,6 +34,9 @@ SettingsController::SettingsController(const QSharedPointer &serve #ifdef Q_OS_ANDROID connect(AndroidController::instance(), &AndroidController::notificationStateChanged, this, &SettingsController::onNotificationStateChanged); #endif + + m_isDevModeEnabled = m_settings->isDevGatewayEnv(); + toggleDevGatewayEnv(m_isDevModeEnabled); } QString getPlatformName() diff --git a/client/ui/qml/Pages2/PageHome.qml b/client/ui/qml/Pages2/PageHome.qml index 43a9df32f..d2289ab03 100644 --- a/client/ui/qml/Pages2/PageHome.qml +++ b/client/ui/qml/Pages2/PageHome.qml @@ -109,6 +109,34 @@ PageType { } } + BasicButtonType { + id: devGatewayButton + objectName: "devGatewayButton" + + property bool isDevGatewayEnabled: SettingsController.isDevGatewayEnv + + Layout.alignment: Qt.AlignHCenter + + implicitHeight: 36 + + defaultColor: AmneziaStyle.color.transparent + hoveredColor: AmneziaStyle.color.translucentWhite + pressedColor: AmneziaStyle.color.sheerWhite + disabledColor: AmneziaStyle.color.mutedGray + textColor: AmneziaStyle.color.mutedGray + borderWidth: 0 + + visible: SettingsController.isDevModeEnabled && isDevGatewayEnabled + text: qsTr("Dev gateway enabled") + + Keys.onEnterPressed: this.clicked() + Keys.onReturnPressed: this.clicked() + + onClicked: { + PageController.goToPage(PageEnum.PageDevMenu) + } + } + ConnectButton { id: connectButton objectName: "connectButton"