mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-07 07:55:04 -05:00
Compare commits
9 Commits
v2.6.0-bet
...
v2.5.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d9025f2ca | ||
|
|
38874fbb0a | ||
|
|
90a09f20b3 | ||
|
|
7365e0486b | ||
|
|
593056113c | ||
|
|
888d80240d | ||
|
|
0814c28998 | ||
|
|
1c2b5acb2c | ||
|
|
d24babb96e |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,22 +1,7 @@
|
||||
# v2.6.0-beta2
|
||||
- Improved performance for `cryptonight v7` especially in double hash mode.
|
||||
- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 disabled for internal HTTP API by default, was cause issues on some systems.
|
||||
- Added short aliases for algorithm names: `cn`, `cn-lite` and `cn-heavy`.
|
||||
- Fixed regressions (v2.6.0-beta1 affected)
|
||||
- [#494](https://github.com/xmrig/xmrig/issues/494) Command line option `--donate-level` was broken.
|
||||
- [#502](https://github.com/xmrig/xmrig/issues/502) Build without libmicrohttpd was broken.
|
||||
- Fixed nonce calculation for `--av 4` (software AES, double hash) was cause reduction of effective hashrate and rejected shares on nicehash.
|
||||
|
||||
# v2.6.0-beta1
|
||||
- [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.**
|
||||
- HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization.
|
||||
- Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested.
|
||||
- Added API endpoint `PUT /1/config` to update current config.
|
||||
- Added API endpoint `GET /1/config` to get current active config.
|
||||
- Added API endpoint `GET /1/threads` to get current active threads configuration.
|
||||
- API endpoint `GET /` now deprecated, use `GET /1/summary` instead.
|
||||
- Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API.
|
||||
- Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified.
|
||||
# v2.5.3
|
||||
- Fixed critical bug, in some cases miner was can't recovery connection and switch to failover pool, version 2.5.2 affected. If you use v2.6.0-beta3 this issue doesn't concern you.
|
||||
- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 support disabled for internal HTTP API.
|
||||
- Added workaround for nicehash.com if you use `cryptonightv7.<region>.nicehash.com` option `variant=1` will be set automatically.
|
||||
|
||||
# v2.5.2
|
||||
- [#448](https://github.com/xmrig/xmrig/issues/478) Fixed broken reconnect.
|
||||
|
||||
@@ -3,7 +3,6 @@ project(xmrig)
|
||||
|
||||
option(WITH_LIBCPUID "Use Libcpuid" ON)
|
||||
option(WITH_AEON "CryptoNight-Lite support" ON)
|
||||
option(WITH_SUMO "CryptoNight-Heavy support" ON)
|
||||
option(WITH_HTTPD "HTTP REST API" ON)
|
||||
option(BUILD_STATIC "Build static binary" OFF)
|
||||
|
||||
@@ -12,28 +11,18 @@ include (cmake/cpu.cmake)
|
||||
|
||||
|
||||
set(HEADERS
|
||||
src/api/Api.h
|
||||
src/api/ApiState.h
|
||||
src/api/NetworkState.h
|
||||
src/App.h
|
||||
src/Console.h
|
||||
src/core/CommonConfig.h
|
||||
src/core/Config.cpp
|
||||
src/core/ConfigLoader.cpp
|
||||
src/core/ConfigLoader.h
|
||||
src/core/ConfigLoader_platform.h
|
||||
src/core/ConfigWatcher.cpp
|
||||
src/core/Controller.h
|
||||
src/Cpu.h
|
||||
src/interfaces/IClientListener.h
|
||||
src/interfaces/IConfig.h
|
||||
src/interfaces/IConfigCreator.h
|
||||
src/interfaces/IConsoleListener.h
|
||||
src/interfaces/IControllerListener.h
|
||||
src/interfaces/IJobResultListener.h
|
||||
src/interfaces/ILogBackend.h
|
||||
src/interfaces/IStrategy.h
|
||||
src/interfaces/IStrategyListener.h
|
||||
src/interfaces/IThread.h
|
||||
src/interfaces/IWatcherListener.h
|
||||
src/interfaces/IWorker.h
|
||||
src/log/ConsoleLog.h
|
||||
src/log/FileLog.h
|
||||
@@ -44,16 +33,15 @@ set(HEADERS
|
||||
src/net/Job.h
|
||||
src/net/JobResult.h
|
||||
src/net/Network.h
|
||||
src/net/Storage.h
|
||||
src/net/strategies/DonateStrategy.h
|
||||
src/net/strategies/FailoverStrategy.h
|
||||
src/net/strategies/SinglePoolStrategy.h
|
||||
src/net/SubmitResult.h
|
||||
src/net/Url.h
|
||||
src/Options.h
|
||||
src/Platform.h
|
||||
src/Summary.h
|
||||
src/version.h
|
||||
src/workers/CpuThread.h
|
||||
src/workers/DoubleWorker.h
|
||||
src/workers/Handle.h
|
||||
src/workers/Hashrate.h
|
||||
@@ -70,7 +58,6 @@ set(HEADERS_CRYPTO
|
||||
src/crypto/c_keccak.h
|
||||
src/crypto/c_skein.h
|
||||
src/crypto/CryptoNight.h
|
||||
src/crypto/CryptoNight_constants.h
|
||||
src/crypto/CryptoNight_monero.h
|
||||
src/crypto/CryptoNight_test.h
|
||||
src/crypto/groestl_tables.h
|
||||
@@ -86,14 +73,11 @@ else()
|
||||
endif()
|
||||
|
||||
set(SOURCES
|
||||
src/api/Api.cpp
|
||||
src/api/ApiState.cpp
|
||||
src/api/NetworkState.cpp
|
||||
src/App.cpp
|
||||
src/Console.cpp
|
||||
src/core/CommonConfig.cpp
|
||||
src/core/Config.cpp
|
||||
src/core/ConfigLoader.cpp
|
||||
src/core/ConfigWatcher.cpp
|
||||
src/core/Controller.cpp
|
||||
src/log/ConsoleLog.cpp
|
||||
src/log/FileLog.cpp
|
||||
src/log/Log.cpp
|
||||
@@ -106,9 +90,9 @@ set(SOURCES
|
||||
src/net/strategies/SinglePoolStrategy.cpp
|
||||
src/net/SubmitResult.cpp
|
||||
src/net/Url.cpp
|
||||
src/Options.cpp
|
||||
src/Platform.cpp
|
||||
src/Summary.cpp
|
||||
src/workers/CpuThread.cpp
|
||||
src/workers/DoubleWorker.cpp
|
||||
src/workers/Handle.cpp
|
||||
src/workers/Hashrate.cpp
|
||||
@@ -124,6 +108,7 @@ set(SOURCES_CRYPTO
|
||||
src/crypto/c_blake256.c
|
||||
src/crypto/c_jh.c
|
||||
src/crypto/c_skein.c
|
||||
src/crypto/CryptoNight.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
@@ -202,27 +187,12 @@ if (NOT WITH_AEON)
|
||||
add_definitions(/DXMRIG_NO_AEON)
|
||||
endif()
|
||||
|
||||
if (NOT WITH_SUMO)
|
||||
add_definitions(/DXMRIG_NO_SUMO)
|
||||
endif()
|
||||
|
||||
if (WITH_HTTPD)
|
||||
find_package(MHD)
|
||||
|
||||
if (MHD_FOUND)
|
||||
include_directories(${MHD_INCLUDE_DIRS})
|
||||
set(HTTPD_SOURCES
|
||||
src/api/Api.h
|
||||
src/api/ApiRouter.h
|
||||
src/api/HttpBody.h
|
||||
src/api/Httpd.h
|
||||
src/api/HttpReply.h
|
||||
src/api/HttpRequest.h
|
||||
src/api/Api.cpp
|
||||
src/api/ApiRouter.cpp
|
||||
src/api/Httpd.cpp
|
||||
src/api/HttpRequest.cpp
|
||||
)
|
||||
set(HTTPD_SOURCES src/api/Httpd.h src/api/Httpd.cpp)
|
||||
else()
|
||||
message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_HTTPD=OFF` to build without http deamon support")
|
||||
endif()
|
||||
|
||||
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
||||
# XMRig
|
||||
|
||||
:warning: **You must update miners to version 2.5 before April 6 due [Monero PoW change](https://getmonero.org/2018/02/11/PoW-change-and-key-reuse.html).**
|
||||
:warning: **If you mine Monero, Aeon, Sumokoin, Turtlecoin, Stellite, GRAFT, Haven Protocol, IPBC, [PLEASE READ](https://github.com/xmrig/xmrig/issues/482)!** :warning:
|
||||
|
||||
[](https://github.com/xmrig/xmrig/releases)
|
||||
[](https://github.com/xmrig/xmrig/releases)
|
||||
@@ -124,10 +124,10 @@ Please note performance is highly dependent on system load. The numbers above ar
|
||||
## Release checksums
|
||||
### SHA-256
|
||||
```
|
||||
232af0c5f3b1cdbc2d90b514873a764b434d5621d2790da67954b35c17e44fe3 xmrig-2.6.0-beta2-xenial-amd64.tar.gz/xmrig-2.6.0-beta2/xmrig
|
||||
2366a06729d4de538ef511862bf11d0c7ad40fd245e7aeab3c1957307d63471a xmrig-2.6.0-beta2-gcc-win32.zip/xmrig.exe
|
||||
2f6538c765e001d13ca380cbc1558d51efcb97d4bccdfa40993cb872be4e9efd xmrig-2.6.0-beta2-gcc-win64.zip/xmrig.exe
|
||||
3c0479acb78a3cee8fe416ee438dbff09c786acf50fbaf28a820127fcd0c6e62 xmrig-2.6.0-beta2-msvc-win64.zip/xmrig.exe
|
||||
5ae25d05b7735dd6e2482e8dba0cf0f5d10f9738855c4ad4eaf449b8ccd2e5be xmrig-2.5.3-xenial-amd64.tar.gz/xmrig-2.5.3/xmrig
|
||||
f11f3b381425ca4181c425d5b693407431f964759bb903f66b7cd2345fcdd786 xmrig-2.5.3-gcc-win32.zip/xmrig.exe
|
||||
67df8b89714e2921931092861361dbae4716c4ab872c767c92adae24dca01514 xmrig-2.5.3-gcc-win64.zip/xmrig.exe
|
||||
52bf6e0ef72c84282f4df411125384444c521ed9143e5d8c7e7e445d7d55e143 xmrig-2.5.3-msvc-win64.zip/xmrig.exe
|
||||
```
|
||||
|
||||
## Contacts
|
||||
|
||||
90
src/App.cpp
90
src/App.cpp
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -29,8 +29,6 @@
|
||||
#include "api/Api.h"
|
||||
#include "App.h"
|
||||
#include "Console.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "log/ConsoleLog.h"
|
||||
@@ -38,12 +36,17 @@
|
||||
#include "log/Log.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Network.h"
|
||||
#include "Options.h"
|
||||
#include "Platform.h"
|
||||
#include "Summary.h"
|
||||
#include "version.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
# include "log/SysLog.h"
|
||||
#endif
|
||||
|
||||
#ifndef XMRIG_NO_HTTPD
|
||||
# include "api/Httpd.h"
|
||||
#endif
|
||||
@@ -55,19 +58,40 @@ App *App::m_self = nullptr;
|
||||
|
||||
App::App(int argc, char **argv) :
|
||||
m_console(nullptr),
|
||||
m_httpd(nullptr)
|
||||
m_httpd(nullptr),
|
||||
m_network(nullptr),
|
||||
m_options(nullptr)
|
||||
{
|
||||
m_self = this;
|
||||
|
||||
m_controller = new xmrig::Controller();
|
||||
if (m_controller->init(argc, argv) != 0) {
|
||||
Cpu::init();
|
||||
m_options = Options::parse(argc, argv);
|
||||
if (!m_options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_controller->config()->isBackground()) {
|
||||
Log::init();
|
||||
|
||||
if (!m_options->background()) {
|
||||
Log::add(new ConsoleLog(m_options->colors()));
|
||||
m_console = new Console(this);
|
||||
}
|
||||
|
||||
if (m_options->logFile()) {
|
||||
Log::add(new FileLog(m_options->logFile()));
|
||||
}
|
||||
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
if (m_options->syslog()) {
|
||||
Log::add(new SysLog());
|
||||
}
|
||||
# endif
|
||||
|
||||
Platform::init(m_options->userAgent());
|
||||
Platform::setProcessPriority(m_options->priority());
|
||||
|
||||
m_network = new Network(m_options);
|
||||
|
||||
uv_signal_init(uv_default_loop(), &m_sigHUP);
|
||||
uv_signal_init(uv_default_loop(), &m_sigINT);
|
||||
uv_signal_init(uv_default_loop(), &m_sigTERM);
|
||||
@@ -76,22 +100,19 @@ App::App(int argc, char **argv) :
|
||||
|
||||
App::~App()
|
||||
{
|
||||
Mem::release();
|
||||
|
||||
uv_tty_reset_mode();
|
||||
|
||||
delete m_console;
|
||||
delete m_controller;
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
delete m_httpd;
|
||||
# endif
|
||||
|
||||
delete m_console;
|
||||
}
|
||||
|
||||
|
||||
int App::exec()
|
||||
{
|
||||
if (!m_controller->isReady()) {
|
||||
if (!m_options) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -101,15 +122,15 @@ int App::exec()
|
||||
|
||||
background();
|
||||
|
||||
Mem::allocate(m_controller->config()->algorithm(),
|
||||
m_controller->config()->threadsCount(),
|
||||
m_controller->config()->isDoubleHash(),
|
||||
m_controller->config()->isHugePages()
|
||||
);
|
||||
if (!CryptoNight::init(m_options->algo(), m_options->algoVariant())) {
|
||||
LOG_ERR("\"%s\" hash self-test failed.", m_options->algoName());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Summary::print(m_controller);
|
||||
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages());
|
||||
Summary::print();
|
||||
|
||||
if (m_controller->config()->isDryRun()) {
|
||||
if (m_options->dryRun()) {
|
||||
LOG_NOTICE("OK");
|
||||
release();
|
||||
|
||||
@@ -117,23 +138,17 @@ int App::exec()
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
Api::start(m_controller);
|
||||
Api::start();
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
m_httpd = new Httpd(
|
||||
m_controller->config()->apiPort(),
|
||||
m_controller->config()->apiToken(),
|
||||
m_controller->config()->isApiIPv6(),
|
||||
m_controller->config()->isApiRestricted()
|
||||
);
|
||||
|
||||
m_httpd = new Httpd(m_options->apiPort(), m_options->apiToken());
|
||||
m_httpd->start();
|
||||
# endif
|
||||
|
||||
Workers::start(m_controller);
|
||||
Workers::start(m_options->affinity(), m_options->priority());
|
||||
|
||||
m_controller->network()->connect();
|
||||
m_network->connect();
|
||||
|
||||
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
uv_loop_close(uv_default_loop());
|
||||
@@ -154,7 +169,7 @@ void App::onConsoleCommand(char command)
|
||||
case 'p':
|
||||
case 'P':
|
||||
if (Workers::isEnabled()) {
|
||||
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
||||
Workers::setEnabled(false);
|
||||
}
|
||||
break;
|
||||
@@ -162,7 +177,7 @@ void App::onConsoleCommand(char command)
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (!Workers::isEnabled()) {
|
||||
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;32mresumed" : "resumed");
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;32mresumed" : "resumed");
|
||||
Workers::setEnabled(true);
|
||||
}
|
||||
break;
|
||||
@@ -180,7 +195,7 @@ void App::onConsoleCommand(char command)
|
||||
|
||||
void App::close()
|
||||
{
|
||||
m_controller->network()->stop();
|
||||
m_network->stop();
|
||||
Workers::stop();
|
||||
|
||||
uv_stop(uv_default_loop());
|
||||
@@ -189,6 +204,13 @@ void App::close()
|
||||
|
||||
void App::release()
|
||||
{
|
||||
if (m_network) {
|
||||
delete m_network;
|
||||
}
|
||||
|
||||
Options::release();
|
||||
Mem::release();
|
||||
Platform::release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
src/App.h
12
src/App.h
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -37,11 +37,6 @@ class Network;
|
||||
class Options;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class App : public IConsoleListener
|
||||
{
|
||||
public:
|
||||
@@ -64,10 +59,11 @@ private:
|
||||
|
||||
Console *m_console;
|
||||
Httpd *m_httpd;
|
||||
Network *m_network;
|
||||
Options *m_options;
|
||||
uv_signal_t m_sigHUP;
|
||||
uv_signal_t m_sigINT;
|
||||
uv_signal_t m_sigTERM;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -29,22 +29,20 @@
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "log/Log.h"
|
||||
#include "Options.h"
|
||||
|
||||
|
||||
void App::background()
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
const int64_t affinity = m_controller->config()->affinity();
|
||||
if (affinity != -1L) {
|
||||
Cpu::setAffinity(-1, affinity);
|
||||
if (m_options->affinity() != -1L) {
|
||||
Cpu::setAffinity(-1, m_options->affinity());
|
||||
}
|
||||
|
||||
if (!m_controller->config()->isBackground()) {
|
||||
if (!m_options->background()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,19 +27,17 @@
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "Options.h"
|
||||
#include "Cpu.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Config.h"
|
||||
|
||||
|
||||
void App::background()
|
||||
{
|
||||
const int64_t affinity = m_controller->config()->affinity();
|
||||
if (affinity != -1L) {
|
||||
Cpu::setAffinity(-1, affinity);
|
||||
if (m_options->affinity() != -1L) {
|
||||
Cpu::setAffinity(-1, m_options->affinity());
|
||||
}
|
||||
|
||||
if (!m_controller->config()->isBackground()) {
|
||||
if (!m_options->background()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
19
src/Cpu.cpp
19
src/Cpu.cpp
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0;
|
||||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
if (m_totalThreads == 1) {
|
||||
return 1;
|
||||
@@ -54,18 +54,7 @@ int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
int size = 2048;
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_LITE) {
|
||||
size = 1024;
|
||||
}
|
||||
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
size = 4096;
|
||||
}
|
||||
|
||||
if (doubleHash) {
|
||||
size *= 2;
|
||||
}
|
||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
||||
|
||||
if (cache) {
|
||||
count = cache / size;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -28,9 +28,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Cpu
|
||||
{
|
||||
public:
|
||||
@@ -40,7 +37,7 @@ public:
|
||||
BMI2 = 4
|
||||
};
|
||||
|
||||
static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage);
|
||||
static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
|
||||
static void init();
|
||||
static void setAffinity(int id, uint64_t mask);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ int Cpu::m_totalCores = 0;
|
||||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
return m_totalThreads;
|
||||
}
|
||||
|
||||
12
src/Mem.cpp
12
src/Mem.cpp
@@ -27,8 +27,9 @@
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "Mem.h"
|
||||
#include "Options.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::m_doubleHash = false;
|
||||
@@ -43,18 +44,15 @@ alignas(16) uint8_t *Mem::m_memory = nullptr;
|
||||
cryptonight_ctx *Mem::create(int threadId)
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algo == xmrig::CRYPTONIGHT_LITE) {
|
||||
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
|
||||
return createLite(threadId);
|
||||
}
|
||||
# endif
|
||||
|
||||
const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory<xmrig::CRYPTONIGHT_HEAVY>()
|
||||
: xmrig::cn_select_memory<xmrig::CRYPTONIGHT>();
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
|
||||
const int ratio = m_doubleHash ? 2 : 1;
|
||||
ctx->memory = &m_memory[size * (threadId * ratio + 1)];
|
||||
ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
struct cryptonight_ctx;
|
||||
|
||||
|
||||
@@ -45,7 +42,7 @@ public:
|
||||
Lock = 4
|
||||
};
|
||||
|
||||
static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled);
|
||||
static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
|
||||
static cryptonight_ctx *create(int threadId);
|
||||
static void *calloc(size_t num, size_t size);
|
||||
static void release();
|
||||
|
||||
@@ -37,22 +37,19 @@
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "log/Log.h"
|
||||
#include "Mem.h"
|
||||
#include "Options.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
m_doubleHash = doubleHash;
|
||||
|
||||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "log/Log.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "Mem.h"
|
||||
#include "Options.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
@@ -145,19 +146,15 @@ static BOOL TrySetLockPagesPrivilege() {
|
||||
}
|
||||
|
||||
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
m_doubleHash = doubleHash;
|
||||
|
||||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
||||
761
src/Options.cpp
Normal file
761
src/Options.cpp
Normal file
@@ -0,0 +1,761 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include "getopt/getopt.h"
|
||||
#else
|
||||
# include <getopt.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_HTTPD
|
||||
# include <microhttpd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "Cpu.h"
|
||||
#include "donate.h"
|
||||
#include "net/Url.h"
|
||||
#include "Options.h"
|
||||
#include "Platform.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
#include "rapidjson/filereadstream.h"
|
||||
#include "version.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
|
||||
Options *Options::m_self = nullptr;
|
||||
|
||||
|
||||
static char const usage[] = "\
|
||||
Usage: " APP_ID " [OPTIONS]\n\
|
||||
Options:\n\
|
||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
|
||||
-o, --url=URL URL of mining server\n\
|
||||
-O, --userpass=U:P username:password pair for mining server\n\
|
||||
-u, --user=USERNAME username for mining server\n\
|
||||
-p, --pass=PASSWORD password for mining server\n\
|
||||
-t, --threads=N number of miner threads\n\
|
||||
-v, --av=N algorithm variation, 0 auto select\n\
|
||||
-k, --keepalive send keepalived for prevent timeout (need pool support)\n\
|
||||
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
|
||||
-R, --retry-pause=N time to pause between retries (default: 5)\n\
|
||||
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
|
||||
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
|
||||
--no-huge-pages disable huge pages support\n\
|
||||
--no-color disable colored output\n\
|
||||
--variant algorithm PoW variant\n\
|
||||
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
|
||||
--user-agent set custom user-agent string for pool\n\
|
||||
-B, --background run the miner in the background\n\
|
||||
-c, --config=FILE load a JSON-format configuration file\n\
|
||||
-l, --log-file=FILE log all output to a file\n"
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
"\
|
||||
-S, --syslog use system log for output messages\n"
|
||||
# endif
|
||||
"\
|
||||
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\
|
||||
--safe safe adjust threads and av settings for current CPU\n\
|
||||
--nicehash enable nicehash/xmrig-proxy support\n\
|
||||
--print-time=N print hashrate report every N seconds\n\
|
||||
--api-port=N port for the miner API\n\
|
||||
--api-access-token=T access token for API\n\
|
||||
--api-worker-id=ID custom worker-id for API\n\
|
||||
-h, --help display this help and exit\n\
|
||||
-V, --version output version information and exit\n\
|
||||
";
|
||||
|
||||
|
||||
static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
|
||||
|
||||
|
||||
static struct option const options[] = {
|
||||
{ "algo", 1, nullptr, 'a' },
|
||||
{ "api-access-token", 1, nullptr, 4001 },
|
||||
{ "api-port", 1, nullptr, 4000 },
|
||||
{ "api-worker-id", 1, nullptr, 4002 },
|
||||
{ "av", 1, nullptr, 'v' },
|
||||
{ "background", 0, nullptr, 'B' },
|
||||
{ "config", 1, nullptr, 'c' },
|
||||
{ "cpu-affinity", 1, nullptr, 1020 },
|
||||
{ "cpu-priority", 1, nullptr, 1021 },
|
||||
{ "donate-level", 1, nullptr, 1003 },
|
||||
{ "dry-run", 0, nullptr, 5000 },
|
||||
{ "help", 0, nullptr, 'h' },
|
||||
{ "keepalive", 0, nullptr ,'k' },
|
||||
{ "log-file", 1, nullptr, 'l' },
|
||||
{ "max-cpu-usage", 1, nullptr, 1004 },
|
||||
{ "nicehash", 0, nullptr, 1006 },
|
||||
{ "no-color", 0, nullptr, 1002 },
|
||||
{ "no-huge-pages", 0, nullptr, 1009 },
|
||||
{ "variant", 1, nullptr, 1010 },
|
||||
{ "pass", 1, nullptr, 'p' },
|
||||
{ "print-time", 1, nullptr, 1007 },
|
||||
{ "retries", 1, nullptr, 'r' },
|
||||
{ "retry-pause", 1, nullptr, 'R' },
|
||||
{ "safe", 0, nullptr, 1005 },
|
||||
{ "syslog", 0, nullptr, 'S' },
|
||||
{ "threads", 1, nullptr, 't' },
|
||||
{ "url", 1, nullptr, 'o' },
|
||||
{ "user", 1, nullptr, 'u' },
|
||||
{ "user-agent", 1, nullptr, 1008 },
|
||||
{ "userpass", 1, nullptr, 'O' },
|
||||
{ "version", 0, nullptr, 'V' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const config_options[] = {
|
||||
{ "algo", 1, nullptr, 'a' },
|
||||
{ "av", 1, nullptr, 'v' },
|
||||
{ "background", 0, nullptr, 'B' },
|
||||
{ "colors", 0, nullptr, 2000 },
|
||||
{ "cpu-affinity", 1, nullptr, 1020 },
|
||||
{ "cpu-priority", 1, nullptr, 1021 },
|
||||
{ "donate-level", 1, nullptr, 1003 },
|
||||
{ "dry-run", 0, nullptr, 5000 },
|
||||
{ "huge-pages", 0, nullptr, 1009 },
|
||||
{ "log-file", 1, nullptr, 'l' },
|
||||
{ "max-cpu-usage", 1, nullptr, 1004 },
|
||||
{ "print-time", 1, nullptr, 1007 },
|
||||
{ "retries", 1, nullptr, 'r' },
|
||||
{ "retry-pause", 1, nullptr, 'R' },
|
||||
{ "safe", 0, nullptr, 1005 },
|
||||
{ "syslog", 0, nullptr, 'S' },
|
||||
{ "threads", 1, nullptr, 't' },
|
||||
{ "user-agent", 1, nullptr, 1008 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const pool_options[] = {
|
||||
{ "url", 1, nullptr, 'o' },
|
||||
{ "pass", 1, nullptr, 'p' },
|
||||
{ "user", 1, nullptr, 'u' },
|
||||
{ "userpass", 1, nullptr, 'O' },
|
||||
{ "keepalive", 0, nullptr ,'k' },
|
||||
{ "variant", 1, nullptr, 1010 },
|
||||
{ "nicehash", 0, nullptr, 1006 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const api_options[] = {
|
||||
{ "port", 1, nullptr, 4000 },
|
||||
{ "access-token", 1, nullptr, 4001 },
|
||||
{ "worker-id", 1, nullptr, 4002 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static const char *algo_names[] = {
|
||||
"cryptonight",
|
||||
# ifndef XMRIG_NO_AEON
|
||||
"cryptonight-lite"
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
Options *Options::parse(int argc, char **argv)
|
||||
{
|
||||
Options *options = new Options(argc, argv);
|
||||
if (options->isReady()) {
|
||||
m_self = options;
|
||||
return m_self;
|
||||
}
|
||||
|
||||
delete options;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const char *Options::algoName() const
|
||||
{
|
||||
return algo_names[m_algo];
|
||||
}
|
||||
|
||||
|
||||
Options::Options(int argc, char **argv) :
|
||||
m_background(false),
|
||||
m_colors(true),
|
||||
m_doubleHash(false),
|
||||
m_dryRun(false),
|
||||
m_hugePages(true),
|
||||
m_ready(false),
|
||||
m_safe(false),
|
||||
m_syslog(false),
|
||||
m_apiToken(nullptr),
|
||||
m_apiWorkerId(nullptr),
|
||||
m_logFile(nullptr),
|
||||
m_userAgent(nullptr),
|
||||
m_algo(0),
|
||||
m_algoVariant(0),
|
||||
m_apiPort(0),
|
||||
m_donateLevel(kDonateLevel),
|
||||
m_maxCpuUsage(75),
|
||||
m_printTime(60),
|
||||
m_priority(-1),
|
||||
m_retries(5),
|
||||
m_retryPause(5),
|
||||
m_threads(0),
|
||||
m_affinity(-1L)
|
||||
{
|
||||
m_pools.push_back(new Url());
|
||||
|
||||
int key;
|
||||
|
||||
while (1) {
|
||||
key = getopt_long(argc, argv, short_options, options, NULL);
|
||||
if (key < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!parseArg(key, optarg)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "%s: unsupported non-option argument '%s'\n", argv[0], argv[optind]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_pools[0]->isValid()) {
|
||||
parseConfig(Platform::defaultConfigName());
|
||||
}
|
||||
|
||||
if (!m_pools[0]->isValid()) {
|
||||
fprintf(stderr, "No pool URL supplied. Exiting.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
m_algoVariant = getAlgoVariant();
|
||||
if (m_algoVariant == AV2_AESNI_DOUBLE || m_algoVariant == AV4_SOFT_AES_DOUBLE) {
|
||||
m_doubleHash = true;
|
||||
}
|
||||
|
||||
if (!m_threads) {
|
||||
m_threads = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage);
|
||||
}
|
||||
else if (m_safe) {
|
||||
const int count = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage);
|
||||
if (m_threads > count) {
|
||||
m_threads = count;
|
||||
}
|
||||
}
|
||||
|
||||
adjust();
|
||||
|
||||
m_ready = true;
|
||||
}
|
||||
|
||||
|
||||
Options::~Options()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Options::getJSON(const char *fileName, rapidjson::Document &doc)
|
||||
{
|
||||
uv_fs_t req;
|
||||
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd));
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
FILE *fp = fdopen(fd, "rb");
|
||||
char buf[8192];
|
||||
rapidjson::FileReadStream is(fp, buf, sizeof(buf));
|
||||
|
||||
doc.ParseStream(is);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
if (doc.HasParseError()) {
|
||||
printf("%s:%d: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return doc.IsObject();
|
||||
}
|
||||
|
||||
|
||||
bool Options::parseArg(int key, const char *arg)
|
||||
{
|
||||
switch (key) {
|
||||
case 'a': /* --algo */
|
||||
if (!setAlgo(arg)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o': /* --url */
|
||||
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
|
||||
Url *url = new Url(arg);
|
||||
if (url->isValid()) {
|
||||
m_pools.push_back(url);
|
||||
}
|
||||
else {
|
||||
delete url;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pools[0]->parse(arg);
|
||||
}
|
||||
|
||||
if (!m_pools.back()->isValid()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'O': /* --userpass */
|
||||
if (!m_pools.back()->setUserpass(arg)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'u': /* --user */
|
||||
m_pools.back()->setUser(arg);
|
||||
break;
|
||||
|
||||
case 'p': /* --pass */
|
||||
m_pools.back()->setPassword(arg);
|
||||
break;
|
||||
|
||||
case 'l': /* --log-file */
|
||||
free(m_logFile);
|
||||
m_logFile = strdup(arg);
|
||||
m_colors = false;
|
||||
break;
|
||||
|
||||
case 4001: /* --access-token */
|
||||
free(m_apiToken);
|
||||
m_apiToken = strdup(arg);
|
||||
break;
|
||||
|
||||
case 4002: /* --worker-id */
|
||||
free(m_apiWorkerId);
|
||||
m_apiWorkerId = strdup(arg);
|
||||
break;
|
||||
|
||||
case 'r': /* --retries */
|
||||
case 'R': /* --retry-pause */
|
||||
case 'v': /* --av */
|
||||
case 1003: /* --donate-level */
|
||||
case 1004: /* --max-cpu-usage */
|
||||
case 1007: /* --print-time */
|
||||
case 1021: /* --cpu-priority */
|
||||
case 4000: /* --api-port */
|
||||
case 1010: /* --variant */
|
||||
return parseArg(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case 'B': /* --background */
|
||||
case 'k': /* --keepalive */
|
||||
case 'S': /* --syslog */
|
||||
case 1005: /* --safe */
|
||||
case 1006: /* --nicehash */
|
||||
case 5000: /* --dry-run */
|
||||
return parseBoolean(key, true);
|
||||
|
||||
case 1002: /* --no-color */
|
||||
case 1009: /* --no-huge-pages */
|
||||
return parseBoolean(key, false);
|
||||
|
||||
case 't': /* --threads */
|
||||
if (strncmp(arg, "all", 3) == 0) {
|
||||
m_threads = Cpu::threads();
|
||||
return true;
|
||||
}
|
||||
|
||||
return parseArg(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case 'V': /* --version */
|
||||
showVersion();
|
||||
return false;
|
||||
|
||||
case 'h': /* --help */
|
||||
showUsage(0);
|
||||
return false;
|
||||
|
||||
case 'c': /* --config */
|
||||
parseConfig(arg);
|
||||
break;
|
||||
|
||||
case 1020: { /* --cpu-affinity */
|
||||
const char *p = strstr(arg, "0x");
|
||||
return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
|
||||
}
|
||||
|
||||
case 1008: /* --user-agent */
|
||||
free(m_userAgent);
|
||||
m_userAgent = strdup(arg);
|
||||
break;
|
||||
|
||||
default:
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Options::parseArg(int key, uint64_t arg)
|
||||
{
|
||||
switch (key) {
|
||||
case 'r': /* --retries */
|
||||
if (arg < 1 || arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retries = (int) arg;
|
||||
break;
|
||||
|
||||
case 'R': /* --retry-pause */
|
||||
if (arg < 1 || arg > 3600) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retryPause = (int) arg;
|
||||
break;
|
||||
|
||||
case 't': /* --threads */
|
||||
if (arg < 1 || arg > 1024) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_threads = (int) arg;
|
||||
break;
|
||||
|
||||
case 'v': /* --av */
|
||||
if (arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_algoVariant = (int) arg;
|
||||
break;
|
||||
|
||||
case 1003: /* --donate-level */
|
||||
if (arg < 1 || arg > 99) {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_donateLevel = (int) arg;
|
||||
break;
|
||||
|
||||
case 1004: /* --max-cpu-usage */
|
||||
if (arg < 1 || arg > 100) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_maxCpuUsage = (int) arg;
|
||||
break;
|
||||
|
||||
case 1007: /* --print-time */
|
||||
if (arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_printTime = (int) arg;
|
||||
break;
|
||||
|
||||
case 1010: /* --variant */
|
||||
m_pools.back()->setVariant((int) arg);
|
||||
break;
|
||||
|
||||
case 1020: /* --cpu-affinity */
|
||||
if (arg) {
|
||||
m_affinity = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1021: /* --cpu-priority */
|
||||
if (arg <= 5) {
|
||||
m_priority = (int) arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4000: /* --api-port */
|
||||
if (arg <= 65536) {
|
||||
m_apiPort = (int) arg;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Options::parseBoolean(int key, bool enable)
|
||||
{
|
||||
switch (key) {
|
||||
case 'k': /* --keepalive */
|
||||
m_pools.back()->setKeepAlive(enable);
|
||||
break;
|
||||
|
||||
case 'B': /* --background */
|
||||
m_background = enable;
|
||||
m_colors = enable ? false : m_colors;
|
||||
break;
|
||||
|
||||
case 'S': /* --syslog */
|
||||
m_syslog = enable;
|
||||
m_colors = enable ? false : m_colors;
|
||||
break;
|
||||
|
||||
case 1002: /* --no-color */
|
||||
m_colors = enable;
|
||||
break;
|
||||
|
||||
case 1005: /* --safe */
|
||||
m_safe = enable;
|
||||
break;
|
||||
|
||||
case 1006: /* --nicehash */
|
||||
m_pools.back()->setNicehash(enable);
|
||||
break;
|
||||
|
||||
case 1009: /* --no-huge-pages */
|
||||
m_hugePages = enable;
|
||||
break;
|
||||
|
||||
case 2000: /* colors */
|
||||
m_colors = enable;
|
||||
break;
|
||||
|
||||
case 5000: /* --dry-run */
|
||||
m_dryRun = enable;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Url *Options::parseUrl(const char *arg) const
|
||||
{
|
||||
auto url = new Url(arg);
|
||||
if (!url->isValid()) {
|
||||
delete url;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
void Options::adjust()
|
||||
{
|
||||
for (Url *url : m_pools) {
|
||||
url->adjust(m_algo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Options::parseConfig(const char *fileName)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (!getJSON(fileName, doc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
|
||||
parseJSON(&config_options[i], doc);
|
||||
}
|
||||
|
||||
const rapidjson::Value &pools = doc["pools"];
|
||||
if (pools.IsArray()) {
|
||||
for (const rapidjson::Value &value : pools.GetArray()) {
|
||||
if (!value.IsObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(pool_options); i++) {
|
||||
parseJSON(&pool_options[i], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value &api = doc["api"];
|
||||
if (api.IsObject()) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) {
|
||||
parseJSON(&api_options[i], api);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Options::parseJSON(const struct option *option, const rapidjson::Value &object)
|
||||
{
|
||||
if (!option->name || !object.HasMember(option->name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rapidjson::Value &value = object[option->name];
|
||||
|
||||
if (option->has_arg && value.IsString()) {
|
||||
parseArg(option->val, value.GetString());
|
||||
}
|
||||
else if (option->has_arg && value.IsInt64()) {
|
||||
parseArg(option->val, value.GetUint64());
|
||||
}
|
||||
else if (!option->has_arg && value.IsBool()) {
|
||||
parseBoolean(option->val, value.IsTrue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Options::showUsage(int status) const
|
||||
{
|
||||
if (status) {
|
||||
fprintf(stderr, "Try \"" APP_ID "\" --help' for more information.\n");
|
||||
}
|
||||
else {
|
||||
printf(usage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Options::showVersion()
|
||||
{
|
||||
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
|
||||
|
||||
# if defined(__clang__)
|
||||
" with clang " __clang_version__);
|
||||
# elif defined(__GNUC__)
|
||||
" with GCC");
|
||||
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
" with MSVC");
|
||||
printf(" %d", MSVC_VERSION);
|
||||
# else
|
||||
);
|
||||
# endif
|
||||
|
||||
printf("\n features:"
|
||||
# if defined(__i386__) || defined(_M_IX86)
|
||||
" i386"
|
||||
# elif defined(__x86_64__) || defined(_M_AMD64)
|
||||
" x86_64"
|
||||
# endif
|
||||
|
||||
# if defined(__AES__) || defined(_MSC_VER)
|
||||
" AES-NI"
|
||||
# endif
|
||||
"\n");
|
||||
|
||||
printf("\nlibuv/%s\n", uv_version_string());
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
printf("libmicrohttpd/%s\n", MHD_get_version());
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool Options::setAlgo(const char *algo)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(algo_names); i++) {
|
||||
if (algo_names[i] && !strcmp(algo, algo_names[i])) {
|
||||
m_algo = (int) i;
|
||||
break;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) {
|
||||
m_algo = xmrig::ALGO_CRYPTONIGHT_LITE;
|
||||
break;
|
||||
}
|
||||
# endif
|
||||
|
||||
if (i == ARRAY_SIZE(algo_names) - 1) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int Options::getAlgoVariant() const
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
|
||||
return getAlgoVariantLite();
|
||||
}
|
||||
# endif
|
||||
|
||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV1_AESNI : AV3_SOFT_AES;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
||||
return m_algoVariant + 2;
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
int Options::getAlgoVariantLite() const
|
||||
{
|
||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV2_AESNI_DOUBLE : AV4_SOFT_AES_DOUBLE;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
||||
return m_algoVariant + 2;
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
}
|
||||
#endif
|
||||
133
src/Options.h
Normal file
133
src/Options.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __OPTIONS_H__
|
||||
#define __OPTIONS_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
class Url;
|
||||
struct option;
|
||||
|
||||
|
||||
class Options
|
||||
{
|
||||
public:
|
||||
enum AlgoVariant {
|
||||
AV0_AUTO,
|
||||
AV1_AESNI,
|
||||
AV2_AESNI_DOUBLE,
|
||||
AV3_SOFT_AES,
|
||||
AV4_SOFT_AES_DOUBLE,
|
||||
AV_MAX
|
||||
};
|
||||
|
||||
static inline Options* i() { return m_self; }
|
||||
static Options *parse(int argc, char **argv);
|
||||
|
||||
inline bool background() const { return m_background; }
|
||||
inline bool colors() const { return m_colors; }
|
||||
inline bool doubleHash() const { return m_doubleHash; }
|
||||
inline bool dryRun() const { return m_dryRun; }
|
||||
inline bool hugePages() const { return m_hugePages; }
|
||||
inline bool syslog() const { return m_syslog; }
|
||||
inline const char *apiToken() const { return m_apiToken; }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline const char *logFile() const { return m_logFile; }
|
||||
inline const char *userAgent() const { return m_userAgent; }
|
||||
inline const std::vector<Url*> &pools() const { return m_pools; }
|
||||
inline int algo() const { return m_algo; }
|
||||
inline int algoVariant() const { return m_algoVariant; }
|
||||
inline int apiPort() const { return m_apiPort; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
inline void setColors(bool colors) { m_colors = colors; }
|
||||
|
||||
inline static void release() { delete m_self; }
|
||||
|
||||
const char *algoName() const;
|
||||
|
||||
private:
|
||||
Options(int argc, char **argv);
|
||||
~Options();
|
||||
|
||||
inline bool isReady() const { return m_ready; }
|
||||
|
||||
static Options *m_self;
|
||||
|
||||
bool getJSON(const char *fileName, rapidjson::Document &doc);
|
||||
bool parseArg(int key, const char *arg);
|
||||
bool parseArg(int key, uint64_t arg);
|
||||
bool parseBoolean(int key, bool enable);
|
||||
Url *parseUrl(const char *arg) const;
|
||||
void adjust();
|
||||
void parseConfig(const char *fileName);
|
||||
void parseJSON(const struct option *option, const rapidjson::Value &object);
|
||||
void showUsage(int status) const;
|
||||
void showVersion(void);
|
||||
|
||||
bool setAlgo(const char *algo);
|
||||
|
||||
int getAlgoVariant() const;
|
||||
# ifndef XMRIG_NO_AEON
|
||||
int getAlgoVariantLite() const;
|
||||
# endif
|
||||
|
||||
bool m_background;
|
||||
bool m_colors;
|
||||
bool m_doubleHash;
|
||||
bool m_dryRun;
|
||||
bool m_hugePages;
|
||||
bool m_ready;
|
||||
bool m_safe;
|
||||
bool m_syslog;
|
||||
char *m_apiToken;
|
||||
char *m_apiWorkerId;
|
||||
char *m_logFile;
|
||||
char *m_userAgent;
|
||||
int m_algo;
|
||||
int m_algoVariant;
|
||||
int m_apiPort;
|
||||
int m_donateLevel;
|
||||
int m_maxCpuUsage;
|
||||
int m_printTime;
|
||||
int m_priority;
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
std::vector<Url*> m_pools;
|
||||
};
|
||||
|
||||
#endif /* __OPTIONS_H__ */
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,17 +27,16 @@
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "log/Log.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Url.h"
|
||||
#include "Options.h"
|
||||
#include "Summary.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
static void print_versions(xmrig::Config *config)
|
||||
static void print_versions()
|
||||
{
|
||||
char buf[16];
|
||||
|
||||
@@ -52,13 +51,13 @@ static void print_versions(xmrig::Config *config)
|
||||
# endif
|
||||
|
||||
|
||||
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s",
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s",
|
||||
APP_VERSION, uv_version_string(), buf);
|
||||
}
|
||||
|
||||
|
||||
static void print_memory(xmrig::Config *config) {
|
||||
if (config->isColors()) {
|
||||
static void print_memory() {
|
||||
if (Options::i()->colors()) {
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s",
|
||||
Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable",
|
||||
Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled");
|
||||
@@ -69,9 +68,9 @@ static void print_memory(xmrig::Config *config) {
|
||||
}
|
||||
|
||||
|
||||
static void print_cpu(xmrig::Config *config)
|
||||
static void print_cpu()
|
||||
{
|
||||
if (config->isColors()) {
|
||||
if (Options::i()->colors()) {
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI",
|
||||
Cpu::brand(),
|
||||
Cpu::sockets(),
|
||||
@@ -90,32 +89,32 @@ static void print_cpu(xmrig::Config *config)
|
||||
}
|
||||
|
||||
|
||||
static void print_threads(xmrig::Config *config)
|
||||
static void print_threads()
|
||||
{
|
||||
char buf[32];
|
||||
if (config->affinity() != -1L) {
|
||||
snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity());
|
||||
if (Options::i()->affinity() != -1L) {
|
||||
snprintf(buf, 32, ", affinity=0x%" PRIX64, Options::i()->affinity());
|
||||
}
|
||||
else {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s",
|
||||
config->threadsCount(),
|
||||
config->algoName(),
|
||||
config->algoVariant(),
|
||||
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "",
|
||||
config->donateLevel(),
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s",
|
||||
Options::i()->threads(),
|
||||
Options::i()->algoName(),
|
||||
Options::i()->algoVariant(),
|
||||
Options::i()->colors() && Options::i()->donateLevel() == 0 ? "\x1B[01;31m" : "",
|
||||
Options::i()->donateLevel(),
|
||||
buf);
|
||||
}
|
||||
|
||||
|
||||
static void print_pools(xmrig::Config *config)
|
||||
static void print_pools()
|
||||
{
|
||||
const std::vector<Url*> &pools = config->pools();
|
||||
const std::vector<Url*> &pools = Options::i()->pools();
|
||||
|
||||
for (size_t i = 0; i < pools.size(); ++i) {
|
||||
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d",
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d",
|
||||
i + 1,
|
||||
pools[i]->host(),
|
||||
pools[i]->port());
|
||||
@@ -123,29 +122,27 @@ static void print_pools(xmrig::Config *config)
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
for (size_t i = 0; i < pools.size(); ++i) {
|
||||
Log::i()->text("%s:%d, user: %s, pass: %s, ka: %d, nicehash: %d", pools[i]->host(), pools[i]->port(), pools[i]->user(), pools[i]->password(), pools[i]->keepAlive(), pools[i]->isNicehash());
|
||||
Log::i()->text("%s:%d, user: %s, pass: %s, ka: %d, nicehash: %d", pools[i]->host(), pools[i]->port(), pools[i]->user(), pools[i]->password(), pools[i]->isKeepAlive(), pools[i]->isNicehash());
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_API
|
||||
static void print_api(xmrig::Config *config)
|
||||
static void print_api()
|
||||
{
|
||||
const int port = config->apiPort();
|
||||
if (port == 0) {
|
||||
if (Options::i()->apiPort() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI BIND: \x1B[01;36m%s:%d" : " * API BIND: %s:%d",
|
||||
config->isApiIPv6() ? "[::]" : "0.0.0.0", port);
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", Options::i()->apiPort());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void print_commands(xmrig::Config *config)
|
||||
static void print_commands()
|
||||
{
|
||||
if (config->isColors()) {
|
||||
if (Options::i()->colors()) {
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume");
|
||||
}
|
||||
else {
|
||||
@@ -154,19 +151,19 @@ static void print_commands(xmrig::Config *config)
|
||||
}
|
||||
|
||||
|
||||
void Summary::print(xmrig::Controller *controller)
|
||||
void Summary::print()
|
||||
{
|
||||
print_versions(controller->config());
|
||||
print_memory(controller->config());
|
||||
print_cpu(controller->config());
|
||||
print_threads(controller->config());
|
||||
print_pools(controller->config());
|
||||
print_versions();
|
||||
print_memory();
|
||||
print_cpu();
|
||||
print_threads();
|
||||
print_pools();
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
print_api(controller->config());
|
||||
print_api();
|
||||
# endif
|
||||
|
||||
print_commands(controller->config());
|
||||
print_commands();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,15 +25,10 @@
|
||||
#define __SUMMARY_H__
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Summary
|
||||
{
|
||||
public:
|
||||
static void print(xmrig::Controller *controller);
|
||||
static void print();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,17 +25,17 @@
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "api/ApiRouter.h"
|
||||
#include "api/HttpReply.h"
|
||||
#include "api/HttpRequest.h"
|
||||
#include "api/ApiState.h"
|
||||
|
||||
|
||||
ApiRouter *Api::m_router = nullptr;
|
||||
ApiState *Api::m_state = nullptr;
|
||||
uv_mutex_t Api::m_mutex;
|
||||
|
||||
|
||||
bool Api::start(xmrig::Controller *controller)
|
||||
bool Api::start()
|
||||
{
|
||||
m_router = new ApiRouter(controller);
|
||||
uv_mutex_init(&m_mutex);
|
||||
m_state = new ApiState();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -43,40 +43,43 @@ bool Api::start(xmrig::Controller *controller)
|
||||
|
||||
void Api::release()
|
||||
{
|
||||
delete m_router;
|
||||
delete m_state;
|
||||
}
|
||||
|
||||
|
||||
void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
|
||||
char *Api::get(const char *url, int *status)
|
||||
{
|
||||
if (!m_router) {
|
||||
reply.status = 500;
|
||||
return;
|
||||
if (!m_state) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (req.method() == xmrig::HttpRequest::Get) {
|
||||
return m_router->get(req, reply);
|
||||
}
|
||||
uv_mutex_lock(&m_mutex);
|
||||
char *buf = m_state->get(url, status);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
m_router->exec(req, reply);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
void Api::tick(const Hashrate *hashrate)
|
||||
{
|
||||
if (!m_router) {
|
||||
if (!m_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_router->tick(hashrate);
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_state->tick(hashrate);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
|
||||
void Api::tick(const NetworkState &network)
|
||||
{
|
||||
if (!m_router) {
|
||||
if (!m_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_router->tick(network);
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_state->tick(network);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -28,30 +28,24 @@
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
class ApiRouter;
|
||||
class ApiState;
|
||||
class Hashrate;
|
||||
class NetworkState;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
class HttpReply;
|
||||
class HttpRequest;
|
||||
}
|
||||
|
||||
|
||||
class Api
|
||||
{
|
||||
public:
|
||||
static bool start(xmrig::Controller *controller);
|
||||
static bool start();
|
||||
static void release();
|
||||
|
||||
static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
|
||||
static char *get(const char *url, int *status);
|
||||
static void tick(const Hashrate *hashrate);
|
||||
static void tick(const NetworkState &results);
|
||||
|
||||
private:
|
||||
static ApiRouter *m_router;
|
||||
static ApiState *m_state;
|
||||
static uv_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
#endif /* __API_H__ */
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -32,19 +32,15 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "api/ApiRouter.h"
|
||||
#include "api/HttpReply.h"
|
||||
#include "api/HttpRequest.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "api/ApiState.h"
|
||||
#include "Cpu.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Job.h"
|
||||
#include "Options.h"
|
||||
#include "Platform.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "version.h"
|
||||
#include "workers/Hashrate.h"
|
||||
|
||||
@@ -65,47 +61,34 @@ static inline double normalize(double d)
|
||||
}
|
||||
|
||||
|
||||
ApiRouter::ApiRouter(xmrig::Controller *controller) :
|
||||
m_controller(controller)
|
||||
ApiState::ApiState()
|
||||
{
|
||||
m_threads = controller->config()->threadsCount();
|
||||
m_threads = Options::i()->threads();
|
||||
m_hashrate = new double[m_threads * 3]();
|
||||
|
||||
memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
|
||||
memset(m_workerId, 0, sizeof(m_workerId));
|
||||
|
||||
setWorkerId(controller->config()->apiWorkerId());
|
||||
if (Options::i()->apiWorkerId()) {
|
||||
strncpy(m_workerId, Options::i()->apiWorkerId(), sizeof(m_workerId) - 1);
|
||||
}
|
||||
else {
|
||||
gethostname(m_workerId, sizeof(m_workerId) - 1);
|
||||
}
|
||||
|
||||
genId();
|
||||
}
|
||||
|
||||
|
||||
ApiRouter::~ApiRouter()
|
||||
ApiState::~ApiState()
|
||||
{
|
||||
delete [] m_hashrate;
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const
|
||||
char *ApiState::get(const char *url, int *status) const
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
|
||||
if (req.match("/1/config")) {
|
||||
if (req.isRestricted()) {
|
||||
reply.status = 403;
|
||||
return;
|
||||
}
|
||||
|
||||
m_controller->config()->getJSON(doc);
|
||||
|
||||
return finalize(reply, doc);
|
||||
}
|
||||
|
||||
if (req.match("/1/threads")) {
|
||||
getThreads(doc);
|
||||
|
||||
return finalize(reply, doc);
|
||||
}
|
||||
|
||||
doc.SetObject();
|
||||
|
||||
getIdentify(doc);
|
||||
@@ -114,22 +97,11 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
|
||||
getResults(doc);
|
||||
getConnection(doc);
|
||||
|
||||
return finalize(reply, doc);
|
||||
return finalize(doc);
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
|
||||
{
|
||||
if (req.method() == xmrig::HttpRequest::Put && req.match("/1/config")) {
|
||||
m_controller->config()->reload(req.body());
|
||||
return;
|
||||
}
|
||||
|
||||
reply.status = 404;
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::tick(const Hashrate *hashrate)
|
||||
void ApiState::tick(const Hashrate *hashrate)
|
||||
{
|
||||
for (int i = 0; i < m_threads; ++i) {
|
||||
m_hashrate[i * 3] = hashrate->calc((size_t) i, Hashrate::ShortInterval);
|
||||
@@ -144,32 +116,24 @@ void ApiRouter::tick(const Hashrate *hashrate)
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::tick(const NetworkState &network)
|
||||
void ApiState::tick(const NetworkState &network)
|
||||
{
|
||||
m_network = network;
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig)
|
||||
{
|
||||
updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const
|
||||
char *ApiState::finalize(rapidjson::Document &doc) const
|
||||
{
|
||||
rapidjson::StringBuffer buffer(0, 4096);
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
||||
writer.SetMaxDecimalPlaces(10);
|
||||
doc.Accept(writer);
|
||||
|
||||
reply.status = 200;
|
||||
reply.buf = strdup(buffer.GetString());
|
||||
reply.size = buffer.GetSize();
|
||||
return strdup(buffer.GetString());
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::genId()
|
||||
void ApiState::genId()
|
||||
{
|
||||
memset(m_id, 0, sizeof(m_id));
|
||||
|
||||
@@ -202,7 +166,7 @@ void ApiRouter::genId()
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getConnection(rapidjson::Document &doc) const
|
||||
void ApiState::getConnection(rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
@@ -217,7 +181,7 @@ void ApiRouter::getConnection(rapidjson::Document &doc) const
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getHashrate(rapidjson::Document &doc) const
|
||||
void ApiState::getHashrate(rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
@@ -245,14 +209,14 @@ void ApiRouter::getHashrate(rapidjson::Document &doc) const
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getIdentify(rapidjson::Document &doc) const
|
||||
void ApiState::getIdentify(rapidjson::Document &doc) const
|
||||
{
|
||||
doc.AddMember("id", rapidjson::StringRef(m_id), doc.GetAllocator());
|
||||
doc.AddMember("worker_id", rapidjson::StringRef(m_workerId), doc.GetAllocator());
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getMiner(rapidjson::Document &doc) const
|
||||
void ApiState::getMiner(rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
@@ -266,13 +230,13 @@ void ApiRouter::getMiner(rapidjson::Document &doc) const
|
||||
doc.AddMember("kind", APP_KIND, allocator);
|
||||
doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator);
|
||||
doc.AddMember("cpu", cpu, allocator);
|
||||
doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algoName()), allocator);
|
||||
doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator);
|
||||
doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator);
|
||||
doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator);
|
||||
doc.AddMember("donate_level", Options::i()->donateLevel(), allocator);
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getResults(rapidjson::Document &doc) const
|
||||
void ApiState::getResults(rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
@@ -294,42 +258,3 @@ void ApiRouter::getResults(rapidjson::Document &doc) const
|
||||
|
||||
doc.AddMember("results", results, allocator);
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::getThreads(rapidjson::Document &doc) const
|
||||
{
|
||||
doc.SetArray();
|
||||
|
||||
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
|
||||
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
doc.PushBack(thread->toAPI(doc), doc.GetAllocator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::setWorkerId(const char *id)
|
||||
{
|
||||
memset(m_workerId, 0, sizeof(m_workerId));
|
||||
|
||||
if (id && strlen(id) > 0) {
|
||||
strncpy(m_workerId, id, sizeof(m_workerId) - 1);
|
||||
}
|
||||
else {
|
||||
gethostname(m_workerId, sizeof(m_workerId) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::updateWorkerId(const char *id, const char *previousId)
|
||||
{
|
||||
if (id == previousId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (id != nullptr && previousId != nullptr && strcmp(id, previousId) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setWorkerId(id);
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,51 +21,35 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __APIROUTER_H__
|
||||
#define __APIROUTER_H__
|
||||
#ifndef __APISTATE_H__
|
||||
#define __APISTATE_H__
|
||||
|
||||
|
||||
#include "api/NetworkState.h"
|
||||
#include "interfaces/IControllerListener.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
class Hashrate;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
class HttpReply;
|
||||
class HttpRequest;
|
||||
}
|
||||
|
||||
|
||||
class ApiRouter : public xmrig::IControllerListener
|
||||
class ApiState
|
||||
{
|
||||
public:
|
||||
ApiRouter(xmrig::Controller *controller);
|
||||
~ApiRouter();
|
||||
|
||||
void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const;
|
||||
void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
|
||||
ApiState();
|
||||
~ApiState();
|
||||
|
||||
char *get(const char *url, int *status) const;
|
||||
void tick(const Hashrate *hashrate);
|
||||
void tick(const NetworkState &results);
|
||||
|
||||
protected:
|
||||
void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override;
|
||||
|
||||
private:
|
||||
void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const;
|
||||
char *finalize(rapidjson::Document &doc) const;
|
||||
void genId();
|
||||
void getConnection(rapidjson::Document &doc) const;
|
||||
void getHashrate(rapidjson::Document &doc) const;
|
||||
void getIdentify(rapidjson::Document &doc) const;
|
||||
void getMiner(rapidjson::Document &doc) const;
|
||||
void getResults(rapidjson::Document &doc) const;
|
||||
void getThreads(rapidjson::Document &doc) const;
|
||||
void setWorkerId(const char *id);
|
||||
void updateWorkerId(const char *id, const char *previousId);
|
||||
|
||||
char m_id[17];
|
||||
char m_workerId[128];
|
||||
@@ -74,7 +58,6 @@ private:
|
||||
double m_totalHashrate[3];
|
||||
int m_threads;
|
||||
NetworkState m_network;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
#endif /* __APIROUTER_H__ */
|
||||
#endif /* __APISTATE_H__ */
|
||||
@@ -1,69 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __HTTPBODY_H__
|
||||
#define __HTTPBODY_H__
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class HttpBody
|
||||
{
|
||||
public:
|
||||
inline HttpBody() :
|
||||
m_pos(0)
|
||||
{}
|
||||
|
||||
|
||||
inline bool write(const char *data, size_t size)
|
||||
{
|
||||
if (size > (sizeof(m_data) - m_pos - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_data + m_pos, data, size);
|
||||
|
||||
m_pos += size;
|
||||
m_data[m_pos] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline const char *data() const { return m_data; }
|
||||
|
||||
private:
|
||||
char m_data[32768];
|
||||
size_t m_pos;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __HTTPBODY_H__ */
|
||||
@@ -1,53 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __HTTPREPLY_H__
|
||||
#define __HTTPREPLY_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class HttpReply
|
||||
{
|
||||
public:
|
||||
HttpReply() :
|
||||
buf(nullptr),
|
||||
status(200),
|
||||
size(0)
|
||||
{}
|
||||
|
||||
char *buf;
|
||||
int status;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __HTTPREPLY_H__ */
|
||||
@@ -1,175 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <microhttpd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "api/HttpBody.h"
|
||||
#include "api/HttpRequest.h"
|
||||
#include "api/HttpReply.h"
|
||||
|
||||
|
||||
#ifndef MHD_HTTP_PAYLOAD_TOO_LARGE
|
||||
# define MHD_HTTP_PAYLOAD_TOO_LARGE 413
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::HttpRequest::HttpRequest(MHD_Connection *connection, const char *url, const char *method, const char *uploadData, size_t *uploadSize, void **cls) :
|
||||
m_fulfilled(true),
|
||||
m_restricted(true),
|
||||
m_uploadData(uploadData),
|
||||
m_url(url),
|
||||
m_body(static_cast<HttpBody*>(*cls)),
|
||||
m_method(Unsupported),
|
||||
m_connection(connection),
|
||||
m_uploadSize(uploadSize),
|
||||
m_cls(cls)
|
||||
{
|
||||
if (strcmp(method, MHD_HTTP_METHOD_OPTIONS) == 0) {
|
||||
m_method = Options;
|
||||
}
|
||||
else if (strcmp(method, MHD_HTTP_METHOD_GET) == 0) {
|
||||
m_method = Get;
|
||||
}
|
||||
else if (strcmp(method, MHD_HTTP_METHOD_PUT) == 0) {
|
||||
m_method = Put;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::HttpRequest::~HttpRequest()
|
||||
{
|
||||
if (m_fulfilled) {
|
||||
delete m_body;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpRequest::match(const char *path) const
|
||||
{
|
||||
return strcmp(m_url, path) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::HttpRequest::process(const char *accessToken, bool restricted, xmrig::HttpReply &reply)
|
||||
{
|
||||
m_restricted = restricted || !accessToken;
|
||||
|
||||
if (m_body) {
|
||||
if (*m_uploadSize != 0) {
|
||||
if (!m_body->write(m_uploadData, *m_uploadSize)) {
|
||||
*m_cls = nullptr;
|
||||
m_fulfilled = true;
|
||||
reply.status = MHD_HTTP_PAYLOAD_TOO_LARGE;
|
||||
return false;
|
||||
}
|
||||
|
||||
*m_uploadSize = 0;
|
||||
m_fulfilled = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
m_fulfilled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
reply.status = auth(accessToken);
|
||||
if (reply.status != MHD_HTTP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_restricted && m_method != Get) {
|
||||
reply.status = MHD_HTTP_FORBIDDEN;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_method == Get) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *contentType = MHD_lookup_connection_value(m_connection, MHD_HEADER_KIND, "Content-Type");
|
||||
if (!contentType || strcmp(contentType, "application/json") != 0) {
|
||||
reply.status = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_body = new xmrig::HttpBody();
|
||||
m_fulfilled = false;
|
||||
*m_cls = m_body;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::HttpRequest::body() const
|
||||
{
|
||||
return m_body ? m_body->data() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::HttpRequest::end(const HttpReply &reply)
|
||||
{
|
||||
if (reply.buf) {
|
||||
return end(reply.status, MHD_create_response_from_buffer(reply.size ? reply.size : strlen(reply.buf), (void*) reply.buf, MHD_RESPMEM_MUST_FREE));
|
||||
}
|
||||
|
||||
return end(reply.status, nullptr);
|
||||
}
|
||||
|
||||
|
||||
int xmrig::HttpRequest::end(int status, MHD_Response *rsp)
|
||||
{
|
||||
if (!rsp) {
|
||||
rsp = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
|
||||
}
|
||||
|
||||
MHD_add_response_header(rsp, "Content-Type", "application/json");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET, PUT");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization");
|
||||
|
||||
const int ret = MHD_queue_response(m_connection, status, rsp);
|
||||
MHD_destroy_response(rsp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::HttpRequest::auth(const char *accessToken)
|
||||
{
|
||||
if (!accessToken) {
|
||||
return MHD_HTTP_OK;
|
||||
}
|
||||
|
||||
const char *header = MHD_lookup_connection_value(m_connection, MHD_HEADER_KIND, "Authorization");
|
||||
if (accessToken && !header) {
|
||||
return MHD_HTTP_UNAUTHORIZED;
|
||||
}
|
||||
|
||||
const size_t size = strlen(header);
|
||||
if (size < 8 || strlen(accessToken) != size - 7 || memcmp("Bearer ", header, 7) != 0) {
|
||||
return MHD_HTTP_FORBIDDEN;
|
||||
}
|
||||
|
||||
return strncmp(accessToken, header + 7, strlen(accessToken)) == 0 ? MHD_HTTP_OK : MHD_HTTP_FORBIDDEN;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __HTTPREQUEST_H__
|
||||
#define __HTTPREQUEST_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
struct MHD_Connection;
|
||||
struct MHD_Response;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class HttpBody;
|
||||
class HttpReply;
|
||||
|
||||
|
||||
class HttpRequest
|
||||
{
|
||||
public:
|
||||
enum Method {
|
||||
Unsupported,
|
||||
Options,
|
||||
Get,
|
||||
Put
|
||||
};
|
||||
|
||||
HttpRequest(MHD_Connection *connection, const char *url, const char *method, const char *uploadData, size_t *uploadSize, void **cls);
|
||||
~HttpRequest();
|
||||
|
||||
inline bool isFulfilled() const { return m_fulfilled; }
|
||||
inline bool isRestricted() const { return m_restricted; }
|
||||
inline Method method() const { return m_method; }
|
||||
|
||||
bool match(const char *path) const;
|
||||
bool process(const char *accessToken, bool restricted, xmrig::HttpReply &reply);
|
||||
const char *body() const;
|
||||
int end(const HttpReply &reply);
|
||||
int end(int status, MHD_Response *rsp);
|
||||
|
||||
private:
|
||||
int auth(const char *accessToken);
|
||||
|
||||
bool m_fulfilled;
|
||||
bool m_restricted;
|
||||
const char *m_uploadData;
|
||||
const char *m_url;
|
||||
HttpBody *m_body;
|
||||
Method m_method;
|
||||
MHD_Connection *m_connection;
|
||||
size_t *m_uploadSize;
|
||||
void **m_cls;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __HTTPREQUEST_H__ */
|
||||
@@ -28,64 +28,14 @@
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "api/Httpd.h"
|
||||
#include "api/HttpReply.h"
|
||||
#include "api/HttpRequest.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
class UploadCtx
|
||||
{
|
||||
public:
|
||||
inline UploadCtx() :
|
||||
m_pos(0)
|
||||
{}
|
||||
|
||||
|
||||
inline bool write(const char *data, size_t size)
|
||||
{
|
||||
if (size > (sizeof(m_data) - m_pos - 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_data + m_pos, data, size);
|
||||
|
||||
m_pos += size;
|
||||
m_data[m_pos] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline const char *data() const { return m_data; }
|
||||
|
||||
private:
|
||||
char m_data[32768];
|
||||
size_t m_pos;
|
||||
};
|
||||
|
||||
|
||||
Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
|
||||
m_idle(true),
|
||||
m_IPv6(IPv6),
|
||||
m_restricted(restricted),
|
||||
m_accessToken(accessToken ? strdup(accessToken) : nullptr),
|
||||
Httpd::Httpd(int port, const char *accessToken) :
|
||||
m_accessToken(accessToken),
|
||||
m_port(port),
|
||||
m_daemon(nullptr)
|
||||
{
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
m_timer.data = this;
|
||||
}
|
||||
|
||||
|
||||
Httpd::~Httpd()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
|
||||
if (m_daemon) {
|
||||
MHD_stop_daemon(m_daemon);
|
||||
}
|
||||
|
||||
delete m_accessToken;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,14 +45,11 @@ bool Httpd::start()
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int flags = 0;
|
||||
# if MHD_VERSION >= 0x00093500
|
||||
if (m_IPv6 && MHD_is_feature_supported(MHD_FEATURE_IPv6)) {
|
||||
flags |= MHD_USE_DUAL_STACK;
|
||||
}
|
||||
unsigned int flags = MHD_USE_SELECT_INTERNALLY;
|
||||
|
||||
# if MHD_VERSION >= 0x00093500
|
||||
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
|
||||
flags |= MHD_USE_EPOLL_LINUX_ONLY;
|
||||
flags = MHD_USE_EPOLL_LINUX_ONLY | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY;
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -112,61 +59,66 @@ bool Httpd::start()
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int Httpd::process(xmrig::HttpRequest &req)
|
||||
int Httpd::auth(const char *header)
|
||||
{
|
||||
xmrig::HttpReply reply;
|
||||
if (!req.process(m_accessToken, m_restricted, reply)) {
|
||||
return req.end(reply);
|
||||
if (!m_accessToken) {
|
||||
return MHD_HTTP_OK;
|
||||
}
|
||||
|
||||
if (!req.isFulfilled()) {
|
||||
return MHD_YES;
|
||||
if (m_accessToken && !header) {
|
||||
return MHD_HTTP_UNAUTHORIZED;
|
||||
}
|
||||
|
||||
Api::exec(req, reply);
|
||||
const size_t size = strlen(header);
|
||||
if (size < 8 || strlen(m_accessToken) != size - 7 || memcmp("Bearer ", header, 7) != 0) {
|
||||
return MHD_HTTP_FORBIDDEN;
|
||||
}
|
||||
|
||||
return req.end(reply);
|
||||
return strncmp(m_accessToken, header + 7, strlen(m_accessToken)) == 0 ? MHD_HTTP_OK : MHD_HTTP_FORBIDDEN;
|
||||
}
|
||||
|
||||
|
||||
void Httpd::run()
|
||||
int Httpd::done(MHD_Connection *connection, int status, MHD_Response *rsp)
|
||||
{
|
||||
MHD_run(m_daemon);
|
||||
if (!rsp) {
|
||||
rsp = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
|
||||
}
|
||||
|
||||
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
|
||||
if (m_idle && info->num_connections) {
|
||||
uv_timer_set_repeat(&m_timer, kActiveInterval);
|
||||
m_idle = false;
|
||||
}
|
||||
else if (!m_idle && !info->num_connections) {
|
||||
uv_timer_set_repeat(&m_timer, kIdleInterval);
|
||||
m_idle = true;
|
||||
}
|
||||
MHD_add_response_header(rsp, "Content-Type", "application/json");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization");
|
||||
|
||||
const int ret = MHD_queue_response(connection, status, rsp);
|
||||
MHD_destroy_response(rsp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls)
|
||||
int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
|
||||
{
|
||||
xmrig::HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls);
|
||||
|
||||
if (req.method() == xmrig::HttpRequest::Options) {
|
||||
return req.end(MHD_HTTP_OK, nullptr);
|
||||
if (strcmp(method, "OPTIONS") == 0) {
|
||||
return done(connection, MHD_HTTP_OK, nullptr);
|
||||
}
|
||||
|
||||
if (req.method() == xmrig::HttpRequest::Unsupported) {
|
||||
return req.end(MHD_HTTP_METHOD_NOT_ALLOWED, nullptr);
|
||||
if (strcmp(method, "GET") != 0) {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
return static_cast<Httpd*>(cls)->process(req);
|
||||
}
|
||||
int status = static_cast<Httpd*>(cls)->auth(MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Authorization"));
|
||||
if (status != MHD_HTTP_OK) {
|
||||
return done(connection, status, nullptr);
|
||||
}
|
||||
|
||||
char *buf = Api::get(url, &status);
|
||||
if (buf == nullptr) {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
void Httpd::onTimer(uv_timer_t *handle)
|
||||
{
|
||||
static_cast<Httpd*>(handle->data)->run();
|
||||
MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*) buf, MHD_RESPMEM_MUST_FREE);
|
||||
return done(connection, status, rsp);
|
||||
}
|
||||
|
||||
@@ -33,38 +33,21 @@ struct MHD_Daemon;
|
||||
struct MHD_Response;
|
||||
|
||||
|
||||
class UploadCtx;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class HttpRequest;
|
||||
}
|
||||
|
||||
|
||||
class Httpd
|
||||
{
|
||||
public:
|
||||
Httpd(int port, const char *accessToken, bool IPv6, bool restricted);
|
||||
~Httpd();
|
||||
Httpd(int port, const char *accessToken);
|
||||
bool start();
|
||||
|
||||
private:
|
||||
constexpr static const int kIdleInterval = 200;
|
||||
constexpr static const int kActiveInterval = 25;
|
||||
int auth(const char *header);
|
||||
|
||||
int process(xmrig::HttpRequest &req);
|
||||
void run();
|
||||
static int done(MHD_Connection *connection, int status, MHD_Response *rsp);
|
||||
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
|
||||
|
||||
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls);
|
||||
static void onTimer(uv_timer_t *handle);
|
||||
|
||||
bool m_idle;
|
||||
bool m_IPv6;
|
||||
bool m_restricted;
|
||||
const char *m_accessToken;
|
||||
const int m_port;
|
||||
MHD_Daemon *m_daemon;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
#endif /* __HTTPD_H__ */
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
"api": {
|
||||
"port": 0, // port for the miner API https://github.com/xmrig/xmrig/wiki/API
|
||||
"access-token": null, // access token for API
|
||||
"worker-id": null, // custom worker-id for API
|
||||
"ipv6": false,
|
||||
"restricted": true
|
||||
"worker-id": null // custom worker-id for API
|
||||
}
|
||||
}
|
||||
@@ -1,396 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "core/CommonConfig.h"
|
||||
#include "donate.h"
|
||||
#include "log/Log.h"
|
||||
#include "net/Url.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
static const char *algoNames[] = {
|
||||
"cryptonight",
|
||||
"cryptonight-lite",
|
||||
"cryptonight-heavy"
|
||||
};
|
||||
|
||||
|
||||
static const char *algoNamesShort[] = {
|
||||
"cn",
|
||||
"cn-lite",
|
||||
"cn-heavy"
|
||||
};
|
||||
|
||||
|
||||
#if defined(_WIN32) && !defined(strcasecmp)
|
||||
# define strcasecmp _stricmp
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::CommonConfig::CommonConfig() :
|
||||
m_algorithm(CRYPTONIGHT),
|
||||
m_adjusted(false),
|
||||
m_apiIPv6(false),
|
||||
m_apiRestricted(true),
|
||||
m_background(false),
|
||||
m_colors(true),
|
||||
m_syslog(false),
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_watch(true),
|
||||
# else
|
||||
m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested.
|
||||
# endif
|
||||
|
||||
m_apiToken(nullptr),
|
||||
m_apiWorkerId(nullptr),
|
||||
m_fileName(nullptr),
|
||||
m_logFile(nullptr),
|
||||
m_userAgent(nullptr),
|
||||
m_apiPort(0),
|
||||
m_donateLevel(kDefaultDonateLevel),
|
||||
m_printTime(60),
|
||||
m_retries(5),
|
||||
m_retryPause(5)
|
||||
{
|
||||
m_pools.push_back(new Url());
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_retries = 2;
|
||||
m_retryPause = 1;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
xmrig::CommonConfig::~CommonConfig()
|
||||
{
|
||||
for (Url *url : m_pools) {
|
||||
delete url;
|
||||
}
|
||||
|
||||
m_pools.clear();
|
||||
|
||||
free(m_fileName);
|
||||
free(m_apiToken);
|
||||
free(m_apiWorkerId);
|
||||
free(m_logFile);
|
||||
free(m_userAgent);
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::CommonConfig::algoName(Algo algorithm)
|
||||
{
|
||||
return algoNames[algorithm];
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::adjust()
|
||||
{
|
||||
if (m_adjusted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_adjusted = true;
|
||||
|
||||
for (Url *url : m_pools) {
|
||||
url->adjust(algorithm());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::isValid() const
|
||||
{
|
||||
return m_pools[0]->isValid();
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
||||
{
|
||||
switch (key) {
|
||||
case BackgroundKey: /* --background */
|
||||
m_background = enable;
|
||||
break;
|
||||
|
||||
case SyslogKey: /* --syslog */
|
||||
m_syslog = enable;
|
||||
break;
|
||||
|
||||
case KeepAliveKey: /* --keepalive */
|
||||
m_pools.back()->setKeepAlive(enable ? Url::kKeepAliveTimeout : 0);
|
||||
break;
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
case NicehashKey: /* --nicehash */
|
||||
m_pools.back()->setNicehash(enable);
|
||||
break;
|
||||
# endif
|
||||
|
||||
case ColorKey: /* --no-color */
|
||||
m_colors = enable;
|
||||
break;
|
||||
|
||||
case WatchKey: /* watch */
|
||||
m_watch = enable;
|
||||
break;
|
||||
|
||||
case ApiIPv6Key: /* ipv6 */
|
||||
m_apiIPv6 = enable;
|
||||
|
||||
case ApiRestrictedKey: /* restricted */
|
||||
m_apiRestricted = enable;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::parseString(int key, const char *arg)
|
||||
{
|
||||
switch (key) {
|
||||
case AlgorithmKey: /* --algo */
|
||||
setAlgo(arg);
|
||||
break;
|
||||
|
||||
case UserpassKey: /* --userpass */
|
||||
if (!m_pools.back()->setUserpass(arg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case UrlKey: /* --url */
|
||||
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
|
||||
Url *url = new Url(arg);
|
||||
if (url->isValid()) {
|
||||
m_pools.push_back(url);
|
||||
}
|
||||
else {
|
||||
delete url;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pools[0]->parse(arg);
|
||||
}
|
||||
|
||||
if (!m_pools.back()->isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case UserKey: /* --user */
|
||||
m_pools.back()->setUser(arg);
|
||||
break;
|
||||
|
||||
case PasswordKey: /* --pass */
|
||||
m_pools.back()->setPassword(arg);
|
||||
break;
|
||||
|
||||
case LogFileKey: /* --log-file */
|
||||
free(m_logFile);
|
||||
m_logFile = strdup(arg);
|
||||
break;
|
||||
|
||||
case ApiAccessTokenKey: /* --api-access-token */
|
||||
free(m_apiToken);
|
||||
m_apiToken = strdup(arg);
|
||||
break;
|
||||
|
||||
case ApiWorkerIdKey: /* --api-worker-id */
|
||||
free(m_apiWorkerId);
|
||||
m_apiWorkerId = strdup(arg);
|
||||
break;
|
||||
|
||||
case UserAgentKey: /* --user-agent */
|
||||
free(m_userAgent);
|
||||
m_userAgent = strdup(arg);
|
||||
break;
|
||||
|
||||
case RetriesKey: /* --retries */
|
||||
case RetryPauseKey: /* --retry-pause */
|
||||
case VariantKey: /* --variant */
|
||||
case ApiPort: /* --api-port */
|
||||
case PrintTimeKey: /* --cpu-priority */
|
||||
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case BackgroundKey: /* --background */
|
||||
case SyslogKey: /* --syslog */
|
||||
case KeepAliveKey: /* --keepalive */
|
||||
case NicehashKey: /* --nicehash */
|
||||
return parseBoolean(key, true);
|
||||
|
||||
case ColorKey: /* --no-color */
|
||||
case WatchKey: /* --no-watch */
|
||||
case ApiRestrictedKey: /* --api-no-restricted */
|
||||
case ApiIPv6Key: /* --api-no-ipv6 */
|
||||
return parseBoolean(key, false);
|
||||
|
||||
case DonateLevelKey: /* --donate-level */
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
if (strncmp(arg, "minemonero.pro", 14) == 0) {
|
||||
m_donateLevel = 0;
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg)
|
||||
{
|
||||
return parseInt(key, static_cast<int>(arg));
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::save()
|
||||
{
|
||||
if (!m_fileName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_fs_t req;
|
||||
const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName, O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
rapidjson::Document doc;
|
||||
getJSON(doc);
|
||||
|
||||
FILE *fp = fdopen(fd, "w");
|
||||
|
||||
char buf[4096];
|
||||
rapidjson::FileWriteStream os(fp, buf, sizeof(buf));
|
||||
rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os);
|
||||
doc.Accept(writer);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CommonConfig::setFileName(const char *fileName)
|
||||
{
|
||||
free(m_fileName);
|
||||
m_fileName = fileName ? strdup(fileName) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::CommonConfig::parseInt(int key, int arg)
|
||||
{
|
||||
switch (key) {
|
||||
case RetriesKey: /* --retries */
|
||||
if (arg > 0 && arg <= 1000) {
|
||||
m_retries = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case RetryPauseKey: /* --retry-pause */
|
||||
if (arg > 0 && arg <= 3600) {
|
||||
m_retryPause = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case KeepAliveKey: /* --keepalive */
|
||||
m_pools.back()->setKeepAlive(arg);
|
||||
break;
|
||||
|
||||
case VariantKey: /* --variant */
|
||||
m_pools.back()->setVariant(arg);
|
||||
break;
|
||||
|
||||
case DonateLevelKey: /* --donate-level */
|
||||
if (arg >= kMinimumDonateLevel && arg <= 99) {
|
||||
m_donateLevel = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case ApiPort: /* --api-port */
|
||||
if (arg > 0 && arg <= 65536) {
|
||||
m_apiPort = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case PrintTimeKey: /* --print-time */
|
||||
if (arg >= 0 && arg <= 3600) {
|
||||
m_printTime = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CommonConfig::setAlgo(const char *algo)
|
||||
{
|
||||
if (strcasecmp(algo, "cryptonight-light") == 0) {
|
||||
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
|
||||
|
||||
m_algorithm = CRYPTONIGHT_LITE;
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t size = sizeof(algoNames) / sizeof(algoNames[0]);
|
||||
|
||||
assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0])));
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) {
|
||||
m_algorithm = static_cast<Algo>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __COMMONCONFIG_H__
|
||||
#define __COMMONCONFIG_H__
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "interfaces/IConfig.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CommonConfig : public IConfig
|
||||
{
|
||||
public:
|
||||
CommonConfig();
|
||||
~CommonConfig();
|
||||
|
||||
static const char *algoName(Algo algorithm);
|
||||
|
||||
inline Algo algorithm() const { return m_algorithm; }
|
||||
inline bool isApiIPv6() const { return m_apiIPv6; }
|
||||
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isColors() const { return m_colors; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *algoName() const { return algoName(m_algorithm); }
|
||||
inline const char *apiToken() const { return m_apiToken; }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline const char *logFile() const { return m_logFile; }
|
||||
inline const char *userAgent() const { return m_userAgent; }
|
||||
inline const std::vector<Url*> &pools() const { return m_pools; }
|
||||
inline int apiPort() const { return m_apiPort; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline void setColors(bool colors) { m_colors = colors; }
|
||||
|
||||
inline bool isWatch() const override { return m_watch && m_fileName; }
|
||||
inline const char *fileName() const override { return m_fileName; }
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool isValid() const override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
bool save() override;
|
||||
void setFileName(const char *fileName) override;
|
||||
|
||||
Algo m_algorithm;
|
||||
bool m_adjusted;
|
||||
bool m_apiIPv6;
|
||||
bool m_apiRestricted;
|
||||
bool m_background;
|
||||
bool m_colors;
|
||||
bool m_syslog;
|
||||
bool m_watch;
|
||||
char *m_apiToken;
|
||||
char *m_apiWorkerId;
|
||||
char *m_fileName;
|
||||
char *m_logFile;
|
||||
char *m_userAgent;
|
||||
int m_apiPort;
|
||||
int m_donateLevel;
|
||||
int m_printTime;
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
std::vector<Url*> m_pools;
|
||||
|
||||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
void setAlgo(const char *algo);
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __COMMONCONFIG_H__ */
|
||||
@@ -1,346 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/ConfigCreator.h"
|
||||
#include "core/ConfigLoader.h"
|
||||
#include "Cpu.h"
|
||||
#include "net/Url.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
static char affinity_tmp[20] = { 0 };
|
||||
|
||||
|
||||
xmrig::Config::Config() : xmrig::CommonConfig(),
|
||||
m_algoVariant(AV_AUTO),
|
||||
m_doubleHash(false),
|
||||
m_dryRun(false),
|
||||
m_hugePages(true),
|
||||
m_safe(false),
|
||||
m_maxCpuUsage(75),
|
||||
m_printTime(60),
|
||||
m_priority(-1),
|
||||
m_affinity(-1L),
|
||||
m_threadsCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Config::~Config()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::reload(const char *json)
|
||||
{
|
||||
return xmrig::ConfigLoader::reload(this, json);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
doc.SetObject();
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
doc.AddMember("algo", rapidjson::StringRef(algoName()), allocator);
|
||||
|
||||
rapidjson::Value api(rapidjson::kObjectType);
|
||||
api.AddMember("port", apiPort(), allocator);
|
||||
api.AddMember("access-token", apiToken() ? rapidjson::Value(rapidjson::StringRef(apiToken())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
|
||||
api.AddMember("worker-id", apiWorkerId() ? rapidjson::Value(rapidjson::StringRef(apiWorkerId())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
|
||||
api.AddMember("ipv6", isApiIPv6(), allocator);
|
||||
api.AddMember("restricted", isApiRestricted(), allocator);
|
||||
doc.AddMember("api", api, allocator);
|
||||
|
||||
doc.AddMember("av", algoVariant(), allocator);
|
||||
doc.AddMember("background", isBackground(), allocator);
|
||||
|
||||
doc.AddMember("colors", isColors(), allocator);
|
||||
|
||||
if (affinity() != -1L) {
|
||||
snprintf(affinity_tmp, sizeof(affinity_tmp) - 1, "0x%" PRIX64, affinity());
|
||||
doc.AddMember("cpu-affinity", rapidjson::StringRef(affinity_tmp), allocator);
|
||||
}
|
||||
else {
|
||||
doc.AddMember("cpu-affinity", rapidjson::kNullType, allocator);
|
||||
}
|
||||
|
||||
if (priority() != -1) {
|
||||
doc.AddMember("cpu-priority", priority(), allocator);
|
||||
}
|
||||
else {
|
||||
doc.AddMember("cpu-priority", rapidjson::kNullType, allocator);
|
||||
}
|
||||
|
||||
doc.AddMember("donate-level", donateLevel(), allocator);
|
||||
doc.AddMember("huge-pages", isHugePages(), allocator);
|
||||
doc.AddMember("log-file", logFile() ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
|
||||
doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator);
|
||||
|
||||
rapidjson::Value pools(rapidjson::kArrayType);
|
||||
|
||||
for (const Url *url : m_pools) {
|
||||
rapidjson::Value obj(rapidjson::kObjectType);
|
||||
|
||||
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
|
||||
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
|
||||
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
|
||||
|
||||
if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) {
|
||||
obj.AddMember("keepalive", url->keepAlive() > 0, allocator);
|
||||
}
|
||||
else {
|
||||
obj.AddMember("keepalive", url->keepAlive(), allocator);
|
||||
}
|
||||
|
||||
obj.AddMember("nicehash", url->isNicehash(), allocator);
|
||||
obj.AddMember("variant", url->variant(), allocator);
|
||||
|
||||
pools.PushBack(obj, allocator);
|
||||
}
|
||||
|
||||
doc.AddMember("pools", pools, allocator);
|
||||
doc.AddMember("print-time", printTime(), allocator);
|
||||
doc.AddMember("retries", retries(), allocator);
|
||||
doc.AddMember("retry-pause", retryPause(), allocator);
|
||||
doc.AddMember("safe", m_safe, allocator);
|
||||
doc.AddMember("threads", threadsCount(), allocator);
|
||||
doc.AddMember("user-agent", userAgent() ? rapidjson::Value(rapidjson::StringRef(userAgent())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
|
||||
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
doc.AddMember("syslog", isSyslog(), allocator);
|
||||
# endif
|
||||
|
||||
doc.AddMember("watch", m_watch, allocator);
|
||||
}
|
||||
|
||||
|
||||
xmrig::Config *xmrig::Config::load(int argc, char **argv, IWatcherListener *listener)
|
||||
{
|
||||
return static_cast<Config*>(ConfigLoader::load(argc, argv, new ConfigCreator(), listener));
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::adjust()
|
||||
{
|
||||
if (!CommonConfig::adjust()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_algoVariant = getAlgoVariant();
|
||||
if (m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT) {
|
||||
m_doubleHash = true;
|
||||
}
|
||||
|
||||
if (!m_threadsCount) {
|
||||
m_threadsCount = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
}
|
||||
else if (m_safe) {
|
||||
const size_t count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
if (m_threadsCount > count) {
|
||||
m_threadsCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_threadsCount; ++i) {
|
||||
m_threads.push_back(CpuThread::createFromAV(i, m_algorithm, m_algoVariant, m_affinity, m_priority));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::parseBoolean(int key, bool enable)
|
||||
{
|
||||
if (!CommonConfig::parseBoolean(key, enable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case xmrig::IConfig::SafeKey: /* --safe */
|
||||
m_safe = enable;
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */
|
||||
m_hugePages = enable;
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::DryRunKey: /* --dry-run */
|
||||
m_dryRun = enable;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::parseString(int key, const char *arg)
|
||||
{
|
||||
if (!CommonConfig::parseString(key, arg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case xmrig::IConfig::AVKey: /* --av */
|
||||
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */
|
||||
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */
|
||||
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case xmrig::IConfig::SafeKey: /* --safe */
|
||||
case xmrig::IConfig::DryRunKey: /* --dry-run */
|
||||
return parseBoolean(key, true);
|
||||
|
||||
case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */
|
||||
return parseBoolean(key, false);
|
||||
|
||||
case xmrig::IConfig::ThreadsKey: /* --threads */
|
||||
if (strncmp(arg, "all", 3) == 0) {
|
||||
m_threadsCount = Cpu::threads();
|
||||
return true;
|
||||
}
|
||||
|
||||
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */
|
||||
{
|
||||
const char *p = strstr(arg, "0x");
|
||||
return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::parseUint64(int key, uint64_t arg)
|
||||
{
|
||||
if (!CommonConfig::parseUint64(key, arg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */
|
||||
if (arg) {
|
||||
m_affinity = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return parseInt(key, static_cast<int>(arg));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Config::parseJSON(const rapidjson::Document &doc)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Config::parseInt(int key, int arg)
|
||||
{
|
||||
switch (key) {
|
||||
case xmrig::IConfig::ThreadsKey: /* --threads */
|
||||
if (m_threadsCount >= 0 && arg < 1024) {
|
||||
m_threadsCount = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::AVKey: /* --av */
|
||||
if (arg >= AV_AUTO && arg < AV_MAX) {
|
||||
m_algoVariant = static_cast<AlgoVariant>(arg);
|
||||
}
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */
|
||||
if (m_maxCpuUsage > 0 && arg <= 100) {
|
||||
m_maxCpuUsage = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */
|
||||
if (arg >= 0 && arg <= 5) {
|
||||
m_priority = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algorithm == xmrig::CRYPTONIGHT_LITE) {
|
||||
return getAlgoVariantLite();
|
||||
}
|
||||
# endif
|
||||
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_SINGLE : AV_SINGLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const
|
||||
{
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
}
|
||||
#endif
|
||||
@@ -1,113 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "core/CommonConfig.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Addr;
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ConfigLoader;
|
||||
class IThread;
|
||||
class IWatcherListener;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Config class
|
||||
*
|
||||
* Options with dynamic reload:
|
||||
* colors
|
||||
* debug
|
||||
* verbose
|
||||
* custom-diff (only for new connections)
|
||||
* api/worker-id
|
||||
* pools/
|
||||
*/
|
||||
class Config : public CommonConfig
|
||||
{
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
bool reload(const char *json);
|
||||
|
||||
void getJSON(rapidjson::Document &doc) const override;
|
||||
|
||||
inline AlgoVariant algoVariant() const { return m_algoVariant; }
|
||||
inline bool isDoubleHash() const { return m_doubleHash; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isHugePages() const { return m_hugePages; }
|
||||
inline const std::vector<IThread *> &threads() const { return m_threads; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int threadsCount() const { return m_threadsCount; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
|
||||
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
void parseJSON(const rapidjson::Document &doc) override;
|
||||
|
||||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
|
||||
AlgoVariant getAlgoVariant() const;
|
||||
# ifndef XMRIG_NO_AEON
|
||||
AlgoVariant getAlgoVariantLite() const;
|
||||
# endif
|
||||
|
||||
AlgoVariant m_algoVariant;
|
||||
bool m_doubleHash;
|
||||
bool m_dryRun;
|
||||
bool m_hugePages;
|
||||
bool m_safe;
|
||||
int m_maxCpuUsage;
|
||||
int m_printTime;
|
||||
int m_priority;
|
||||
int64_t m_affinity;
|
||||
size_t m_threadsCount;
|
||||
std::vector<IThread *> m_threads;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIG_H__ */
|
||||
@@ -1,50 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGCREATOR_H__
|
||||
#define __CONFIGCREATOR_H__
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "interfaces/IConfigCreator.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig;
|
||||
|
||||
|
||||
class ConfigCreator : public IConfigCreator
|
||||
{
|
||||
public:
|
||||
inline IConfig *create() const override
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __CONFIGCREATOR_H__
|
||||
@@ -1,311 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_HTTPD
|
||||
# include <microhttpd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "core/ConfigCreator.h"
|
||||
#include "core/ConfigLoader.h"
|
||||
#include "core/ConfigLoader_platform.h"
|
||||
#include "core/ConfigWatcher.h"
|
||||
#include "interfaces/IConfig.h"
|
||||
#include "interfaces/IWatcherListener.h"
|
||||
#include "net/Url.h"
|
||||
#include "Platform.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
#include "rapidjson/filereadstream.h"
|
||||
|
||||
|
||||
xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr;
|
||||
xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr;
|
||||
xmrig::IWatcherListener *xmrig::ConfigLoader::m_listener = nullptr;
|
||||
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::loadFromFile(xmrig::IConfig *config, const char *fileName)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
if (!getJSON(fileName, doc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
config->setFileName(fileName);
|
||||
|
||||
return loadFromJSON(config, doc);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const char *json)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(json);
|
||||
|
||||
if (doc.HasParseError() || !doc.IsObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return loadFromJSON(config, doc);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson::Document &doc)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
|
||||
parseJSON(config, &config_options[i], doc);
|
||||
}
|
||||
|
||||
const rapidjson::Value &pools = doc["pools"];
|
||||
if (pools.IsArray()) {
|
||||
for (const rapidjson::Value &value : pools.GetArray()) {
|
||||
if (!value.IsObject()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(pool_options); i++) {
|
||||
parseJSON(config, &pool_options[i], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value &api = doc["api"];
|
||||
if (api.IsObject()) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) {
|
||||
parseJSON(config, &api_options[i], api);
|
||||
}
|
||||
}
|
||||
|
||||
config->parseJSON(doc);
|
||||
config->adjust();
|
||||
|
||||
return config->isValid();
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json)
|
||||
{
|
||||
xmrig::IConfig *config = m_creator->create();
|
||||
if (!loadFromJSON(config, json)) {
|
||||
delete config;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
config->setFileName(oldConfig->fileName());
|
||||
const bool saved = config->save();
|
||||
|
||||
if (config->isWatch() && m_watcher && saved) {
|
||||
delete config;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
m_listener->onNewConfig(config);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener)
|
||||
{
|
||||
m_creator = creator;
|
||||
m_listener = listener;
|
||||
|
||||
xmrig::IConfig *config = m_creator->create();
|
||||
int key;
|
||||
|
||||
while (1) {
|
||||
key = getopt_long(argc, argv, short_options, options, NULL);
|
||||
if (key < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!parseArg(config, key, optarg)) {
|
||||
delete config;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "%s: unsupported non-option argument '%s'\n", argv[0], argv[optind]);
|
||||
delete config;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!config->isValid()) {
|
||||
loadFromFile(config, Platform::defaultConfigName());
|
||||
}
|
||||
|
||||
if (!config->isValid()) {
|
||||
fprintf(stderr, "No pool URL supplied. Exiting.\n");
|
||||
delete config;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (config->isWatch()) {
|
||||
m_watcher = new xmrig::ConfigWatcher(config->fileName(), creator, listener);
|
||||
}
|
||||
|
||||
config->adjust();
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigLoader::release()
|
||||
{
|
||||
delete m_watcher;
|
||||
delete m_creator;
|
||||
|
||||
m_watcher = nullptr;
|
||||
m_creator = nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc)
|
||||
{
|
||||
uv_fs_t req;
|
||||
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd));
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
FILE *fp = fdopen(fd, "rb");
|
||||
char buf[8192];
|
||||
rapidjson::FileReadStream is(fp, buf, sizeof(buf));
|
||||
|
||||
doc.ParseStream(is);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
if (doc.HasParseError()) {
|
||||
printf("%s<%d>: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return doc.IsObject();
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConfigLoader::parseArg(xmrig::IConfig *config, int key, const char *arg)
|
||||
{
|
||||
switch (key) {
|
||||
case xmrig::IConfig::VersionKey: /* --version */
|
||||
showVersion();
|
||||
return false;
|
||||
|
||||
case xmrig::IConfig::HelpKey: /* --help */
|
||||
showUsage();
|
||||
return false;
|
||||
|
||||
case xmrig::IConfig::ConfigKey: /* --config */
|
||||
loadFromFile(config, arg);
|
||||
break;
|
||||
|
||||
default:
|
||||
return config->parseString(key, arg);;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigLoader::parseJSON(xmrig::IConfig *config, const struct option *option, const rapidjson::Value &object)
|
||||
{
|
||||
if (!option->name || !object.HasMember(option->name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rapidjson::Value &value = object[option->name];
|
||||
|
||||
if (option->has_arg) {
|
||||
if (value.IsString()) {
|
||||
config->parseString(option->val, value.GetString());
|
||||
}
|
||||
else if (value.IsInt64()) {
|
||||
config->parseUint64(option->val, value.GetUint64());
|
||||
}
|
||||
else if (value.IsBool()) {
|
||||
config->parseBoolean(option->val, value.IsTrue());
|
||||
}
|
||||
}
|
||||
else if (value.IsBool()) {
|
||||
config->parseBoolean(option->val, value.IsTrue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigLoader::showUsage()
|
||||
{
|
||||
printf(usage);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigLoader::showVersion()
|
||||
{
|
||||
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
|
||||
|
||||
# if defined(__clang__)
|
||||
" with clang " __clang_version__);
|
||||
# elif defined(__GNUC__)
|
||||
" with GCC");
|
||||
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
" with MSVC");
|
||||
printf(" %d", MSVC_VERSION);
|
||||
# else
|
||||
);
|
||||
# endif
|
||||
|
||||
printf("\n features:"
|
||||
# if defined(__i386__) || defined(_M_IX86)
|
||||
" i386"
|
||||
# elif defined(__x86_64__) || defined(_M_AMD64)
|
||||
" x86_64"
|
||||
# endif
|
||||
|
||||
# if defined(__AES__) || defined(_MSC_VER)
|
||||
" AES-NI"
|
||||
# endif
|
||||
"\n");
|
||||
|
||||
printf("\nlibuv/%s\n", uv_version_string());
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
printf("libmicrohttpd/%s\n", MHD_get_version());
|
||||
# endif
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGLOADER_H__
|
||||
#define __CONFIGLOADER_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
struct option;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ConfigWatcher;
|
||||
class IConfigCreator;
|
||||
class IWatcherListener;
|
||||
class IConfig;
|
||||
|
||||
|
||||
class ConfigLoader
|
||||
{
|
||||
public:
|
||||
static bool loadFromFile(IConfig *config, const char *fileName);
|
||||
static bool loadFromJSON(IConfig *config, const char *json);
|
||||
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
|
||||
static bool reload(IConfig *oldConfig, const char *json);
|
||||
static IConfig *load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener);
|
||||
static void release();
|
||||
|
||||
private:
|
||||
static bool getJSON(const char *fileName, rapidjson::Document &doc);
|
||||
static bool parseArg(IConfig *config, int key, const char *arg);
|
||||
static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object);
|
||||
static void showUsage();
|
||||
static void showVersion();
|
||||
|
||||
static ConfigWatcher *m_watcher;
|
||||
static IConfigCreator *m_creator;
|
||||
static IWatcherListener *m_listener;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGLOADER_H__ */
|
||||
@@ -1,171 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGLOADER_PLATFORM_H__
|
||||
#define __CONFIGLOADER_PLATFORM_H__
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include "getopt/getopt.h"
|
||||
#else
|
||||
# include <getopt.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "version.h"
|
||||
#include "interfaces/IConfig.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static char const usage[] = "\
|
||||
Usage: " APP_ID " [OPTIONS]\n\
|
||||
Options:\n\
|
||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
|
||||
-o, --url=URL URL of mining server\n\
|
||||
-O, --userpass=U:P username:password pair for mining server\n\
|
||||
-u, --user=USERNAME username for mining server\n\
|
||||
-p, --pass=PASSWORD password for mining server\n\
|
||||
-t, --threads=N number of miner threads\n\
|
||||
-v, --av=N algorithm variation, 0 auto select\n\
|
||||
-k, --keepalive send keepalived for prevent timeout (need pool support)\n\
|
||||
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
|
||||
-R, --retry-pause=N time to pause between retries (default: 5)\n\
|
||||
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
|
||||
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
|
||||
--no-huge-pages disable huge pages support\n\
|
||||
--no-color disable colored output\n\
|
||||
--variant algorithm PoW variant\n\
|
||||
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
|
||||
--user-agent set custom user-agent string for pool\n\
|
||||
-B, --background run the miner in the background\n\
|
||||
-c, --config=FILE load a JSON-format configuration file\n\
|
||||
-l, --log-file=FILE log all output to a file\n"
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
"\
|
||||
-S, --syslog use system log for output messages\n"
|
||||
# endif
|
||||
"\
|
||||
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\
|
||||
--safe safe adjust threads and av settings for current CPU\n\
|
||||
--nicehash enable nicehash/xmrig-proxy support\n\
|
||||
--print-time=N print hashrate report every N seconds\n\
|
||||
--api-port=N port for the miner API\n\
|
||||
--api-access-token=T access token for API\n\
|
||||
--api-worker-id=ID custom worker-id for API\n\
|
||||
-h, --help display this help and exit\n\
|
||||
-V, --version output version information and exit\n\
|
||||
";
|
||||
|
||||
|
||||
static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
|
||||
|
||||
|
||||
static struct option const options[] = {
|
||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
||||
{ "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
||||
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
|
||||
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "api-no-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
||||
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
||||
{ "config", 1, nullptr, xmrig::IConfig::ConfigKey },
|
||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
||||
{ "help", 0, nullptr, xmrig::IConfig::HelpKey },
|
||||
{ "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "no-color", 0, nullptr, xmrig::IConfig::ColorKey },
|
||||
{ "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
||||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "version", 0, nullptr, xmrig::IConfig::VersionKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const config_options[] = {
|
||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
||||
{ "colors", 0, nullptr, xmrig::IConfig::ColorKey },
|
||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
||||
{ "huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
||||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const pool_options[] = {
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const api_options[] = {
|
||||
{ "port", 1, nullptr, xmrig::IConfig::ApiPort },
|
||||
{ "access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
||||
{ "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
||||
{ "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGLOADER_PLATFORM_H__ */
|
||||
@@ -1,107 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "core/ConfigCreator.h"
|
||||
#include "core/ConfigLoader.h"
|
||||
#include "core/ConfigWatcher.h"
|
||||
#include "interfaces/IWatcherListener.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) :
|
||||
m_path(strdup(path)),
|
||||
m_creator(creator),
|
||||
m_listener(listener)
|
||||
{
|
||||
uv_fs_event_init(uv_default_loop(), &m_fsEvent);
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
|
||||
m_fsEvent.data = m_timer.data = this;
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
xmrig::ConfigWatcher::~ConfigWatcher()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
uv_fs_event_stop(&m_fsEvent);
|
||||
|
||||
free(m_path);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::onTimer(uv_timer_t* handle)
|
||||
{
|
||||
static_cast<xmrig::ConfigWatcher *>(handle->data)->reload();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status)
|
||||
{
|
||||
if (!filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
static_cast<xmrig::ConfigWatcher *>(handle->data)->queueUpdate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::queueUpdate()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
uv_timer_start(&m_timer, xmrig::ConfigWatcher::onTimer, kDelay, 0);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::reload()
|
||||
{
|
||||
LOG_WARN("\"%s\" was changed, reloading configuration", m_path);
|
||||
|
||||
IConfig *config = m_creator->create();
|
||||
ConfigLoader::loadFromFile(config, m_path);
|
||||
|
||||
if (!config->isValid()) {
|
||||
LOG_ERR("reloading failed");
|
||||
|
||||
delete config;
|
||||
return;
|
||||
}
|
||||
|
||||
m_listener->onNewConfig(config);
|
||||
|
||||
# ifndef _WIN32
|
||||
uv_fs_event_stop(&m_fsEvent);
|
||||
start();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::start()
|
||||
{
|
||||
uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path, 0);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONFIGWATCHER_H__
|
||||
#define __CONFIGWATCHER_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
struct option;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfigCreator;
|
||||
class IWatcherListener;
|
||||
|
||||
|
||||
class ConfigWatcher
|
||||
{
|
||||
public:
|
||||
ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener);
|
||||
~ConfigWatcher();
|
||||
|
||||
private:
|
||||
constexpr static int kDelay = 500;
|
||||
|
||||
static void onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status);
|
||||
static void onTimer(uv_timer_t* handle);
|
||||
void queueUpdate();
|
||||
void reload();
|
||||
void start();
|
||||
|
||||
char *m_path;
|
||||
IConfigCreator *m_creator;
|
||||
IWatcherListener *m_listener;
|
||||
uv_fs_event_t m_fsEvent;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGWATCHER_H__ */
|
||||
@@ -1,152 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/ConfigLoader.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "interfaces/IControllerListener.h"
|
||||
#include "log/ConsoleLog.h"
|
||||
#include "log/FileLog.h"
|
||||
#include "log/Log.h"
|
||||
#include "net/Network.h"
|
||||
#include "Platform.h"
|
||||
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
# include "log/SysLog.h"
|
||||
#endif
|
||||
|
||||
|
||||
class xmrig::ControllerPrivate
|
||||
{
|
||||
public:
|
||||
inline ControllerPrivate() :
|
||||
network(nullptr),
|
||||
config(nullptr)
|
||||
{}
|
||||
|
||||
|
||||
inline ~ControllerPrivate()
|
||||
{
|
||||
delete network;
|
||||
delete config;
|
||||
}
|
||||
|
||||
|
||||
Network *network;
|
||||
std::vector<xmrig::IControllerListener *> listeners;
|
||||
xmrig::Config *config;
|
||||
};
|
||||
|
||||
|
||||
xmrig::Controller::Controller()
|
||||
: d_ptr(new ControllerPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Controller::~Controller()
|
||||
{
|
||||
ConfigLoader::release();
|
||||
Platform::release();
|
||||
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Controller::isReady() const
|
||||
{
|
||||
return d_ptr->config && d_ptr->network;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Config *xmrig::Controller::config() const
|
||||
{
|
||||
assert(d_ptr->config != nullptr);
|
||||
|
||||
return d_ptr->config;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Controller::init(int argc, char **argv)
|
||||
{
|
||||
Cpu::init();
|
||||
|
||||
d_ptr->config = xmrig::Config::load(argc, argv, this);
|
||||
if (!d_ptr->config) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Log::init();
|
||||
Platform::init(config()->userAgent());
|
||||
Platform::setProcessPriority(d_ptr->config->priority());
|
||||
|
||||
if (!config()->isBackground()) {
|
||||
Log::add(new ConsoleLog(this));
|
||||
}
|
||||
|
||||
if (config()->logFile()) {
|
||||
Log::add(new FileLog(config()->logFile()));
|
||||
}
|
||||
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
if (config()->isSyslog()) {
|
||||
Log::add(new SysLog());
|
||||
}
|
||||
# endif
|
||||
|
||||
d_ptr->network = new Network(this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Network *xmrig::Controller::network() const
|
||||
{
|
||||
assert(d_ptr->network != nullptr);
|
||||
|
||||
return d_ptr->network;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Controller::addListener(IControllerListener *listener)
|
||||
{
|
||||
d_ptr->listeners.push_back(listener);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Controller::onNewConfig(IConfig *config)
|
||||
{
|
||||
Config *previousConfig = d_ptr->config;
|
||||
d_ptr->config = static_cast<Config*>(config);
|
||||
|
||||
for (xmrig::IControllerListener *listener : d_ptr->listeners) {
|
||||
listener->onConfigChanged(d_ptr->config, previousConfig);
|
||||
}
|
||||
|
||||
delete previousConfig;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CONTROLLER_H__
|
||||
#define __CONTROLLER_H__
|
||||
|
||||
|
||||
#include "interfaces/IWatcherListener.h"
|
||||
|
||||
|
||||
class Network;
|
||||
class StatsData;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Config;
|
||||
class ControllerPrivate;
|
||||
class IControllerListener;
|
||||
|
||||
|
||||
class Controller : public IWatcherListener
|
||||
{
|
||||
public:
|
||||
Controller();
|
||||
~Controller();
|
||||
|
||||
bool isReady() const;
|
||||
Config *config() const;
|
||||
int init(int argc, char **argv);
|
||||
Network *network() const;
|
||||
void addListener(IControllerListener *listener);
|
||||
|
||||
protected:
|
||||
void onNewConfig(IConfig *config) override;
|
||||
|
||||
private:
|
||||
ControllerPrivate *d_ptr;
|
||||
};
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONTROLLER_H__ */
|
||||
192
src/crypto/CryptoNight.cpp
Normal file
192
src/crypto/CryptoNight.cpp
Normal file
@@ -0,0 +1,192 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
|
||||
|
||||
#if defined(XMRIG_ARM)
|
||||
# include "crypto/CryptoNight_arm.h"
|
||||
#else
|
||||
# include "crypto/CryptoNight_x86.h"
|
||||
#endif
|
||||
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "net/Job.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "Options.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr;
|
||||
|
||||
|
||||
#define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \
|
||||
switch (variant) { \
|
||||
case xmrig::VARIANT_V1: \
|
||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
|
||||
\
|
||||
case xmrig::VARIANT_NONE: \
|
||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
|
||||
\
|
||||
default: \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, struct cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
static void cryptonight_lite_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
|
||||
}
|
||||
|
||||
void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
||||
cryptonight_av1_aesni,
|
||||
cryptonight_av2_aesni_double,
|
||||
cryptonight_av3_softaes,
|
||||
cryptonight_av4_softaes_double,
|
||||
cryptonight_lite_av1_aesni,
|
||||
cryptonight_lite_av2_aesni_double,
|
||||
cryptonight_lite_av3_softaes,
|
||||
cryptonight_lite_av4_softaes_double
|
||||
};
|
||||
#else
|
||||
void (*cryptonight_variations[4])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
||||
cryptonight_av1_aesni,
|
||||
cryptonight_av2_aesni_double,
|
||||
cryptonight_av3_softaes,
|
||||
cryptonight_av4_softaes_double
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx)
|
||||
{
|
||||
cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx, job.variant());
|
||||
|
||||
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
|
||||
}
|
||||
|
||||
|
||||
bool CryptoNight::init(int algo, int variant)
|
||||
{
|
||||
if (variant < 1 || variant > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
const int index = algo == xmrig::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
|
||||
# else
|
||||
const int index = variant - 1;
|
||||
# endif
|
||||
|
||||
cryptonight_hash_ctx = cryptonight_variations[index];
|
||||
|
||||
return selfTest(algo);
|
||||
}
|
||||
|
||||
|
||||
void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant)
|
||||
{
|
||||
cryptonight_hash_ctx(input, size, output, ctx, variant);
|
||||
}
|
||||
|
||||
|
||||
bool CryptoNight::selfTest(int algo) {
|
||||
if (cryptonight_hash_ctx == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t output[64];
|
||||
|
||||
struct cryptonight_ctx *ctx = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 16));
|
||||
ctx->memory = static_cast<uint8_t *>(_mm_malloc(MONERO_MEMORY * 2, 16));
|
||||
|
||||
cryptonight_hash_ctx(test_input, 76, output, ctx, 0);
|
||||
|
||||
const bool doubleHash = Options::i()->doubleHash();
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0;
|
||||
# else
|
||||
bool rc = memcmp(output, test_output_v0, (doubleHash ? 64 : 32)) == 0;
|
||||
# endif
|
||||
|
||||
if (rc) {
|
||||
cryptonight_hash_ctx(test_input, 76, output, ctx, 1);
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, (doubleHash ? 64 : 32)) == 0;
|
||||
# else
|
||||
rc = memcmp(output, test_output_v1, (doubleHash ? 64 : 32)) == 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
_mm_free(ctx->memory);
|
||||
_mm_free(ctx);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -46,4 +46,19 @@ struct cryptonight_ctx {
|
||||
};
|
||||
|
||||
|
||||
class Job;
|
||||
class JobResult;
|
||||
|
||||
|
||||
class CryptoNight
|
||||
{
|
||||
public:
|
||||
static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx);
|
||||
static bool init(int algo, int variant);
|
||||
static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant);
|
||||
|
||||
private:
|
||||
static bool selfTest(int algo);
|
||||
};
|
||||
|
||||
#endif /* __CRYPTONIGHT_H__ */
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "crypto/CryptoNight_monero.h"
|
||||
#include "crypto/soft_aes.h"
|
||||
|
||||
@@ -207,21 +206,7 @@ static inline void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2,
|
||||
}
|
||||
|
||||
|
||||
inline void mix_and_propagate(__m128i& x0, __m128i& x1, __m128i& x2, __m128i& x3, __m128i& x4, __m128i& x5, __m128i& x6, __m128i& x7)
|
||||
{
|
||||
__m128i tmp0 = x0;
|
||||
x0 = _mm_xor_si128(x0, x1);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x2 = _mm_xor_si128(x2, x3);
|
||||
x3 = _mm_xor_si128(x3, x4);
|
||||
x4 = _mm_xor_si128(x4, x5);
|
||||
x5 = _mm_xor_si128(x5, x6);
|
||||
x6 = _mm_xor_si128(x6, x7);
|
||||
x7 = _mm_xor_si128(x7, tmp0);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7;
|
||||
@@ -238,40 +223,6 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
xin6 = _mm_load_si128(input + 10);
|
||||
xin7 = _mm_load_si128(input + 11);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k2, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k3, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k4, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k5, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k6, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k7, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k8, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xin0 ^= k9;
|
||||
xin1 ^= k9;
|
||||
xin2 ^= k9;
|
||||
xin3 ^= k9;
|
||||
xin4 ^= k9;
|
||||
xin5 ^= k9;
|
||||
xin6 ^= k9;
|
||||
xin7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
@@ -313,7 +264,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7;
|
||||
@@ -368,85 +319,6 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
xout0 = _mm_xor_si128(_mm_load_si128(input + i + 0), xout0);
|
||||
xout1 = _mm_xor_si128(_mm_load_si128(input + i + 1), xout1);
|
||||
xout2 = _mm_xor_si128(_mm_load_si128(input + i + 2), xout2);
|
||||
xout3 = _mm_xor_si128(_mm_load_si128(input + i + 3), xout3);
|
||||
xout4 = _mm_xor_si128(_mm_load_si128(input + i + 4), xout4);
|
||||
xout5 = _mm_xor_si128(_mm_load_si128(input + i + 5), xout5);
|
||||
xout6 = _mm_xor_si128(_mm_load_si128(input + i + 6), xout6);
|
||||
xout7 = _mm_xor_si128(_mm_load_si128(input + i + 7), xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xout0 ^= k9;
|
||||
xout1 ^= k9;
|
||||
xout2 ^= k9;
|
||||
xout3 ^= k9;
|
||||
xout4 ^= k9;
|
||||
xout5 ^= k9;
|
||||
xout6 ^= k9;
|
||||
xout7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xout0 ^= k9;
|
||||
xout1 ^= k9;
|
||||
xout2 ^= k9;
|
||||
xout3 ^= k9;
|
||||
xout4 ^= k9;
|
||||
xout5 ^= k9;
|
||||
xout6 ^= k9;
|
||||
xout7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
_mm_store_si128(output + 4, xout0);
|
||||
@@ -460,23 +332,14 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 32);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
|
||||
VARIANT1_INIT(0);
|
||||
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
@@ -521,36 +384,18 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
||||
ah0 ^= ch;
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 64);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
keccak(input + size, (int) size, ctx->state1, 200);
|
||||
|
||||
@@ -562,8 +407,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
uint64_t* h1 = reinterpret_cast<uint64_t*>(ctx->state1);
|
||||
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
uint64_t al1 = h1[0] ^ h1[4];
|
||||
@@ -620,15 +465,6 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
|
||||
cl = ((uint64_t*) &l1[idx1 & MASK])[0];
|
||||
ch = ((uint64_t*) &l1[idx1 & MASK])[1];
|
||||
lo = __umul128(idx1, cl, &hi);
|
||||
@@ -644,19 +480,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
ah1 ^= ch;
|
||||
al1 ^= cl;
|
||||
idx1 = al1;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l1[idx1 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l1[idx1 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
|
||||
idx1 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
|
||||
keccakf(h0, 24);
|
||||
keccakf(h1, 24);
|
||||
@@ -665,22 +492,4 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* __CRYPTONIGHT_ARM_H__ */
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CRYPTONIGHT_CONSTANTS_H__
|
||||
#define __CRYPTONIGHT_CONSTANTS_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
namespace xmrig
|
||||
{
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000;
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_LITE_ITER = 0x40000;
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_HEAVY_MEMORY = 4 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_HEAVY_MASK = 0x3FFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_HEAVY_ITER = 0x40000;
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr size_t cn_select_memory() { return 0; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT>() { return CRYPTONIGHT_MEMORY; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_MEMORY; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_MEMORY; }
|
||||
|
||||
inline size_t cn_select_memory(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_MEMORY;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_MEMORY;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_MEMORY;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr uint32_t cn_select_mask() { return 0; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT>() { return CRYPTONIGHT_MASK; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_MASK; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_MASK; }
|
||||
|
||||
inline uint32_t cn_select_mask(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_MASK;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_MASK;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_MASK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr uint32_t cn_select_iter() { return 0; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT>() { return CRYPTONIGHT_ITER; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_ITER; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_ITER; }
|
||||
|
||||
inline uint32_t cn_select_iter(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_ITER;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_ITER;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_ITER;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __CRYPTONIGHT_CONSTANTS_H__ */
|
||||
@@ -66,7 +66,7 @@ const static uint8_t test_output_v0_lite[64] = {
|
||||
};
|
||||
|
||||
|
||||
// AEON v7
|
||||
// AEON v2
|
||||
const static uint8_t test_output_v1_lite[64] = {
|
||||
0x87, 0xC4, 0xE5, 0x70, 0x65, 0x3E, 0xB4, 0xC2, 0xB4, 0x2B, 0x7A, 0x0D, 0x54, 0x65, 0x59, 0x45,
|
||||
0x2D, 0xFA, 0xB5, 0x73, 0xB8, 0x2E, 0xC5, 0x2F, 0x15, 0x2B, 0x7F, 0xF9, 0x8E, 0x79, 0x44, 0x6F,
|
||||
@@ -76,14 +76,4 @@ const static uint8_t test_output_v1_lite[64] = {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_SUMO
|
||||
const static uint8_t test_output_heavy[64] = {
|
||||
0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A,
|
||||
0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D,
|
||||
0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64,
|
||||
0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __CRYPTONIGHT_TEST_H__ */
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "crypto/CryptoNight_monero.h"
|
||||
#include "crypto/soft_aes.h"
|
||||
|
||||
@@ -218,21 +217,7 @@ static inline void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2,
|
||||
}
|
||||
|
||||
|
||||
inline void mix_and_propagate(__m128i& x0, __m128i& x1, __m128i& x2, __m128i& x3, __m128i& x4, __m128i& x5, __m128i& x6, __m128i& x7)
|
||||
{
|
||||
__m128i tmp0 = x0;
|
||||
x0 = _mm_xor_si128(x0, x1);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x2 = _mm_xor_si128(x2, x3);
|
||||
x3 = _mm_xor_si128(x3, x4);
|
||||
x4 = _mm_xor_si128(x4, x5);
|
||||
x5 = _mm_xor_si128(x5, x6);
|
||||
x6 = _mm_xor_si128(x6, x7);
|
||||
x7 = _mm_xor_si128(x7, tmp0);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7;
|
||||
@@ -249,23 +234,6 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
xin6 = _mm_load_si128(input + 10);
|
||||
xin7 = _mm_load_si128(input + 11);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k2, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k3, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k4, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k5, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k6, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k7, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k8, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k9, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
||||
mix_and_propagate(xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
@@ -290,7 +258,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7;
|
||||
@@ -328,51 +296,6 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
xout0 = _mm_xor_si128(_mm_load_si128(input + i + 0), xout0);
|
||||
xout1 = _mm_xor_si128(_mm_load_si128(input + i + 1), xout1);
|
||||
xout2 = _mm_xor_si128(_mm_load_si128(input + i + 2), xout2);
|
||||
xout3 = _mm_xor_si128(_mm_load_si128(input + i + 3), xout3);
|
||||
xout4 = _mm_xor_si128(_mm_load_si128(input + i + 4), xout4);
|
||||
xout5 = _mm_xor_si128(_mm_load_si128(input + i + 5), xout5);
|
||||
xout6 = _mm_xor_si128(_mm_load_si128(input + i + 6), xout6);
|
||||
xout7 = _mm_xor_si128(_mm_load_si128(input + i + 7), xout7);
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
_mm_store_si128(output + 4, xout0);
|
||||
@@ -386,39 +309,14 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
}
|
||||
|
||||
|
||||
static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp)
|
||||
{
|
||||
mem_out[0] = EXTRACT64(tmp);
|
||||
|
||||
tmp = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(tmp), _mm_castsi128_ps(tmp)));
|
||||
uint64_t vh = EXTRACT64(tmp);
|
||||
|
||||
uint8_t x = vh >> 24;
|
||||
static const uint16_t table = 0x7531;
|
||||
const uint8_t index = (((x >> 3) & 6) | (x & 1)) << 1;
|
||||
vh ^= ((table >> index) & 0x3) << 28;
|
||||
|
||||
mem_out[1] = vh;
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 32);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
|
||||
VARIANT1_INIT(0)
|
||||
VARIANT1_INIT(0);
|
||||
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
@@ -439,13 +337,8 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
||||
cx = _mm_load_si128((__m128i *) &l0[idx0 & MASK]);
|
||||
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
|
||||
}
|
||||
|
||||
if (VARIANT > 0) {
|
||||
cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
|
||||
} else {
|
||||
_mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
|
||||
}
|
||||
|
||||
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
|
||||
VARIANT1_1(&l0[idx0 & MASK]);
|
||||
idx0 = EXTRACT64(cx);
|
||||
bx0 = cx;
|
||||
|
||||
@@ -465,36 +358,18 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
||||
ah0 ^= ch;
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 64);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
keccak(input + size, (int) size, ctx->state1, 200);
|
||||
|
||||
@@ -506,8 +381,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
uint64_t* h1 = reinterpret_cast<uint64_t*>(ctx->state1);
|
||||
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
uint64_t al1 = h1[0] ^ h1[4];
|
||||
@@ -534,13 +409,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1));
|
||||
}
|
||||
|
||||
if (VARIANT > 0) {
|
||||
cryptonight_monero_tweak((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
|
||||
cryptonight_monero_tweak((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
|
||||
} else {
|
||||
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
|
||||
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
|
||||
}
|
||||
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
|
||||
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
|
||||
VARIANT1_1(&l0[idx0 & MASK]);
|
||||
VARIANT1_1(&l1[idx1 & MASK]);
|
||||
|
||||
idx0 = EXTRACT64(cx0);
|
||||
idx1 = EXTRACT64(cx1);
|
||||
@@ -565,15 +437,6 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
|
||||
cl = ((uint64_t*) &l1[idx1 & MASK])[0];
|
||||
ch = ((uint64_t*) &l1[idx1 & MASK])[1];
|
||||
lo = __umul128(idx1, cl, &hi);
|
||||
@@ -589,19 +452,10 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
ah1 ^= ch;
|
||||
al1 ^= cl;
|
||||
idx1 = al1;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l1[idx1 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l1[idx1 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
|
||||
idx1 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
|
||||
keccakf(h0, 24);
|
||||
keccakf(h1, 24);
|
||||
@@ -610,22 +464,4 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
||||
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* __CRYPTONIGHT_X86_H__ */
|
||||
|
||||
14
src/donate.h
14
src/donate.h
@@ -29,22 +29,16 @@
|
||||
* Dev donation.
|
||||
*
|
||||
* Percentage of your hashing power that you want to donate to the developer, can be 0 if you don't want to do that.
|
||||
*
|
||||
* Example of how it works for the setting of 1%:
|
||||
* You miner will mine into your usual pool for random time (in range from 49.5 to 148.5 minutes),
|
||||
* then switch to the developer's pool for 1 minute, then switch again to your pool for 99 minutes
|
||||
* and then switch agaiin to developer's pool for 1 minute, these rounds will continue until miner working.
|
||||
*
|
||||
* Randomised only first round, to prevent waves on the donation pool.
|
||||
*
|
||||
* Example of how it works for the default setting of 1:
|
||||
* You miner will mine into your usual pool for 99 minutes, then switch to the developer's pool for 1 minute.
|
||||
* Since v2.5.1 start time randomized in range from 50 to 150 minutes minus donation time.
|
||||
* Switching is instant, and only happens after a successful connection, so you never loose any hashes.
|
||||
*
|
||||
* If you plan on changing this setting to 0 please consider making a one off donation to my wallet:
|
||||
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
|
||||
* BTC: 1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT
|
||||
*/
|
||||
constexpr const int kDefaultDonateLevel = 5;
|
||||
constexpr const int kMinimumDonateLevel = 1;
|
||||
constexpr const int kDonateLevel = 5;
|
||||
|
||||
|
||||
#endif /* __DONATE_H__ */
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ICONFIG_H__
|
||||
#define __ICONFIG_H__
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig
|
||||
{
|
||||
public:
|
||||
enum Keys {
|
||||
// common
|
||||
AlgorithmKey = 'a',
|
||||
ApiPort = 4000,
|
||||
ApiAccessTokenKey = 4001,
|
||||
ApiWorkerIdKey = 4002,
|
||||
ApiIPv6Key = 4003,
|
||||
ApiRestrictedKey = 4004,
|
||||
BackgroundKey = 'B',
|
||||
ConfigKey = 'c',
|
||||
DonateLevelKey = 1003,
|
||||
HelpKey = 'h',
|
||||
KeepAliveKey = 'k',
|
||||
LogFileKey = 'l',
|
||||
ColorKey = 1002,
|
||||
WatchKey = 1105,
|
||||
PasswordKey = 'p',
|
||||
RetriesKey = 'r',
|
||||
RetryPauseKey = 'R',
|
||||
SyslogKey = 'S',
|
||||
UrlKey = 'o',
|
||||
UserKey = 'u',
|
||||
UserAgentKey = 1008,
|
||||
UserpassKey = 'O',
|
||||
VerboseKey = 1100,
|
||||
VersionKey = 'V',
|
||||
VariantKey = 1010,
|
||||
|
||||
// xmrig common
|
||||
CPUPriorityKey = 1021,
|
||||
NicehashKey = 1006,
|
||||
PrintTimeKey = 1007,
|
||||
|
||||
// xmrig cpu
|
||||
AVKey = 'v',
|
||||
CPUAffinityKey = 1020,
|
||||
DryRunKey = 5000,
|
||||
HugePagesKey = 1009,
|
||||
MaxCPUUsageKey = 1004,
|
||||
SafeKey = 1005,
|
||||
ThreadsKey = 't',
|
||||
|
||||
// xmrig-proxy
|
||||
AccessLogFileKey = 'A',
|
||||
BindKey = 'b',
|
||||
CoinKey = 1104,
|
||||
CustomDiffKey = 1102,
|
||||
DebugKey = 1101,
|
||||
ModeKey = 'm',
|
||||
PoolCoinKey = 'C',
|
||||
ReuseTimeoutKey = 1106,
|
||||
WorkersKey = 1103,
|
||||
};
|
||||
|
||||
virtual ~IConfig() {}
|
||||
|
||||
virtual bool adjust() = 0;
|
||||
virtual bool isValid() const = 0;
|
||||
virtual bool isWatch() const = 0;
|
||||
virtual bool parseBoolean(int key, bool enable) = 0;
|
||||
virtual bool parseString(int key, const char *arg) = 0;
|
||||
virtual bool parseUint64(int key, uint64_t arg) = 0;
|
||||
virtual bool save() = 0;
|
||||
virtual const char *fileName() const = 0;
|
||||
virtual void getJSON(rapidjson::Document &doc) const = 0;
|
||||
virtual void parseJSON(const rapidjson::Document &doc) = 0;
|
||||
virtual void setFileName(const char *fileName) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONFIG_H__
|
||||
@@ -1,45 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ICONFIGCREATOR_H__
|
||||
#define __ICONFIGCREATOR_H__
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig;
|
||||
|
||||
|
||||
class IConfigCreator
|
||||
{
|
||||
public:
|
||||
virtual ~IConfigCreator() {}
|
||||
|
||||
virtual IConfig *create() const = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONFIGCREATOR_H__
|
||||
@@ -1,46 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ICONTROLLERLISTENER_H__
|
||||
#define __ICONTROLLERLISTENER_H__
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Config;
|
||||
|
||||
|
||||
class IControllerListener
|
||||
{
|
||||
public:
|
||||
virtual ~IControllerListener() {}
|
||||
|
||||
virtual void onConfigChanged(Config *config, Config *previousConfig) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONTROLLERLISTENER_H__
|
||||
@@ -1,64 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ITHREAD_H__
|
||||
#define __ITHREAD_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IThread
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
CPU,
|
||||
OpenCL,
|
||||
CUDA
|
||||
};
|
||||
|
||||
virtual ~IThread() {}
|
||||
|
||||
virtual Algo algorithm() const = 0;
|
||||
virtual int multiway() const = 0;
|
||||
virtual int priority() const = 0;
|
||||
virtual int64_t affinity() const = 0;
|
||||
virtual size_t index() const = 0;
|
||||
virtual Type type() const = 0;
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
virtual rapidjson::Value toAPI(rapidjson::Document &doc) const = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ITHREAD_H__
|
||||
@@ -1,46 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __IWATCHERLISTENER_H__
|
||||
#define __IWATCHERLISTENER_H__
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig;
|
||||
|
||||
|
||||
class IWatcherListener
|
||||
{
|
||||
public:
|
||||
virtual ~IWatcherListener() {}
|
||||
|
||||
virtual void onNewConfig(IConfig *config) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __IWATCHERLISTENER_H__
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -33,10 +33,9 @@ class IWorker
|
||||
public:
|
||||
virtual ~IWorker() {}
|
||||
|
||||
virtual bool start() = 0;
|
||||
virtual size_t id() const = 0;
|
||||
virtual uint64_t hashCount() const = 0;
|
||||
virtual uint64_t timestamp() const = 0;
|
||||
virtual void start() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -34,18 +34,18 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "log/ConsoleLog.h"
|
||||
#include "log/Log.h"
|
||||
#include "Options.h"
|
||||
|
||||
|
||||
ConsoleLog::ConsoleLog(xmrig::Controller *controller) :
|
||||
m_stream(nullptr),
|
||||
m_controller(controller)
|
||||
ConsoleLog::ConsoleLog(bool colors) :
|
||||
m_colors(colors),
|
||||
m_stream(nullptr)
|
||||
{
|
||||
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
|
||||
controller->config()->setColors(false);
|
||||
Options::i()->setColors(false);
|
||||
m_colors = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,9 +78,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
||||
# endif
|
||||
|
||||
const char* color = nullptr;
|
||||
const bool colors = m_controller->config()->isColors();
|
||||
|
||||
if (colors) {
|
||||
if (m_colors) {
|
||||
switch (level) {
|
||||
case Log::ERR:
|
||||
color = Log::kCL_RED;
|
||||
@@ -111,9 +109,9 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
||||
stime.tm_hour,
|
||||
stime.tm_min,
|
||||
stime.tm_sec,
|
||||
colors ? color : "",
|
||||
m_colors ? color : "",
|
||||
fmt,
|
||||
colors ? Log::kCL_N : ""
|
||||
m_colors ? Log::kCL_N : ""
|
||||
);
|
||||
|
||||
print(args);
|
||||
@@ -122,7 +120,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
||||
|
||||
void ConsoleLog::text(const char* fmt, va_list args)
|
||||
{
|
||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_controller->config()->isColors() ? Log::kCL_N : "");
|
||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
|
||||
|
||||
print(args);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -31,15 +31,10 @@
|
||||
#include "interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class ConsoleLog : public ILogBackend
|
||||
{
|
||||
public:
|
||||
ConsoleLog(xmrig::Controller *controller);
|
||||
ConsoleLog(bool colors);
|
||||
|
||||
void message(int level, const char *fmt, va_list args) override;
|
||||
void text(const char *fmt, va_list args) override;
|
||||
@@ -48,12 +43,12 @@ private:
|
||||
bool isWritable() const;
|
||||
void print(va_list args);
|
||||
|
||||
bool m_colors;
|
||||
char m_buf[512];
|
||||
char m_fmt[256];
|
||||
uv_buf_t m_uvBuf;
|
||||
uv_stream_t *m_stream;
|
||||
uv_tty_t m_tty;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
#endif /* __CONSOLELOG_H__ */
|
||||
|
||||
@@ -47,6 +47,8 @@ void Log::message(Log::Level level, const char* fmt, ...)
|
||||
backend->message(level, fmt, copy);
|
||||
va_end(copy);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
|
||||
|
||||
int64_t Client::m_sequence = 1;
|
||||
xmrig::Storage<Client> Client::m_storage;
|
||||
|
||||
|
||||
Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
@@ -68,17 +67,13 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
m_state(UnconnectedState),
|
||||
m_expire(0),
|
||||
m_jobs(0),
|
||||
m_keepAlive(0),
|
||||
m_key(0),
|
||||
m_stream(nullptr),
|
||||
m_socket(nullptr)
|
||||
{
|
||||
m_key = m_storage.add(this);
|
||||
|
||||
memset(m_ip, 0, sizeof(m_ip));
|
||||
memset(&m_hints, 0, sizeof(m_hints));
|
||||
|
||||
m_resolver.data = m_storage.ptr(m_key);
|
||||
m_resolver.data = this;
|
||||
|
||||
m_hints.ai_family = AF_UNSPEC;
|
||||
m_hints.ai_socktype = SOCK_STREAM;
|
||||
@@ -86,6 +81,11 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
|
||||
m_recvBuf.base = m_buf;
|
||||
m_recvBuf.len = sizeof(m_buf);
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
m_keepAliveTimer.data = this;
|
||||
uv_timer_init(uv_default_loop(), &m_keepAliveTimer);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -121,13 +121,8 @@ void Client::deleteLater()
|
||||
|
||||
m_listener = nullptr;
|
||||
|
||||
if (state() == HostLookupState) {
|
||||
uv_cancel(reinterpret_cast<uv_req_t*>(&m_resolver));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!disconnect() && m_state != ClosingState) {
|
||||
m_storage.remove(m_key);
|
||||
if (!disconnect()) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,17 +139,17 @@ void Client::setUrl(const Url *url)
|
||||
|
||||
void Client::tick(uint64_t now)
|
||||
{
|
||||
if (m_state == ConnectedState) {
|
||||
if (m_expire && now > m_expire) {
|
||||
LOG_DEBUG_ERR("[%s:%u] timeout", m_url.host(), m_url.port());
|
||||
close();
|
||||
}
|
||||
else if (m_keepAlive && now > m_keepAlive) {
|
||||
ping();
|
||||
}
|
||||
if (m_expire == 0 || now < m_expire) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_expire && now > m_expire && m_state == ConnectingState) {
|
||||
if (m_state == ConnectedState) {
|
||||
LOG_DEBUG_ERR("[%s:%u] timeout", m_url.host(), m_url.port());
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
if (m_state == ConnectingState) {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
@@ -162,9 +157,12 @@ void Client::tick(uint64_t now)
|
||||
|
||||
bool Client::disconnect()
|
||||
{
|
||||
m_keepAlive = 0;
|
||||
m_expire = 0;
|
||||
m_failures = -1;
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
uv_timer_stop(&m_keepAliveTimer);
|
||||
# endif
|
||||
|
||||
m_expire = 0;
|
||||
m_failures = -1;
|
||||
|
||||
return close();
|
||||
}
|
||||
@@ -207,28 +205,7 @@ bool Client::close()
|
||||
|
||||
setState(ClosingState);
|
||||
|
||||
uv_stream_t *stream = reinterpret_cast<uv_stream_t*>(m_socket);
|
||||
|
||||
if (uv_is_readable(stream) == 1) {
|
||||
uv_read_stop(stream);
|
||||
}
|
||||
|
||||
if (uv_is_writable(stream) == 1) {
|
||||
const int rc = uv_shutdown(new uv_shutdown_t, stream, [](uv_shutdown_t* req, int status) {
|
||||
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(req->handle)) == 0) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(req->handle), Client::onClose);
|
||||
}
|
||||
|
||||
delete req;
|
||||
});
|
||||
|
||||
assert(rc == 0);
|
||||
|
||||
if (rc != 0) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_socket)) == 0) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(m_socket), Client::onClose);
|
||||
}
|
||||
|
||||
@@ -406,10 +383,10 @@ void Client::connect(sockaddr *addr)
|
||||
delete m_socket;
|
||||
|
||||
uv_connect_t *req = new uv_connect_t;
|
||||
req->data = m_storage.ptr(m_key);
|
||||
req->data = this;
|
||||
|
||||
m_socket = new uv_tcp_t;
|
||||
m_socket->data = m_storage.ptr(m_key);
|
||||
m_socket->data = this;
|
||||
|
||||
uv_tcp_init(uv_default_loop(), m_socket);
|
||||
uv_tcp_nodelay(m_socket, 1);
|
||||
@@ -569,7 +546,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
|
||||
LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), message, error["code"].GetInt());
|
||||
}
|
||||
|
||||
if (isCriticalError(message)) {
|
||||
if (id == 1 || isCriticalError(message)) {
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -615,13 +592,18 @@ void Client::ping()
|
||||
void Client::reconnect()
|
||||
{
|
||||
if (!m_listener) {
|
||||
m_storage.remove(m_key);
|
||||
delete this;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
setState(ConnectingState);
|
||||
m_keepAlive = 0;
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
if (m_url.isKeepAlive()) {
|
||||
uv_timer_stop(&m_keepAliveTimer);
|
||||
}
|
||||
# endif
|
||||
|
||||
if (m_failures == -1) {
|
||||
return m_listener->onClose(this, -1);
|
||||
@@ -650,9 +632,13 @@ void Client::startTimeout()
|
||||
{
|
||||
m_expire = 0;
|
||||
|
||||
if (m_url.keepAlive()) {
|
||||
m_keepAlive = uv_now(uv_default_loop()) + (m_url.keepAlive() * 1000);
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
if (!m_url.isKeepAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uv_timer_start(&m_keepAliveTimer, [](uv_timer_t *handle) { getClient(handle->data)->ping(); }, kKeepAliveTimeout, 0);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -683,7 +669,6 @@ void Client::onConnect(uv_connect_t *req, int status)
|
||||
{
|
||||
auto client = getClient(req->data);
|
||||
if (!client) {
|
||||
delete req;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -729,11 +714,6 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
return;
|
||||
}
|
||||
|
||||
assert(client->m_listener != nullptr);
|
||||
if (!client->m_listener) {
|
||||
return client->reconnect();
|
||||
}
|
||||
|
||||
client->m_recvBufPos += nread;
|
||||
|
||||
char* end;
|
||||
@@ -770,11 +750,6 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
|
||||
return;
|
||||
}
|
||||
|
||||
assert(client->m_listener != nullptr);
|
||||
if (!client->m_listener) {
|
||||
return client->reconnect();
|
||||
}
|
||||
|
||||
if (status < 0) {
|
||||
if (!client->m_quiet) {
|
||||
LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
|
||||
#include "net/Id.h"
|
||||
#include "net/Job.h"
|
||||
#include "net/Storage.h"
|
||||
#include "net/SubmitResult.h"
|
||||
#include "net/Url.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
@@ -54,9 +53,9 @@ public:
|
||||
};
|
||||
|
||||
constexpr static int kResponseTimeout = 20 * 1000;
|
||||
constexpr static int kKeepAliveTimeout = 60 * 1000;
|
||||
|
||||
Client(int id, const char *agent, IClientListener *listener);
|
||||
~Client();
|
||||
|
||||
bool disconnect();
|
||||
int64_t submit(const JobResult &result);
|
||||
@@ -77,6 +76,8 @@ public:
|
||||
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
||||
|
||||
private:
|
||||
~Client();
|
||||
|
||||
bool close();
|
||||
bool isCriticalError(const char *message);
|
||||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
||||
@@ -102,7 +103,7 @@ private:
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
static void onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res);
|
||||
|
||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||
static inline Client *getClient(void *data) { return static_cast<Client*>(data); }
|
||||
|
||||
addrinfo m_hints;
|
||||
bool m_ipv6;
|
||||
@@ -119,11 +120,10 @@ private:
|
||||
Job m_job;
|
||||
size_t m_recvBufPos;
|
||||
SocketState m_state;
|
||||
static int64_t m_sequence;
|
||||
std::map<int64_t, SubmitResult> m_results;
|
||||
uint64_t m_expire;
|
||||
uint64_t m_jobs;
|
||||
uint64_t m_keepAlive;
|
||||
uintptr_t m_key;
|
||||
Url m_url;
|
||||
uv_buf_t m_recvBuf;
|
||||
uv_getaddrinfo_t m_resolver;
|
||||
@@ -131,8 +131,9 @@ private:
|
||||
uv_tcp_t *m_socket;
|
||||
xmrig::Id m_rpcId;
|
||||
|
||||
static int64_t m_sequence;
|
||||
static xmrig::Storage<Client> m_storage;
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
uv_timer_t m_keepAliveTimer;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -60,14 +59,14 @@ static inline char hf_bin2hex(unsigned char c)
|
||||
Job::Job() :
|
||||
m_nicehash(false),
|
||||
m_coin(),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_poolId(-2),
|
||||
m_threadId(-1),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob(),
|
||||
m_variant(xmrig::VARIANT_AUTO)
|
||||
m_blob()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,12 +77,12 @@ Job::Job(int poolId, bool nicehash, int algo, int variant) :
|
||||
m_algo(algo),
|
||||
m_poolId(poolId),
|
||||
m_threadId(-1),
|
||||
m_variant(variant),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob()
|
||||
{
|
||||
setVariant(variant);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +164,7 @@ void Job::setCoin(const char *coin)
|
||||
}
|
||||
|
||||
strncpy(m_coin, coin, sizeof(m_coin));
|
||||
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::CRYPTONIGHT_LITE : xmrig::CRYPTONIGHT;
|
||||
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::ALGO_CRYPTONIGHT_LITE : xmrig::ALGO_CRYPTONIGHT;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,12 +174,10 @@ void Job::setVariant(int variant)
|
||||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_NONE:
|
||||
case xmrig::VARIANT_V1:
|
||||
m_variant = static_cast<xmrig::Variant>(variant);
|
||||
m_variant = variant;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
m_variant = xmrig::VARIANT_AUTO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
inline const xmrig::Id &id() const { return m_id; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline int variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint32_t diff() const { return (uint32_t) m_diff; }
|
||||
@@ -62,7 +63,6 @@ public:
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||
inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_NONE) : m_variant); }
|
||||
|
||||
static bool fromHex(const char* in, unsigned int len, unsigned char* out);
|
||||
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
|
||||
@@ -78,12 +78,12 @@ private:
|
||||
int m_algo;
|
||||
int m_poolId;
|
||||
int m_threadId;
|
||||
int m_variant;
|
||||
size_t m_size;
|
||||
uint64_t m_diff;
|
||||
uint64_t m_target;
|
||||
uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
xmrig::Id m_id;
|
||||
xmrig::Variant m_variant;
|
||||
};
|
||||
|
||||
#endif /* __JOB_H__ */
|
||||
|
||||
@@ -39,30 +39,29 @@
|
||||
#include "net/strategies/SinglePoolStrategy.h"
|
||||
#include "net/SubmitResult.h"
|
||||
#include "net/Url.h"
|
||||
#include "Options.h"
|
||||
#include "workers/Workers.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Config.h"
|
||||
|
||||
|
||||
Network::Network(xmrig::Controller *controller) :
|
||||
m_donate(nullptr),
|
||||
m_controller(controller)
|
||||
Network::Network(const Options *options) :
|
||||
m_options(options),
|
||||
m_donate(nullptr)
|
||||
{
|
||||
srand(time(0) ^ (uintptr_t) this);
|
||||
|
||||
Workers::setListener(this);
|
||||
|
||||
const std::vector<Url*> &pools = controller->config()->pools();
|
||||
const std::vector<Url*> &pools = options->pools();
|
||||
|
||||
if (pools.size() > 1) {
|
||||
m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this);
|
||||
m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this);
|
||||
}
|
||||
else {
|
||||
m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), this);
|
||||
m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this);
|
||||
}
|
||||
|
||||
if (controller->config()->donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front()->user(), controller->config()->algorithm(), this);
|
||||
if (m_options->donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), this);
|
||||
}
|
||||
|
||||
m_timer.data = this;
|
||||
@@ -102,7 +101,7 @@ void Network::onActive(IStrategy *strategy, Client *client)
|
||||
|
||||
m_state.setPool(client->host(), client->port(), client->ip());
|
||||
|
||||
LOG_INFO(isColors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip());
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip());
|
||||
}
|
||||
|
||||
|
||||
@@ -147,27 +146,21 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit
|
||||
m_state.add(result, error);
|
||||
|
||||
if (error) {
|
||||
LOG_INFO(isColors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
|
||||
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
|
||||
}
|
||||
else {
|
||||
LOG_INFO(isColors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
|
||||
m_state.accepted, m_state.rejected, result.diff, result.elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Network::isColors() const
|
||||
{
|
||||
return m_controller->config()->isColors();
|
||||
}
|
||||
|
||||
|
||||
void Network::setJob(Client *client, const Job &job, bool donate)
|
||||
{
|
||||
if (isColors()) {
|
||||
if (m_options->colors()) {
|
||||
LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -35,18 +35,14 @@
|
||||
|
||||
|
||||
class IStrategy;
|
||||
class Options;
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Network : public IJobResultListener, public IStrategyListener
|
||||
{
|
||||
public:
|
||||
Network(xmrig::Controller *controller);
|
||||
Network(const Options *options);
|
||||
~Network();
|
||||
|
||||
void connect();
|
||||
@@ -62,17 +58,16 @@ protected:
|
||||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
bool isColors() const;
|
||||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
||||
const Options *m_options;
|
||||
IStrategy *m_donate;
|
||||
IStrategy *m_strategy;
|
||||
NetworkState m_state;
|
||||
uv_timer_t m_timer;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __STORAGE_H__
|
||||
#define __STORAGE_H__
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
template <class TYPE>
|
||||
class Storage
|
||||
{
|
||||
public:
|
||||
inline Storage() :
|
||||
m_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline uintptr_t add(TYPE *ptr)
|
||||
{
|
||||
m_data[m_counter] = ptr;
|
||||
|
||||
return m_counter++;
|
||||
}
|
||||
|
||||
|
||||
inline static void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
|
||||
|
||||
|
||||
inline TYPE *get(void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline TYPE *get(uintptr_t id) const
|
||||
{
|
||||
assert(m_data.count(id) > 0);
|
||||
|
||||
if (m_data.count(id) == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return m_data.at(id);
|
||||
}
|
||||
|
||||
|
||||
inline void remove(void *id) { remove(reinterpret_cast<uintptr_t>(id)); }
|
||||
inline void remove(uintptr_t id)
|
||||
{
|
||||
TYPE *obj = get(id);
|
||||
if (obj == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = m_data.find(id);
|
||||
if (it != m_data.end()) {
|
||||
m_data.erase(it);
|
||||
}
|
||||
|
||||
delete obj;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::map<uintptr_t, TYPE *> m_data;
|
||||
uint64_t m_counter;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __STORAGE_H__ */
|
||||
@@ -37,12 +37,12 @@
|
||||
|
||||
|
||||
Url::Url() :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
@@ -62,12 +62,12 @@ Url::Url() :
|
||||
* @param url
|
||||
*/
|
||||
Url::Url(const char *url) :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
@@ -76,12 +76,12 @@ Url::Url(const char *url) :
|
||||
}
|
||||
|
||||
|
||||
Url::Url(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, int variant) :
|
||||
Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash, int variant) :
|
||||
m_keepAlive(keepAlive),
|
||||
m_nicehash(nicehash),
|
||||
m_password(password ? strdup(password) : nullptr),
|
||||
m_user(user ? strdup(user) : nullptr),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(keepAlive),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_variant(variant),
|
||||
m_url(nullptr),
|
||||
m_port(port)
|
||||
@@ -180,6 +180,10 @@ void Url::adjust(int algo)
|
||||
if (strstr(m_host, ".nicehash.com")) {
|
||||
m_keepAlive = false;
|
||||
m_nicehash = true;
|
||||
|
||||
if (strstr(m_host, "cryptonightv7.")) {
|
||||
m_variant = xmrig::VARIANT_V1;
|
||||
}
|
||||
}
|
||||
|
||||
if (strstr(m_host, ".minergate.com")) {
|
||||
|
||||
@@ -34,23 +34,22 @@ public:
|
||||
constexpr static const char *kDefaultPassword = "x";
|
||||
constexpr static const char *kDefaultUser = "x";
|
||||
constexpr static uint16_t kDefaultPort = 3333;
|
||||
constexpr static int kKeepAliveTimeout = 60;
|
||||
|
||||
Url();
|
||||
Url(const char *url);
|
||||
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, int keepAlive = 0, bool nicehash = false, int variant = -1);
|
||||
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = -1);
|
||||
~Url();
|
||||
|
||||
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_host && m_port > 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
inline const char *password() const { return m_password ? m_password : kDefaultPassword; }
|
||||
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
||||
inline int algo() const { return m_algo; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline int variant() const { return m_variant; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setVariant(bool monero) { m_variant = monero; }
|
||||
|
||||
@@ -68,12 +67,12 @@ public:
|
||||
private:
|
||||
bool parseIPv6(const char *addr);
|
||||
|
||||
bool m_keepAlive;
|
||||
bool m_nicehash;
|
||||
char *m_host;
|
||||
char *m_password;
|
||||
char *m_user;
|
||||
int m_algo;
|
||||
int m_keepAlive;
|
||||
int m_variant;
|
||||
mutable char *m_url;
|
||||
uint16_t m_port;
|
||||
|
||||
@@ -41,8 +41,8 @@ const static char *kDonatePool1 = "miner.fee.xmrig.com";
|
||||
const static char *kDonatePool2 = "emergency.fee.xmrig.com";
|
||||
|
||||
|
||||
static inline float randomf(float min, float max) {
|
||||
return (max - min) * ((((float) rand()) / (float) RAND_MAX)) + min;
|
||||
static inline int random(int min, int max){
|
||||
return min + rand() / (RAND_MAX / (max - min + 1) + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,15 +59,11 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL
|
||||
keccak(reinterpret_cast<const uint8_t *>(user), static_cast<int>(strlen(user)), hash, sizeof(hash));
|
||||
Job::toHex(hash, 32, userId);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT) {
|
||||
if (algo == xmrig::ALGO_CRYPTONIGHT) {
|
||||
m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
|
||||
}
|
||||
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_pools.push_back(new Url(kDonatePool1, 8888, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 8889, userId, nullptr, false, true));
|
||||
}
|
||||
else {
|
||||
m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true));
|
||||
@@ -78,7 +74,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL
|
||||
m_timer.data = this;
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
|
||||
idle(m_idleTime * randomf(0.5, 1.5));
|
||||
idle(random(3000, 9000) * 1000 - m_donateTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
#define APP_ID "xmrig"
|
||||
#define APP_NAME "XMRig"
|
||||
#define APP_DESC "XMRig CPU miner"
|
||||
#define APP_VERSION "2.6.0-beta2"
|
||||
#define APP_VERSION "2.5.3"
|
||||
#define APP_DOMAIN "xmrig.com"
|
||||
#define APP_SITE "www.xmrig.com"
|
||||
#define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com"
|
||||
#define APP_KIND "cpu"
|
||||
|
||||
#define APP_VER_MAJOR 2
|
||||
#define APP_VER_MINOR 6
|
||||
#define APP_VER_BUILD 0
|
||||
#define APP_VER_REV 2
|
||||
#define APP_VER_MINOR 5
|
||||
#define APP_VER_BUILD 3
|
||||
#define APP_VER_REV 0
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# if (_MSC_VER >= 1910)
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "core/CommonConfig.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/CpuThread.h"
|
||||
|
||||
|
||||
#if defined(XMRIG_ARM)
|
||||
# include "crypto/CryptoNight_arm.h"
|
||||
#else
|
||||
# include "crypto/CryptoNight_x86.h"
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::CpuThread::CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch) :
|
||||
m_algorithm(algorithm),
|
||||
m_av(av),
|
||||
m_prefetch(prefetch),
|
||||
m_softAES(softAES),
|
||||
m_priority(priority),
|
||||
m_affinity(affinity),
|
||||
m_multiway(multiway),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread::~CpuThread()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant)
|
||||
{
|
||||
assert(variant == VARIANT_NONE || variant == VARIANT_V1);
|
||||
|
||||
static const cn_hash_fun func_table[50] = {
|
||||
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
|
||||
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
# else
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
cryptonight_single_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
# else
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
# endif
|
||||
};
|
||||
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
if (algorithm == CRYPTONIGHT_HEAVY) {
|
||||
variant = VARIANT_NONE;
|
||||
}
|
||||
# endif
|
||||
|
||||
return func_table[20 * algorithm + 10 * variant + av - 1];
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority)
|
||||
{
|
||||
assert(av > AV_AUTO && av < AV_MAX);
|
||||
|
||||
Multiway multiway = SingleWay;
|
||||
bool softAES = false;
|
||||
|
||||
switch (av) {
|
||||
case AV_SINGLE_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
case AV_DOUBLE_SOFT:
|
||||
softAES = true;
|
||||
case AV_DOUBLE:
|
||||
multiway = DoubleWay;
|
||||
break;
|
||||
|
||||
case AV_TRIPLE_SOFT:
|
||||
softAES = true;
|
||||
case AV_TRIPLE:
|
||||
multiway = TripleWay;
|
||||
break;
|
||||
|
||||
case AV_QUAD_SOFT:
|
||||
softAES = true;
|
||||
case AV_QUAD:
|
||||
multiway = QuadWay;
|
||||
break;
|
||||
|
||||
case AV_PENTA_SOFT:
|
||||
softAES = true;
|
||||
case AV_PENTA:
|
||||
multiway = PentaWay;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int64_t cpuId = -1L;
|
||||
|
||||
if (affinity != -1L) {
|
||||
size_t idx = 0;
|
||||
|
||||
for (size_t i = 0; i < 64; i++) {
|
||||
if (!(affinity & (1ULL << i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx == index) {
|
||||
cpuId = i;
|
||||
break;
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
return new CpuThread(index, algorithm, av, multiway, cpuId, priority, softAES, false);
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_API
|
||||
rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const
|
||||
{
|
||||
rapidjson::Value obj(rapidjson::kObjectType);
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
obj.AddMember("type", "cpu", allocator);
|
||||
obj.AddMember("algo", rapidjson::StringRef(CommonConfig::algoName(algorithm())), allocator);
|
||||
obj.AddMember("av", m_av, allocator);
|
||||
obj.AddMember("low_power_mode", multiway(), allocator);
|
||||
obj.AddMember("affine_to_cpu", affinity(), allocator);
|
||||
obj.AddMember("priority", priority(), allocator);
|
||||
obj.AddMember("soft_aes", isSoftAES(), allocator);
|
||||
|
||||
return obj;
|
||||
}
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CPUTHREAD_H__
|
||||
#define __CPUTHREAD_H__
|
||||
|
||||
|
||||
#include "interfaces/IThread.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
struct cryptonight_ctx;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CpuThread : public IThread
|
||||
{
|
||||
public:
|
||||
enum Multiway {
|
||||
SingleWay = 1,
|
||||
DoubleWay,
|
||||
TripleWay,
|
||||
QuadWay,
|
||||
PentaWay
|
||||
};
|
||||
|
||||
CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch);
|
||||
~CpuThread();
|
||||
|
||||
typedef void (*cn_hash_fun)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx);
|
||||
|
||||
static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant);
|
||||
static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority);
|
||||
|
||||
inline bool isPrefetch() const { return m_prefetch; }
|
||||
inline bool isSoftAES() const { return m_softAES; }
|
||||
inline cn_hash_fun fn(Variant variant) const { return fn(m_algorithm, m_av, variant); }
|
||||
|
||||
inline Algo algorithm() const override { return m_algorithm; }
|
||||
inline int multiway() const override { return m_multiway; }
|
||||
inline int priority() const override { return m_priority; }
|
||||
inline int64_t affinity() const override { return m_affinity; }
|
||||
inline size_t index() const override { return m_index; }
|
||||
inline Type type() const override { return CPU; }
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
||||
# endif
|
||||
|
||||
private:
|
||||
const Algo m_algorithm;
|
||||
const AlgoVariant m_av;
|
||||
const bool m_prefetch;
|
||||
const bool m_softAES;
|
||||
const int m_priority;
|
||||
const int64_t m_affinity;
|
||||
const Multiway m_multiway;
|
||||
const size_t m_index;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __CPUTHREAD_H__ */
|
||||
@@ -26,8 +26,7 @@
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "workers/DoubleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
@@ -62,12 +61,8 @@ DoubleWorker::~DoubleWorker()
|
||||
}
|
||||
|
||||
|
||||
bool DoubleWorker::start()
|
||||
void DoubleWorker::start()
|
||||
{
|
||||
if (!selfTest()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
@@ -91,7 +86,7 @@ bool DoubleWorker::start()
|
||||
*Job::nonce(m_state->blob) = ++m_state->nonce1;
|
||||
*Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2;
|
||||
|
||||
m_thread->fn(m_state->job.variant())(m_state->blob, m_state->job.size(), m_hash, m_ctx);
|
||||
CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx, m_state->job.variant());
|
||||
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + 24) < m_state->job.target()) {
|
||||
Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff()));
|
||||
@@ -106,8 +101,6 @@ bool DoubleWorker::start()
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,32 +115,6 @@ bool DoubleWorker::resume(const Job &job)
|
||||
}
|
||||
|
||||
|
||||
bool DoubleWorker::selfTest()
|
||||
{
|
||||
if (m_thread->fn(xmrig::VARIANT_NONE) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_thread->fn(xmrig::VARIANT_NONE)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, 64) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
return memcmp(m_hash, test_output_v1, 64) == 0;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, 64) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
return memcmp(m_hash, test_output_v1_lite, 64) == 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return memcmp(m_hash, test_output_heavy, 64) == 0;
|
||||
}
|
||||
|
||||
|
||||
void DoubleWorker::consumeJob()
|
||||
{
|
||||
Job job = Workers::job();
|
||||
@@ -167,12 +134,12 @@ void DoubleWorker::consumeJob()
|
||||
memcpy(m_state->blob + m_state->job.size(), m_state->job.blob(), m_state->job.size());
|
||||
|
||||
if (m_state->job.isNicehash()) {
|
||||
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
|
||||
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalThreads));
|
||||
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id);
|
||||
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / (m_threads * 2) * (m_id + m_threads));
|
||||
}
|
||||
else {
|
||||
m_state->nonce1 = 0xffffffffU / m_totalWays * m_id;
|
||||
m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalThreads);
|
||||
m_state->nonce1 = 0xffffffffU / (m_threads * 2) * m_id;
|
||||
m_state->nonce2 = 0xffffffffU / (m_threads * 2) * (m_id + m_threads);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,10 @@ public:
|
||||
DoubleWorker(Handle *handle);
|
||||
~DoubleWorker();
|
||||
|
||||
bool start() override;
|
||||
void start() override;
|
||||
|
||||
private:
|
||||
bool resume(const Job &job);
|
||||
bool selfTest();
|
||||
void consumeJob();
|
||||
void save(const Job &job);
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -25,12 +25,12 @@
|
||||
#include "workers/Handle.h"
|
||||
|
||||
|
||||
Handle::Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays, int64_t affinity) :
|
||||
Handle::Handle(int threadId, int threads, int64_t affinity, int priority) :
|
||||
m_priority(priority),
|
||||
m_threadId(threadId),
|
||||
m_threads(threads),
|
||||
m_affinity(affinity),
|
||||
m_worker(nullptr),
|
||||
m_totalThreads(totalThreads),
|
||||
m_totalWays(totalWays),
|
||||
m_config(config)
|
||||
m_worker(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -29,34 +29,30 @@
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "interfaces/IThread.h"
|
||||
|
||||
|
||||
class IWorker;
|
||||
|
||||
|
||||
class Handle
|
||||
{
|
||||
public:
|
||||
Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays, int64_t affinity);
|
||||
Handle(int threadId, int threads, int64_t affinity, int priority);
|
||||
void join();
|
||||
void start(void (*callback) (void *));
|
||||
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline size_t threadId() const { return m_config->index(); }
|
||||
inline size_t totalThreads() const { return m_totalThreads; }
|
||||
inline size_t totalWays() const { return m_totalWays; }
|
||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||
inline xmrig::IThread *config() const { return m_config; }
|
||||
|
||||
private:
|
||||
int m_priority;
|
||||
int m_threadId;
|
||||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
IWorker *m_worker;
|
||||
size_t m_totalThreads;
|
||||
size_t m_totalWays;
|
||||
uv_thread_t m_thread;
|
||||
xmrig::IThread *m_config;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,10 +27,8 @@
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "log/Log.h"
|
||||
#include "Options.h"
|
||||
#include "workers/Hashrate.h"
|
||||
|
||||
|
||||
@@ -45,10 +43,9 @@ inline const char *format(double h, char* buf, size_t size)
|
||||
}
|
||||
|
||||
|
||||
Hashrate::Hashrate(int threads, xmrig::Controller *controller) :
|
||||
Hashrate::Hashrate(int threads) :
|
||||
m_highest(0.0),
|
||||
m_threads(threads),
|
||||
m_controller(controller)
|
||||
m_threads(threads)
|
||||
{
|
||||
m_counts = new uint64_t*[threads];
|
||||
m_timestamps = new uint64_t*[threads];
|
||||
@@ -63,7 +60,7 @@ Hashrate::Hashrate(int threads, xmrig::Controller *controller) :
|
||||
memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize);
|
||||
}
|
||||
|
||||
const int printTime = controller->config()->printTime();
|
||||
const int printTime = Options::i()->printTime();
|
||||
|
||||
if (printTime > 0) {
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
@@ -156,7 +153,7 @@ void Hashrate::print()
|
||||
char num3[8];
|
||||
char num4[8];
|
||||
|
||||
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s",
|
||||
LOG_INFO(Options::i()->colors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s",
|
||||
format(calc(ShortInterval), num1, sizeof(num1)),
|
||||
format(calc(MediumInterval), num2, sizeof(num2)),
|
||||
format(calc(LargeInterval), num3, sizeof(num3)),
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -29,11 +29,6 @@
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Hashrate
|
||||
{
|
||||
public:
|
||||
@@ -43,7 +38,7 @@ public:
|
||||
LargeInterval = 900000
|
||||
};
|
||||
|
||||
Hashrate(int threads, xmrig::Controller *controller);
|
||||
Hashrate(int threads);
|
||||
double calc(size_t ms) const;
|
||||
double calc(size_t threadId, size_t ms) const;
|
||||
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
||||
@@ -66,7 +61,6 @@ private:
|
||||
uint64_t** m_counts;
|
||||
uint64_t** m_timestamps;
|
||||
uv_timer_t m_timer;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
@@ -38,12 +37,8 @@ SingleWorker::SingleWorker(Handle *handle)
|
||||
}
|
||||
|
||||
|
||||
bool SingleWorker::start()
|
||||
void SingleWorker::start()
|
||||
{
|
||||
if (!selfTest()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
@@ -66,8 +61,7 @@ bool SingleWorker::start()
|
||||
m_count++;
|
||||
*m_job.nonce() = ++m_result.nonce;
|
||||
|
||||
m_thread->fn(m_job.variant())(m_job.blob(), m_job.size(), m_result.result, m_ctx);
|
||||
if (*reinterpret_cast<uint64_t*>(m_result.result + 24) < m_job.target()) {
|
||||
if (CryptoNight::hash(m_job, m_result, m_ctx)) {
|
||||
Workers::submit(m_result);
|
||||
}
|
||||
|
||||
@@ -76,8 +70,6 @@ bool SingleWorker::start()
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,32 +86,6 @@ bool SingleWorker::resume(const Job &job)
|
||||
}
|
||||
|
||||
|
||||
bool SingleWorker::selfTest()
|
||||
{
|
||||
if (m_thread->fn(xmrig::VARIANT_NONE) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_thread->fn(xmrig::VARIANT_NONE)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_result.result, test_output_v0, 32) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
return memcmp(m_result.result, test_output_v1, 32) == 0;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_result.result, test_output_v0_lite, 32) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
return memcmp(m_result.result, test_output_v1_lite, 32) == 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_result.result, test_output_heavy, 32) == 0;
|
||||
}
|
||||
|
||||
|
||||
void SingleWorker::consumeJob()
|
||||
{
|
||||
Job job = Workers::job();
|
||||
@@ -138,10 +104,10 @@ void SingleWorker::consumeJob()
|
||||
m_result = m_job;
|
||||
|
||||
if (m_job.isNicehash()) {
|
||||
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
|
||||
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id);
|
||||
}
|
||||
else {
|
||||
m_result.nonce = 0xffffffffU / m_totalWays * m_id;
|
||||
m_result.nonce = 0xffffffffU / m_threads * m_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,10 @@ class SingleWorker : public Worker
|
||||
public:
|
||||
SingleWorker(Handle *handle);
|
||||
|
||||
bool start() override;
|
||||
void start() override;
|
||||
|
||||
private:
|
||||
bool resume(const Job &job);
|
||||
bool selfTest();
|
||||
void consumeJob();
|
||||
void save(const Job &job);
|
||||
|
||||
|
||||
@@ -27,26 +27,23 @@
|
||||
#include "Cpu.h"
|
||||
#include "Mem.h"
|
||||
#include "Platform.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "workers/Handle.h"
|
||||
#include "workers/Worker.h"
|
||||
|
||||
|
||||
Worker::Worker(Handle *handle) :
|
||||
m_id(handle->threadId()),
|
||||
m_totalThreads(handle->totalThreads()),
|
||||
m_totalWays(handle->totalWays()),
|
||||
m_threads(handle->threads()),
|
||||
m_hashCount(0),
|
||||
m_timestamp(0),
|
||||
m_count(0),
|
||||
m_sequence(0),
|
||||
m_thread(static_cast<xmrig::CpuThread *>(handle->config()))
|
||||
m_sequence(0)
|
||||
{
|
||||
if (Cpu::threads() > 1 && handle->affinity() != -1L) {
|
||||
Cpu::setAffinity(m_id, handle->affinity());
|
||||
}
|
||||
|
||||
Platform::setThreadPriority(handle->config()->priority());
|
||||
Platform::setThreadPriority(handle->priority());
|
||||
m_ctx = Mem::create(m_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,18 +36,12 @@ struct cryptonight_ctx;
|
||||
class Handle;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class CpuThread;
|
||||
}
|
||||
|
||||
|
||||
class Worker : public IWorker
|
||||
{
|
||||
public:
|
||||
Worker(Handle *handle);
|
||||
~Worker();
|
||||
|
||||
inline size_t id() const override { return m_id; }
|
||||
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
|
||||
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
|
||||
|
||||
@@ -55,14 +49,12 @@ protected:
|
||||
void storeStats();
|
||||
|
||||
cryptonight_ctx *m_ctx;
|
||||
size_t m_id;
|
||||
size_t m_totalThreads;
|
||||
size_t m_totalWays;
|
||||
int m_id;
|
||||
int m_threads;
|
||||
std::atomic<uint64_t> m_hashCount;
|
||||
std::atomic<uint64_t> m_timestamp;
|
||||
uint64_t m_count;
|
||||
uint64_t m_sequence;
|
||||
xmrig::CpuThread *m_thread;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -22,23 +22,18 @@
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "Options.h"
|
||||
#include "workers/DoubleWorker.h"
|
||||
#include "workers/Handle.h"
|
||||
#include "workers/Hashrate.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
bool Workers::m_active = false;
|
||||
bool Workers::m_enabled = true;
|
||||
@@ -108,16 +103,10 @@ void Workers::setJob(const Job &job, bool donate)
|
||||
}
|
||||
|
||||
|
||||
void Workers::start(xmrig::Controller *controller)
|
||||
void Workers::start(int64_t affinity, int priority)
|
||||
{
|
||||
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
|
||||
|
||||
size_t totalWays = 0;
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
totalWays += thread->multiway();
|
||||
}
|
||||
|
||||
m_hashrate = new Hashrate(threads.size(), controller);
|
||||
const int threads = Mem::threads();
|
||||
m_hashrate = new Hashrate(threads);
|
||||
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
@@ -129,8 +118,8 @@ void Workers::start(xmrig::Controller *controller)
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
for (xmrig::IThread *thread : threads) {
|
||||
Handle *handle = new Handle(thread, threads.size(), totalWays, controller->config()->affinity());
|
||||
for (int i = 0; i < threads; ++i) {
|
||||
Handle *handle = new Handle(i, threads, affinity, priority);
|
||||
m_workers.push_back(handle);
|
||||
handle->start(Workers::onReady);
|
||||
}
|
||||
@@ -172,13 +161,7 @@ void Workers::onReady(void *arg)
|
||||
handle->setWorker(new SingleWorker(handle));
|
||||
}
|
||||
|
||||
const bool rc = handle->worker()->start();
|
||||
|
||||
if (!rc) {
|
||||
uv_mutex_lock(&m_mutex);
|
||||
LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
handle->worker()->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -39,11 +39,6 @@ class Hashrate;
|
||||
class IJobResultListener;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Workers
|
||||
{
|
||||
public:
|
||||
@@ -51,7 +46,7 @@ public:
|
||||
static void printHashrate(bool detail);
|
||||
static void setEnabled(bool enabled);
|
||||
static void setJob(const Job &job, bool donate);
|
||||
static void start(xmrig::Controller *controller);
|
||||
static void start(int64_t affinity, int priority);
|
||||
static void stop();
|
||||
static void submit(const JobResult &result);
|
||||
|
||||
|
||||
34
src/xmrig.h
34
src/xmrig.h
@@ -30,40 +30,18 @@ namespace xmrig
|
||||
|
||||
|
||||
enum Algo {
|
||||
CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */
|
||||
};
|
||||
|
||||
|
||||
//--av=1 For CPUs with hardware AES.
|
||||
//--av=2 Lower power mode (double hash) of 1.
|
||||
//--av=3 Software AES implementation.
|
||||
//--av=4 Lower power mode (double hash) of 3.
|
||||
enum AlgoVariant {
|
||||
AV_AUTO, // --av=0 Automatic mode.
|
||||
AV_SINGLE, // --av=1 Single hash mode
|
||||
AV_DOUBLE, // --av=2 Double hash mode
|
||||
AV_SINGLE_SOFT, // --av=3 Single hash mode (Software AES)
|
||||
AV_DOUBLE_SOFT, // --av=4 Double hash mode (Software AES)
|
||||
AV_TRIPLE, // --av=5 Triple hash mode
|
||||
AV_QUAD, // --av=6 Quard hash mode
|
||||
AV_PENTA, // --av=7 Penta hash mode
|
||||
AV_TRIPLE_SOFT, // --av=8 Triple hash mode (Software AES)
|
||||
AV_QUAD_SOFT, // --av=9 Quard hash mode (Software AES)
|
||||
AV_PENTA_SOFT, // --av=10 Penta hash mode (Software AES)
|
||||
AV_MAX
|
||||
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
};
|
||||
|
||||
|
||||
enum Variant {
|
||||
VARIANT_AUTO = -1, // Autodetect
|
||||
VARIANT_NONE = 0, // Original CryptoNight
|
||||
VARIANT_V1 = 1 // Monero v7 PoW
|
||||
VARIANT_AUTO = -1,
|
||||
VARIANT_NONE = 0,
|
||||
VARIANT_V1 = 1
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} /* xmrig */
|
||||
|
||||
|
||||
#endif /* __XMRIG_H__ */
|
||||
|
||||
Reference in New Issue
Block a user