From 6ac8e7a464cc56190854121e3ec4e42363cadc9e Mon Sep 17 00:00:00 2001 From: selsta Date: Sun, 9 Apr 2023 03:00:42 +0200 Subject: [PATCH 1/2] p2pool: add more detailed failure message --- pages/Mining.qml | 19 +++++++++++++++++-- src/p2pool/P2PoolManager.cpp | 11 +++++++---- src/p2pool/P2PoolManager.h | 11 ++++++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/pages/Mining.qml b/pages/Mining.qml index 025f8b92..e0f220aa 100644 --- a/pages/Mining.qml +++ b/pages/Mining.qml @@ -641,10 +641,25 @@ allArgs = allArgs.filter( ( el ) => !defaultArgs.includes( el.split(" ")[0] ) ) } } - function p2poolDownloadFailed() { + function p2poolDownloadFailed(errorCode) { statusMessage.visible = false errorPopup.title = qsTr("P2Pool Installation Failed") + translationManager.emptyString; - errorPopup.text = qsTr("P2Pool installation failed.") + isWindows ? (" " + qsTr("Try starting the program with administrator privileges.")) : "" + switch (errorCode) { + case P2PoolManager.HashVerificationFailed: + errorPopup.text = qsTr("Hash verification failed.") + translationManager.emptyString; + break; + case P2PoolManager.BinaryNotAvailable: + errorPopup.text = qsTr("P2Pool download is not available.") + translationManager.emptyString; + break; + case P2PoolManager.ConnectionIssue: + errorPopup.text = qsTr("P2Pool download failed due to a connection issue.") + translationManager.emptyString; + break; + case P2PoolManager.InstallationFailed: + errorPopup.text = qsTr("P2Pool installation failed.") + (isWindows ? (" " + qsTr("Try starting the program with administrator privileges.")) : "") + break; + default: + errorPopup.text = qsTr("Unknown error.") + translationManager.emptyString; + } errorPopup.icon = StandardIcon.Critical errorPopup.open() update() diff --git a/src/p2pool/P2PoolManager.cpp b/src/p2pool/P2PoolManager.cpp index e4655c14..0119aa98 100644 --- a/src/p2pool/P2PoolManager.cpp +++ b/src/p2pool/P2PoolManager.cpp @@ -68,7 +68,10 @@ void P2PoolManager::download() { std::chrono::milliseconds timeout = std::chrono::seconds(10); http_client.set_server(url.host().toStdString(), "443", {}); bool success = http_client.invoke_get(url.path().toStdString(), timeout, {}, std::addressof(response), {{"User-Agent", userAgent}}); - if (response->m_response_code == 302) { + if (response->m_response_code == 404) { + emit p2poolDownloadFailure(BinaryNotAvailable); + return; + } else if (response->m_response_code == 302) { epee::net_utils::http::fields_list fields = response->m_header_info.m_etc_fields; for (std::pair i : fields) { if (i.first == "Location") { @@ -82,7 +85,7 @@ void P2PoolManager::download() { } } if (!success) { - emit p2poolDownloadFailure(); + emit p2poolDownloadFailure(ConnectionIssue); } else { std::string stringData = response->m_body; @@ -90,7 +93,7 @@ void P2PoolManager::download() { QByteArray hashData = QCryptographicHash::hash(data, QCryptographicHash::Sha256); QString hash = hashData.toHex(); if (hash != validHash) { - emit p2poolDownloadFailure(); + emit p2poolDownloadFailure(HashVerificationFailed); } else { file.open(QIODevice::WriteOnly); @@ -102,7 +105,7 @@ void P2PoolManager::download() { emit p2poolDownloadSuccess(); } else { - emit p2poolDownloadFailure(); + emit p2poolDownloadFailure(InstallationFailed); } } } diff --git a/src/p2pool/P2PoolManager.h b/src/p2pool/P2PoolManager.h index f1679567..b813e042 100644 --- a/src/p2pool/P2PoolManager.h +++ b/src/p2pool/P2PoolManager.h @@ -51,13 +51,22 @@ public: Q_INVOKABLE bool isInstalled(); Q_INVOKABLE void getStatus(); Q_INVOKABLE void download(); + + enum DownloadError { + BinaryNotAvailable, + ConnectionIssue, + HashVerificationFailed, + InstallationFailed, + }; + Q_ENUM(DownloadError) + private: bool running(NetworkType::Type nettype) const; signals: void p2poolStartFailure() const; void p2poolStatus(bool isMining, int hashrate) const; - void p2poolDownloadFailure() const; + void p2poolDownloadFailure(int errorCode) const; void p2poolDownloadSuccess() const; private: From 33310786dbb2e8817bfe4cac36b45069031d14bd Mon Sep 17 00:00:00 2001 From: selsta Date: Sun, 9 Apr 2023 18:26:03 +0200 Subject: [PATCH 2/2] p2pool: fix crash without network connection --- src/p2pool/P2PoolManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p2pool/P2PoolManager.cpp b/src/p2pool/P2PoolManager.cpp index 0119aa98..74391528 100644 --- a/src/p2pool/P2PoolManager.cpp +++ b/src/p2pool/P2PoolManager.cpp @@ -68,10 +68,10 @@ void P2PoolManager::download() { std::chrono::milliseconds timeout = std::chrono::seconds(10); http_client.set_server(url.host().toStdString(), "443", {}); bool success = http_client.invoke_get(url.path().toStdString(), timeout, {}, std::addressof(response), {{"User-Agent", userAgent}}); - if (response->m_response_code == 404) { + if (success && response->m_response_code == 404) { emit p2poolDownloadFailure(BinaryNotAvailable); return; - } else if (response->m_response_code == 302) { + } else if (success && response->m_response_code == 302) { epee::net_utils::http::fields_list fields = response->m_header_info.m_etc_fields; for (std::pair i : fields) { if (i.first == "Location") {