Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2pool: add more detailed failure message, fix crash #4147

Merged
merged 2 commits into from
Aug 17, 2023
Merged
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
19 changes: 17 additions & 2 deletions pages/Mining.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
11 changes: 7 additions & 4 deletions src/p2pool/P2PoolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (success && response->m_response_code == 404) {
emit p2poolDownloadFailure(BinaryNotAvailable);
return;
} 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<std::string, std::string> i : fields) {
if (i.first == "Location") {
Expand All @@ -82,15 +85,15 @@ void P2PoolManager::download() {
}
}
if (!success) {
emit p2poolDownloadFailure();
emit p2poolDownloadFailure(ConnectionIssue);
}
else {
std::string stringData = response->m_body;
QByteArray data(stringData.c_str(), stringData.length());
QByteArray hashData = QCryptographicHash::hash(data, QCryptographicHash::Sha256);
QString hash = hashData.toHex();
if (hash != validHash) {
emit p2poolDownloadFailure();
emit p2poolDownloadFailure(HashVerificationFailed);
}
else {
file.open(QIODevice::WriteOnly);
Expand All @@ -102,7 +105,7 @@ void P2PoolManager::download() {
emit p2poolDownloadSuccess();
}
else {
emit p2poolDownloadFailure();
emit p2poolDownloadFailure(InstallationFailed);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/p2pool/P2PoolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ class P2PoolManager : public QObject
Q_INVOKABLE bool isInstalled();
Q_INVOKABLE void getStatus();
Q_INVOKABLE void download();

enum DownloadError {
selsta marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down