Xmrig: add support for TLS. Tor default off. Save username/password in wallet cache.

Signed-off-by: dsc <dsc@xmr.pm>
This commit is contained in:
dsc 2020-10-16 21:01:18 +02:00
parent c5a055eb70
commit 1ef29207d5
No known key found for this signature in database
GPG key ID: 521F1E7991AA42DC
9 changed files with 185 additions and 99 deletions

View file

@ -12,7 +12,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "widgets/ccswidget.h" #include "widgets/ccswidget.h"
#include "widgets/redditwidget.h" #include "widgets/redditwidget.h"
#include "widgets/xmrigwidget.h"
#include "dialog/txconfdialog.h" #include "dialog/txconfdialog.h"
#include "dialog/debuginfodialog.h" #include "dialog/debuginfodialog.h"
#include "dialog/walletinfodialog.h" #include "dialog/walletinfodialog.h"
@ -168,11 +167,13 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
connect(m_ctx->nodes, &Nodes::WSNodeExhausted, this, &MainWindow::showWSNodeExhaustedMessage); connect(m_ctx->nodes, &Nodes::WSNodeExhausted, this, &MainWindow::showWSNodeExhaustedMessage);
// XMRig // XMRig
connect(m_ctx, &AppContext::XMRigDownloads, ui->xmrigWidget, &XMRigWidget::onDownloads); m_xmrig = new XMRigWidget(m_ctx, this);
connect(m_ctx, &AppContext::walletClosed, ui->xmrigWidget, &XMRigWidget::onStopClicked); ui->xmrRigLayout->addWidget(m_xmrig);
connect(m_ctx, &AppContext::walletClosed, ui->xmrigWidget, &XMRigWidget::onClearClicked); connect(m_ctx, &AppContext::walletOpened, m_xmrig, &XMRigWidget::onWalletOpened);
connect(ui->xmrigWidget, &XMRigWidget::miningStarted, [=]{ m_ctx->setWindowTitle(true); }); connect(m_ctx, &AppContext::XMRigDownloads, m_xmrig, &XMRigWidget::onDownloads);
connect(ui->xmrigWidget, &XMRigWidget::miningEnded, [=]{ m_ctx->setWindowTitle(false); }); connect(m_ctx, &AppContext::walletClosed, m_xmrig, &XMRigWidget::onWalletClosed);
connect(m_xmrig, &XMRigWidget::miningStarted, [=]{ m_ctx->setWindowTitle(true); });
connect(m_xmrig, &XMRigWidget::miningEnded, [=]{ m_ctx->setWindowTitle(false); });
// CCS/Reddit widget // CCS/Reddit widget
m_ccsWidget = new CCSWidget(this); m_ccsWidget = new CCSWidget(this);

View file

@ -19,6 +19,7 @@
#include "widgets/ccswidget.h" #include "widgets/ccswidget.h"
#include "widgets/redditwidget.h" #include "widgets/redditwidget.h"
#include "widgets/tickerwidget.h" #include "widgets/tickerwidget.h"
#include "widgets/xmrigwidget.h"
#include "utils/networking.h" #include "utils/networking.h"
#include "appcontext.h" #include "appcontext.h"
#include "utils/config.h" #include "utils/config.h"
@ -144,6 +145,7 @@ private:
SignVerifyDialog *m_windowSignVerify = nullptr; SignVerifyDialog *m_windowSignVerify = nullptr;
RestoreDialog *m_restoreDialog = nullptr; RestoreDialog *m_restoreDialog = nullptr;
AboutDialog *m_aboutDialog = nullptr; AboutDialog *m_aboutDialog = nullptr;
XMRigWidget *m_xmrig = nullptr;
bool m_windowSpawned = false; bool m_windowSpawned = false;

View file

@ -290,7 +290,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="XMRigWidget" name="xmrigWidget" native="true"/> <layout class="QGridLayout" name="xmrRigLayout"/>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -305,7 +305,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>894</width> <width>894</width>
<height>30</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -655,12 +655,6 @@
<header>calcwidget.h</header> <header>calcwidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>XMRigWidget</class>
<extends>QWidget</extends>
<header>widgets/xmrigwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="assets.qrc"/> <include location="assets.qrc"/>

View file

@ -35,7 +35,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::autoOpenWalletPath,{QS("autoOpenWalletPath"), ""}}, {Config::autoOpenWalletPath,{QS("autoOpenWalletPath"), ""}},
{Config::walletPath,{QS("walletPath"), ""}}, {Config::walletPath,{QS("walletPath"), ""}},
{Config::xmrigPath,{QS("xmrigPath"), ""}}, {Config::xmrigPath,{QS("xmrigPath"), ""}},
{Config::xmrigPool,{QS("xmrigPool"), "pool.xmr.pt:5555"}}, {Config::xmrigPool,{QS("xmrigPool"), "pool.xmr.pt:9000"}},
{Config::nodes,{QS("nodes"), "{}"}}, {Config::nodes,{QS("nodes"), "{}"}},
{Config::websocketEnabled,{QS("websocketEnabled"), true}}, {Config::websocketEnabled,{QS("websocketEnabled"), true}},
{Config::nodeSource,{QS("nodeSource"), 0}}, {Config::nodeSource,{QS("nodeSource"), 0}},

View file

@ -33,7 +33,11 @@ void XMRig::terminate() {
m_process.terminate(); m_process.terminate();
} }
void XMRig::start(unsigned int threads, const QString &pool_name, const QString &receiving_address, bool tor) { void XMRig::start(unsigned int threads,
const QString &pool_name,
const QString &username,
const QString &password,
bool tor, bool tls) {
auto state = m_process.state(); auto state = m_process.state();
if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) { if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) {
emit error("Can't start XMRig, already running or starting"); emit error("Can't start XMRig, already running or starting");
@ -54,12 +58,14 @@ void XMRig::start(unsigned int threads, const QString &pool_name, const QString
QStringList arguments; QStringList arguments;
arguments << "-o" << pool_name; arguments << "-o" << pool_name;
arguments << "-a" << "rx/0"; arguments << "-a" << "rx/0";
arguments << "-u" << receiving_address; arguments << "-u" << username;
arguments << "-p" << "featherwallet"; arguments << "-p" << password;
arguments << "--no-color"; arguments << "--no-color";
arguments << "-t" << QString::number(threads); arguments << "-t" << QString::number(threads);
if(tor) if(tor)
arguments << "-x" << QString("%1:%2").arg(Tor::torHost).arg(Tor::torPort); arguments << "-x" << QString("%1:%2").arg(Tor::torHost).arg(Tor::torPort);
if(tls)
arguments << "--tls";
QString cmd = QString("%1 %2").arg(path, arguments.join(" ")); QString cmd = QString("%1 %2").arg(path, arguments.join(" "));
emit output(cmd.toUtf8()); emit output(cmd.toUtf8());

View file

@ -22,7 +22,7 @@ Q_OBJECT
public: public:
explicit XMRig(QObject *parent = nullptr); explicit XMRig(QObject *parent = nullptr);
void start(unsigned int threads, const QString &pool_name, const QString &receiving_address, bool tor = false); void start(unsigned int threads, const QString &pool_name, const QString &username, const QString &password, bool tor = false, bool tls = true);
void stop(); void stop();
void terminate(); void terminate();

View file

@ -15,9 +15,10 @@
#include "ui_xmrigwidget.h" #include "ui_xmrigwidget.h"
#include "utils/utils.h" #include "utils/utils.h"
XMRigWidget::XMRigWidget(QWidget *parent) : XMRigWidget::XMRigWidget(AppContext *ctx, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::XMRigWidget), ui(new Ui::XMRigWidget),
m_ctx(ctx),
m_model(new QStandardItemModel(this)), m_model(new QStandardItemModel(this)),
m_contextMenu(new QMenu(this)) m_contextMenu(new QMenu(this))
{ {
@ -56,8 +57,10 @@ XMRigWidget::XMRigWidget(QWidget *parent) :
// defaults // defaults
ui->btn_stop->setEnabled(false); ui->btn_stop->setEnabled(false);
ui->check_autoscroll->setChecked(true); ui->check_autoscroll->setChecked(true);
ui->relayTor->setChecked(true); ui->relayTor->setChecked(false);
ui->check_tls->setChecked(true);
ui->label_status->setTextInteractionFlags(Qt::TextSelectableByMouse); ui->label_status->setTextInteractionFlags(Qt::TextSelectableByMouse);
// XMRig binary // XMRig binary
auto path = config()->get(Config::xmrigPath).toString(); auto path = config()->get(Config::xmrigPath).toString();
ui->lineEdit_path->setText(path); ui->lineEdit_path->setText(path);
@ -79,6 +82,40 @@ XMRigWidget::XMRigWidget(QWidget *parent) :
else else
ui->console->appendPlainText(QString("XMRig path set to %1").arg(path)); ui->console->appendPlainText(QString("XMRig path set to %1").arg(path));
ui->console->appendPlainText("Ready to mine."); ui->console->appendPlainText("Ready to mine.");
// username/password
connect(ui->lineEdit_password, &QLineEdit::editingFinished, [=]() {
m_ctx->currentWallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text());
m_ctx->currentWallet->store();
});
connect(ui->lineEdit_address, &QLineEdit::editingFinished, [=]() {
m_ctx->currentWallet->setCacheAttribute("feather.xmrig_username", ui->lineEdit_address->text());
m_ctx->currentWallet->store();
});
}
void XMRigWidget::onWalletClosed() {
this->onStopClicked();
this->onClearClicked();
ui->lineEdit_password->setText("");
ui->lineEdit_address->setText("");
}
void XMRigWidget::onWalletOpened(){
// Xmrig username
auto username = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_username");
if(!username.isEmpty())
ui->lineEdit_address->setText(username);
// Xmrig passwd
auto password = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_password");
if(!password.isEmpty()) {
ui->lineEdit_password->setText(password);
} else {
ui->lineEdit_password->setText("featherwallet");
m_ctx->currentWallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text());
}
} }
void XMRigWidget::onThreadsValueChanged(int threads) { void XMRigWidget::onThreadsValueChanged(int threads) {
@ -104,13 +141,22 @@ void XMRigWidget::onClearClicked() {
void XMRigWidget::onStartClicked() { void XMRigWidget::onStartClicked() {
auto pool_name = config()->get(Config::xmrigPool).toString(); auto pool_name = config()->get(Config::xmrigPool).toString();
auto addy = ui->lineEdit_address->text();
if(addy.isEmpty()) { // fix error in config
if(!m_pools.contains(pool_name)) {
pool_name = m_pools.at(0);
config()->set(Config::xmrigPool, pool_name);
}
auto username = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_username");
auto password = m_ctx->currentWallet->getCacheAttribute("feather.xmrig_password");
if(username.isEmpty()) {
Utils::showMessageBox("Error", "Please specify a receiving address on the Settings screen", true); Utils::showMessageBox("Error", "Please specify a receiving address on the Settings screen", true);
return; return;
} }
m_rig->start(m_threads, pool_name, addy, ui->relayTor->isChecked()); m_rig->start(m_threads, pool_name, username, password, ui->relayTor->isChecked(), ui->check_tls->isChecked());
ui->btn_start->setEnabled(false); ui->btn_start->setEnabled(false);
ui->btn_stop->setEnabled(true); ui->btn_stop->setEnabled(true);
emit miningStarted(); emit miningStarted();

View file

@ -10,6 +10,7 @@
#include "utils/xmrig.h" #include "utils/xmrig.h"
#include "utils/config.h" #include "utils/config.h"
#include "appcontext.h"
namespace Ui { namespace Ui {
class XMRigWidget; class XMRigWidget;
@ -20,11 +21,13 @@ class XMRigWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit XMRigWidget(QWidget *parent = nullptr); explicit XMRigWidget(AppContext *ctx, QWidget *parent = nullptr);
~XMRigWidget(); ~XMRigWidget();
QStandardItemModel *model(); QStandardItemModel *model();
public slots: public slots:
void onWalletClosed();
void onWalletOpened();
void onStartClicked(); void onStartClicked();
void onStopClicked(); void onStopClicked();
void onClearClicked(); void onClearClicked();
@ -46,12 +49,13 @@ signals:
private: private:
void showContextMenu(const QPoint &pos); void showContextMenu(const QPoint &pos);
AppContext *m_ctx;
Ui::XMRigWidget *ui; Ui::XMRigWidget *ui;
QStandardItemModel *m_model; QStandardItemModel *m_model;
QMenu *m_contextMenu; QMenu *m_contextMenu;
unsigned int m_threads; unsigned int m_threads;
QStringList m_urls; QStringList m_urls;
QStringList m_pools{"pool.xmr.pt:5555", "pool.supportxmr.com:3333", "mine.xmrpool.net:3333", "xmrpool.eu:5555", "xmr-eu1.nanopool.org:14444", "pool.minexmr.com:4444", "monerohash.com:2222"}; QStringList m_pools{"pool.xmr.pt:9000", "pool.supportxmr.com:9000", "mine.xmrpool.net:443", "xmrpool.eu:9999", "xmr-eu1.nanopool.org:14433", "pool.minexmr.com:6666", "us-west.minexmr.com:6666", "monerohash.com:9999"};
XMRig *m_rig; XMRig *m_rig;
}; };

View file

@ -125,7 +125,7 @@
<attribute name="title"> <attribute name="title">
<string>Settings</string> <string>Settings</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_7">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
@ -152,46 +152,9 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="text">
<string>Receiving address</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_address"/> <layout class="QVBoxLayout" name="verticalLayout_4">
</item>
<item>
<widget class="QLabel" name="label_threads">
<property name="text">
<string>Threads: </string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSlider" name="threadSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
@ -211,6 +174,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="check_tls">
<property name="text">
<string>TLS</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="relayTor">
<property name="text">
<string>Tor</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
@ -226,13 +203,69 @@
</item> </item>
</layout> </layout>
</item> </item>
</layout>
</item>
<item> <item>
<widget class="QCheckBox" name="relayTor"> <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_threads">
<property name="text"> <property name="text">
<string>Relay over Tor</string> <string>Threads: </string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSlider" name="threadSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Pool worker name (optional)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLineEdit" name="lineEdit_password"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Receiving address</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_address"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>