Options class replaced to xmrig::Config.

This commit is contained in:
XMRig 2018-03-31 16:29:47 +07:00
parent aad19f1a35
commit aac7b0404a
25 changed files with 240 additions and 1104 deletions

View file

@ -48,7 +48,6 @@ set(HEADERS
src/net/strategies/SinglePoolStrategy.h src/net/strategies/SinglePoolStrategy.h
src/net/SubmitResult.h src/net/SubmitResult.h
src/net/Url.h src/net/Url.h
src/Options.h
src/Platform.h src/Platform.h
src/Summary.h src/Summary.h
src/version.h src/version.h
@ -104,7 +103,6 @@ set(SOURCES
src/net/strategies/SinglePoolStrategy.cpp src/net/strategies/SinglePoolStrategy.cpp
src/net/SubmitResult.cpp src/net/SubmitResult.cpp
src/net/Url.cpp src/net/Url.cpp
src/Options.cpp
src/Platform.cpp src/Platform.cpp
src/Summary.cpp src/Summary.cpp
src/workers/DoubleWorker.cpp src/workers/DoubleWorker.cpp

View file

@ -29,6 +29,7 @@
#include "api/Api.h" #include "api/Api.h"
#include "App.h" #include "App.h"
#include "Console.h" #include "Console.h"
#include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "Cpu.h" #include "Cpu.h"
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
@ -37,17 +38,12 @@
#include "log/Log.h" #include "log/Log.h"
#include "Mem.h" #include "Mem.h"
#include "net/Network.h" #include "net/Network.h"
#include "Options.h"
#include "Platform.h" #include "Platform.h"
#include "Summary.h" #include "Summary.h"
#include "version.h" #include "version.h"
#include "workers/Workers.h" #include "workers/Workers.h"
#ifdef HAVE_SYSLOG_H
# include "log/SysLog.h"
#endif
#ifndef XMRIG_NO_HTTPD #ifndef XMRIG_NO_HTTPD
# include "api/Httpd.h" # include "api/Httpd.h"
#endif #endif
@ -59,42 +55,19 @@ App *App::m_self = nullptr;
App::App(int argc, char **argv) : App::App(int argc, char **argv) :
m_console(nullptr), m_console(nullptr),
m_httpd(nullptr), m_httpd(nullptr)
m_network(nullptr),
m_options(nullptr)
{ {
m_self = this; m_self = this;
m_controller = new xmrig::Controller(); m_controller = new xmrig::Controller();
if (m_controller->init(argc, argv) != 0) {
Cpu::init();
m_options = Options::parse(argc, argv);
if (!m_options) {
return; return;
} }
Log::init(); if (!m_controller->config()->isBackground()) {
if (!m_options->background()) {
Log::add(new ConsoleLog(m_options->colors()));
m_console = new Console(this); 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_sigHUP);
uv_signal_init(uv_default_loop(), &m_sigINT); uv_signal_init(uv_default_loop(), &m_sigINT);
uv_signal_init(uv_default_loop(), &m_sigTERM); uv_signal_init(uv_default_loop(), &m_sigTERM);
@ -103,19 +76,22 @@ App::App(int argc, char **argv) :
App::~App() App::~App()
{ {
Mem::release();
uv_tty_reset_mode(); uv_tty_reset_mode();
delete m_console;
delete m_controller;
# ifndef XMRIG_NO_HTTPD # ifndef XMRIG_NO_HTTPD
delete m_httpd; delete m_httpd;
# endif # endif
delete m_console;
} }
int App::exec() int App::exec()
{ {
if (!m_options) { if (!m_controller->config()) {
return 2; return 2;
} }
@ -125,15 +101,20 @@ int App::exec()
background(); background();
if (!CryptoNight::init(m_options->algo(), m_options->algoVariant())) { if (!CryptoNight::init(m_controller->config()->algorithm(), m_controller->config()->algoVariant(), m_controller->config()->isDoubleHash())) {
LOG_ERR("\"%s\" hash self-test failed.", m_options->algoName()); LOG_ERR("\"%s\" hash self-test failed.", m_controller->config()->algoName());
return 1; return 1;
} }
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages()); Mem::allocate(m_controller->config()->algorithm(),
Summary::print(); m_controller->config()->threads(),
m_controller->config()->isDoubleHash(),
m_controller->config()->isHugePages()
);
if (m_options->dryRun()) { Summary::print(m_controller);
if (m_controller->config()->isDryRun()) {
LOG_NOTICE("OK"); LOG_NOTICE("OK");
release(); release();
@ -145,13 +126,19 @@ int App::exec()
# endif # endif
# ifndef XMRIG_NO_HTTPD # ifndef XMRIG_NO_HTTPD
m_httpd = new Httpd(m_options->apiPort(), m_options->apiToken(), true, true); m_httpd = new Httpd(
m_controller->config()->apiPort(),
m_controller->config()->apiToken(),
m_controller->config()->isApiIPv6(),
m_controller->config()->isApiRestricted()
);
m_httpd->start(); m_httpd->start();
# endif # endif
Workers::start(m_options->affinity(), m_options->priority()); Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller);
m_network->connect(); m_controller->network()->connect();
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_loop_close(uv_default_loop()); uv_loop_close(uv_default_loop());
@ -172,7 +159,7 @@ void App::onConsoleCommand(char command)
case 'p': case 'p':
case 'P': case 'P':
if (Workers::isEnabled()) { if (Workers::isEnabled()) {
LOG_INFO(m_options->colors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume"); LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
Workers::setEnabled(false); Workers::setEnabled(false);
} }
break; break;
@ -180,7 +167,7 @@ void App::onConsoleCommand(char command)
case 'r': case 'r':
case 'R': case 'R':
if (!Workers::isEnabled()) { if (!Workers::isEnabled()) {
LOG_INFO(m_options->colors() ? "\x1B[01;32mresumed" : "resumed"); LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;32mresumed" : "resumed");
Workers::setEnabled(true); Workers::setEnabled(true);
} }
break; break;
@ -198,7 +185,7 @@ void App::onConsoleCommand(char command)
void App::close() void App::close()
{ {
m_network->stop(); m_controller->network()->stop();
Workers::stop(); Workers::stop();
uv_stop(uv_default_loop()); uv_stop(uv_default_loop());
@ -207,13 +194,6 @@ void App::close()
void App::release() void App::release()
{ {
if (m_network) {
delete m_network;
}
Options::release();
Mem::release();
Platform::release();
} }

View file

@ -64,8 +64,6 @@ private:
Console *m_console; Console *m_console;
Httpd *m_httpd; Httpd *m_httpd;
Network *m_network;
Options *m_options;
uv_signal_t m_sigHUP; uv_signal_t m_sigHUP;
uv_signal_t m_sigINT; uv_signal_t m_sigINT;
uv_signal_t m_sigTERM; uv_signal_t m_sigTERM;

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,17 +27,19 @@
#include "App.h" #include "App.h"
#include "Options.h"
#include "Cpu.h" #include "Cpu.h"
#include "core/Controller.h"
#include "core/Config.h"
void App::background() void App::background()
{ {
if (m_options->affinity() != -1L) { const int64_t affinity = m_controller->config()->affinity();
Cpu::setAffinity(-1, m_options->affinity()); if (affinity != -1L) {
Cpu::setAffinity(-1, affinity);
} }
if (!m_options->background()) { if (!m_controller->config()->isBackground()) {
return; return;
} }

View file

@ -28,7 +28,6 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h"
#include "xmrig.h" #include "xmrig.h"

View file

@ -37,7 +37,6 @@
#include "log/Log.h" #include "log/Log.h"
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h"
#include "xmrig.h" #include "xmrig.h"

View file

@ -1,761 +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>
#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

View file

@ -1,133 +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 __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__ */

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,16 +27,17 @@
#include <uv.h> #include <uv.h>
#include "core/Config.h"
#include "core/Controller.h"
#include "Cpu.h" #include "Cpu.h"
#include "log/Log.h" #include "log/Log.h"
#include "Mem.h" #include "Mem.h"
#include "net/Url.h" #include "net/Url.h"
#include "Options.h"
#include "Summary.h" #include "Summary.h"
#include "version.h" #include "version.h"
static void print_versions() static void print_versions(xmrig::Config *config)
{ {
char buf[16]; char buf[16];
@ -51,13 +52,13 @@ static void print_versions()
# endif # endif
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", 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",
APP_VERSION, uv_version_string(), buf); APP_VERSION, uv_version_string(), buf);
} }
static void print_memory() { static void print_memory(xmrig::Config *config) {
if (Options::i()->colors()) { if (config->isColors()) {
Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s", Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s",
Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable", Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable",
Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled"); Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled");
@ -68,9 +69,9 @@ static void print_memory() {
} }
static void print_cpu() static void print_cpu(xmrig::Config *config)
{ {
if (Options::i()->colors()) { if (config->isColors()) {
Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI",
Cpu::brand(), Cpu::brand(),
Cpu::sockets(), Cpu::sockets(),
@ -89,32 +90,32 @@ static void print_cpu()
} }
static void print_threads() static void print_threads(xmrig::Config *config)
{ {
char buf[32]; char buf[32];
if (Options::i()->affinity() != -1L) { if (config->affinity() != -1L) {
snprintf(buf, 32, ", affinity=0x%" PRIX64, Options::i()->affinity()); snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity());
} }
else { else {
buf[0] = '\0'; buf[0] = '\0';
} }
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", 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",
Options::i()->threads(), config->threads(),
Options::i()->algoName(), config->algoName(),
Options::i()->algoVariant(), config->algoVariant(),
Options::i()->colors() && Options::i()->donateLevel() == 0 ? "\x1B[01;31m" : "", config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "",
Options::i()->donateLevel(), config->donateLevel(),
buf); buf);
} }
static void print_pools() static void print_pools(xmrig::Config *config)
{ {
const std::vector<Url*> &pools = Options::i()->pools(); const std::vector<Url*> &pools = config->pools();
for (size_t i = 0; i < pools.size(); ++i) { for (size_t i = 0; i < pools.size(); ++i) {
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d", Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d",
i + 1, i + 1,
pools[i]->host(), pools[i]->host(),
pools[i]->port()); pools[i]->port());
@ -129,20 +130,20 @@ static void print_pools()
#ifndef XMRIG_NO_API #ifndef XMRIG_NO_API
static void print_api() static void print_api(xmrig::Config *config)
{ {
if (Options::i()->apiPort() == 0) { if (config->apiPort() == 0) {
return; return;
} }
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", Options::i()->apiPort()); Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", config->apiPort());
} }
#endif #endif
static void print_commands() static void print_commands(xmrig::Config *config)
{ {
if (Options::i()->colors()) { if (config->isColors()) {
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"); 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 { else {
@ -151,19 +152,19 @@ static void print_commands()
} }
void Summary::print() void Summary::print(xmrig::Controller *controller)
{ {
print_versions(); print_versions(controller->config());
print_memory(); print_memory(controller->config());
print_cpu(); print_cpu(controller->config());
print_threads(); print_threads(controller->config());
print_pools(); print_pools(controller->config());
# ifndef XMRIG_NO_API # ifndef XMRIG_NO_API
print_api(); print_api(controller->config());
# endif # endif
print_commands(); print_commands(controller->config());
} }

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -25,10 +25,15 @@
#define __SUMMARY_H__ #define __SUMMARY_H__
namespace xmrig {
class Controller;
}
class Summary class Summary
{ {
public: public:
static void print(); static void print(xmrig::Controller *controller);
}; };

View file

@ -35,14 +35,15 @@
#include "api/ApiRouter.h" #include "api/ApiRouter.h"
#include "api/HttpReply.h" #include "api/HttpReply.h"
#include "api/HttpRequest.h" #include "api/HttpRequest.h"
#include "core/Config.h"
#include "core/Controller.h"
#include "Cpu.h" #include "Cpu.h"
#include "Mem.h" #include "Mem.h"
#include "net/Job.h" #include "net/Job.h"
#include "Options.h"
#include "Platform.h" #include "Platform.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h" #include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"
#include "version.h" #include "version.h"
#include "workers/Hashrate.h" #include "workers/Hashrate.h"
@ -66,13 +67,13 @@ static inline double normalize(double d)
ApiRouter::ApiRouter(xmrig::Controller *controller) : ApiRouter::ApiRouter(xmrig::Controller *controller) :
m_controller(controller) m_controller(controller)
{ {
m_threads = Options::i()->threads(); m_threads = controller->config()->threads();
m_hashrate = new double[m_threads * 3](); m_hashrate = new double[m_threads * 3]();
memset(m_totalHashrate, 0, sizeof(m_totalHashrate)); memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
memset(m_workerId, 0, sizeof(m_workerId)); memset(m_workerId, 0, sizeof(m_workerId));
setWorkerId(Options::i()->apiWorkerId()); setWorkerId(controller->config()->apiWorkerId());
genId(); genId();
} }
@ -100,10 +101,10 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
{ {
// if (req.method() == xmrig::HttpRequest::Put && req.match("/1/config")) { if (req.method() == xmrig::HttpRequest::Put && req.match("/1/config")) {
// m_controller->config()->reload(req.body()); m_controller->config()->reload(req.body());
// return; return;
// } }
reply.status = 404; reply.status = 404;
} }
@ -246,9 +247,9 @@ void ApiRouter::getMiner(rapidjson::Document &doc) const
doc.AddMember("kind", APP_KIND, allocator); doc.AddMember("kind", APP_KIND, allocator);
doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator); doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator);
doc.AddMember("cpu", cpu, allocator); doc.AddMember("cpu", cpu, allocator);
doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator); doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algoName()), allocator);
doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator); doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator);
doc.AddMember("donate_level", Options::i()->donateLevel(), allocator); doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator);
} }

View file

@ -40,7 +40,6 @@ xmrig::Config::Config() : xmrig::CommonConfig(),
m_dryRun(false), m_dryRun(false),
m_hugePages(true), m_hugePages(true),
m_safe(false), m_safe(false),
m_algo(0),
m_algoVariant(0), m_algoVariant(0),
m_maxCpuUsage(75), m_maxCpuUsage(75),
m_printTime(60), m_printTime(60),
@ -151,10 +150,10 @@ bool xmrig::Config::adjust()
} }
if (!m_threads) { if (!m_threads) {
m_threads = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage); m_threads = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
} }
else if (m_safe) { else if (m_safe) {
const int count = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage); const int count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
if (m_threads > count) { if (m_threads > count) {
m_threads = count; m_threads = count;
} }
@ -296,7 +295,7 @@ bool xmrig::Config::parseInt(int key, int arg)
int xmrig::Config::getAlgoVariant() const int xmrig::Config::getAlgoVariant() const
{ {
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) { if (m_algorithm == xmrig::ALGO_CRYPTONIGHT_LITE) {
return getAlgoVariantLite(); return getAlgoVariantLite();
} }
# endif # endif

View file

@ -79,7 +79,6 @@ public:
inline bool isDoubleHash() const { return m_doubleHash; } inline bool isDoubleHash() const { return m_doubleHash; }
inline bool isDryRun() const { return m_dryRun; } inline bool isDryRun() const { return m_dryRun; }
inline bool isHugePages() const { return m_hugePages; } inline bool isHugePages() const { return m_hugePages; }
inline int algo() const { return m_algo; }
inline int algoVariant() const { return m_algoVariant; } inline int algoVariant() const { return m_algoVariant; }
inline int printTime() const { return m_printTime; } inline int printTime() const { return m_printTime; }
inline int priority() const { return m_priority; } inline int priority() const { return m_priority; }
@ -107,7 +106,6 @@ private:
bool m_dryRun; bool m_dryRun;
bool m_hugePages; bool m_hugePages;
bool m_safe; bool m_safe;
int m_algo;
int m_algoVariant; int m_algoVariant;
int m_maxCpuUsage; int m_maxCpuUsage;
int m_printTime; int m_printTime;

View file

@ -22,15 +22,19 @@
*/ */
//#include "core/Config.h" #include <assert.h>
//#include "core/ConfigLoader.h"
#include "core/Config.h"
#include "core/ConfigLoader.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "Cpu.h"
#include "interfaces/IControllerListener.h"
#include "log/ConsoleLog.h" #include "log/ConsoleLog.h"
#include "log/FileLog.h" #include "log/FileLog.h"
#include "log/Log.h" #include "log/Log.h"
#include "net/Network.h"
#include "Platform.h" #include "Platform.h"
//#include "proxy/Proxy.h"
#include "interfaces/IControllerListener.h"
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
@ -42,18 +46,21 @@ class xmrig::ControllerPrivate
{ {
public: public:
inline ControllerPrivate() : inline ControllerPrivate() :
network(nullptr),
config(nullptr) config(nullptr)
{} {}
inline ~ControllerPrivate() inline ~ControllerPrivate()
{ {
// delete config; delete network;
delete config;
} }
xmrig::Config *config; Network *network;
std::vector<xmrig::IControllerListener *> listeners; std::vector<xmrig::IControllerListener *> listeners;
xmrig::Config *config;
}; };
@ -65,7 +72,8 @@ xmrig::Controller::Controller()
xmrig::Controller::~Controller() xmrig::Controller::~Controller()
{ {
// ConfigLoader::release(); ConfigLoader::release();
Platform::release();
delete d_ptr; delete d_ptr;
} }
@ -73,39 +81,52 @@ xmrig::Controller::~Controller()
xmrig::Config *xmrig::Controller::config() const xmrig::Config *xmrig::Controller::config() const
{ {
assert(d_ptr->config != nullptr);
return d_ptr->config; return d_ptr->config;
} }
int xmrig::Controller::init(int argc, char **argv) int xmrig::Controller::init(int argc, char **argv)
{ {
// d_ptr->config = xmrig::Config::load(argc, argv, this); Cpu::init();
// if (!d_ptr->config) {
// return 1;
// }
// Log::init(); d_ptr->config = xmrig::Config::load(argc, argv, this);
// Platform::init(config()->userAgent()); if (!d_ptr->config) {
return 1;
}
// if (!config()->background()) { Log::init();
// Log::add(new ConsoleLog(this)); Platform::init(config()->userAgent());
// } Platform::setProcessPriority(d_ptr->config->priority());
// if (config()->logFile()) { if (!config()->isBackground()) {
// Log::add(new FileLog(config()->logFile())); Log::add(new ConsoleLog(this));
// } }
//# ifdef HAVE_SYSLOG_H if (config()->logFile()) {
// if (config()->syslog()) { Log::add(new FileLog(config()->logFile()));
// Log::add(new SysLog()); }
// }
//# endif
// d_ptr->proxy = new Proxy(this); # ifdef HAVE_SYSLOG_H
if (config()->syslog()) {
Log::add(new SysLog());
}
# endif
d_ptr->network = new Network(this);
return 0; return 0;
} }
Network *xmrig::Controller::network() const
{
assert(d_ptr->network != nullptr);
return d_ptr->network;
}
void xmrig::Controller::addListener(IControllerListener *listener) void xmrig::Controller::addListener(IControllerListener *listener)
{ {
d_ptr->listeners.push_back(listener); d_ptr->listeners.push_back(listener);
@ -114,12 +135,12 @@ void xmrig::Controller::addListener(IControllerListener *listener)
void xmrig::Controller::onNewConfig(IConfig *config) void xmrig::Controller::onNewConfig(IConfig *config)
{ {
// xmrig::Config *previousConfig = d_ptr->config; Config *previousConfig = d_ptr->config;
// d_ptr->config = config; d_ptr->config = static_cast<Config*>(config);
// for (xmrig::IControllerListener *listener : d_ptr->listeners) { for (xmrig::IControllerListener *listener : d_ptr->listeners) {
// listener->onConfigChanged(config, previousConfig); listener->onConfigChanged(d_ptr->config, previousConfig);
// } }
// delete previousConfig; delete previousConfig;
} }

View file

@ -28,7 +28,7 @@
#include "interfaces/IWatcherListener.h" #include "interfaces/IWatcherListener.h"
class Proxy; class Network;
class StatsData; class StatsData;
@ -48,7 +48,7 @@ public:
Config *config() const; Config *config() const;
int init(int argc, char **argv); int init(int argc, char **argv);
Proxy *proxy() const; Network *network() const;
void addListener(IControllerListener *listener); void addListener(IControllerListener *listener);
protected: protected:

View file

@ -35,7 +35,6 @@
#include "crypto/CryptoNight_test.h" #include "crypto/CryptoNight_test.h"
#include "net/Job.h" #include "net/Job.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "Options.h"
#include "xmrig.h" #include "xmrig.h"
@ -131,7 +130,7 @@ bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx)
} }
bool CryptoNight::init(int algo, int variant) bool CryptoNight::init(int algo, int variant, bool doubleHash)
{ {
if (variant < 1 || variant > 4) { if (variant < 1 || variant > 4) {
return false; return false;
@ -145,7 +144,7 @@ bool CryptoNight::init(int algo, int variant)
cryptonight_hash_ctx = cryptonight_variations[index]; cryptonight_hash_ctx = cryptonight_variations[index];
return selfTest(algo); return selfTest(algo, doubleHash);
} }
@ -155,7 +154,7 @@ void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, crypt
} }
bool CryptoNight::selfTest(int algo) { bool CryptoNight::selfTest(int algo, bool doubleHash) {
if (cryptonight_hash_ctx == nullptr) { if (cryptonight_hash_ctx == nullptr) {
return false; return false;
} }
@ -167,8 +166,6 @@ bool CryptoNight::selfTest(int algo) {
cryptonight_hash_ctx(test_input, 76, output, ctx, 0); cryptonight_hash_ctx(test_input, 76, output, ctx, 0);
const bool doubleHash = Options::i()->doubleHash();
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0; bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0;
# else # else

View file

@ -54,11 +54,11 @@ class CryptoNight
{ {
public: public:
static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx); static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx);
static bool init(int algo, int variant); static bool init(int algo, int variant, bool doubleHash);
static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant); static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant);
private: private:
static bool selfTest(int algo); static bool selfTest(int algo, bool doubleHash);
}; };
#endif /* __CRYPTONIGHT_H__ */ #endif /* __CRYPTONIGHT_H__ */

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -34,18 +34,18 @@
#endif #endif
#include "core/Config.h"
#include "core/Controller.h"
#include "log/ConsoleLog.h" #include "log/ConsoleLog.h"
#include "log/Log.h" #include "log/Log.h"
#include "Options.h"
ConsoleLog::ConsoleLog(bool colors) : ConsoleLog::ConsoleLog(xmrig::Controller *controller) :
m_colors(colors), m_stream(nullptr),
m_stream(nullptr) m_controller(controller)
{ {
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
Options::i()->setColors(false); controller->config()->setColors(false);
m_colors = false;
return; return;
} }
@ -78,7 +78,9 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
# endif # endif
const char* color = nullptr; const char* color = nullptr;
if (m_colors) { const bool colors = m_controller->config()->isColors();
if (colors) {
switch (level) { switch (level) {
case Log::ERR: case Log::ERR:
color = Log::kCL_RED; color = Log::kCL_RED;
@ -109,9 +111,9 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
stime.tm_hour, stime.tm_hour,
stime.tm_min, stime.tm_min,
stime.tm_sec, stime.tm_sec,
m_colors ? color : "", colors ? color : "",
fmt, fmt,
m_colors ? Log::kCL_N : "" colors ? Log::kCL_N : ""
); );
print(args); print(args);
@ -120,7 +122,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
void ConsoleLog::text(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_colors ? Log::kCL_N : ""); snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_controller->config()->isColors() ? Log::kCL_N : "");
print(args); print(args);
} }

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -31,10 +31,15 @@
#include "interfaces/ILogBackend.h" #include "interfaces/ILogBackend.h"
namespace xmrig {
class Controller;
}
class ConsoleLog : public ILogBackend class ConsoleLog : public ILogBackend
{ {
public: public:
ConsoleLog(bool colors); ConsoleLog(xmrig::Controller *controller);
void message(int level, const char *fmt, va_list args) override; void message(int level, const char *fmt, va_list args) override;
void text(const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override;
@ -43,12 +48,12 @@ private:
bool isWritable() const; bool isWritable() const;
void print(va_list args); void print(va_list args);
bool m_colors;
char m_buf[512]; char m_buf[512];
char m_fmt[256]; char m_fmt[256];
uv_buf_t m_uvBuf; uv_buf_t m_uvBuf;
uv_stream_t *m_stream; uv_stream_t *m_stream;
uv_tty_t m_tty; uv_tty_t m_tty;
xmrig::Controller *m_controller;
}; };
#endif /* __CONSOLELOG_H__ */ #endif /* __CONSOLELOG_H__ */

View file

@ -39,29 +39,30 @@
#include "net/strategies/SinglePoolStrategy.h" #include "net/strategies/SinglePoolStrategy.h"
#include "net/SubmitResult.h" #include "net/SubmitResult.h"
#include "net/Url.h" #include "net/Url.h"
#include "Options.h"
#include "workers/Workers.h" #include "workers/Workers.h"
#include "core/Controller.h"
#include "core/Config.h"
Network::Network(const Options *options) : Network::Network(xmrig::Controller *controller) :
m_options(options), m_donate(nullptr),
m_donate(nullptr) m_controller(controller)
{ {
srand(time(0) ^ (uintptr_t) this); srand(time(0) ^ (uintptr_t) this);
Workers::setListener(this); Workers::setListener(this);
const std::vector<Url*> &pools = options->pools(); const std::vector<Url*> &pools = controller->config()->pools();
if (pools.size() > 1) { if (pools.size() > 1) {
m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this); m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this);
} }
else { else {
m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this); m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), this);
} }
if (m_options->donateLevel() > 0) { if (controller->config()->donateLevel() > 0) {
m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), this); m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front()->user(), controller->config()->algorithm(), this);
} }
m_timer.data = this; m_timer.data = this;
@ -101,7 +102,7 @@ void Network::onActive(IStrategy *strategy, Client *client)
m_state.setPool(client->host(), client->port(), client->ip()); m_state.setPool(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()); 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());
} }
@ -146,21 +147,27 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit
m_state.add(result, error); m_state.add(result, error);
if (error) { if (error) {
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)" 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)", : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed); m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
} }
else { else {
LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" 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)", : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
m_state.accepted, m_state.rejected, result.diff, result.elapsed); 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) void Network::setJob(Client *client, const Job &job, bool donate)
{ {
if (m_options->colors()) { if (isColors()) {
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()); 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 { else {

View file

@ -35,14 +35,18 @@
class IStrategy; class IStrategy;
class Options;
class Url; class Url;
namespace xmrig {
class Controller;
}
class Network : public IJobResultListener, public IStrategyListener class Network : public IJobResultListener, public IStrategyListener
{ {
public: public:
Network(const Options *options); Network(xmrig::Controller *controller);
~Network(); ~Network();
void connect(); void connect();
@ -58,16 +62,17 @@ protected:
private: private:
constexpr static int kTickInterval = 1 * 1000; constexpr static int kTickInterval = 1 * 1000;
bool isColors() const;
void setJob(Client *client, const Job &job, bool donate); void setJob(Client *client, const Job &job, bool donate);
void tick(); void tick();
static void onTick(uv_timer_t *handle); static void onTick(uv_timer_t *handle);
const Options *m_options;
IStrategy *m_donate; IStrategy *m_donate;
IStrategy *m_strategy; IStrategy *m_strategy;
NetworkState m_state; NetworkState m_state;
uv_timer_t m_timer; uv_timer_t m_timer;
xmrig::Controller *m_controller;
}; };

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,8 +27,10 @@
#include <memory.h> #include <memory.h>
#include <stdio.h> #include <stdio.h>
#include "core/Config.h"
#include "core/Controller.h"
#include "log/Log.h" #include "log/Log.h"
#include "Options.h"
#include "workers/Hashrate.h" #include "workers/Hashrate.h"
@ -43,9 +45,10 @@ inline const char *format(double h, char* buf, size_t size)
} }
Hashrate::Hashrate(int threads) : Hashrate::Hashrate(int threads, xmrig::Controller *controller) :
m_highest(0.0), m_highest(0.0),
m_threads(threads) m_threads(threads),
m_controller(controller)
{ {
m_counts = new uint64_t*[threads]; m_counts = new uint64_t*[threads];
m_timestamps = new uint64_t*[threads]; m_timestamps = new uint64_t*[threads];
@ -60,7 +63,7 @@ Hashrate::Hashrate(int threads) :
memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize); memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize);
} }
const int printTime = Options::i()->printTime(); const int printTime = controller->config()->printTime();
if (printTime > 0) { if (printTime > 0) {
uv_timer_init(uv_default_loop(), &m_timer); uv_timer_init(uv_default_loop(), &m_timer);
@ -153,7 +156,7 @@ void Hashrate::print()
char num3[8]; char num3[8];
char num4[8]; char num4[8];
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", 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",
format(calc(ShortInterval), num1, sizeof(num1)), format(calc(ShortInterval), num1, sizeof(num1)),
format(calc(MediumInterval), num2, sizeof(num2)), format(calc(MediumInterval), num2, sizeof(num2)),
format(calc(LargeInterval), num3, sizeof(num3)), format(calc(LargeInterval), num3, sizeof(num3)),

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -29,6 +29,11 @@
#include <uv.h> #include <uv.h>
namespace xmrig {
class Controller;
}
class Hashrate class Hashrate
{ {
public: public:
@ -38,7 +43,7 @@ public:
LargeInterval = 900000 LargeInterval = 900000
}; };
Hashrate(int threads); Hashrate(int threads, xmrig::Controller *controller);
double calc(size_t ms) const; double calc(size_t ms) const;
double calc(size_t threadId, size_t ms) const; double calc(size_t threadId, size_t ms) const;
void add(size_t threadId, uint64_t count, uint64_t timestamp); void add(size_t threadId, uint64_t count, uint64_t timestamp);
@ -61,6 +66,7 @@ private:
uint64_t** m_counts; uint64_t** m_counts;
uint64_t** m_timestamps; uint64_t** m_timestamps;
uv_timer_t m_timer; uv_timer_t m_timer;
xmrig::Controller *m_controller;
}; };

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -27,7 +27,6 @@
#include "api/Api.h" #include "api/Api.h"
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h"
#include "workers/DoubleWorker.h" #include "workers/DoubleWorker.h"
#include "workers/Handle.h" #include "workers/Handle.h"
#include "workers/Hashrate.h" #include "workers/Hashrate.h"
@ -103,10 +102,10 @@ void Workers::setJob(const Job &job, bool donate)
} }
void Workers::start(int64_t affinity, int priority) void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller)
{ {
const int threads = Mem::threads(); const int threads = Mem::threads();
m_hashrate = new Hashrate(threads); m_hashrate = new Hashrate(threads, controller);
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); uv_rwlock_init(&m_rwlock);

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.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 * 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 * it under the terms of the GNU General Public License as published by
@ -39,6 +39,11 @@ class Hashrate;
class IJobResultListener; class IJobResultListener;
namespace xmrig {
class Controller;
}
class Workers class Workers
{ {
public: public:
@ -46,7 +51,7 @@ public:
static void printHashrate(bool detail); static void printHashrate(bool detail);
static void setEnabled(bool enabled); static void setEnabled(bool enabled);
static void setJob(const Job &job, bool donate); static void setJob(const Job &job, bool donate);
static void start(int64_t affinity, int priority); static void start(int64_t affinity, int priority, xmrig::Controller *controller);
static void stop(); static void stop();
static void submit(const JobResult &result); static void submit(const JobResult &result);