Merge branch 'dev'
This commit is contained in:
commit
3cc18d30de
26 changed files with 620 additions and 575 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,5 +1,13 @@
|
|||
# v2.2.0
|
||||
- [#46](https://github.com/xmrig/xmrig/issues/46) Restored config file support. Now possible use multiple config files and combine with command line options also added support for default config.
|
||||
- Improved colors support on Windows, now used uv_tty, legacy code removed.
|
||||
- QuickEdit Mode now disabled on Windows.
|
||||
- Added interactive commands in console window:: **h**ashrate, **p**ause, **r**esume.
|
||||
- Fixed autoconf mode for AMD FX CPUs.
|
||||
|
||||
# v2.1.0
|
||||
- [#40](https://github.com/xmrig/xmrig/issues/40) Improved miner shutdown, fixed crash on exit for Linux and OS X.
|
||||
- [#40](https://github.com/xmrig/xmrig/issues/40)
|
||||
Improved miner shutdown, fixed crash on exit for Linux and OS X.
|
||||
- Fixed, login request was contain malformed JSON if username or password has some special characters for example `\`.
|
||||
- [#220](https://github.com/fireice-uk/xmr-stak-cpu/pull/220) Better support for Round Robin DNS, IP address now always chosen randomly instead of stuck on first one.
|
||||
- Changed donation address, new [xmrig-proxy](https://github.com/xmrig/xmrig-proxy) is coming soon.
|
||||
|
|
|
@ -11,8 +11,10 @@ include (CheckIncludeFile)
|
|||
set(HEADERS
|
||||
src/3rdparty/align.h
|
||||
src/App.h
|
||||
src/Console.h
|
||||
src/Cpu.h
|
||||
src/interfaces/IClientListener.h
|
||||
src/interfaces/IConsoleListener.h
|
||||
src/interfaces/IJobResultListener.h
|
||||
src/interfaces/ILogBackend.h
|
||||
src/interfaces/IStrategy.h
|
||||
|
@ -58,6 +60,7 @@ set(HEADERS_CRYPTO
|
|||
|
||||
set(SOURCES
|
||||
src/App.cpp
|
||||
src/Console.cpp
|
||||
src/log/ConsoleLog.cpp
|
||||
src/log/FileLog.cpp
|
||||
src/log/Log.cpp
|
||||
|
@ -65,10 +68,10 @@ set(SOURCES
|
|||
src/net/Client.cpp
|
||||
src/net/Job.cpp
|
||||
src/net/Network.cpp
|
||||
src/net/Url.cpp
|
||||
src/net/strategies/DonateStrategy.cpp
|
||||
src/net/strategies/FailoverStrategy.cpp
|
||||
src/net/strategies/SinglePoolStrategy.cpp
|
||||
src/net/Url.cpp
|
||||
src/Options.cpp
|
||||
src/Summary.cpp
|
||||
src/workers/DoubleWorker.cpp
|
||||
|
@ -94,8 +97,6 @@ set(SOURCES_CRYPTO
|
|||
if (WIN32)
|
||||
set(SOURCES_OS
|
||||
res/app.rc
|
||||
src/3rdparty/winansi.cpp
|
||||
src/3rdparty/winansi.h
|
||||
src/App_win.cpp
|
||||
src/Cpu_win.cpp
|
||||
src/Mem_win.cpp
|
||||
|
|
392
src/3rdparty/winansi.cpp
vendored
392
src/3rdparty/winansi.cpp
vendored
|
@ -1,392 +0,0 @@
|
|||
/**
|
||||
* Old Git implementation of windows terminal colors (2009)
|
||||
* before use of a threaded wrapper.
|
||||
*/
|
||||
|
||||
#undef NOGDI
|
||||
#include <windows.h>
|
||||
#include <wingdi.h>
|
||||
#include <winreg.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
|
||||
#include "winansi.h"
|
||||
/*
|
||||
* Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
Functions to be wrapped:
|
||||
*/
|
||||
#undef printf
|
||||
#undef fprintf
|
||||
#undef fputs
|
||||
#undef vfprintf
|
||||
/* TODO: write */
|
||||
|
||||
/*
|
||||
ANSI codes used by git: m, K
|
||||
|
||||
This file is git-specific. Therefore, this file does not attempt
|
||||
to implement any codes that are not used by git.
|
||||
*/
|
||||
|
||||
static HANDLE console;
|
||||
static WORD plain_attr;
|
||||
static WORD attr;
|
||||
static int negative;
|
||||
|
||||
static void init(void)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
|
||||
static int initialized = 0;
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
console = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (console == INVALID_HANDLE_VALUE)
|
||||
console = NULL;
|
||||
|
||||
if (!console)
|
||||
return;
|
||||
|
||||
GetConsoleScreenBufferInfo(console, &sbi);
|
||||
attr = plain_attr = sbi.wAttributes;
|
||||
negative = 0;
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
static int write_console(const char *str, int len)
|
||||
{
|
||||
/* convert utf-8 to utf-16, write directly to console */
|
||||
int wlen = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
|
||||
wchar_t *wbuf = (wchar_t *)alloca(wlen * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, len, wbuf, wlen);
|
||||
|
||||
WriteConsoleW(console, wbuf, wlen, NULL, NULL);
|
||||
|
||||
/* return original (utf-8 encoded) length */
|
||||
return len;
|
||||
}
|
||||
|
||||
#define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||
#define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
|
||||
|
||||
static void set_console_attr(void)
|
||||
{
|
||||
WORD attributes = attr;
|
||||
if (negative) {
|
||||
attributes &= ~FOREGROUND_ALL;
|
||||
attributes &= ~BACKGROUND_ALL;
|
||||
|
||||
/* This could probably use a bitmask
|
||||
instead of a series of ifs */
|
||||
if (attr & FOREGROUND_RED)
|
||||
attributes |= BACKGROUND_RED;
|
||||
if (attr & FOREGROUND_GREEN)
|
||||
attributes |= BACKGROUND_GREEN;
|
||||
if (attr & FOREGROUND_BLUE)
|
||||
attributes |= BACKGROUND_BLUE;
|
||||
|
||||
if (attr & BACKGROUND_RED)
|
||||
attributes |= FOREGROUND_RED;
|
||||
if (attr & BACKGROUND_GREEN)
|
||||
attributes |= FOREGROUND_GREEN;
|
||||
if (attr & BACKGROUND_BLUE)
|
||||
attributes |= FOREGROUND_BLUE;
|
||||
}
|
||||
SetConsoleTextAttribute(console, attributes);
|
||||
}
|
||||
|
||||
static void erase_in_line(void)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO sbi;
|
||||
DWORD dummy; /* Needed for Windows 7 (or Vista) regression */
|
||||
|
||||
if (!console)
|
||||
return;
|
||||
|
||||
GetConsoleScreenBufferInfo(console, &sbi);
|
||||
FillConsoleOutputCharacterA(console, ' ',
|
||||
sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition,
|
||||
&dummy);
|
||||
}
|
||||
|
||||
|
||||
static const char *set_attr(const char *str)
|
||||
{
|
||||
const char *func;
|
||||
size_t len = strspn(str, "0123456789;");
|
||||
func = str + len;
|
||||
|
||||
switch (*func) {
|
||||
case 'm':
|
||||
do {
|
||||
long val = strtol(str, (char **)&str, 10);
|
||||
switch (val) {
|
||||
case 0: /* reset */
|
||||
attr = plain_attr;
|
||||
negative = 0;
|
||||
break;
|
||||
case 1: /* bold */
|
||||
attr |= FOREGROUND_INTENSITY;
|
||||
break;
|
||||
case 2: /* faint */
|
||||
case 22: /* normal */
|
||||
attr &= ~FOREGROUND_INTENSITY;
|
||||
break;
|
||||
case 3: /* italic */
|
||||
/* Unsupported */
|
||||
break;
|
||||
case 4: /* underline */
|
||||
case 21: /* double underline */
|
||||
/* Wikipedia says this flag does nothing */
|
||||
/* Furthermore, mingw doesn't define this flag
|
||||
attr |= COMMON_LVB_UNDERSCORE; */
|
||||
break;
|
||||
case 24: /* no underline */
|
||||
/* attr &= ~COMMON_LVB_UNDERSCORE; */
|
||||
break;
|
||||
case 5: /* slow blink */
|
||||
case 6: /* fast blink */
|
||||
/* We don't have blink, but we do have
|
||||
background intensity */
|
||||
attr |= BACKGROUND_INTENSITY;
|
||||
break;
|
||||
case 25: /* no blink */
|
||||
attr &= ~BACKGROUND_INTENSITY;
|
||||
break;
|
||||
case 7: /* negative */
|
||||
negative = 1;
|
||||
break;
|
||||
case 27: /* positive */
|
||||
negative = 0;
|
||||
break;
|
||||
case 8: /* conceal */
|
||||
case 28: /* reveal */
|
||||
/* Unsupported */
|
||||
break;
|
||||
case 30: /* Black */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
break;
|
||||
case 31: /* Red */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_RED;
|
||||
break;
|
||||
case 32: /* Green */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_GREEN;
|
||||
break;
|
||||
case 33: /* Yellow */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_RED | FOREGROUND_GREEN;
|
||||
break;
|
||||
case 34: /* Blue */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_BLUE;
|
||||
break;
|
||||
case 35: /* Magenta */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_RED | FOREGROUND_BLUE;
|
||||
break;
|
||||
case 36: /* Cyan */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
break;
|
||||
case 37: /* White */
|
||||
attr |= FOREGROUND_RED |
|
||||
FOREGROUND_GREEN |
|
||||
FOREGROUND_BLUE;
|
||||
break;
|
||||
case 38: /* Unknown */
|
||||
break;
|
||||
case 39: /* reset */
|
||||
attr &= ~FOREGROUND_ALL;
|
||||
attr |= (plain_attr & FOREGROUND_ALL);
|
||||
break;
|
||||
case 40: /* Black */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
break;
|
||||
case 41: /* Red */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_RED;
|
||||
break;
|
||||
case 42: /* Green */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_GREEN;
|
||||
break;
|
||||
case 43: /* Yellow */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_RED | BACKGROUND_GREEN;
|
||||
break;
|
||||
case 44: /* Blue */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_BLUE;
|
||||
break;
|
||||
case 45: /* Magenta */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_RED | BACKGROUND_BLUE;
|
||||
break;
|
||||
case 46: /* Cyan */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= BACKGROUND_GREEN | BACKGROUND_BLUE;
|
||||
break;
|
||||
case 47: /* White */
|
||||
attr |= BACKGROUND_RED |
|
||||
BACKGROUND_GREEN |
|
||||
BACKGROUND_BLUE;
|
||||
break;
|
||||
case 48: /* Unknown */
|
||||
break;
|
||||
case 49: /* reset */
|
||||
attr &= ~BACKGROUND_ALL;
|
||||
attr |= (plain_attr & BACKGROUND_ALL);
|
||||
break;
|
||||
default:
|
||||
/* Unsupported code */
|
||||
break;
|
||||
}
|
||||
str++;
|
||||
} while (*(str - 1) == ';');
|
||||
|
||||
set_console_attr();
|
||||
break;
|
||||
case 'K':
|
||||
erase_in_line();
|
||||
break;
|
||||
default:
|
||||
/* Unsupported code */
|
||||
break;
|
||||
}
|
||||
|
||||
return func + 1;
|
||||
}
|
||||
|
||||
static int ansi_emulate(const char *str, FILE *stream)
|
||||
{
|
||||
int rv = 0;
|
||||
const char *pos = str;
|
||||
|
||||
fflush(stream);
|
||||
|
||||
while (*pos) {
|
||||
pos = strstr(str, "\033[");
|
||||
if (pos) {
|
||||
int len = (int) (pos - str);
|
||||
|
||||
if (len) {
|
||||
int out_len = write_console(str, len);
|
||||
rv += out_len;
|
||||
if (out_len < len)
|
||||
return rv;
|
||||
}
|
||||
|
||||
str = pos + 2;
|
||||
rv += 2;
|
||||
|
||||
pos = set_attr(str);
|
||||
rv += (int) (pos - str);
|
||||
str = pos;
|
||||
}
|
||||
else {
|
||||
int len = (int) strlen(str);
|
||||
rv += write_console(str, len);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int winansi_fputs(const char *str, FILE *stream)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (!isatty(fileno(stream)))
|
||||
return fputs(str, stream);
|
||||
|
||||
init();
|
||||
|
||||
if (!console)
|
||||
return fputs(str, stream);
|
||||
|
||||
rv = ansi_emulate(str, stream);
|
||||
|
||||
if (rv >= 0)
|
||||
return 0;
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
|
||||
int winansi_vfprintf(FILE *stream, const char *format, va_list list)
|
||||
{
|
||||
int len, rv;
|
||||
char small_buf[256] = { 0 };
|
||||
char *buf = small_buf;
|
||||
va_list cp;
|
||||
|
||||
if (!isatty(fileno(stream)))
|
||||
goto abort;
|
||||
|
||||
init();
|
||||
|
||||
if (!console)
|
||||
goto abort;
|
||||
|
||||
va_copy(cp, list);
|
||||
len = vsnprintf(small_buf, sizeof(small_buf), format, cp);
|
||||
#ifdef WIN32
|
||||
/* bug on long strings without that */
|
||||
if (len == -1)
|
||||
len = _vscprintf(format, cp);
|
||||
#endif
|
||||
va_end(cp);
|
||||
|
||||
if ((unsigned) len > sizeof(small_buf) - 1) {
|
||||
buf = (char*)malloc(len + 1);
|
||||
if (!buf)
|
||||
goto abort;
|
||||
|
||||
len = vsnprintf(buf, len + 1, format, list);
|
||||
#ifdef WIN32
|
||||
if (len == -1)
|
||||
len = _vscprintf(format, list);
|
||||
#endif
|
||||
}
|
||||
|
||||
rv = ansi_emulate(buf, stream);
|
||||
|
||||
if (buf != small_buf)
|
||||
free(buf);
|
||||
return rv;
|
||||
|
||||
abort:
|
||||
rv = vfprintf(stream, format, list);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int winansi_fprintf(FILE *stream, const char *format, ...)
|
||||
{
|
||||
va_list list;
|
||||
int rv;
|
||||
|
||||
va_start(list, format);
|
||||
rv = winansi_vfprintf(stream, format, list);
|
||||
va_end(list);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int winansi_printf(const char *format, ...)
|
||||
{
|
||||
va_list list;
|
||||
int rv;
|
||||
|
||||
va_start(list, format);
|
||||
rv = winansi_vfprintf(stdout, format, list);
|
||||
va_end(list);
|
||||
|
||||
return rv;
|
||||
}
|
29
src/3rdparty/winansi.h
vendored
29
src/3rdparty/winansi.h
vendored
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* ANSI emulation wrappers
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define fileno(fd) _fileno(fd)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int winansi_fputs(const char *str, FILE *stream);
|
||||
int winansi_printf(const char *format, ...);
|
||||
int winansi_fprintf(FILE *stream, const char *format, ...);
|
||||
int winansi_vfprintf(FILE *stream, const char *format, va_list list);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef fputs
|
||||
#undef fprintf
|
||||
#undef vfprintf
|
||||
|
||||
#define fputs winansi_fputs
|
||||
#define printf winansi_printf
|
||||
#define fprintf winansi_fprintf
|
||||
#define vfprintf winansi_vfprintf
|
37
src/App.cpp
37
src/App.cpp
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
#include "App.h"
|
||||
#include "Console.h"
|
||||
#include "Cpu.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "log/ConsoleLog.h"
|
||||
|
@ -50,6 +51,7 @@ App *App::m_self = nullptr;
|
|||
|
||||
|
||||
App::App(int argc, char **argv) :
|
||||
m_console(nullptr),
|
||||
m_network(nullptr),
|
||||
m_options(nullptr)
|
||||
{
|
||||
|
@ -62,6 +64,7 @@ App::App(int argc, char **argv) :
|
|||
|
||||
if (!m_options->background()) {
|
||||
Log::add(new ConsoleLog(m_options->colors()));
|
||||
m_console = new Console(this);
|
||||
}
|
||||
|
||||
if (m_options->logFile()) {
|
||||
|
@ -82,6 +85,7 @@ App::App(int argc, char **argv) :
|
|||
|
||||
App::~App()
|
||||
{
|
||||
delete m_console;
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,6 +125,39 @@ int App::exec()
|
|||
}
|
||||
|
||||
|
||||
void App::onConsoleCommand(char command)
|
||||
{
|
||||
switch (command) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
Workers::printHashrate(true);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'P':
|
||||
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;
|
||||
|
||||
case 'r':
|
||||
case 'R':
|
||||
if (!Workers::isEnabled()) {
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;32mresumed" : "resumed");
|
||||
Workers::setEnabled(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
LOG_WARN("Ctrl+C received, exiting");
|
||||
close();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void App::close()
|
||||
{
|
||||
m_network->stop();
|
||||
|
|
10
src/App.h
10
src/App.h
|
@ -28,11 +28,15 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#include "interfaces/IConsoleListener.h"
|
||||
|
||||
|
||||
class Console;
|
||||
class Network;
|
||||
class Options;
|
||||
|
||||
|
||||
class App
|
||||
class App : public IConsoleListener
|
||||
{
|
||||
public:
|
||||
App(int argc, char **argv);
|
||||
|
@ -40,6 +44,9 @@ public:
|
|||
|
||||
int exec();
|
||||
|
||||
protected:
|
||||
void onConsoleCommand(char command) override;
|
||||
|
||||
private:
|
||||
void background();
|
||||
void close();
|
||||
|
@ -48,6 +55,7 @@ private:
|
|||
|
||||
static App *m_self;
|
||||
|
||||
Console *m_console;
|
||||
Network *m_network;
|
||||
Options *m_options;
|
||||
uv_signal_t m_signal;
|
||||
|
|
57
src/Console.cpp
Normal file
57
src/Console.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* 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-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
|
||||
* 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 "Console.h"
|
||||
#include "interfaces/IConsoleListener.h"
|
||||
|
||||
|
||||
Console::Console(IConsoleListener *listener)
|
||||
: m_listener(listener)
|
||||
{
|
||||
m_tty.data = this;
|
||||
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
|
||||
uv_tty_set_mode(&m_tty, UV_TTY_MODE_RAW);
|
||||
|
||||
uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), Console::onAllocBuffer, Console::onRead);
|
||||
}
|
||||
|
||||
|
||||
void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
|
||||
{
|
||||
auto console = static_cast<Console*>(handle->data);
|
||||
buf->len = 1;
|
||||
buf->base = console->m_buf;
|
||||
}
|
||||
|
||||
|
||||
void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
if (nread < 0) {
|
||||
return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);
|
||||
}
|
||||
|
||||
if (nread == 1) {
|
||||
static_cast<Console*>(stream->data)->m_listener->onConsoleCommand(buf->base[0]);
|
||||
}
|
||||
}
|
49
src/Console.h
Normal file
49
src/Console.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* 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-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
|
||||
* 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 __CONSOLE_H__
|
||||
#define __CONSOLE_H__
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
class IConsoleListener;
|
||||
|
||||
|
||||
class Console
|
||||
{
|
||||
public:
|
||||
Console(IConsoleListener *listener);
|
||||
|
||||
private:
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
||||
char m_buf[1];
|
||||
IConsoleListener *m_listener;
|
||||
uv_tty_t m_tty;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __CONSOLE_H__ */
|
27
src/Cpu.cpp
27
src/Cpu.cpp
|
@ -29,13 +29,14 @@
|
|||
#include "Cpu.h"
|
||||
|
||||
|
||||
char Cpu::m_brand[64] = { 0 };
|
||||
int Cpu::m_flags = 0;
|
||||
int Cpu::m_l2_cache = 0;
|
||||
int Cpu::m_l3_cache = 0;
|
||||
int Cpu::m_sockets = 1;
|
||||
int Cpu::m_totalCores = 0;
|
||||
int Cpu::m_totalThreads = 0;
|
||||
bool Cpu::m_l2_exclusive = false;
|
||||
char Cpu::m_brand[64] = { 0 };
|
||||
int Cpu::m_flags = 0;
|
||||
int Cpu::m_l2_cache = 0;
|
||||
int Cpu::m_l3_cache = 0;
|
||||
int Cpu::m_sockets = 1;
|
||||
int Cpu::m_totalCores = 0;
|
||||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
|
@ -44,7 +45,14 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int cache = m_l3_cache ? m_l3_cache : m_l2_cache;
|
||||
int cache = 0;
|
||||
if (m_l3_cache) {
|
||||
cache = m_l2_exclusive ? (m_l2_cache + m_l3_cache) : m_l3_cache;
|
||||
}
|
||||
else {
|
||||
cache = m_l2_cache;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
||||
|
||||
|
@ -84,8 +92,9 @@ void Cpu::initCommon()
|
|||
m_l3_cache = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0;
|
||||
|
||||
// Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97
|
||||
if (data.vendor == VENDOR_AMD && data.l3_cache <= 0 && data.l2_assoc == 16 && data.ext_family >= 21) {
|
||||
if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) {
|
||||
m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets;
|
||||
m_l2_exclusive = true;
|
||||
}
|
||||
else {
|
||||
m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0;
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
private:
|
||||
static void initCommon();
|
||||
|
||||
static bool m_l2_exclusive;
|
||||
static char m_brand[64];
|
||||
static int m_flags;
|
||||
static int m_l2_cache;
|
||||
|
|
381
src/Options.cpp
381
src/Options.cpp
|
@ -113,6 +113,36 @@ static struct option const options[] = {
|
|||
};
|
||||
|
||||
|
||||
static struct option const config_options[] = {
|
||||
{ "algo", 1, nullptr, 'a' },
|
||||
{ "av", 1, nullptr, 'v' },
|
||||
{ "background", 0, nullptr, 'B' },
|
||||
{ "cpu-affinity", 1, nullptr, 1020 },
|
||||
{ "donate-level", 1, nullptr, 1003 },
|
||||
{ "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' },
|
||||
{ "colors", 0, nullptr, 2000 },
|
||||
{ 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' },
|
||||
{ "nicehash", 0, nullptr, 1006 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static const char *algo_names[] = {
|
||||
"cryptonight",
|
||||
# ifndef XMRIG_NO_AEON
|
||||
|
@ -121,6 +151,34 @@ static const char *algo_names[] = {
|
|||
};
|
||||
|
||||
|
||||
static char *defaultConfigName()
|
||||
{
|
||||
size_t size = 512;
|
||||
char *buf = new char[size];
|
||||
|
||||
if (uv_exepath(buf, &size) < 0) {
|
||||
delete [] buf;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (size < 500) {
|
||||
# ifdef WIN32
|
||||
char *p = strrchr(buf, '\\');
|
||||
# else
|
||||
char *p = strrchr(buf, '/');
|
||||
# endif
|
||||
|
||||
if (p) {
|
||||
strcpy(p + 1, "config.json");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] buf;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Options *Options::parse(int argc, char **argv)
|
||||
{
|
||||
if (!m_self) {
|
||||
|
@ -176,7 +234,13 @@ Options::Options(int argc, char **argv) :
|
|||
}
|
||||
|
||||
if (!m_pools[0]->isValid()) {
|
||||
fprintf(stderr, "No pool URL supplied. Exiting.");
|
||||
char *fileName = defaultConfigName();
|
||||
parseConfig(fileName);
|
||||
delete [] fileName;
|
||||
}
|
||||
|
||||
if (!m_pools[0]->isValid()) {
|
||||
fprintf(stderr, "No pool URL supplied. Exiting.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -204,11 +268,8 @@ Options::~Options()
|
|||
}
|
||||
|
||||
|
||||
bool Options::parseArg(int key, char *arg)
|
||||
bool Options::parseArg(int key, const char *arg)
|
||||
{
|
||||
char *p;
|
||||
int v;
|
||||
|
||||
switch (key) {
|
||||
case 'a': /* --algo */
|
||||
if (!setAlgo(arg)) {
|
||||
|
@ -216,13 +277,6 @@ bool Options::parseArg(int key, char *arg)
|
|||
}
|
||||
break;
|
||||
|
||||
case 'O': /* --userpass */
|
||||
if (!m_pools.back()->setUserpass(arg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'o': /* --url */
|
||||
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
|
||||
Url *url = new Url(arg);
|
||||
|
@ -240,7 +294,12 @@ bool Options::parseArg(int key, char *arg)
|
|||
if (!m_pools.back()->isValid()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'O': /* --userpass */
|
||||
if (!m_pools.back()->setUserpass(arg)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'u': /* --user */
|
||||
|
@ -257,53 +316,22 @@ bool Options::parseArg(int key, char *arg)
|
|||
m_colors = false;
|
||||
break;
|
||||
|
||||
case 'r': /* --retries */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 1 || v > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retries = v;
|
||||
break;
|
||||
|
||||
case 'R': /* --retry-pause */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 1 || v > 3600) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retryPause = v;
|
||||
break;
|
||||
|
||||
case 't': /* --threads */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 1 || v > 1024) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_threads = v;
|
||||
break;
|
||||
|
||||
case 'r': /* --retries */
|
||||
case 'R': /* --retry-pause */
|
||||
case 't': /* --threads */
|
||||
case 'v': /* --av */
|
||||
case 1003: /* --donate-level */
|
||||
case 1004: /* --max-cpu-usage */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 1 || v > 100) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_maxCpuUsage = v;
|
||||
break;
|
||||
case 1007: /* --print-time */
|
||||
return parseArg(key, strtol(arg, nullptr, 10));
|
||||
|
||||
case 'B': /* --background */
|
||||
case 'k': /* --keepalive */
|
||||
case 'S': /* --syslog */
|
||||
case 1002: /* --no-color */
|
||||
case 1005: /* --safe */
|
||||
m_safe = true;
|
||||
break;
|
||||
|
||||
case 'k': /* --keepalive */
|
||||
m_pools.back()->setKeepAlive(true);
|
||||
break;
|
||||
case 1006: /* --nicehash */
|
||||
return parseBoolean(key, true);
|
||||
|
||||
case 'V': /* --version */
|
||||
showVersion();
|
||||
|
@ -313,59 +341,15 @@ bool Options::parseArg(int key, char *arg)
|
|||
showUsage(0);
|
||||
return false;
|
||||
|
||||
case 'B': /* --background */
|
||||
m_background = true;
|
||||
m_colors = false;
|
||||
case 'c': /* --config */
|
||||
parseConfig(arg);
|
||||
break;
|
||||
|
||||
case 'S': /* --syslog */
|
||||
m_syslog = true;
|
||||
m_colors = false;
|
||||
break;
|
||||
|
||||
case 'v': /* --av */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 0 || v > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
case 1020: { /* --cpu-affinity */
|
||||
const char *p = strstr(arg, "0x");
|
||||
return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
|
||||
}
|
||||
|
||||
m_algoVariant = v;
|
||||
break;
|
||||
|
||||
case 1020: /* --cpu-affinity */
|
||||
p = strstr(arg, "0x");
|
||||
m_affinity = p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10);
|
||||
break;
|
||||
|
||||
case 1002: /* --no-color */
|
||||
m_colors = false;
|
||||
break;
|
||||
|
||||
case 1003: /* --donate-level */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 1 || v > 99) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_donateLevel = v;
|
||||
break;
|
||||
|
||||
case 1006: /* --nicehash */
|
||||
m_pools.back()->setNicehash(true);
|
||||
break;
|
||||
|
||||
case 1007: /* --print-time */
|
||||
v = strtol(arg, nullptr, 10);
|
||||
if (v < 0 || v > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_printTime = v;
|
||||
break;
|
||||
|
||||
default:
|
||||
showUsage(1);
|
||||
return false;
|
||||
|
@ -375,6 +359,127 @@ bool Options::parseArg(int key, char *arg)
|
|||
}
|
||||
|
||||
|
||||
bool Options::parseArg(int key, uint64_t arg)
|
||||
{
|
||||
switch (key) {
|
||||
case 'r': /* --retries */
|
||||
if (arg < 1 || arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retries = arg;
|
||||
break;
|
||||
|
||||
case 'R': /* --retry-pause */
|
||||
if (arg < 1 || arg > 3600) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_retryPause = arg;
|
||||
break;
|
||||
|
||||
case 't': /* --threads */
|
||||
if (arg < 1 || arg > 1024) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_threads = arg;
|
||||
break;
|
||||
|
||||
case 'v': /* --av */
|
||||
if (arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_algoVariant = arg;
|
||||
break;
|
||||
|
||||
case 1003: /* --donate-level */
|
||||
if (arg < 1 || arg > 99) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_donateLevel = arg;
|
||||
break;
|
||||
|
||||
case 1004: /* --max-cpu-usage */
|
||||
if (arg < 1 || arg > 100) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_maxCpuUsage = arg;
|
||||
break;
|
||||
|
||||
case 1007: /* --print-time */
|
||||
if (arg > 1000) {
|
||||
showUsage(1);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_printTime = arg;
|
||||
break;
|
||||
|
||||
case 1020: /* --cpu-affinity */
|
||||
if (arg) {
|
||||
m_affinity = 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 2000: /* colors */
|
||||
m_colors = enable;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Url *Options::parseUrl(const char *arg) const
|
||||
{
|
||||
auto url = new Url(arg);
|
||||
|
@ -387,6 +492,72 @@ Url *Options::parseUrl(const char *arg) const
|
|||
}
|
||||
|
||||
|
||||
void Options::parseConfig(const char *fileName)
|
||||
{
|
||||
json_error_t err;
|
||||
json_t *config = json_load_file(fileName, 0, &err);
|
||||
|
||||
if (!json_is_object(config)) {
|
||||
if (config) {
|
||||
json_decref(config);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err.line < 0) {
|
||||
fprintf(stderr, "%s\n", err.text);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s:%d: %s\n", fileName, err.line, err.text);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
|
||||
parseJSON(&config_options[i], config);
|
||||
}
|
||||
|
||||
json_t *pools = json_object_get(config, "pools");
|
||||
if (json_is_array(pools)) {
|
||||
size_t index;
|
||||
json_t *value;
|
||||
|
||||
json_array_foreach(pools, index, value) {
|
||||
if (json_is_object(value)) {
|
||||
for (size_t i = 0; i < ARRAY_SIZE(pool_options); i++) {
|
||||
parseJSON(&pool_options[i], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_decref(config);
|
||||
}
|
||||
|
||||
|
||||
void Options::parseJSON(const struct option *option, json_t *object)
|
||||
{
|
||||
if (!option->name) {
|
||||
return;
|
||||
}
|
||||
|
||||
json_t *val = json_object_get(object, option->name);
|
||||
if (!val) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (option->has_arg && json_is_string(val)) {
|
||||
parseArg(option->val, json_string_value(val));
|
||||
}
|
||||
else if (option->has_arg && json_is_integer(val)) {
|
||||
parseArg(option->val, json_integer_value(val));
|
||||
}
|
||||
else if (!option->has_arg && json_is_boolean(val)) {
|
||||
parseBoolean(option->val, json_is_true(val));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Options::showUsage(int status) const
|
||||
{
|
||||
if (status) {
|
||||
|
|
|
@ -25,11 +25,13 @@
|
|||
#define __OPTIONS_H__
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <jansson.h>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Url;
|
||||
struct option;
|
||||
|
||||
|
||||
class Options
|
||||
|
@ -76,8 +78,12 @@ private:
|
|||
|
||||
static Options *m_self;
|
||||
|
||||
bool parseArg(int key, char *arg);
|
||||
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 parseConfig(const char *fileName);
|
||||
void parseJSON(const struct option *option, json_t *object);
|
||||
void showUsage(int status) const;
|
||||
void showVersion(void);
|
||||
|
||||
|
|
|
@ -50,11 +50,8 @@ static void print_versions()
|
|||
# endif
|
||||
|
||||
|
||||
if (Options::i()->colors()) {
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s", APP_VERSION, uv_version_string(), buf);
|
||||
} else {
|
||||
Log::i()->text(" * VERSIONS: XMRig/%s libuv/%s%s", APP_VERSION, uv_version_string(), buf);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,6 +127,17 @@ static void print_pools()
|
|||
}
|
||||
|
||||
|
||||
static void print_commands()
|
||||
{
|
||||
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 {
|
||||
Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Summary::print()
|
||||
{
|
||||
print_versions();
|
||||
|
@ -137,6 +145,7 @@ void Summary::print()
|
|||
print_cpu();
|
||||
print_threads();
|
||||
print_pools();
|
||||
print_commands();
|
||||
}
|
||||
|
||||
|
||||
|
|
25
src/config.json
Normal file
25
src/config.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"algo": "cryptonight",
|
||||
"av": 0,
|
||||
"background": false,
|
||||
"colors": true,
|
||||
"cpu-affinity": null,
|
||||
"donate-level": 5,
|
||||
"log-file": null,
|
||||
"max-cpu-usage": 75,
|
||||
"print-time": 60,
|
||||
"retries": 5,
|
||||
"retry-pause": 5,
|
||||
"safe": false,
|
||||
"syslog": false,
|
||||
"threads": null,
|
||||
"pools": [
|
||||
{
|
||||
"url": "pool.minemonero.pro:5555",
|
||||
"user": "",
|
||||
"pass": "x",
|
||||
"keepalive": true,
|
||||
"nicehash": false
|
||||
}
|
||||
]
|
||||
}
|
37
src/interfaces/IConsoleListener.h
Normal file
37
src/interfaces/IConsoleListener.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* 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-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
|
||||
* 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 __ICONSOLELISTENER_H__
|
||||
#define __ICONSOLELISTENER_H__
|
||||
|
||||
|
||||
class IConsoleListener
|
||||
{
|
||||
public:
|
||||
virtual ~IConsoleListener() {}
|
||||
|
||||
virtual void onConsoleCommand(char command) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // __ICONSOLELISTENER_H__
|
|
@ -27,13 +27,12 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <malloc.h>
|
||||
# include "3rdparty/winansi.h"
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "log/ConsoleLog.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
|
@ -41,6 +40,19 @@
|
|||
ConsoleLog::ConsoleLog(bool colors) :
|
||||
m_colors(colors)
|
||||
{
|
||||
uv_tty_init(uv_default_loop(), &m_tty, 1, 0);
|
||||
uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL);
|
||||
|
||||
# ifdef WIN32
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (GetConsoleMode(handle, &mode)) {
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -81,7 +93,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
|||
}
|
||||
|
||||
const size_t len = 64 + strlen(fmt) + 2;
|
||||
char *buf = static_cast<char *>(alloca(len));
|
||||
char *buf = new char[len];
|
||||
|
||||
sprintf(buf, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
|
||||
stime.tm_year + 1900,
|
||||
|
@ -95,18 +107,35 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
|||
m_colors ? Log::kCL_N : ""
|
||||
);
|
||||
|
||||
vfprintf(stdout, buf, args);
|
||||
fflush(stdout);
|
||||
print(buf, args);
|
||||
}
|
||||
|
||||
|
||||
void ConsoleLog::text(const char* fmt, va_list args)
|
||||
{
|
||||
const int len = 64 + strlen(fmt) + 2;
|
||||
char *buf = static_cast<char *>(alloca(len));
|
||||
char *buf = new char[len];
|
||||
|
||||
sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
|
||||
|
||||
vfprintf(stdout, buf, args);
|
||||
fflush(stdout);
|
||||
print(buf, args);
|
||||
}
|
||||
|
||||
|
||||
void ConsoleLog::print(char *fmt, va_list args)
|
||||
{
|
||||
vsnprintf(m_buf, sizeof(m_buf) - 1, fmt, args);
|
||||
delete [] fmt;
|
||||
|
||||
uv_buf_t buf;
|
||||
buf.base = strdup(m_buf);
|
||||
buf.len = strlen(buf.base);
|
||||
|
||||
uv_write_t *req = new uv_write_t;
|
||||
req->data = buf.base;
|
||||
|
||||
uv_write(req, reinterpret_cast<uv_stream_t*>(&m_tty), &buf, 1, [](uv_write_t *req, int status) {
|
||||
free(req->data);
|
||||
delete req;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#define __CONSOLELOG_H__
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
|
@ -33,11 +36,15 @@ class ConsoleLog : public ILogBackend
|
|||
public:
|
||||
ConsoleLog(bool colors);
|
||||
|
||||
void message(int level, const char* fmt, va_list args) override;
|
||||
void text(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;
|
||||
|
||||
private:
|
||||
void print(char *fmt, va_list args);
|
||||
|
||||
bool m_colors;
|
||||
char m_buf[512];
|
||||
uv_tty_t m_tty;
|
||||
};
|
||||
|
||||
#endif /* __CONSOLELOG_H__ */
|
||||
|
|
|
@ -28,13 +28,6 @@
|
|||
#include <time.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <malloc.h>
|
||||
# include "3rdparty/winansi.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "log/FileLog.h"
|
||||
|
||||
|
||||
|
|
|
@ -28,12 +28,6 @@
|
|||
#include <time.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <malloc.h>
|
||||
# include "3rdparty/winansi.h"
|
||||
#endif
|
||||
|
||||
#include "interfaces/ILogBackend.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
|
|
|
@ -100,12 +100,12 @@ int64_t Client::send(char *data, size_t size)
|
|||
|
||||
uv_buf_t buf = uv_buf_init(data, size ? size : strlen(data));
|
||||
|
||||
uv_write_t *req = static_cast<uv_write_t*>(malloc(sizeof(uv_write_t)));
|
||||
uv_write_t *req = new uv_write_t;
|
||||
req->data = buf.base;
|
||||
|
||||
uv_write(req, m_stream, &buf, 1, [](uv_write_t *req, int status) {
|
||||
free(req->data);
|
||||
free(req);
|
||||
delete req;
|
||||
});
|
||||
|
||||
uv_timer_start(&m_responseTimer, [](uv_timer_t *handle) { getClient(handle->data)->close(); }, kResponseTimeout, 0);
|
||||
|
@ -529,6 +529,10 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
|||
return client->close();;
|
||||
}
|
||||
|
||||
if ((size_t) nread > (kRecvBufSize - 8 - client->m_recvBufPos)) {
|
||||
return client->close();;
|
||||
}
|
||||
|
||||
client->m_recvBufPos += nread;
|
||||
|
||||
char* end;
|
||||
|
|
|
@ -66,6 +66,11 @@ void FailoverStrategy::stop()
|
|||
for (size_t i = 0; i < m_pools.size(); ++i) {
|
||||
m_pools[i]->disconnect();
|
||||
}
|
||||
|
||||
m_index = 0;
|
||||
m_active = -1;
|
||||
|
||||
m_listener->onPause(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
#define APP_ID "xmrig"
|
||||
#define APP_NAME "XMRig"
|
||||
#define APP_DESC "Monero (XMR) CPU miner"
|
||||
#define APP_VERSION "2.1.0"
|
||||
#define APP_VERSION "2.2.0-dev"
|
||||
#define APP_DOMAIN "xmrig.com"
|
||||
#define APP_SITE "www.xmrig.com"
|
||||
#define APP_COPYRIGHT "Copyright (C) 2016-2017 xmrig.com"
|
||||
|
||||
#define APP_VER_MAJOR 2
|
||||
#define APP_VER_MINOR 1
|
||||
#define APP_VER_MINOR 2
|
||||
#define APP_VER_BUILD 0
|
||||
#define APP_VER_REV 0
|
||||
|
||||
|
|
|
@ -69,6 +69,10 @@ void DoubleWorker::start()
|
|||
}
|
||||
while (Workers::isPaused());
|
||||
|
||||
if (Workers::sequence() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,10 @@ void SingleWorker::start()
|
|||
}
|
||||
while (Workers::isPaused());
|
||||
|
||||
if (Workers::sequence() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,12 @@ Job Workers::job()
|
|||
}
|
||||
|
||||
|
||||
void Workers::printHashrate(bool detail)
|
||||
{
|
||||
m_hashrate->print();
|
||||
}
|
||||
|
||||
|
||||
void Workers::setEnabled(bool enabled)
|
||||
{
|
||||
if (m_enabled == enabled) {
|
||||
|
@ -121,6 +127,7 @@ void Workers::stop()
|
|||
m_hashrate->stop();
|
||||
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
|
||||
m_paused = 0;
|
||||
m_sequence = 0;
|
||||
|
||||
for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||
|
|
|
@ -43,6 +43,7 @@ class Workers
|
|||
{
|
||||
public:
|
||||
static Job job();
|
||||
static void printHashrate(bool detail);
|
||||
static void setEnabled(bool enabled);
|
||||
static void setJob(const Job &job);
|
||||
static void start(int64_t affinity);
|
||||
|
|
Loading…
Reference in a new issue