- Embed XMRig executable (baked into buildbot image)

- Refactored CMake related to Tor/XMRig
- Move executables to `src/assets/exec`
- Embedding executables require passing definition to CMake, e.g:
  - `-DTOR=/path/to/tor`
  - `-DXMRIG=/path/to/xmrig`
- Allow solo mining for XMRig
- Redesign XMRig settings screen
This commit is contained in:
dsc
2020-10-18 22:01:14 +02:00
parent 5d8700370b
commit aee60f33b7
24 changed files with 548 additions and 268 deletions
+14 -14
View File
@@ -43,9 +43,15 @@ Tor::Tor(AppContext *ctx, QObject *parent)
return;
}
#ifndef HAS_TOR
qCritical() << "Feather built without embedded Tor. Assuming --use-local-tor";
this->localTor = true;
return;
#endif
bool unpacked = this->unpackBins();
if (!unpacked) {
qCritical() << "Feather built without embedded Tor. Assuming --use-local-tor";
qCritical() << "Error unpacking embedded Tor. Assuming --use-local-tor";
this->localTor = true;
return;
}
@@ -175,11 +181,9 @@ void Tor::handleProcessError(QProcess::ProcessError error) {
bool Tor::unpackBins() {
QString torFile;
// @TODO: refactor for Mac OS - should compile Tor statically.
#if defined(Q_OS_MAC) && defined(DRONE)
// Tor on Mac requires libevent.dylib, borrowed the executable from
// the official Tor Browser release for now.
QString libEvent = ":/tor/libevent-2.1.7.dylib";
// On MacOS write libevent to disk
#if defined(Q_OS_MAC)
QString libEvent = ":/assets/exec/libevent-2.1.7.dylib";
if (Utils::fileExists(libEvent)) {
QFile e(libEvent);
QFileInfo eventInfo(e);
@@ -190,18 +194,15 @@ bool Tor::unpackBins() {
}
#endif
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
torFile = ":/tor/tor";
#elif defined(Q_OS_WIN)
torFile = ":/tor/tor.exe";
#endif
torFile = ":/assets/exec/tor";
if (!Utils::fileExists(torFile))
return false;
// write to disk
QFile f(torFile);
QFileInfo fileInfo(f);
this->torPath = QDir(this->torDir).filePath(fileInfo.fileName());
qDebug() << this->torPath;
qDebug() << "Writing Tor executable to " << this->torPath;
f.copy(torPath);
f.close();
@@ -209,7 +210,6 @@ bool Tor::unpackBins() {
QFile torBin(this->torPath);
torBin.setPermissions(QFile::ExeGroup | QFile::ExeOther | QFile::ExeOther | QFile::ExeUser);
#endif
return true;
}
+50 -20
View File
@@ -13,28 +13,37 @@
#include "appcontext.h"
XMRig::XMRig(QObject *parent) : QObject(parent)
{
qDebug() << "Using embedded tor instance";
m_process.setProcessChannelMode(QProcess::MergedChannels);
connect(&m_process, &QProcess::readyReadStandardOutput, this, &XMRig::handleProcessOutput);
connect(&m_process, &QProcess::errorOccurred, this, &XMRig::handleProcessError);
connect(&m_process, &QProcess::stateChanged, this, &XMRig::stateChanged);
XmRig::XmRig(const QString &configDir, QObject *parent) : QObject(parent) {
this->rigDir = QDir(configDir).filePath("xmrig");
}
void XMRig::stop() {
void XmRig::prepare() {
// unpack and set process signals
if(!this->unpackBins()) {
qCritical() << "failed to write XMRig to config directory";
return;
}
m_process.setProcessChannelMode(QProcess::MergedChannels);
connect(&m_process, &QProcess::readyReadStandardOutput, this, &XmRig::handleProcessOutput);
connect(&m_process, &QProcess::errorOccurred, this, &XmRig::handleProcessError);
connect(&m_process, &QProcess::stateChanged, this, &XmRig::stateChanged);
}
void XmRig::stop() {
if(m_process.state() == QProcess::Running)
m_process.kill();
}
void XMRig::terminate() {
void XmRig::terminate() {
if(m_process.state() == QProcess::Running)
m_process.terminate();
}
void XMRig::start(unsigned int threads,
const QString &pool_name,
void XmRig::start(const QString &path,
unsigned int threads,
const QString &address,
const QString &username,
const QString &password,
bool tor, bool tls) {
@@ -44,22 +53,22 @@ void XMRig::start(unsigned int threads,
return;
}
auto path = config()->get(Config::xmrigPath).toString();
if(path.isEmpty()) {
emit error("Please set path to XMRig binary before starting.");
emit error("XmRig->Start path parameter missing.");
return;
}
if(!Utils::fileExists(path)) {
emit error("Path to XMRig binary invalid; file does not exist.");
emit error(QString("Path to XMRig binary invalid; file does not exist: %1").arg(path));
return;
}
QStringList arguments;
arguments << "-o" << pool_name;
arguments << "-o" << address;
arguments << "-a" << "rx/0";
arguments << "-u" << username;
arguments << "-p" << password;
if(!password.isEmpty())
arguments << "-p" << password;
arguments << "--no-color";
arguments << "-t" << QString::number(threads);
if(tor)
@@ -72,14 +81,14 @@ void XMRig::start(unsigned int threads,
m_process.start(path, arguments);
}
void XMRig::stateChanged(QProcess::ProcessState state) {
void XmRig::stateChanged(QProcess::ProcessState state) {
if(state == QProcess::ProcessState::Running)
emit output("XMRig started");
else if (state == QProcess::ProcessState::NotRunning)
emit output("XMRig stopped");
}
void XMRig::handleProcessOutput() {
void XmRig::handleProcessOutput() {
QByteArray _output = m_process.readAllStandardOutput();
if(_output.contains("miner") && _output.contains("speed")) {
// detect hashrate
@@ -93,7 +102,7 @@ void XMRig::handleProcessOutput() {
emit output(_output);
}
void XMRig::handleProcessError(QProcess::ProcessError err) {
void XmRig::handleProcessError(QProcess::ProcessError err) {
if (err == QProcess::ProcessError::Crashed)
emit error("XMRig crashed or killed");
else if (err == QProcess::ProcessError::FailedToStart) {
@@ -102,3 +111,24 @@ void XMRig::handleProcessError(QProcess::ProcessError err) {
}
}
bool XmRig::unpackBins() {
QString rigFile;
rigFile = ":/assets/exec/xmrig";
if (!Utils::fileExists(rigFile))
return false;
// write to disk
QFile f(rigFile);
QFileInfo fileInfo(f);
this->rigPath = QDir(this->rigDir).filePath(fileInfo.fileName());
qDebug() << "Writing XMRig executable to " << this->rigPath;
f.copy(rigPath);
f.close();
#if defined(Q_OS_UNIX)
QFile torBin(this->rigPath);
torBin.setPermissions(QFile::ExeGroup | QFile::ExeOther | QFile::ExeOther | QFile::ExeUser);
#endif
return true;
}
+8 -3
View File
@@ -15,16 +15,21 @@
#include "utils/childproc.h"
class XMRig : public QObject
class XmRig : public QObject
{
Q_OBJECT
public:
explicit XMRig(QObject *parent = nullptr);
explicit XmRig(const QString &configDir, QObject *parent = nullptr);
void prepare();
void start(unsigned int threads, const QString &pool_name, const QString &username, const QString &password, bool tor = false, bool tls = true);
void start(const QString &path, unsigned int threads, const QString &address, const QString &username, const QString &password, bool tor = false, bool tls = true);
void stop();
void terminate();
bool unpackBins();
QString rigDir;
QString rigPath;
signals:
void error(const QString &msg);