Compare commits

...

44 Commits
beta ... v5.5.0

Author SHA1 Message Date
XMRig
74cb25c6e9 v5.5.0 2019-12-29 21:33:37 +07:00
XMRig
bc56a0f057 Merge branch 'dev' 2019-12-29 21:32:50 +07:00
xmrig
823d2e1eb9 Update CHANGELOG.md 2019-12-29 21:19:59 +07:00
XMRig
1ba46e0677 Fix for potential crash. 2019-12-29 21:14:35 +07:00
xmrig
6693cc90db Merge pull request #376 from CR4DL/dev
Use custom-diff shares for better proxy and worker stats
2019-12-29 21:08:10 +07:00
CR4DL
6ce8fbdd4a Add custom-diff-stats option for alternative hashrate calculation 2019-12-29 13:04:39 +01:00
CR4DL
0b10ef62a7 Fix: Consider correct diff value for custom-diff stats 2019-12-28 23:17:52 +01:00
xmrig
3d8d11822a Update CHANGELOG.md 2019-12-29 04:00:03 +07:00
XMRig
6eef5a429c Sync changes. 2019-12-29 03:34:35 +07:00
CR4DL
45490e77f1 Use custom-diff shares for better proxy and worker stats 2019-12-27 20:36:27 +01:00
XMRig
691d64bad6 Merge branch 'master' of https://github.com/CR4DL/xmrig-proxy into dev 2019-12-27 17:31:59 +07:00
CR4DL
2727687d64 64bit diff + new log style in ShareLog and ProxyDebug 2019-12-27 10:20:12 +01:00
CR4DL
53b409c78c Fix print-time config option 2019-12-27 10:19:51 +01:00
XMRig
7bf75b44fa Sync changes. 2019-12-27 01:00:16 +07:00
XMRig
f60ebbe066 Merge branch 'master' into dev 2019-12-26 23:49:56 +07:00
XMRig
e8654d411b v5.4.0 2019-12-21 16:15:21 +07:00
XMRig
2e149582b9 Merge branch 'dev' 2019-12-21 16:14:48 +07:00
xmrig
e1d82fe8f0 Update CHANGELOG.md 2019-12-21 00:25:56 +07:00
XMRig
011a2050d1 v5.4.0-dev 2019-12-21 00:22:52 +07:00
XMRig
0581513570 Added RandomV support. 2019-12-20 19:55:15 +07:00
XMRig
5117034c17 Fix verbose. 2019-12-18 02:32:16 +07:00
XMRig
9b1aab91df Sync with miner. 2019-12-18 01:55:19 +07:00
XMRig
d683a8f5c1 Sync changes with miner. 2019-12-17 17:04:02 +07:00
XMRig
b099bdbf11 #367 Added "cert-key" alias, fixed --tls-cert-key command line option. 2019-12-06 13:45:36 +07:00
XMRig
40041cd7cb Sync changes with miner. 2019-11-30 07:46:42 +07:00
XMRig
6df80209b2 v5.0.2-dev 2019-11-30 07:46:06 +07:00
XMRig
cff12d49fe Merge branch 'master' into dev 2019-11-30 07:45:21 +07:00
XMRig
bae9edcf35 v5.0.1 2019-11-28 12:12:19 +07:00
XMRig
589c87cfa0 Merge branch 'dev' 2019-11-28 12:11:18 +07:00
xmrig
7c509b4714 Update CHANGELOG.md 2019-11-28 12:06:57 +07:00
XMRig
fc35957d83 Fixed memory leak. 2019-11-28 07:25:10 +07:00
XMRig
f65b647791 Sync changes. 2019-11-28 05:21:29 +07:00
XMRig
eede0a9935 Sync missing changes with miner. 2019-11-28 04:48:22 +07:00
XMRig
24cea5ca07 Fixed incorrect job method for SelfSelectClient. 2019-11-24 02:58:02 +07:00
XMRig
4328daf835 Added GPG key and signed hashes for 5.0.0 release. 2019-11-21 02:47:17 +07:00
XMRig
b74b9a1196 Fixed isTLS method. 2019-11-20 15:39:28 +07:00
XMRig
2585dac204 Use static OpenSSL libs on macOS. 2019-11-16 22:16:45 +07:00
XMRig
393364b67f v5.0.1-dev 2019-11-16 22:12:49 +07:00
XMRig
a1f52905a6 Merge branch 'master' into dev 2019-11-16 22:12:22 +07:00
XMRig
682f1be7e4 Merge branch 'dev' 2019-11-13 13:49:42 +07:00
XMRig
054ecc64df v5.0.0-dev 2019-11-13 13:44:05 +07:00
XMRig
f6079fdc65 Merge branch 'evo' into dev 2019-11-13 13:43:32 +07:00
XMRig
598f04fe21 v3.2.1 2019-11-02 19:24:17 +07:00
XMRig
9f2a049013 Merge branch 'dev' 2019-11-02 19:23:44 +07:00
88 changed files with 915 additions and 488 deletions

View File

@@ -1,4 +1,24 @@
# v4.5.0-beta
# v5.5.0
- [#179](https://github.com/xmrig/xmrig/issues/179) Added support for [environment variables](https://xmrig.com/docs/miner/environment-variables) in config file.
- [#375](https://github.com/xmrig/xmrig-proxy/pull/375) Bugfixes: 64bit diff in logs + `"print-time"` config.
- [#376](https://github.com/xmrig/xmrig-proxy/pull/376) Added support for custom-diff shares for better proxy and worker stats.
- Added `"custom-diff-stats"` config option.
- Added `--custom-diff-stats` command line option.
- [#1445](https://github.com/xmrig/xmrig/pull/1445) Removed `rx/v` algorithm.
- [#1466](https://github.com/xmrig/xmrig/pull/1466) Added `cn-pico/tlo` algorithm.
- Added console title for Windows with proxy name and version.
# v5.4.0
- [#1434](https://github.com/xmrig/xmrig/pull/1434) Added RandomSFX (`rx/sfx`) algorithm for Safex Cash.
- [#1445](https://github.com/xmrig/xmrig/pull/1445) Added RandomV (`rx/v`) algorithm for *new* MoneroV.
- [#367](https://github.com/xmrig/xmrig-proxy/issues/367) Added "cert-key" alias, fixed --tls-cert-key command line option.
# v5.0.1
- **Fixed memory leak.**
- Fixed crash if no valid configuration found.
- Other minor fixes.
# v5.0.0
- Proxy rebased to latest miner codebase.
- [#1068](https://github.com/xmrig/xmrig/pull/1068) Added support for `self-select` stratum protocol extension.
- [#1227](https://github.com/xmrig/xmrig/pull/1227) Added new algorithm `rx/arq`, RandomX variant for upcoming ArQmA fork.

View File

@@ -9,6 +9,7 @@ option(WITH_TLS "Enable OpenSSL support" ON)
include (CheckIncludeFile)
include (cmake/os.cmake)
include (src/base/base.cmake)

View File

@@ -1,49 +0,0 @@
# - Try to find MHD
# Once done this will define
#
# MHD_FOUND - system has MHD
# MHD_INCLUDE_DIRS - the MHD include directory
# MHD_LIBRARY - Link these to use MHD
find_path(
MHD_INCLUDE_DIR
NAMES microhttpd.h
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
PATH_SUFFIXES "include"
DOC "microhttpd include dir"
NO_DEFAULT_PATH
)
find_path(MHD_INCLUDE_DIR NAMES microhttpd.h)
find_library(
MHD_LIBRARY
NAMES libmicrohttpd.a microhttpd libmicrohttpd
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
PATH_SUFFIXES "lib"
DOC "microhttpd library"
NO_DEFAULT_PATH
)
find_library(MHD_LIBRARY NAMES microhttpd libmicrohttpd)
set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR})
set(MHD_LIBRARIES ${MHD_LIBRARY})
# debug library on windows
# same naming convention as in qt (appending debug library with d)
# boost is using the same "hack" as us with "optimized" and "debug"
# official MHD project actually uses _d suffix
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
find_library(
MHD_LIBRARY_DEBUG
NAMES microhttpd_d microhttpd-10_d libmicrohttpd_d libmicrohttpd-dll_d
DOC "mhd debug library"
)
set(MHD_LIBRARIES optimized ${MHD_LIBRARIES} debug ${MHD_LIBRARY_DEBUG})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MHD DEFAULT_MSG MHD_LIBRARY MHD_INCLUDE_DIR)
mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY)

View File

@@ -6,6 +6,8 @@ if (WITH_TLS)
set(OPENSSL_MSVC_STATIC_RT TRUE)
set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32)
elseif (APPLE)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
find_package(OpenSSL)

45
cmake/os.cmake Normal file
View File

@@ -0,0 +1,45 @@
if (WIN32)
set(XMRIG_OS_WIN ON)
elseif (APPLE)
set(XMRIG_OS_APPLE ON)
if (IOS OR CMAKE_SYSTEM_NAME STREQUAL iOS)
set(XMRIG_OS_IOS ON)
else()
set(XMRIG_OS_MACOS ON)
endif()
else()
set(XMRIG_OS_UNIX ON)
if (ANDROID OR CMAKE_SYSTEM_NAME MATCHES "Android")
set(XMRIG_OS_ANDROID ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(XMRIG_OS_LINUX ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(XMRIG_OS_FREEBSD ON)
endif()
endif()
if (XMRIG_OS_WIN)
add_definitions(/DWIN32)
add_definitions(/DXMRIG_OS_WIN)
elseif(XMRIG_OS_APPLE)
add_definitions(/DXMRIG_OS_APPLE)
if (XMRIG_OS_IOS)
add_definitions(/DXMRIG_OS_IOS)
else()
add_definitions(/DXMRIG_OS_MACOS)
endif()
elseif(XMRIG_OS_UNIX)
add_definitions(/DXMRIG_OS_UNIX)
if (XMRIG_OS_ANDROID)
add_definitions(/DXMRIG_OS_ANDROID)
elseif (XMRIG_OS_LINUX)
add_definitions(/DXMRIG_OS_LINUX)
elseif (XMRIG_OS_FREEBSD)
add_definitions(/DXMRIG_OS_FREEBSD)
endif()
endif()

30
doc/gpg_keys/xmrig.asc Normal file
View File

@@ -0,0 +1,30 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBF3VSRIBCADfFjDUbq0WLGulFeSou0A+jTvweNllPyLNOn3SNCC0XLEYyEcu
JiEBK80DlvR06TVr8Aw1rT5S2iH0i5Tl8DqShH2mmcN1rBp1M0Y95D89KVj3BIhE
nxmgmD4N3Wgm+5FmEH4W/RpG1xdYWJx3eJhtWPdFJqpg083E2D5P30wIQem+EnTR
5YrtTZPh5cPj2KRY+UmsDE3ahmxCgP7LYgnnpZQlWBBiMV932s7MvYBPJQc1wecS
0wi1zxyS81xHc3839EkA7wueCeNo+5jha+KH66tMKsfrI2WvfPHTCPjK9v7WJc/O
/eRp9d+wacn09D1L6CoRO0ers5p10GO84VhTABEBAAG0GVhNUmlnIDxzdXBwb3J0
QHhtcmlnLmNvbT6JAU4EEwEIADgWIQSaxM6o5m41pcfN3BtEalNji+lECQUCXdVJ
EgIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRBEalNji+lECbkQB/9nRou0
tOlBwYn8xVgBu7IiDWNVETRWfrjrtdTvSahgbbo6lWgjA/vBLkjN9fISdBQ/n/Mt
hNDJbEtxHHt2baJhvT8du1eWcIHHXCV/rmv+iY/hTXa1gKqHiHDJrtYSVBG3BMme
1rdsUHTiKf3t5yRHOXAfY2C+XNblKAV7mhlxQBiKxdFDIkFEQKNrHNUvnzkOqoCT
2kTZZ2tPUMQdOn1eek6zG/+C7SwcBpJnakJ8jce4yA/xZbOVKetNWO3Ufu3TE34k
OdA+H4PU9+fV77XfOY8DtXeS3boUI97ei+4s/mwX/NFC0i8CPXyefxl3WRUBGDOI
w//kPNQVh4HobOCeuQENBF3VSRIBCADl29WorEi+vRA/3kg9VUXtxSU6caibFS3N
VXANiFRjrOmICdfrIgOSGNrYCQFsXu0Xe0udDYVX8yX6WJk+CT02Pdg0gkXiKoze
KrnK15mo3xXbb2tr1o9ROPgwY/o2AwQHj0o1JhdS2cybfuRiUQRoGgBX7a9X0cTY
r4ZJvOjzgAajl3ciwB3yWUmDiRlzZpO7YWESXbOhGVzyCnP5MlMEJ/fPRw9h38vK
HNKLhzcRfsLpXk34ghY3SxIv4NWUfuZXFWqpSdC9JgNc5zA72lJEQcF4DHJCKl7B
ddmrfsr9mdiIpo+/ZZFPPngdeZ2kvkJ2YKaZNVu2XooJARPQ8B8tABEBAAGJATYE
GAEIACAWIQSaxM6o5m41pcfN3BtEalNji+lECQUCXdVJEgIbDAAKCRBEalNji+lE
CdPUB/4nH1IdhHGmfko2kxdaHqQgCGLqh3pcrQXD9mBv/LYVnoHZpVRHsIDgg2Z4
lQYrIRRqe69FjVxo7sA2eMIlV0GRDlUrw+HeURFpEhKPEdwFy6i/cti2MY0YxOrB
TvQoRutUoMnyjM4TBJWaaqccbTsavMdLmG3JHdAkiHtUis/fUwVctmEQwN+d/J2b
wJAtliqw3nXchUfdIfwHF/7hg8seUuYUaifzkazBZhVWvRkTVLVanzZ51HRfuzwD
ntaa7kfYGdE+4TKOylAPh+8E6WnR19RRTpsaW0dVBgOiBTE0uc7rUv2HWS/u6RUR
t7ldSBzkuDTlM2V59Iq2hXoSC6dT
=cIG9
-----END PGP PUBLIC KEY BLOCK-----

View File

@@ -0,0 +1,3 @@
e12d814f584cecbb6cec9c394e49989f53ae61d4079c51c7682d938a03963b96 xmrig-proxy-5.0.0-gcc-win32.zip
0a5e143c979ef163247439da3049492ecfad49355e34ae371b14a8e08529230e xmrig-proxy-5.0.0-msvc-win64.zip
af7564afbb7e69aea52e6a2a945cb04caa09a993a468d5c1fdd73c3d337da05e xmrig-proxy-5.0.0-xenial-x64.tar.gz

View File

@@ -0,0 +1,11 @@
-----BEGIN PGP SIGNATURE-----
iQEzBAABCgAdFiEEmsTOqOZuNaXHzdwbRGpTY4vpRAkFAl3Vl4YACgkQRGpTY4vp
RAlj+Qf/TeSwcQ7HoDeCk7kAVTu25gZDf/gqTyYVNPt8x4pSjc0ofxXNo/q0Yrla
Dy5Ovjy0ZHJVYAC3vYdaDEaTWkZ0DVCytYDHEtsOgaA4jQm5baHGyIjREq1II8sl
QU27VhiOsX39jxrV4bGJvSkgLRpljFSIlbwn8+yP+sCwPMJ4MMEoJCC60agIsZBu
PsJQGVxAJ/n3nk2zvUuz/5DGqFyeOJ2MjqnLcaP6IoJ/PHxUngVi7k9qIggi6EFg
Ou/M0VMNpSo9uengCKoOsidtTkoek3MXGw+eS/JVB0qNCGHaNHqj3bTRD8yk7Klv
qq5hC4F84jAPPO8QHago9n4UcoYSkQ==
=M0Ty
-----END PGP SIGNATURE-----

View File

@@ -22,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <cstdlib>
#include <uv.h>
@@ -38,18 +38,9 @@
#include "version.h"
xmrig::App::App(Process *process) :
m_console(nullptr),
m_signals(nullptr)
xmrig::App::App(Process *process)
{
m_controller = new Controller(process);
if (m_controller->init() != 0) {
return;
}
if (!m_controller->config()->isBackground()) {
m_console = new Console(this);
}
}
@@ -63,19 +54,39 @@ xmrig::App::~App()
int xmrig::App::exec()
{
if (!m_controller->config()) {
if (!m_controller->isReady()) {
LOG_EMERG("no valid configuration found.");
return 2;
}
m_signals = new Signals(this);
background();
int rc = 0;
if (background(rc)) {
return rc;
}
rc = m_controller->init();
if (rc != 0) {
return rc;
}
if (!m_controller->isBackground()) {
m_console = new Console(this);
}
Summary::print(m_controller);
if (m_controller->config()->isDryRun()) {
LOG_NOTICE("OK");
return 0;
}
m_controller->start();
const int rc = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
rc = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_loop_close(uv_default_loop());
return rc;

View File

@@ -28,9 +28,7 @@
#include "base/kernel/interfaces/IConsoleListener.h"
#include "base/kernel/interfaces/ISignalListener.h"
class Proxy;
#include "base/tools/Object.h"
namespace xmrig {
@@ -45,6 +43,8 @@ class Signals;
class App : public IConsoleListener, public ISignalListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(App)
App(Process *process);
~App() override;
@@ -55,12 +55,12 @@ protected:
void onSignal(int signum) override;
private:
void background();
bool background(int &rc);
void close();
Console *m_console;
Controller *m_controller;
Signals *m_signals;
Console *m_console = nullptr;
Controller *m_controller = nullptr;
Signals *m_signals = nullptr;
};

View File

@@ -22,33 +22,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <cstdlib>
#include <csignal>
#include <cerrno>
#include <unistd.h>
#include "App.h"
#include "base/io/log/Log.h"
#include "core/config/Config.h"
#include "core/Controller.h"
void xmrig::App::background()
bool xmrig::App::background(int &rc)
{
signal(SIGPIPE, SIG_IGN);
if (!m_controller->config()->isBackground()) {
return;
if (!m_controller->isBackground()) {
return false;
}
int i = fork();
if (i < 0) {
exit(1);
rc = 1;
return true;
}
if (i > 0) {
exit(0);
rc = 0;
return true;
}
i = setsid();
@@ -61,4 +65,6 @@ void xmrig::App::background()
if (i < 0) {
LOG_ERR("chdir() failed (errno = %d)", errno);
}
return false;
}

View File

@@ -28,14 +28,13 @@
#include "App.h"
#include "core/config/Config.h"
#include "core/Controller.h"
void xmrig::App::background()
bool xmrig::App::background(int &)
{
if (!m_controller->config()->isBackground()) {
return;
if (!m_controller->isBackground()) {
return false;
}
HWND hcon = GetConsoleWindow();
@@ -46,4 +45,6 @@ void xmrig::App::background()
CloseHandle(h);
FreeConsole();
}
return false;
}

View File

@@ -23,7 +23,7 @@
*/
#include <stdio.h>
#include <cstdio>
#include <uv.h>
@@ -35,18 +35,21 @@
#include "version.h"
namespace xmrig {
static void print_mode(xmrig::Controller *controller)
{
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName());
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName());
}
static void print_bind(xmrig::Controller *controller)
{
const xmrig::BindHosts &bind = controller->config()->bind();
const BindHosts &bind = controller->config()->bind();
for (size_t i = 0; i < bind.size(); ++i) {
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m",
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m",
i + 1,
bind[i].isIPv6() ? "[" : "",
bind[i].host(),
@@ -59,18 +62,21 @@ static void print_bind(xmrig::Controller *controller)
static void print_commands(xmrig::Controller *)
{
if (xmrig::Log::colors) {
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
if (Log::isColors()) {
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
MAGENTA_BOLD("c") WHITE_BOLD("onnections, ")
MAGENTA_BOLD("v") WHITE_BOLD("erbose, ")
MAGENTA_BOLD("w") WHITE_BOLD("orkers"));
}
else {
xmrig::Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers");
Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers");
}
}
} // namespace xmrig
void Summary::print(xmrig::Controller *controller)
{
controller->config()->printVersions();

View File

@@ -22,14 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cmath>
#include <string.h>
#include <uv.h>
#include <thread>
#include "base/api/interfaces/IApiRequest.h"
#include "api/v1/ApiRouter.h"
#include "base/api/interfaces/IApiRequest.h"
#include "base/kernel/Platform.h"
#include "base/tools/Buffer.h"
#include "core/config/Config.h"
@@ -41,6 +35,11 @@
#include "version.h"
#include <cmath>
#include <cstring>
#include <uv.h>
static inline double normalize(double d)
{
if (!std::isnormal(d)) {
@@ -57,9 +56,7 @@ xmrig::ApiRouter::ApiRouter(Base *base) :
}
xmrig::ApiRouter::~ApiRouter()
{
}
xmrig::ApiRouter::~ApiRouter() = default;
void xmrig::ApiRouter::onRequest(IApiRequest &request)
@@ -69,7 +66,6 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
request.accept();
getMiner(request.reply(), request.doc());
getHashrate(request.reply(), request.doc());
getResourcesSummary(request.reply(), request.doc());
getMinersSummary(request.reply(), request.doc());
getResults(request.reply(), request.doc());
}
@@ -196,36 +192,6 @@ void xmrig::ApiRouter::getMinersSummary(rapidjson::Value &reply, rapidjson::Docu
}
void xmrig::ApiRouter::getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
size_t rss = 0;
uv_resident_set_memory(&rss);
Value resources(kObjectType);
Value memory(kObjectType);
Value load_average(kArrayType);
memory.AddMember("total", uv_get_total_memory(), allocator);
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);
double loadavg[3] = { 1.0 };
uv_loadavg(loadavg);
load_average.PushBack(loadavg[0], allocator);
load_average.PushBack(loadavg[1], allocator);
load_average.PushBack(loadavg[2], allocator);
resources.AddMember("memory", memory, allocator);
resources.AddMember("load_average", load_average, allocator);
resources.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);
reply.AddMember("resources", resources, allocator);
}
void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &doc) const
{
auto &allocator = doc.GetAllocator();
@@ -243,8 +209,8 @@ void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &
results.AddMember("hashes_donate", stats.donateHashes, allocator);
rapidjson::Value best(rapidjson::kArrayType);
for (size_t i = 0; i < stats.topDiff.size(); ++i) {
best.PushBack(stats.topDiff[i], allocator);
for (uint64_t i : stats.topDiff) {
best.PushBack(i, allocator);
}
results.AddMember("best", best, allocator);

View File

@@ -27,6 +27,7 @@
#include "base/api/interfaces/IApiListener.h"
#include "base/tools/Object.h"
#include "proxy/StatsData.h"
#include "rapidjson/fwd.h"
@@ -40,6 +41,8 @@ class Base;
class ApiRouter : public xmrig::IApiListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRouter)
ApiRouter(Base *base);
~ApiRouter() override;
@@ -52,7 +55,6 @@ private:
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getMiners(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getMinersSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getResults(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getWorkers(rapidjson::Value &reply, rapidjson::Document &doc) const;

View File

@@ -26,16 +26,13 @@
#include <uv.h>
#ifndef _WIN32
# include <unistd.h>
#endif
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/Api.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/api/requests/HttpApiRequest.h"
#include "base/io/json/Json.h"
#include "base/kernel/Base.h"
#include "base/kernel/Env.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "core/config/Config.h"
@@ -49,12 +46,49 @@
#endif
#include <thread>
namespace xmrig {
static rapidjson::Value getResources(rapidjson::Document &doc)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
size_t rss = 0;
uv_resident_set_memory(&rss);
Value out(kObjectType);
Value memory(kObjectType);
Value load_average(kArrayType);
memory.AddMember("free", uv_get_free_memory(), allocator);
memory.AddMember("total", uv_get_total_memory(), allocator);
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);
double loadavg[3] = { 0.0 };
uv_loadavg(loadavg);
for (double value : loadavg) {
load_average.PushBack(Json::normalize(value, true), allocator);
}
out.AddMember("memory", memory, allocator);
out.AddMember("load_average", load_average, allocator);
out.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);
return out;
}
} // namespace xmrig
xmrig::Api::Api(Base *base) :
m_base(base),
m_id(),
m_workerId(),
m_timestamp(Chrono::currentMSecsSinceEpoch()),
m_httpd(nullptr)
m_timestamp(Chrono::currentMSecsSinceEpoch())
{
base->addListener(this);
@@ -117,10 +151,13 @@ void xmrig::Api::exec(IApiRequest &request)
auto &allocator = request.doc().GetAllocator();
request.accept();
request.reply().AddMember("id", StringRef(m_id), allocator);
request.reply().AddMember("worker_id", StringRef(m_workerId), allocator);
request.reply().AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
request.reply().AddMember("restricted", request.isRestricted(), allocator);
auto &reply = request.reply();
reply.AddMember("id", StringRef(m_id), allocator);
reply.AddMember("worker_id", m_workerId.toJSON(), allocator);
reply.AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
reply.AddMember("restricted", request.isRestricted(), allocator);
reply.AddMember("resources", getResources(request.doc()), allocator);
Value features(kArrayType);
# ifdef XMRIG_FEATURE_API
@@ -144,7 +181,10 @@ void xmrig::Api::exec(IApiRequest &request)
# ifdef XMRIG_FEATURE_OPENCL
features.PushBack("opencl", allocator);
# endif
request.reply().AddMember("features", features, allocator);
# ifdef XMRIG_FEATURE_CUDA
features.PushBack("cuda", allocator);
# endif
reply.AddMember("features", features, allocator);
}
for (IApiListener *listener : m_listeners) {
@@ -179,13 +219,13 @@ void xmrig::Api::genId(const String &id)
if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) {
uint8_t hash[200];
const size_t addrSize = sizeof(interfaces[i].phys_addr);
const size_t inSize = strlen(APP_KIND) + addrSize + sizeof(uint16_t);
const uint16_t port = static_cast<uint16_t>(m_base->config()->http().port());
const size_t inSize = (sizeof(APP_KIND) - 1) + addrSize + sizeof(uint16_t);
const auto port = static_cast<uint16_t>(m_base->config()->http().port());
uint8_t *input = new uint8_t[inSize]();
auto*input = new uint8_t[inSize]();
memcpy(input, &port, sizeof(uint16_t));
memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize);
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND));
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, (sizeof(APP_KIND) - 1));
keccak(input, inSize, hash);
Buffer::toHex(hash, 8, m_id);
@@ -201,12 +241,8 @@ void xmrig::Api::genId(const String &id)
void xmrig::Api::genWorkerId(const String &id)
{
memset(m_workerId, 0, sizeof(m_workerId));
if (id.size() > 0) {
strncpy(m_workerId, id.data(), sizeof(m_workerId) - 1);
}
else {
gethostname(m_workerId, sizeof(m_workerId) - 1);
m_workerId = Env::expand(id);
if (m_workerId.isEmpty()) {
m_workerId = Env::hostname();
}
}

View File

@@ -32,6 +32,7 @@
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/tools/Object.h"
#include "base/tools/String.h"
namespace xmrig {
@@ -70,10 +71,10 @@ private:
void genWorkerId(const String &id);
Base *m_base;
char m_id[32];
char m_workerId[128];
char m_id[32]{};
String m_workerId;
const uint64_t m_timestamp;
Httpd *m_httpd;
Httpd *m_httpd = nullptr;
std::vector<IApiListener *> m_listeners;
};

View File

@@ -23,9 +23,9 @@
*/
#include "base/api/Httpd.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/Api.h"
#include "base/api/Httpd.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpApiResponse.h"
#include "base/net/http/HttpData.h"
@@ -58,9 +58,7 @@ xmrig::Httpd::Httpd(Base *base) :
}
xmrig::Httpd::~Httpd()
{
}
xmrig::Httpd::~Httpd() = default;
bool xmrig::Httpd::start()

View File

@@ -26,11 +26,12 @@
#define XMRIG_HTTPD_H
#include <stdint.h>
#include <cstdint>
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/tools/Object.h"
namespace xmrig {
@@ -44,6 +45,8 @@ class TcpServer;
class Httpd : public IBaseListener, public IHttpListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd)
Httpd(Base *base);
~Httpd() override;

View File

@@ -33,6 +33,4 @@ xmrig::ApiRequest::ApiRequest(Source source, bool restricted) :
}
xmrig::ApiRequest::~ApiRequest()
{
}
xmrig::ApiRequest::~ApiRequest() = default;

View File

@@ -29,6 +29,7 @@
#include "base/api/interfaces/IApiRequest.h"
#include "base/tools/String.h"
#include "base/tools/Object.h"
namespace xmrig {
@@ -37,6 +38,8 @@ namespace xmrig {
class ApiRequest : public IApiRequest
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRequest)
ApiRequest(Source source, bool restricted);
~ApiRequest() override;
@@ -63,8 +66,8 @@ protected:
String m_rpcMethod;
private:
bool m_restricted;
Source m_source;
const bool m_restricted;
const Source m_source;
};

View File

@@ -12,6 +12,7 @@ set(HEADERS_BASE
src/base/kernel/config/BaseConfig.h
src/base/kernel/config/BaseTransform.h
src/base/kernel/Entry.h
src/base/kernel/Env.h
src/base/kernel/interfaces/IBaseListener.h
src/base/kernel/interfaces/IClient.h
src/base/kernel/interfaces/IClientListener.h
@@ -66,6 +67,7 @@ set(SOURCES_BASE
src/base/kernel/config/BaseConfig.cpp
src/base/kernel/config/BaseTransform.cpp
src/base/kernel/Entry.cpp
src/base/kernel/Env.cpp
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp
src/base/kernel/Signals.cpp

View File

@@ -28,6 +28,7 @@
#include <cassert>
#include <cmath>
namespace xmrig {
@@ -50,7 +51,7 @@ bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool def
}
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
{
assert(obj.IsObject());
@@ -154,6 +155,18 @@ unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsi
}
rapidjson::Value xmrig::Json::normalize(double value, bool zero)
{
using namespace rapidjson;
if (!std::isnormal(value)) {
return zero ? Value(0.0) : Value(kNullType);
}
return Value(floor(value * 100.0) / 100.0);
}
bool xmrig::JsonReader::isEmpty() const
{
return !m_obj.IsObject() || m_obj.ObjectEmpty();

View File

@@ -48,6 +48,8 @@ public:
static bool get(const char *fileName, rapidjson::Document &doc);
static bool save(const char *fileName, const rapidjson::Document &doc);
static rapidjson::Value normalize(double value, bool zero);
};

View File

@@ -92,7 +92,7 @@ public:
std::lock_guard<std::mutex> lock(m_mutex);
if (Log::background && m_backends.empty()) {
if (Log::isBackground() && m_backends.empty()) {
return;
}
@@ -195,9 +195,10 @@ private:
};
bool Log::background = false;
bool Log::colors = true;
LogPrivate *Log::d = new LogPrivate();
bool Log::m_background = false;
bool Log::m_colors = true;
LogPrivate *Log::d = new LogPrivate();
uint32_t Log::m_verbose = 0;
} /* namespace xmrig */

View File

@@ -27,6 +27,9 @@
#define XMRIG_LOG_H
#include <cstdint>
namespace xmrig {
@@ -54,10 +57,19 @@ public:
static void print(const char *fmt, ...);
static void print(Level level, const char *fmt, ...);
static bool background;
static bool colors;
static inline bool isBackground() { return m_background; }
static inline bool isColors() { return m_colors; }
static inline bool isVerbose() { return m_verbose > 0; }
static inline uint32_t verbose() { return m_verbose; }
static inline void setBackground(bool background) { m_background = background; }
static inline void setColors(bool colors) { m_colors = colors; }
static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; }
private:
static bool m_background;
static bool m_colors;
static uint32_t m_verbose;
static LogPrivate *d;
};
@@ -83,6 +95,7 @@ private:
#define WHITE_BOLD_S CSI "1;37m" // actually white
#define GREEN_BG_BOLD_S CSI "42;1m"
#define YELLOW_BG_BOLD_S CSI "43;1m"
#define BLUE_BG_S CSI "44m"
#define BLUE_BG_BOLD_S CSI "44;1m"
#define MAGENTA_BG_S CSI "45m"
@@ -109,6 +122,7 @@ private:
#define WHITE_BOLD(x) WHITE_BOLD_S x CLEAR
#define GREEN_BG_BOLD(x) GREEN_BG_BOLD_S x CLEAR
#define YELLOW_BG_BOLD(x) YELLOW_BG_BOLD_S x CLEAR
#define BLUE_BG(x) BLUE_BG_S x CLEAR
#define BLUE_BG_BOLD(x) BLUE_BG_BOLD_S x CLEAR
#define MAGENTA_BG(x) MAGENTA_BG_S x CLEAR
@@ -117,13 +131,14 @@ private:
#define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR
#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__)
#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__)
#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__)
#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__)
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__)
#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__)
#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__)
#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__)
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)

View File

@@ -27,28 +27,29 @@
#include <cstdio>
#include "base/tools/Handle.h"
#include "base/io/log/backends/ConsoleLog.h"
#include "base/tools/Handle.h"
#include "base/io/log/Log.h"
#include "version.h"
xmrig::ConsoleLog::ConsoleLog()
{
if (!isSupported()) {
Log::colors = false;
Log::setColors(false);
return;
}
m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
Log::colors = false;
Log::setColors(false);
return;
}
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef WIN32
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
@@ -59,6 +60,8 @@ xmrig::ConsoleLog::ConsoleLog()
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
}
SetConsoleTitleA(APP_NAME " " APP_VERSION);
# endif
}
@@ -71,11 +74,11 @@ xmrig::ConsoleLog::~ConsoleLog()
void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors)
{
if (!m_tty || Log::colors != colors) {
if (!m_tty || Log::isColors() != colors) {
return;
}
# ifdef _WIN32
# ifdef XMRIG_OS_WIN
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), static_cast<unsigned int>(size));
if (!isWritable()) {
@@ -99,7 +102,7 @@ bool xmrig::ConsoleLog::isSupported() const
}
#ifdef WIN32
#ifdef XMRIG_OS_WIN
bool xmrig::ConsoleLog::isWritable() const
{
if (!m_stream || uv_is_writable(m_stream) != 1) {

View File

@@ -54,7 +54,7 @@ private:
uv_tty_t *m_tty = nullptr;
# ifdef _WIN32
# ifdef XMRIG_OS_WIN
bool isWritable() const;
uv_stream_t *m_stream = nullptr;

View File

@@ -24,17 +24,19 @@
*/
#include <string.h>
#include <uv.h>
#include "base/io/log/backends/FileLog.h"
#include "base/kernel/Env.h"
#include <cassert>
#include <cstring>
#include <uv.h>
xmrig::FileLog::FileLog(const char *fileName)
{
uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
m_file = uv_fs_open(uv_default_loop(), &req, Env::expand(fileName), O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
uv_fs_req_cleanup(&req);
}
@@ -45,13 +47,12 @@ void xmrig::FileLog::print(int, const char *line, size_t, size_t size, bool colo
return;
}
# ifdef _WIN32
uv_buf_t buf = uv_buf_init(strdup(line), static_cast<unsigned int>(size));
# else
uv_buf_t buf = uv_buf_init(strdup(line), size);
# endif
assert(strlen(line) == size);
uv_fs_t *req = new uv_fs_t;
uv_buf_t buf = uv_buf_init(new char[size], size);
memcpy(buf.base, line, size);
auto req = new uv_fs_t;
req->data = buf.base;
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite);

View File

@@ -127,7 +127,7 @@ private:
return config.release();
}
chain.addFile(process->location(Process::ExeLocation, "config.json"));
chain.addFile(Process::location(Process::ExeLocation, "config.json"));
if (read(chain, config)) {
return config.release();
@@ -176,12 +176,8 @@ int xmrig::Base::init()
Platform::init(config()->userAgent());
# ifndef XMRIG_PROXY_PROJECT
Platform::setProcessPriority(config()->cpu().priority());
# endif
if (isBackground()) {
Log::background = true;
Log::setBackground(true);
}
else {
Log::add(new ConsoleLog());

View File

@@ -101,9 +101,9 @@ static int showVersion()
#ifdef XMRIG_FEATURE_HWLOC
static int exportTopology(const Process &process)
static int exportTopology(const Process &)
{
const String path = process.location(Process::ExeLocation, "topology.xml");
const String path = Process::location(Process::ExeLocation, "topology.xml");
hwloc_topology_t topology;
hwloc_topology_init(&topology);

139
src/base/kernel/Env.cpp Normal file
View File

@@ -0,0 +1,139 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 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 "base/kernel/Env.h"
#include "base/kernel/Process.h"
#include "version.h"
#include <regex>
#include <uv.h>
#include <map>
#ifndef _WIN32
# include <unistd.h>
#endif
#ifndef UV_MAXHOSTNAMESIZE
# ifdef MAXHOSTNAMELEN
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
# else
# define UV_MAXHOSTNAMESIZE 256
# endif
#endif
namespace xmrig {
static std::map<String, String> variables;
static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
}
} // namespace xmrig
xmrig::String xmrig::Env::expand(const char *in)
{
if (in == nullptr) {
return {};
}
std::string text(in);
if (text.size() < 4) {
return text.c_str();
}
static const std::regex env_re{R"--(\$\{([^}]+)\})--"};
std::map<std::string, String> vars;
for (std::sregex_iterator i = std::sregex_iterator(text.begin(), text.end(), env_re); i != std::sregex_iterator(); ++i) {
std::smatch m = *i;
const auto var = m.str();
if (vars.count(var)) {
continue;
}
vars.insert({ var, get(m[1].str().c_str()) });
}
for (const auto &kv : vars) {
if (kv.second.isNull()) {
continue;
}
size_t pos = 0;
while ((pos = text.find(kv.first, pos)) != std::string::npos) {
text.replace(pos, kv.first.size(), kv.second);
pos += kv.second.size();
}
}
return text.c_str();
}
xmrig::String xmrig::Env::get(const String &name)
{
if (variables.empty()) {
createVariables();
}
if (variables.count(name)) {
return variables.at(name);
}
return static_cast<const char *>(getenv(name));
}
xmrig::String xmrig::Env::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
size_t size = sizeof(buf);
# if UV_VERSION_HEX >= 0x010c00
if (uv_os_gethostname(buf, &size) == 0) {
return static_cast<const char *>(buf);
}
# else
if (gethostname(buf, size) == 0) {
return static_cast<const char *>(buf);
}
# endif
return {};
}

47
src/base/kernel/Env.h Normal file
View File

@@ -0,0 +1,47 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 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 XMRIG_ENV_H
#define XMRIG_ENV_H
#include "base/tools/String.h"
namespace xmrig {
class Env
{
public:
static String expand(const char *in);
static String get(const String &name);
static String hostname();
};
} /* namespace xmrig */
#endif /* XMRIG_ENV_H */

View File

@@ -83,7 +83,7 @@ void xmrig::Platform::restoreTimerResolution()
}
void xmrig::Platform::setProcessPriority(int priority)
void xmrig::Platform::setProcessPriority(int)
{
}

View File

@@ -111,7 +111,7 @@ void xmrig::Platform::restoreTimerResolution()
}
void xmrig::Platform::setProcessPriority(int priority)
void xmrig::Platform::setProcessPriority(int)
{
}

View File

@@ -31,7 +31,10 @@
#include "base/tools/Chrono.h"
static size_t location(xmrig::Process::Location location, char *buf, size_t max)
namespace xmrig {
static size_t getLocation(Process::Location location, char *buf, size_t max)
{
using namespace xmrig;
@@ -48,6 +51,9 @@ static size_t location(xmrig::Process::Location location, char *buf, size_t max)
}
} // namespace xmrig
xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
@@ -55,12 +61,12 @@ xmrig::Process::Process(int argc, char **argv) :
}
xmrig::String xmrig::Process::location(Location location, const char *fileName) const
xmrig::String xmrig::Process::location(Location location, const char *fileName)
{
constexpr const size_t max = 520;
char *buf = new char[max]();
size_t size = ::location(location, buf, max);
size_t size = getLocation(location, buf, max);
if (size == 0) {
delete [] buf;

View File

@@ -48,7 +48,7 @@ public:
Process(int argc, char **argv);
String location(Location location, const char *fileName = nullptr) const;
static String location(Location location, const char *fileName = nullptr);
inline const Arguments &arguments() const { return m_arguments; }

View File

@@ -23,10 +23,18 @@
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "base/kernel/config/BaseConfig.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "rapidjson/document.h"
#include "version.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <uv.h>
@@ -38,85 +46,6 @@
# include "backend/cpu/Cpu.h"
#endif
#ifdef XMRIG_AMD_PROJECT
# if defined(__APPLE__)
# include <OpenCL/cl.h>
# else
# include "3rdparty/CL/cl.h"
# endif
#endif
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/kernel/config/BaseConfig.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "donate.h"
#include "rapidjson/document.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h"
#include "version.h"
xmrig::BaseConfig::BaseConfig()
{
}
void xmrig::BaseConfig::printVersions()
{
char buf[256] = { 0 };
# if defined(__clang__)
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER)
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
# endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf);
# if defined(XMRIG_AMD_PROJECT)
# if CL_VERSION_2_0
const char *ocl = "2.0";
# elif CL_VERSION_1_2
const char *ocl = "1.2";
# elif CL_VERSION_1_1
const char *ocl = "1.1";
# elif CL_VERSION_1_0
const char *ocl = "1.0";
# else
const char *ocl = "0.0";
# endif
int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl);
# elif defined(XMRIG_NVIDIA_PROJECT)
const int cudaVersion = cuda_get_runtime_version();
int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100);
# endif
std::string libs;
# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT)
{
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
libs += buf;
}
# endif
# if defined(XMRIG_FEATURE_HWLOC)
libs += Cpu::info()->backend();
# endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());
}
bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
{
@@ -131,12 +60,13 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_dryRun = reader.getBool("dry-run", m_dryRun);
m_syslog = reader.getBool("syslog", m_syslog);
m_watch = reader.getBool("watch", m_watch);
Log::colors = reader.getBool("colors", Log::colors);
m_logFile = reader.getString("log-file");
m_userAgent = reader.getString("user-agent");
m_version = reader.getUint("version");
Log::setColors(reader.getBool("colors", Log::isColors()));
setPrintTime(reader.getUint("print-time", 60));
setVerbose(reader.getValue("verbose"));
const rapidjson::Value &api = reader.getObject("api");
if (api.IsObject()) {
@@ -167,3 +97,46 @@ bool xmrig::BaseConfig::save()
return false;
}
void xmrig::BaseConfig::printVersions()
{
char buf[256] = { 0 };
# if defined(__clang__)
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER)
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
# endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf);
std::string libs;
# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT)
{
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
libs += buf;
}
# endif
# if defined(XMRIG_FEATURE_HWLOC)
libs += Cpu::info()->backend();
# endif
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());
}
void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value)
{
if (value.IsBool()) {
Log::setVerbose(value.GetBool() ? 1 : 0);
}
else if (value.IsUint()) {
Log::setVerbose(value.GetUint());
}
}

View File

@@ -31,9 +31,6 @@
#include "base/net/stratum/Pools.h"
struct option;
namespace xmrig {
@@ -43,7 +40,7 @@ class IJsonReader;
class BaseConfig : public IConfig
{
public:
BaseConfig();
BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
@@ -85,6 +82,8 @@ protected:
private:
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }
void setVerbose(const rapidjson::Value &value);
};

View File

@@ -222,6 +222,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::DryRunKey: /* --dry-run */
case IConfig::HttpEnabledKey: /* --http-enabled */
case IConfig::DaemonKey: /* --daemon */
case IConfig::VerboseKey: /* --verbose */
return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */
@@ -273,6 +274,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::DryRunKey: /* --dry-run */
return set(doc, "dry-run", enable);
case IConfig::VerboseKey: /* --verbose */
return set(doc, "verbose", enable);
default:
break;
}

View File

@@ -89,8 +89,13 @@ public:
AssemblyKey = 1015,
RandomXInitKey = 1022,
RandomXNumaKey = 1023,
RandomXModeKey = 1029,
RandomX1GbPagesKey = 1031,
RandomXWrmsrKey = 1032,
RandomXRdmsrKey = 1033,
CPUMaxThreadsKey = 1026,
MemoryPoolKey = 1027,
YieldKey = 1030,
// xmrig amd
OclPlatformKey = 1400,
@@ -110,6 +115,7 @@ public:
AccessLogFileKey = 'A',
BindKey = 'b',
CustomDiffKey = 1102,
CustomDiffStatsKey = 1104,
DebugKey = 1101,
ModeKey = 'm',
PoolCoinKey = 'C',
@@ -125,6 +131,7 @@ public:
TlsProtocolsKey = 1114,
AlgoExtKey = 1115,
ProxyPasswordKey = 1116,
LoginFileKey = 'L',
// xmrig nvidia
CudaMaxThreadsKey = 1200,

View File

@@ -26,7 +26,7 @@
#define XMRIG_ISTRATEGY_H
#include <stdint.h>
#include <cstdint>
namespace xmrig {

View File

@@ -23,9 +23,9 @@
*/
#include "base/net/http/Http.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
#include "base/net/http/Http.h"
namespace xmrig {
@@ -41,10 +41,7 @@ static const char *kToken = "access-token";
xmrig::Http::Http() :
m_enabled(false),
m_restricted(true),
m_host(kLocalhost),
m_port(0)
m_host(kLocalhost)
{
}

View File

@@ -38,7 +38,7 @@ class Http
public:
Http();
inline bool isAuthRequired() const { return m_restricted == false || !m_token.isNull(); }
inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); }
inline bool isEnabled() const { return m_enabled; }
inline bool isRestricted() const { return m_restricted; }
inline const String &host() const { return m_host; }
@@ -58,11 +58,11 @@ public:
void setPort(int port);
private:
bool m_enabled;
bool m_restricted;
bool m_enabled = false;
bool m_restricted = true;
String m_host;
String m_token;
uint16_t m_port;
uint16_t m_port = 0;
};

View File

@@ -66,7 +66,7 @@ public:
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<ClientWriteBaton *>(req->data); }
uv_buf_t bufs[2];
uv_buf_t bufs[2]{};
private:
std::string m_body;

View File

@@ -24,27 +24,30 @@
*/
#include "base/net/http/HttpContext.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/tools/Chrono.h"
#include <algorithm>
#include <uv.h>
#include "3rdparty/http-parser/http_parser.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/net/http/HttpContext.h"
namespace xmrig {
static http_parser_settings http_settings;
static std::map<uint64_t, HttpContext *> storage;
static uint64_t SEQUENCE = 0;
} // namespace xmrig
xmrig::HttpContext::HttpContext(int parser_type, IHttpListener *listener) :
HttpData(SEQUENCE++),
m_wasHeaderValue(false),
m_timestamp(Chrono::steadyMSecs()),
m_listener(listener)
{
storage[id()] = this;
@@ -96,6 +99,12 @@ std::string xmrig::HttpContext::ip() const
}
uint64_t xmrig::HttpContext::elapsed() const
{
return Chrono::steadyMSecs() - m_timestamp;
}
void xmrig::HttpContext::close(int status)
{
if (status < 0 && m_listener) {

View File

@@ -59,6 +59,7 @@ public:
size_t parse(const char *data, size_t size);
std::string ip() const;
uint64_t elapsed() const;
void close(int status = 0);
static HttpContext *get(uint64_t id);
@@ -74,7 +75,8 @@ private:
void setHeader();
bool m_wasHeaderValue;
bool m_wasHeaderValue = false;
const uint64_t m_timestamp;
http_parser *m_parser;
IHttpListener *m_listener;
std::string m_lastHeaderField;

View File

@@ -38,12 +38,12 @@ namespace xmrig {
class HttpData
{
public:
inline HttpData(uint64_t id) : method(0), status(0), m_id(id) {}
inline HttpData(uint64_t id) : m_id(id) {}
inline uint64_t id() const { return m_id; }
int method;
int status;
int method = 0;
int status = 0;
std::map<const std::string, const std::string> headers;
std::string body;
std::string url;

View File

@@ -24,20 +24,23 @@
*/
#include <sstream>
#include <string.h>
#include <uv.h>
#include "base/net/http/HttpResponse.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpContext.h"
#include "base/net/http/HttpResponse.h"
#include "base/tools/Baton.h"
#include "base/tools/Object.h"
#include <cinttypes>
#include <cstring>
#include <sstream>
#include <uv.h>
namespace xmrig {
static const char *kCRLF = "\r\n";
static const char *kUserAgent = "user-agent";
@@ -45,6 +48,8 @@ static const char *kUserAgent = "user-agent";
class WriteBaton : public Baton<uv_write_t>
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(WriteBaton)
inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) :
m_ctx(ctx),
m_header(ss.str())
@@ -79,7 +84,7 @@ public:
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<WriteBaton *>(req->data); }
uv_buf_t bufs[2];
uv_buf_t bufs[2]{};
private:
HttpContext *m_ctx;
@@ -98,7 +103,7 @@ xmrig::HttpResponse::HttpResponse(uint64_t id, int statusCode) :
bool xmrig::HttpResponse::isAlive() const
{
HttpContext *ctx = HttpContext::get(m_id);
auto ctx = HttpContext::get(m_id);
return ctx && uv_is_writable(ctx->stream());
}
@@ -129,8 +134,8 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
ss << kCRLF;
HttpContext *ctx = HttpContext::get(m_id);
WriteBaton *baton = new WriteBaton(ss, data, size, ctx);
auto ctx = HttpContext::get(m_id);
auto baton = new WriteBaton(ss, data, size, ctx);
# ifndef APP_DEBUG
if (statusCode() >= 400)
@@ -138,13 +143,14 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
{
const bool err = statusCode() >= 400;
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") BLACK_BOLD("\"%s\""),
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
ctx->ip().c_str(),
http_method_str(static_cast<http_method>(ctx->method)),
ctx->url.c_str(),
err ? 31 : 32,
statusCode(),
baton->size(),
ctx->elapsed(),
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
);
}

View File

@@ -49,7 +49,7 @@ xmrig::HttpServer::~HttpServer()
void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
{
HttpContext *ctx = new HttpContext(HTTP_REQUEST, m_listener);
auto ctx = new HttpContext(HTTP_REQUEST, m_listener);
uv_accept(stream, ctx->stream());
uv_read_start(ctx->stream(),
@@ -65,11 +65,11 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
},
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
{
HttpContext *ctx = static_cast<HttpContext*>(tcp->data);
auto ctx = static_cast<HttpContext*>(tcp->data);
if (nread >= 0) {
const size_t size = static_cast<size_t>(nread);
const size_t parsed = ctx->parse(buf->base, size);
const auto size = static_cast<size_t>(nread);
const auto parsed = ctx->parse(buf->base, size);
if (parsed < size) {
ctx->close();

View File

@@ -28,11 +28,12 @@
#define XMRIG_HTTPSERVER_H
typedef struct http_parser http_parser;
typedef struct http_parser_settings http_parser_settings;
using http_parser = struct http_parser;
using http_parser_settings = struct http_parser_settings;
#include "base/kernel/interfaces/ITcpServerListener.h"
#include "base/tools/Object.h"
namespace xmrig {
@@ -44,6 +45,8 @@ class IHttpListener;
class HttpServer : public ITcpServerListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpServer)
HttpServer(IHttpListener *listener);
~HttpServer() override;

View File

@@ -23,16 +23,19 @@
*/
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/stratum/BaseClient.h"
#include "base/kernel/Env.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/stratum/SubmitResult.h"
#include "rapidjson/document.h"
namespace xmrig {
int64_t BaseClient::m_sequence = 1;
} /* namespace xmrig */
@@ -43,6 +46,19 @@ xmrig::BaseClient::BaseClient(int id, IClientListener *listener) :
}
void xmrig::BaseClient::setPool(const Pool &pool)
{
if (!pool.isValid()) {
return;
}
m_pool = pool;
m_user = Env::expand(pool.user());
m_password = Env::expand(pool.password());
m_rigId = Env::expand(pool.rigId());
}
bool xmrig::BaseClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
if (id == 1) {

View File

@@ -56,11 +56,12 @@ protected:
inline int64_t sequence() const override { return m_sequence; }
inline void setAlgo(const Algorithm &algo) override { m_pool.setAlgo(algo); }
inline void setEnabled(bool enabled) override { m_enabled = enabled; }
inline void setPool(const Pool &pool) override { if (pool.isValid()) { m_pool = pool; } }
inline void setQuiet(bool quiet) override { m_quiet = quiet; }
inline void setRetries(int retries) override { m_retries = retries; }
inline void setRetryPause(uint64_t ms) override { m_retryPause = ms; }
void setPool(const Pool &pool) override;
protected:
enum SocketState {
UnconnectedState,
@@ -95,6 +96,9 @@ protected:
std::map<int64_t, SendResult> m_callbacks;
std::map<int64_t, SubmitResult> m_results;
String m_ip;
String m_password;
String m_rigId;
String m_user;
uint64_t m_retryPause = 5000;
static int64_t m_sequence;

View File

@@ -79,7 +79,8 @@ static const char *states[] = {
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
BaseClient(id, listener),
m_agent(agent)
m_agent(agent),
m_sendBuf(1024)
{
m_key = m_storage.add(this);
m_dns = new Dns(this);
@@ -158,13 +159,18 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj)
obj.Accept(writer);
const size_t size = buffer.GetSize();
if (size > (sizeof(m_sendBuf) - 2)) {
LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2));
if (size > kMaxSendBufferSize) {
LOG_ERR("[%s] send failed: \"max send buffer size exceeded: %zu\"", url(), size);
close();
return -1;
}
memcpy(m_sendBuf, buffer.GetString(), size);
if (size > (m_sendBuf.size() - 2)) {
m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024);
}
memcpy(m_sendBuf.data(), buffer.GetString(), size);
m_sendBuf[size] = '\n';
m_sendBuf[size + 1] = '\0';
@@ -186,8 +192,8 @@ int64_t xmrig::Client::submit(const JobResult &result)
const char *nonce = result.nonce;
const char *data = result.result;
# else
char *nonce = m_sendBuf;
char *data = m_sendBuf + 16;
char *nonce = m_sendBuf.data();
char *data = m_sendBuf.data() + 16;
Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
nonce[8] = '\0';
@@ -338,6 +344,10 @@ bool xmrig::Client::isCriticalError(const char *message)
return true;
}
if (strncasecmp(message, "Invalid job id", 14) == 0) {
return true;
}
return false;
}
@@ -456,11 +466,7 @@ bool xmrig::Client::send(BIO *bio)
bool result = false;
if (state() == ConnectedState && uv_is_writable(m_stream)) {
result = uv_try_write(m_stream, &buf, 1) > 0;
if (!result) {
close();
}
result = write(buf);
}
else {
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
@@ -501,6 +507,23 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo
}
bool xmrig::Client::write(const uv_buf_t &buf)
{
const int rc = uv_try_write(m_stream, &buf, 1);
if (static_cast<size_t>(rc) == buf.len) {
return true;
}
if (!isQuiet()) {
LOG_ERR("[%s] write error: \"%s\"", url(), uv_strerror(rc));
}
close();
return false;
}
int xmrig::Client::resolve(const String &host)
{
setState(HostLookupState);
@@ -525,11 +548,11 @@ int xmrig::Client::resolve(const String &host)
int64_t xmrig::Client::send(size_t size)
{
LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast<int>(size) - 1, m_sendBuf);
LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast<int>(size) - 1, m_sendBuf.data());
# ifdef XMRIG_FEATURE_TLS
if (isTLS()) {
if (!m_tls->send(m_sendBuf, size)) {
if (!m_tls->send(m_sendBuf.data(), size)) {
return -1;
}
}
@@ -541,10 +564,9 @@ int64_t xmrig::Client::send(size_t size)
return -1;
}
uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size);
uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size);
if (uv_try_write(m_stream, &buf, 1) < 0) {
close();
if (!write(buf)) {
return -1;
}
}
@@ -558,7 +580,7 @@ void xmrig::Client::connect(sockaddr *addr)
{
setState(ConnectingState);
uv_connect_t *req = new uv_connect_t;
auto req = new uv_connect_t;
req->data = m_storage.ptr(m_key);
m_socket = new uv_tcp_t;
@@ -602,12 +624,12 @@ void xmrig::Client::login()
auto &allocator = doc.GetAllocator();
Value params(kObjectType);
params.AddMember("login", m_pool.user().toJSON(), allocator);
params.AddMember("pass", m_pool.password().toJSON(), allocator);
params.AddMember("login", m_user.toJSON(), allocator);
params.AddMember("pass", m_password.toJSON(), allocator);
params.AddMember("agent", StringRef(m_agent), allocator);
if (!m_pool.rigId().isNull()) {
params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
if (!m_rigId.isNull()) {
params.AddMember("rigid", m_rigId.toJSON(), allocator);
}
m_listener->onLogin(this, doc, params);
@@ -791,7 +813,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
void xmrig::Client::ping()
{
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
send(snprintf(m_sendBuf.data(), m_sendBuf.size(), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
m_keepAlive = 0;
}
@@ -799,7 +821,7 @@ void xmrig::Client::ping()
void xmrig::Client::read(ssize_t nread)
{
const size_t size = static_cast<size_t>(nread);
const auto size = static_cast<size_t>(nread);
if (nread > 0 && size > m_recvBuf.available()) {
nread = UV_ENOBUFS;
@@ -859,7 +881,7 @@ void xmrig::Client::reconnect()
void xmrig::Client::setState(SocketState state)
{
LOG_DEBUG("[%s] state: \"%s\"", url(), states[state]);
LOG_DEBUG("[%s] state: \"%s\" -> \"%s\"", url(), states[m_state], states[state]);
if (m_state == state) {
return;
@@ -956,6 +978,12 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
return;
}
if (client->state() == ConnectedState) {
LOG_ERR("[%s] already connected");
return;
}
client->m_stream = static_cast<uv_stream_t*>(req->handle);
client->m_stream->data = req->data;
client->setState(ConnectedState);

View File

@@ -60,14 +60,10 @@ class Client : public BaseClient, public IDnsListener, public ILineListener
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client)
constexpr static uint64_t kConnectTimeout = 20 * 1000;
constexpr static uint64_t kResponseTimeout = 20 * 1000;
# ifdef XMRIG_FEATURE_TLS
constexpr static size_t kInputBufferSize = 1024 * 16;
# else
constexpr static size_t kInputBufferSize = 1024 * 2;
# endif
constexpr static uint64_t kConnectTimeout = 20 * 1000;
constexpr static uint64_t kResponseTimeout = 20 * 1000;
constexpr static size_t kInputBufferSize = 1024 * 16;
constexpr static size_t kMaxSendBufferSize = 1024 * 16;
Client(int id, const char *agent, IClientListener *listener);
~Client() override;
@@ -100,6 +96,7 @@ private:
bool parseLogin(const rapidjson::Value &result, int *code);
bool send(BIO *bio);
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
bool write(const uv_buf_t &buf);
int resolve(const String &host);
int64_t send(size_t size);
void connect(sockaddr *addr);
@@ -128,11 +125,11 @@ private:
static inline Client *getClient(void *data) { return m_storage.get(data); }
char m_sendBuf[2048] = { 0 };
const char *m_agent;
Dns *m_dns;
RecvBuf<kInputBufferSize> m_recvBuf;
std::bitset<EXT_MAX> m_extensions;
std::vector<char> m_sendBuf;
String m_rpcId;
Tls *m_tls = nullptr;
uint64_t m_expire = 0;

View File

@@ -284,8 +284,8 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
auto &allocator = doc.GetAllocator();
Value params(kObjectType);
params.AddMember("wallet_address", m_pool.user().toJSON(), allocator);
params.AddMember("reserve_size", 8, allocator);
params.AddMember("wallet_address", m_user.toJSON(), allocator);
params.AddMember("reserve_size", 8, allocator);
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);

View File

@@ -99,7 +99,7 @@ public:
# endif
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
static inline uint64_t toDiff(uint64_t target) { return target ? (0xFFFFFFFFFFFFFFFFULL / target) : 0; }
inline bool operator!=(const Job &other) const { return !isEqual(other); }
inline bool operator==(const Job &other) const { return isEqual(other); }

View File

@@ -72,7 +72,7 @@ public:
);
inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); }
inline bool isTLS() const { return m_flags.test(FLAG_TLS); }
inline bool isTLS() const { return m_flags.test(FLAG_TLS) || m_url.isTLS(); }
inline bool isValid() const { return m_url.isValid(); }
inline const Algorithm &algorithm() const { return m_algorithm; }
inline const Coin &coin() const { return m_coin; }

View File

@@ -54,7 +54,7 @@ protected:
inline const char *mode() const override { return m_client->mode(); }
inline const char *tlsFingerprint() const override { return m_client->tlsFingerprint(); }
inline const char *tlsVersion() const override { return m_client->tlsVersion(); }
inline const Job &job() const override { return m_client->job(); }
inline const Job &job() const override { return m_job; }
inline const Pool &pool() const override { return m_client->pool(); }
inline const String &ip() const override { return m_client->ip(); }
inline int id() const override { return m_client->id(); }

View File

@@ -60,17 +60,17 @@ void xmrig::Arguments::add(const char *arg)
const size_t size = strlen(arg);
if (size > 4 && arg[0] == '-' && arg[1] == '-') {
const char *p = strstr(arg, "=");
const char *p = strchr(arg, '=');
if (p) {
const size_t keySize = static_cast<size_t>(p - arg);
const auto keySize = static_cast<size_t>(p - arg);
m_data.push_back(String(arg, keySize));
m_data.push_back(arg + keySize + 1);
m_data.emplace_back(arg, keySize);
m_data.emplace_back(arg + keySize + 1);
return;
}
}
m_data.push_back(arg);
m_data.emplace_back(arg);
}

View File

@@ -31,10 +31,12 @@ static inline uint8_t hf_hex2bin(uint8_t c, bool &err)
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'f') {
if (c >= 'a' && c <= 'f') {
return c - 'a' + 0xA;
}
else if (c >= 'A' && c <= 'F') {
if (c >= 'A' && c <= 'F') {
return c - 'A' + 0xA;
}
@@ -77,7 +79,9 @@ xmrig::Buffer::Buffer(const char *data, size_t size)
xmrig::Buffer::Buffer(size_t size) :
m_size(size)
{
m_data = new char[size]();
if (size > 0) {
m_data = new char[size]();
}
}
@@ -105,6 +109,10 @@ void xmrig::Buffer::from(const char *data, size_t size)
xmrig::Buffer xmrig::Buffer::allocUnsafe(size_t size)
{
if (size == 0) {
return {};
}
Buffer buf;
buf.m_size = size;
buf.m_data = new char[size];
@@ -169,6 +177,13 @@ xmrig::String xmrig::Buffer::toHex() const
void xmrig::Buffer::copy(const char *data, size_t size)
{
if (size == 0) {
m_data = nullptr;
m_size = 0;
return;
}
m_data = new char[size];
m_size = size;

View File

@@ -28,6 +28,7 @@
],
"colors": true,
"custom-diff": 0,
"custom-diff-stats": false,
"donate-level": 0,
"log-file": null,
"mode": "nicehash",

View File

@@ -22,9 +22,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <cassert>
#include <climits>
#include <cstring>
#include <uv.h>
@@ -46,16 +46,7 @@ static const char *modeNames[] = {
#endif
xmrig::Config::Config() :
m_algoExt(true),
m_debug(false),
m_verbose(false),
m_mode(NICEHASH_MODE),
m_reuseTimeout(0),
m_diff(0),
m_workersMode(Workers::RigID)
{
}
xmrig::Config::Config() = default;
bool xmrig::Config::isTLS() const
@@ -78,13 +69,19 @@ const char *xmrig::Config::modeName() const
}
bool xmrig::Config::isVerbose() const
{
return Log::isVerbose();
}
bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
{
if (!BaseConfig::read(reader, fileName)) {
return false;
}
m_verbose = reader.getBool("verbose", m_verbose);
m_customDiffStats = reader.getBool("custom-diff-stats", m_customDiffStats);
m_debug = reader.getBool("debug", m_debug);
m_algoExt = reader.getBool("algo-ext", m_algoExt);
m_reuseTimeout = reader.getInt("reuse-timeout", m_reuseTimeout);
@@ -98,7 +95,7 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
# ifdef XMRIG_FEATURE_TLS
const rapidjson::Value &tls = reader.getObject("tls");
if (tls.IsObject()) {
m_tls = std::move(TlsConfig(tls));
m_tls = TlsConfig(tls);
}
# endif
@@ -150,13 +147,14 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember("background", isBackground(), allocator);
Value bind(kArrayType);
for (const xmrig::BindHost &host : m_bind) {
for (const auto &host : m_bind) {
bind.PushBack(host.toJSON(doc), allocator);
}
doc.AddMember("bind", bind, allocator);
doc.AddMember("colors", Log::colors, allocator);
doc.AddMember("colors", Log::isColors(), allocator);
doc.AddMember("custom-diff", diff(), allocator);
doc.AddMember("custom-diff-stats", m_customDiffStats, allocator);
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
doc.AddMember("log-file", m_logFile.toJSON(), allocator);
doc.AddMember("mode", StringRef(modeName()), allocator);
@@ -177,6 +175,12 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
}
void xmrig::Config::toggleVerbose()
{
Log::setVerbose(Log::isVerbose() ? 0 : 1);
}
void xmrig::Config::setCustomDiff(uint64_t diff)
{
if (diff >= 100 && diff < INT_MAX) {

View File

@@ -26,7 +26,7 @@
#define XMRIG_CONFIG_H
#include <stdint.h>
#include <cstdint>
#include <vector>
@@ -74,27 +74,27 @@ public:
bool isTLS() const;
const char *modeName() const;
bool isVerbose() const;
bool read(const IJsonReader &reader, const char *fileName) override;
void getJSON(rapidjson::Document &doc) const override;
void toggleVerbose();
inline bool hasAlgoExt() const { return isDonateOverProxy() ? m_algoExt : true; }
inline bool isCustomDiffStats() const { return m_customDiffStats; }
inline bool isDebug() const { return m_debug; }
inline bool isDonateOverProxy() const { return m_pools.donateLevel() == 0 || m_mode == SIMPLE_MODE; }
inline bool isShouldSave() const { return m_upgrade && isAutoSave(); }
inline bool isVerbose() const { return m_verbose; }
inline const BindHosts &bind() const { return m_bind; }
inline const String &accessLog() const { return m_accessLog; }
inline const String &password() const { return m_password; }
inline const xmrig::BindHosts &bind() const { return m_bind; }
inline int mode() const { return m_mode; }
inline int reuseTimeout() const { return m_reuseTimeout; }
inline static IConfig *create() { return new Config(); }
inline uint64_t diff() const { return m_diff; }
inline void setVerbose(bool verbose) { m_verbose = verbose; }
inline void toggleVerbose() { m_verbose = !m_verbose; }
inline Workers::Mode workersMode() const { return m_workersMode; }
# ifdef XMRIG_FEATURE_TLS
inline const xmrig::TlsConfig &tls() const { return m_tls; }
inline const TlsConfig &tls() const { return m_tls; }
# endif
private:
@@ -103,15 +103,15 @@ private:
void setWorkersMode(const rapidjson::Value &value);
BindHosts m_bind;
bool m_algoExt;
bool m_debug;
bool m_verbose;
int m_mode;
int m_reuseTimeout;
bool m_algoExt = true;
bool m_customDiffStats = false;
bool m_debug = false;
int m_mode = NICEHASH_MODE;
int m_reuseTimeout = 0;
String m_accessLog;
String m_password;
uint64_t m_diff;
Workers::Mode m_workersMode;
uint64_t m_diff = 0;
Workers::Mode m_workersMode = Workers::RigID;
# ifdef XMRIG_FEATURE_TLS
TlsConfig m_tls;

View File

@@ -37,9 +37,7 @@ static const char *kTls = "tls";
}
xmrig::ConfigTransform::ConfigTransform()
{
}
xmrig::ConfigTransform::ConfigTransform() = default;
void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const char *arg)
@@ -68,7 +66,7 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
case IConfig::ProxyPasswordKey: /* --access-password */
return set(doc, "access-password", arg);
case IConfig::VerboseKey: /* --verbose */
case IConfig::CustomDiffStatsKey: /* --custom-diff-stats */
case IConfig::DebugKey: /* --debug */
return transformBoolean(doc, key, true);
@@ -112,8 +110,8 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key, bool enable)
{
switch (key) {
case IConfig::VerboseKey: /* --verbose */
return set(doc, "verbose", enable);
case IConfig::CustomDiffStatsKey: /* --custom-diff-stats */
return set(doc, "custom-diff-stats", enable);
case IConfig::DebugKey: /* --debug */
return set(doc, "debug", enable);

View File

@@ -58,6 +58,7 @@ static struct option const options[] = {
{ "bind", 1, nullptr, IConfig::BindKey },
{ "config", 1, nullptr, IConfig::ConfigKey },
{ "custom-diff", 1, nullptr, IConfig::CustomDiffKey },
{ "custom-diff-stats", 0, nullptr, IConfig::CustomDiffStatsKey},
{ "debug", 0, nullptr, IConfig::DebugKey },
{ "donate-level", 1, nullptr, IConfig::DonateLevelKey },
{ "keepalive", 2, nullptr, IConfig::KeepAliveKey },

View File

@@ -52,6 +52,7 @@ Options:\n\
-r, --retries=N number of times to retry before switch to backup server (default: 1)\n\
-R, --retry-pause=N time to pause between retries (default: 1 second)\n\
--custom-diff=N override pool diff\n\
--custom-diff-stats calculate stats using custom diff shares instead of pool shares\n\
--reuse-timeout=N timeout in seconds for reuse pool connections in simple mode\n\
--verbose verbose output\n\
--user-agent=AGENT set custom user-agent string for pool\n\

View File

@@ -101,6 +101,9 @@ static AlgoName const algorithm_names[] = {
{ "cryptonight-turtle", "cn-trtl", Algorithm::CN_PICO_0 },
{ "cryptonight-ultralite", "cn-ultralite", Algorithm::CN_PICO_0 },
{ "cryptonight_turtle", "cn_turtle", Algorithm::CN_PICO_0 },
{ "cryptonight-pico/tlo", "cn-pico/tlo", Algorithm::CN_PICO_TLO },
{ "cryptonight-talleo", "cn-talleo", Algorithm::CN_PICO_TLO },
{ "cryptonight_talleo", "cn_talleo", Algorithm::CN_PICO_TLO },
# endif
# ifdef XMRIG_ALGO_RANDOMX
{ "randomx/0", "rx/0", Algorithm::RX_0 },
@@ -112,6 +115,8 @@ static AlgoName const algorithm_names[] = {
{ "RandomXL", nullptr, Algorithm::RX_LOKI },
{ "randomx/arq", "rx/arq", Algorithm::RX_ARQ },
{ "RandomARQ", nullptr, Algorithm::RX_ARQ },
{ "randomx/sfx", "rx/sfx", Algorithm::RX_SFX },
{ "RandomSFX", nullptr, Algorithm::RX_SFX },
# endif
# ifdef XMRIG_ALGO_ARGON2
{ "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA },
@@ -138,6 +143,7 @@ size_t xmrig::Algorithm::l2() const
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return 0x40000;
case RX_WOW:
@@ -157,7 +163,9 @@ size_t xmrig::Algorithm::l2() const
size_t xmrig::Algorithm::l3() const
{
# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_ARGON2)
constexpr size_t oneMiB = 0x100000;
# endif
const Family f = family();
assert(f != UNKNOWN);
@@ -171,6 +179,7 @@ size_t xmrig::Algorithm::l3() const
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return oneMiB * 2;
case RX_WOW:
@@ -262,6 +271,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
# ifdef XMRIG_ALGO_CN_PICO
case CN_PICO_0:
case CN_PICO_TLO:
return CN_PICO;
# endif
@@ -270,6 +280,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
case RX_WOW:
case RX_LOKI:
case RX_ARQ:
case RX_SFX:
return RANDOM_X;
# endif

View File

@@ -62,11 +62,13 @@ public:
CN_HEAVY_0, // "cn-heavy/0" CryptoNight-Heavy (4 MB).
CN_HEAVY_TUBE, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only).
CN_HEAVY_XHV, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only).
CN_PICO_0, // "cn-pico" CryptoNight Turtle (TRTL)
CN_PICO_0, // "cn-pico" CryptoNight-Pico
CN_PICO_TLO, // "cn-pico/tlo" CryptoNight-Pico (TLO)
RX_0, // "rx/0" RandomX (reference configuration).
RX_WOW, // "rx/wow" RandomWOW (Wownero).
RX_LOKI, // "rx/loki" RandomXL (Loki).
RX_ARQ, // "rx/arq" RandomARQ (Arqma).
RX_SFX, // "rx/sfx" RandomSFX (Safex Cash).
AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
MAX

View File

@@ -30,6 +30,7 @@
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Job.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "base/tools/Handle.h"
@@ -39,6 +40,7 @@
#include "proxy/Events.h"
#include "proxy/events/CloseEvent.h"
#include "proxy/events/LoginEvent.h"
#include "proxy/events/AcceptEvent.h"
#include "proxy/events/SubmitEvent.h"
#include "proxy/Miner.h"
#include "proxy/tls/TlsContext.h"
@@ -62,7 +64,6 @@ namespace xmrig {
xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port) :
m_ip(),
m_routeId(-1),
m_id(++nextId),
m_loginId(0),
@@ -102,7 +103,12 @@ xmrig::Miner::Miner(const TlsContext *ctx, uint16_t port) :
xmrig::Miner::~Miner()
{
Handle::close(m_socket);
if (uv_is_closing(reinterpret_cast<uv_handle_t *>(m_socket))) {
delete m_socket;
}
else {
uv_close(reinterpret_cast<uv_handle_t *>(m_socket), [](uv_handle_t *handle) { delete handle; });
}
# ifdef XMRIG_FEATURE_TLS
delete m_tls;
@@ -253,6 +259,10 @@ bool xmrig::Miner::parseRequest(int64_t id, const char *method, const rapidjson:
if (event->error() == Error::NoError && m_customDiff && event->request.actualDiff() < m_diff) {
success(id, "OK");
SubmitResult result = SubmitResult(1, m_customDiff, event->request.actualDiff(), event->request.id, 0);
AcceptEvent::start(m_mapperId, this, result, false, true);
return true;
}

View File

@@ -123,9 +123,9 @@ private:
static inline Miner *getMiner(void *data) { return m_storage.get(data); }
char m_buf[4096];
char m_ip[46];
char m_rpcId[37];
char m_buf[4096]{};
char m_ip[46]{};
char m_rpcId[37]{};
int32_t m_routeId;
int64_t m_id;
int64_t m_loginId;
@@ -147,7 +147,7 @@ private:
uint64_t m_tx;
uint8_t m_fixedByte;
uintptr_t m_key;
uv_buf_t m_recvBuf;
uv_buf_t m_recvBuf{};
uv_tcp_t *m_socket;
static char m_sendBuf[2048];

View File

@@ -83,6 +83,7 @@ xmrig::Proxy::Proxy(Controller *controller) :
m_splitter = splitter;
m_donate = new DonateSplitter(controller);
m_stats = new Stats(controller);
m_shareLog = new ShareLog(controller, m_stats);
m_accessLog = new AccessLog(controller);
m_workers = new Workers(controller);
@@ -97,12 +98,12 @@ xmrig::Proxy::Proxy(Controller *controller) :
# endif
Events::subscribe(IEvent::ConnectionType, m_miners);
Events::subscribe(IEvent::ConnectionType, &m_stats);
Events::subscribe(IEvent::ConnectionType, m_stats);
Events::subscribe(IEvent::CloseType, m_miners);
Events::subscribe(IEvent::CloseType, m_donate);
Events::subscribe(IEvent::CloseType, splitter);
Events::subscribe(IEvent::CloseType, &m_stats);
Events::subscribe(IEvent::CloseType, m_stats);
Events::subscribe(IEvent::CloseType, m_accessLog);
Events::subscribe(IEvent::CloseType, m_workers);
@@ -110,16 +111,16 @@ xmrig::Proxy::Proxy(Controller *controller) :
Events::subscribe(IEvent::LoginType, m_donate);
Events::subscribe(IEvent::LoginType, &m_customDiff);
Events::subscribe(IEvent::LoginType, splitter);
Events::subscribe(IEvent::LoginType, &m_stats);
Events::subscribe(IEvent::LoginType, m_stats);
Events::subscribe(IEvent::LoginType, m_accessLog);
Events::subscribe(IEvent::LoginType, m_workers);
Events::subscribe(IEvent::SubmitType, m_donate);
Events::subscribe(IEvent::SubmitType, splitter);
Events::subscribe(IEvent::SubmitType, &m_stats);
Events::subscribe(IEvent::SubmitType, m_stats);
Events::subscribe(IEvent::SubmitType, m_workers);
Events::subscribe(IEvent::AcceptType, &m_stats);
Events::subscribe(IEvent::AcceptType, m_stats);
Events::subscribe(IEvent::AcceptType, m_shareLog);
Events::subscribe(IEvent::AcceptType, m_workers);
@@ -190,7 +191,7 @@ void xmrig::Proxy::printConnections()
void xmrig::Proxy::printHashrate()
{
LOG_INFO("\x1B[01;32m* \x1B[01;37mspeed\x1B[0m \x1B[01;30m(1m) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(10m) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(1h) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(12h) \x1B[01;36m%03.2f\x1B[0m, \x1B[01;30m(24h) \x1B[01;36m%03.2f kH/s",
m_stats.hashrate(60), m_stats.hashrate(600), m_stats.hashrate(3600), m_stats.hashrate(3600 * 12), m_stats.hashrate(3600 * 24));
m_stats->hashrate(60), m_stats->hashrate(600), m_stats->hashrate(3600), m_stats->hashrate(3600 * 12), m_stats->hashrate(3600 * 24));
}
@@ -208,7 +209,7 @@ void xmrig::Proxy::toggleDebug()
const xmrig::StatsData &xmrig::Proxy::statsData() const
{
return m_stats.data();
return m_stats->data();
}
@@ -272,7 +273,7 @@ void xmrig::Proxy::gc()
void xmrig::Proxy::print()
{
LOG_INFO("\x1B[01;36m%03.2f kH/s\x1B[0m, shares: \x1B[01;37m%" PRIu64 "\x1B[0m/%s%" PRIu64 "\x1B[0m +%" PRIu64 ", upstreams: \x1B[01;37m%" PRIu64 "\x1B[0m, miners: \x1B[01;37m%" PRIu64 "\x1B[0m (max \x1B[01;37m%" PRIu64 "\x1B[0m) +%u/-%u",
m_stats.hashrate(60), m_stats.data().accepted, (m_stats.data().rejected ? "\x1B[0;31m" : "\x1B[1;37m"), m_stats.data().rejected,
m_stats->hashrate(m_controller->config()->printTime()), m_stats->data().accepted, (m_stats->data().rejected ? "\x1B[0;31m" : "\x1B[1;37m"), m_stats->data().rejected,
Counters::accepted, m_splitter->upstreams().active, Counters::miners(), Counters::maxMiners(), Counters::added(), Counters::removed());
Counters::reset();
@@ -281,7 +282,7 @@ void xmrig::Proxy::print()
void xmrig::Proxy::tick()
{
m_stats.tick(m_ticks, m_splitter);
m_stats->tick(m_ticks, m_splitter);
m_ticks++;
@@ -289,7 +290,8 @@ void xmrig::Proxy::tick()
gc();
}
if ((m_ticks % kPrintInterval) == 0) {
auto seconds = m_controller->config()->printTime();
if (seconds && (m_ticks % seconds) == 0) {
print();
}

View File

@@ -79,7 +79,6 @@ protected:
void onConfigChanged(Config *config, Config *previousConfig) override;
private:
constexpr static int kPrintInterval = 60;
constexpr static int kGCInterval = 60;
void bind(const BindHost &host);
@@ -100,7 +99,7 @@ private:
Miners *m_miners;
ProxyDebug *m_debug;
ShareLog *m_shareLog;
Stats m_stats;
Stats *m_stats;
std::vector<Server*> m_servers;
TlsContext *m_tls;
uint64_t m_ticks;

View File

@@ -89,7 +89,7 @@ void xmrig::ProxyDebug::onEvent(IEvent *event)
case IEvent::AcceptType: {
auto e = static_cast<AcceptEvent*>(event);
LOG_INFO("[debug] accepted <Miner id=%" PRId64 ", ip=%s>, <Result diff=%u, actualDiff=%" PRIu64 ", elapsed=%" PRIu64 ">",
LOG_INFO("[debug] accepted <Miner id=%" PRId64 ", ip=%s>, <Result diff=%" PRIu64 ", actualDiff=%" PRIu64 ", elapsed=%" PRIu64 ">",
e->miner() ? e->miner()->id() : -1, e->miner() ? e->miner()->ip() : "?.?.?.?", e->result.diff, e->result.actualDiff, e->result.elapsed);
}
break;
@@ -135,7 +135,7 @@ void xmrig::ProxyDebug::onRejectedEvent(IEvent *event)
case IEvent::AcceptType: {
auto e = static_cast<AcceptEvent*>(event);
LOG_ERR("[error] rejected <Miner id=%" PRId64 ", ip=%s>, <Result diff=%u, elapsed=%" PRIu64 ">, error=%s",
LOG_ERR("[error] rejected <Miner id=%" PRId64 ", ip=%s>, <Result diff=%" PRIu64 ", elapsed=%" PRIu64 ">, error=%s",
e->miner() ? e->miner()->id() : -1, e->miner() ? e->miner()->ip() : "?.?.?.?", e->result.diff, e->result.elapsed, e->error());
}
break;

View File

@@ -24,13 +24,16 @@
#include "base/net/stratum/SubmitResult.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "Counters.h"
#include "interfaces/ISplitter.h"
#include "proxy/events/AcceptEvent.h"
#include "proxy/Stats.h"
xmrig::Stats::Stats() :
xmrig::Stats::Stats(Controller *controller) :
m_controller(controller),
m_hashrate(4)
{
}
@@ -107,7 +110,15 @@ void xmrig::Stats::onRejectedEvent(IEvent *event)
void xmrig::Stats::accept(const AcceptEvent *event)
{
m_hashrate.add(event->result.diff);
if (event->isCustomDiff() && !m_controller->config()->isCustomDiffStats()) {
return;
}
m_hashrate.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);
if (event->isCustomDiff()) {
return;
}
m_data.accepted++;
m_data.hashes += event->result.diff;

View File

@@ -38,13 +38,14 @@ namespace xmrig {
class AcceptEvent;
class Controller;
class ISplitter;
class Stats : public IEventListener
{
public:
Stats();
Stats(Controller *controller);
~Stats() override;
void tick(uint64_t ticks, const ISplitter *splitter);
@@ -60,6 +61,7 @@ private:
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);
Controller *m_controller;
StatsData m_data;
TickingCounter<uint32_t> m_hashrate;
};

View File

@@ -26,6 +26,8 @@
#define XMRIG_ACCEPTEVENT_H
#include "base/net/stratum/SubmitResult.h"
#include "proxy/Miner.h"
#include "proxy/events/MinerEvent.h"
#include "proxy/Error.h"
@@ -33,31 +35,31 @@
namespace xmrig {
class SubmitResult;
class AcceptEvent : public MinerEvent
{
public:
static inline bool start(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, const char *error = nullptr)
static inline bool start(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, bool customDiff, const char *error = nullptr)
{
return exec(new (m_buf) AcceptEvent(mapperId, miner, result, donate, error));
return exec(new (m_buf) AcceptEvent(mapperId, miner, result, donate, customDiff, error));
}
const SubmitResult &result;
inline bool isCustomDiff() const { return m_customDiff; }
inline bool isDonate() const { return m_donate; }
inline bool isRejected() const override { return m_error != nullptr; }
inline const char *error() const { return m_error; }
inline size_t mapperId() const { return m_mapperId; }
inline uint64_t statsDiff() const { return (miner() && miner()->customDiff() ? std::min(miner()->customDiff(), result.diff) : result.diff); }
protected:
inline AcceptEvent(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, const char *error)
inline AcceptEvent(size_t mapperId, Miner *miner, const SubmitResult &result, bool donate, bool customDiff, const char *error)
: MinerEvent(AcceptType, miner),
result(result),
m_customDiff(customDiff),
m_donate(donate),
m_error(error),
m_mapperId(mapperId)
@@ -65,6 +67,7 @@ protected:
private:
bool m_customDiff;
bool m_donate;
const char *m_error;
size_t m_mapperId;

View File

@@ -35,7 +35,7 @@
#include "proxy/Stats.h"
xmrig::ShareLog::ShareLog(Controller *controller, const Stats &stats) :
xmrig::ShareLog::ShareLog(Controller *controller, Stats *stats) :
m_stats(stats),
m_controller(controller)
{
@@ -77,12 +77,12 @@ void xmrig::ShareLog::onRejectedEvent(IEvent *event)
void xmrig::ShareLog::accept(const AcceptEvent *event)
{
if (!m_controller->config()->isVerbose() || event->isDonate()) {
if (!m_controller->config()->isVerbose() || event->isDonate() || event->isCustomDiff()) {
return;
}
LOG_INFO("#%03u \x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m ip \x1B[01;37m%s \x1B[01;30m(%" PRIu64 " ms)",
event->mapperId(), m_stats.data().accepted, m_stats.data().rejected, m_stats.data().invalid, event->result.diff, event->ip(), event->result.elapsed);
LOG_INFO("#%03u " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " ip " WHITE_BOLD("%s") " " BLACK_BOLD("(%" PRIu64 " ms)"),
event->mapperId(), m_stats->data().accepted, m_stats->data().rejected, m_stats->data().invalid, event->result.diff, event->ip(), event->result.elapsed);
}
@@ -92,6 +92,6 @@ void xmrig::ShareLog::reject(const AcceptEvent *event)
return;
}
LOG_INFO("#%03u \x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m ip \x1B[01;37m%s \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRId64 " ms)",
event->mapperId(), m_stats.data().accepted, m_stats.data().rejected, m_stats.data().invalid, event->result.diff, event->ip(), event->error(), event->result.elapsed);
LOG_INFO("#%03u " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " ip " WHITE_BOLD("%s") " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
event->mapperId(), m_stats->data().accepted, m_stats->data().rejected, m_stats->data().invalid, event->result.diff, event->ip(), event->error(), event->result.elapsed);
}

View File

@@ -40,7 +40,7 @@ class Stats;
class ShareLog : public IEventListener
{
public:
ShareLog(Controller *controller, const Stats &stats);
ShareLog(Controller *controller, Stats *stats);
~ShareLog() override;
protected:
@@ -51,7 +51,7 @@ private:
void accept(const AcceptEvent *event);
void reject(const AcceptEvent *event);
const Stats &m_stats;
Stats *m_stats;
Controller *m_controller;
};

View File

@@ -117,7 +117,7 @@ void xmrig::DonateMapper::onLoginSuccess(IClient *)
void xmrig::DonateMapper::onResultAccepted(IClient *, const SubmitResult &result, const char *error)
{
AcceptEvent::start(m_id, m_miner, result, true, error);
AcceptEvent::start(m_id, m_miner, result, true, false, error);
if (error) {
m_miner->replyWithError(result.reqId, error);

View File

@@ -245,7 +245,7 @@ void xmrig::NonceMapper::onResultAccepted(IStrategy *, IClient *client, const Su
{
const SubmitCtx ctx = submitCtx(result.seq);
AcceptEvent::start(m_id, ctx.miner, result, client->id() == -1, error);
AcceptEvent::start(m_id, ctx.miner, result, client->id() == -1, false, error);
if (!ctx.miner) {
return;

View File

@@ -218,7 +218,7 @@ void xmrig::SimpleMapper::onPause(IStrategy *strategy)
void xmrig::SimpleMapper::onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error)
{
AcceptEvent::start(m_id, m_miner, result, client->id() == -1, error);
AcceptEvent::start(m_id, m_miner, result, client->id() == -1, false, error);
if (!m_miner) {
return;

View File

@@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2016-2019 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
@@ -49,12 +49,14 @@ xmrig::TlsConfig::TlsConfig(const rapidjson::Value &object) :
setCiphers(object["ciphers"].GetString());
setCipherSuites(object["ciphersuites"].GetString());
setDH(object["dhparam"].GetString());
if (m_key.isNull()) {
setKey(object["cert-key"].GetString());
}
}
xmrig::TlsConfig::~TlsConfig()
{
}
xmrig::TlsConfig::~TlsConfig() = default;
rapidjson::Value xmrig::TlsConfig::toJSON(rapidjson::Document &doc) const

View File

@@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2016-2019 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

View File

@@ -57,12 +57,12 @@ xmrig::Worker::Worker(size_t id, const std::string &name, const std::string &ip)
}
void xmrig::Worker::add(const SubmitResult &result)
void xmrig::Worker::add(uint64_t diff)
{
m_accepted++;
m_hashes += result.diff;
m_hashes += diff;
m_hashrate.add(result.diff);
m_hashrate.add(diff);
using namespace std::chrono;
m_lastHash = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();

View File

@@ -35,16 +35,13 @@
namespace xmrig {
class SubmitResult;
class Worker
{
public:
Worker();
Worker(size_t id, const std::string &name, const std::string &ip);
void add(const SubmitResult &result);
void add(uint64_t diff);
void tick(uint64_t ticks);
inline const char *ip() const { return m_ip.c_str(); }

View File

@@ -294,6 +294,10 @@ size_t xmrig::Workers::add(const Miner *miner)
void xmrig::Workers::accept(const AcceptEvent *event)
{
if (event->isCustomDiff() && !m_controller->config()->isCustomDiffStats()) {
return;
}
size_t index = 0;
if (!indexByMiner(event->miner(), &index)) {
return;
@@ -301,7 +305,7 @@ void xmrig::Workers::accept(const AcceptEvent *event)
Worker &worker = m_workers[index];
if (!event->isRejected()) {
worker.add(event->result);
worker.add(m_controller->config()->isCustomDiffStats() ? event->statsDiff() : event->result.diff);
}
else {
worker.reject(false);

View File

@@ -28,13 +28,13 @@
#define APP_ID "xmrig-proxy"
#define APP_NAME "xmrig-proxy"
#define APP_DESC "XMRig Stratum proxy"
#define APP_VERSION "4.5.0-beta"
#define APP_VERSION "5.5.0"
#define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com"
#define APP_KIND "proxy"
#define APP_VER_MAJOR 4
#define APP_VER_MAJOR 5
#define APP_VER_MINOR 5
#define APP_VER_PATCH 0