Compare commits

...

115 Commits

Author SHA1 Message Date
XMRig
300fb0de26 v5.10.2 2020-05-23 11:11:26 +07:00
XMRig
8f650cca6e Merge branch 'dev' 2020-05-23 11:11:06 +07:00
XMRig
43265dd446 Fixed library name. 2020-05-23 11:09:37 +07:00
xmrig
5797826f23 Update CHANGELOG.md 2020-05-23 10:59:40 +07:00
xmrig
ddc3453dce Update CHANGELOG.md 2020-05-22 12:05:45 +07:00
XMRig
4e5f74b418 Sync changes with the miner. 2020-05-11 20:55:09 +07:00
XMRig
ea85521d9d v5.10.2-dev 2020-04-23 14:33:19 +07:00
XMRig
3008104979 Merge branch 'master' into dev 2020-04-23 14:32:41 +07:00
XMRig
8863625ddb v5.10.1 2020-04-23 12:44:40 +07:00
XMRig
76e4c72e31 Merge branch 'dev' 2020-04-23 12:43:21 +07:00
XMRig
ad1a6b679c Sync changes with the miner. 2020-04-23 12:33:39 +07:00
XMRig
a21b3f61b7 v5.10.1-dev 2020-03-25 03:57:25 +07:00
XMRig
8ab851b4c4 Merge branch 'master' into dev 2020-03-25 03:56:49 +07:00
XMRig
db8a62b855 v5.10.0 2020-03-23 04:06:17 +07:00
XMRig
12bd88d261 Merge branch 'dev' 2020-03-23 04:04:55 +07:00
XMRig
20a45a4f12 Fixed compatibility with OpenSSL 1.0.x. 2020-03-22 06:04:26 +07:00
XMRig
2c261c9a6e Reduced memory consumption by 4 kB per connection. 2020-03-20 20:13:03 +07:00
xmrig
37b3c9eb65 Update CHANGELOG.md 2020-03-19 03:57:58 +07:00
XMRig
b1e2fb49df v5.10.0-dev 2020-03-18 20:25:29 +07:00
XMRig
0f12dd0cf3 Sync changes with miner. 2020-03-18 20:24:18 +07:00
XMRig
7dee572994 Fixed regression. 2020-03-18 15:39:23 +07:00
XMRig
f8b6623b4c Added TLS support for API and many other TLS related changes. 2020-03-18 03:58:20 +07:00
XMRig
7f13fe1081 Always enable TLS, except it is explicitly disabled. 2020-03-14 22:48:22 +07:00
XMRig
4f5527fac7 Fixed command line. 2020-03-13 21:52:25 +07:00
XMRig
5851b7471d Updated default config. 2020-03-13 16:14:42 +07:00
XMRig
895ce77e35 Removed debug code. 2020-03-13 15:49:45 +07:00
XMRig
1321e58c1f Implemented automatic TLS. 2020-03-13 15:45:31 +07:00
XMRig
126fb1cfe6 Rename Tls.* to MinerTls.* 2020-03-13 01:12:00 +07:00
XMRig
8863cd561f Added TLS certificate auto generation. 2020-03-12 01:36:42 +07:00
XMRig
6a039f20b0 Added command line option --data-dir. 2020-03-10 14:50:47 +07:00
XMRig
b292b0e2c3 Move files. 2020-03-09 01:22:05 +07:00
XMRig
35d2d3bda1 v5.9.1-dev 2020-03-08 22:24:24 +07:00
XMRig
94d4cf3352 Merge branch 'master' into dev 2020-03-08 22:23:39 +07:00
XMRig
c3c9886b56 v5.9.0 2020-03-08 13:08:11 +07:00
XMRig
896673cd25 Merge branch 'dev' 2020-03-08 13:07:16 +07:00
XMRig
006c131b13 Fixed build without HTTP support. 2020-03-08 12:30:37 +07:00
XMRig
25f59b8f12 Added FileLogWriter::writeLine 2020-03-08 02:36:20 +07:00
XMRig
bd828a8d2e Added new rx/keva algorithm for upcoming Kevacoin fork. 2020-03-08 01:48:26 +07:00
XMRig
34306b1180 v5.8.2-dev 2020-03-04 12:30:28 +07:00
XMRig
fb95b3542e Merge branch 'master' into dev 2020-03-04 12:26:28 +07:00
XMRig
448c2d5ff9 v5.8.1 2020-03-04 10:21:06 +07:00
XMRig
b103718c5a Merge branch 'dev' 2020-03-04 10:20:33 +07:00
XMRig
359c759f7f Fixed new block detection for DERO solo mining. 2020-03-04 00:11:10 +07:00
XMRig
24e360bc38 v5.8.1-dev 2020-03-03 23:13:55 +07:00
XMRig
bbed27fe0f Merge branch 'master' into dev 2020-03-03 23:13:23 +07:00
XMRig
39f1113402 v5.8.0 2020-03-03 12:11:47 +07:00
XMRig
80f59ada50 Merge branch 'dev' 2020-03-03 12:11:13 +07:00
xmrig
132948f246 Update CHANGELOG.md 2020-03-03 10:08:29 +07:00
XMRig
a92a334c92 Added AstroBWT support. 2020-03-01 14:02:05 +07:00
XMRig
0d84abb707 v5.8.0-dev 2020-03-01 12:37:20 +07:00
XMRig
f2dba7e7ab Merge branch 'master' into dev 2020-03-01 12:36:41 +07:00
XMRig
9bef9dcb0a v5.7.0 2020-02-25 05:40:29 +07:00
XMRig
dd996c42c8 Merge branch 'dev' 2020-02-25 05:38:54 +07:00
XMRig
32ed4f0061 Optimize file log. 2020-02-23 05:40:25 +07:00
XMRig
fff12dddf6 Fixed possible crashes in HTTP client. 2020-02-23 03:32:02 +07:00
xmrig
f9dcf6148e Update CHANGELOG.md 2020-02-21 21:52:46 +07:00
XMRig
629e09ca35 Removed uuid dependency. 2020-02-21 20:54:24 +07:00
XMRig
4a13f85484 Sync changes with miner. 2020-02-21 02:56:17 +07:00
xmrig
de966769b2 Merge pull request #382 from cohcho/delete_m_stats
Memory leak in xmrig::Proxy
2020-01-17 08:40:42 +07:00
cohcho
66e8b81cac Memory leak in xmrig::Proxy
Delete m_stats in destructor of xmrig::Proxy
2020-01-16 20:13:26 +00:00
XMRig
f3bd4b9c8e v5.5.2-dev 2020-01-12 12:57:06 +07:00
XMRig
5070f5e090 Merge branch 'master' into dev 2020-01-12 12:56:33 +07:00
XMRig
d3c096e44a v5.5.1 2020-01-12 08:42:43 +07:00
XMRig
e35eaba450 Merge branch 'dev' 2020-01-12 08:42:01 +07:00
xmrig
0aed0fbca7 Update CHANGELOG.md 2020-01-12 07:44:49 +07:00
XMRig
5309da72a6 Added environment variables support for TLS settings. 2020-01-01 19:12:20 +07:00
XMRig
cb048e6f47 Added UUID_LIBRARY cmake variable. 2019-12-31 01:19:22 +07:00
XMRig
6b1e1c62c5 Added flags.cmake. 2019-12-31 00:56:21 +07:00
XMRig
d29c61dc59 Fixed build with gcc 4.8. 2019-12-31 00:34:17 +07:00
XMRig
690c702332 Code cleanup & sync. 2019-12-30 04:06:53 +07:00
XMRig
693c1a93c7 v5.5.1-dev 2019-12-30 01:09:29 +07:00
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
212 changed files with 5696 additions and 3053 deletions

View File

@@ -1,4 +1,58 @@
# v4.5.0-beta
# v5.10.2
- [#1664](https://github.com/xmrig/xmrig/pull/1664) Improved JSON config error reporting.
- Fixed memory leak in HTTP client.
- Build [dependencies](https://github.com/xmrig/xmrig-deps/releases/tag/v4.1) updated to recent versions.
# v5.10.1
- [#1306](https://github.com/xmrig/xmrig/issues/1306) Fixed possible double connection to a pool.
- [#1654](https://github.com/xmrig/xmrig/issues/1654) Fixed build with LibreSSL.
# v5.10.0
- [#1596](https://github.com/xmrig/xmrig/issues/1596) Major TLS (Transport Layer Security) subsystem update.
- Reduced memory consumption by 4 kB per connection.
- Added command line option `--tls-gen`.
- Added command line option `--data-dir`.
# v5.9.0
- [#1578](https://github.com/xmrig/xmrig/pull/1578) Added new RandomKEVA algorithm for upcoming Kevacoin fork, as `"algo": "rx/keva"` or `"coin": "keva"`.
# v5.8.1
- [#1575](https://github.com/xmrig/xmrig/pull/1575) Fixed new block detection for DERO solo mining.
# v5.8.0
- [#1573](https://github.com/xmrig/xmrig/pull/1573) Added new AstroBWT algorithm for upcoming DERO fork, as `"algo": "astrobwt"` or `"coin": "dero"`.
# v5.7.0
- **Added SOCKS5 proxies support for Tor https://xmrig.com/docs/miner/tor.**
- [#377](https://github.com/xmrig/xmrig-proxy/issues/377) Fixed duplicate jobs in daemon (solo) mining client.
- Removed `libuuid` dependency on Linux.
- Fixed possible crashes in HTTP client.
# v5.5.1
- [#1469](https://github.com/xmrig/xmrig/issues/1469) Fixed build with gcc 4.8.
- Added environment variables support for TLS settings: `cert`, `cert_key`, `dhparam`.
# 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

@@ -6,9 +6,11 @@ option(WITH_GOOGLE_BREAKPAD "Use Google Breakpad" OFF)
option(WITH_DEBUG_LOG "Enable debug log output" OFF)
option(WITH_HTTP "HTTP protocol support (client/server)" ON)
option(WITH_TLS "Enable OpenSSL support" ON)
option(WITH_ENV_VARS "Enable environment variables support in config file" ON)
include (CheckIncludeFile)
include (cmake/os.cmake)
include (src/base/base.cmake)
@@ -21,10 +23,6 @@ set(HEADERS
src/core/config/ConfigTransform.h
src/core/config/usage.h
src/core/Controller.h
src/crypto/cn/CnAlgo.h
src/crypto/common/Algorithm.h
src/crypto/common/Coin.h
src/crypto/common/keccak.h
src/donate.h
src/net/JobResult.h
src/net/strategies/DonateStrategy.h
@@ -62,7 +60,6 @@ set(HEADERS
src/proxy/Stats.h
src/proxy/StatsData.h
src/proxy/TickingCounter.h
src/proxy/Uuid.h
src/proxy/workers/Worker.h
src/proxy/workers/Workers.h
src/Summary.h
@@ -76,9 +73,6 @@ set(SOURCES
src/core/config/Config.cpp
src/core/config/ConfigTransform.cpp
src/core/Controller.cpp
src/crypto/common/Algorithm.cpp
src/crypto/common/Coin.cpp
src/crypto/common/keccak.cpp
src/net/JobResult.cpp
src/net/strategies/DonateStrategy.cpp
src/proxy/BindHost.cpp
@@ -117,7 +111,6 @@ if (WIN32)
"${SOURCES_OS}"
res/app.rc
src/App_win.cpp
src/proxy/Uuid_win.cpp
)
add_definitions(/DWIN32)
@@ -126,7 +119,6 @@ elseif (APPLE)
set(SOURCES_OS
"${SOURCES_OS}"
src/App_unix.cpp
src/proxy/Uuid_mac.cpp
)
find_library(CFLIB CoreFoundation)
@@ -135,17 +127,16 @@ else()
set(SOURCES_OS
"${SOURCES_OS}"
src/App_unix.cpp
src/proxy/Uuid_unix.cpp
)
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(EXTRA_LIBS pthread)
else()
set(EXTRA_LIBS pthread uuid.a rt dl)
set(EXTRA_LIBS pthread rt dl)
endif()
endif()
add_definitions(/DXMRIG_PROXY_PROJECT)
add_definitions(/DXMRIG_PROXY_PROJECT /DXMRIG_FORCE_TLS)
add_definitions(/DUNICODE)
add_definitions(/D__STDC_FORMAT_MACROS)
add_definitions(/DAPP_DEVEL)
@@ -157,6 +148,7 @@ add_definitions(/DXMRIG_ALGO_CN_HEAVY)
add_definitions(/DXMRIG_ALGO_CN_PICO)
add_definitions(/DXMRIG_ALGO_CN_GPU)
add_definitions(/DXMRIG_ALGO_ARGON2)
add_definitions(/DXMRIG_ALGO_ASTROBWT)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(/DRAPIDJSON_SSE2)
@@ -166,54 +158,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(UV REQUIRED)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(/DNDEBUG)
endif()
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-class-memaccess")
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
add_definitions(/D_GNU_SOURCE)
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-2")
if (WITH_GOOGLE_BREAKPAD)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT /GL")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /GL")
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(/DNOMINMAX)
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-overloaded-virtual")
endif()
include(cmake/flags.cmake)
include(cmake/OpenSSL.cmake)
if (WITH_GOOGLE_BREAKPAD)

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

@@ -5,7 +5,9 @@ if (WITH_TLS)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(OPENSSL_MSVC_STATIC_RT TRUE)
set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32)
set(EXTRA_LIBS ${EXTRA_LIBS} crypt32)
elseif (APPLE)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
find_package(OpenSSL)
@@ -14,18 +16,29 @@ if (WITH_TLS)
set(TLS_SOURCES
src/base/net/stratum/Tls.cpp
src/base/net/stratum/Tls.h
src/proxy/tls/Tls.cpp
src/proxy/tls/Tls.h
src/proxy/tls/TlsConfig.cpp
src/proxy/tls/TlsConfig.h
src/proxy/tls/TlsContext.cpp
src/proxy/tls/TlsContext.h
src/base/net/tls/ServerTls.cpp
src/base/net/tls/ServerTls.h
src/base/net/tls/TlsConfig.cpp
src/base/net/tls/TlsConfig.h
src/base/net/tls/TlsContext.cpp
src/base/net/tls/TlsContext.h
src/base/net/tls/TlsGen.cpp
src/base/net/tls/TlsGen.h
src/proxy/tls/MinerTls.cpp
src/proxy/tls/MinerTls.h
)
include_directories(${OPENSSL_INCLUDE_DIR})
if (WITH_HTTP)
set(TLS_SOURCES ${TLS_SOURCES} src/base/net/http/HttpsClient.h src/base/net/http/HttpsClient.cpp)
set(TLS_SOURCES ${TLS_SOURCES}
src/base/net/https/HttpsClient.cpp
src/base/net/https/HttpsClient.h
src/base/net/https/HttpsContext.cpp
src/base/net/https/HttpsContext.h
src/base/net/https/HttpsServer.cpp
src/base/net/https/HttpsServer.h
)
endif()
else()
message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support")
@@ -37,5 +50,12 @@ else()
set(OPENSSL_LIBRARIES "")
remove_definitions(/DXMRIG_FEATURE_TLS)
if (WITH_HTTP)
set(TLS_SOURCES ${TLS_SOURCES}
src/base/net/http/HttpServer.cpp
src/base/net/http/HttpServer.h
)
endif()
set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls")
endif()

55
cmake/flags.cmake Normal file
View File

@@ -0,0 +1,55 @@
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(/DNDEBUG)
endif()
include(CheckSymbolExists)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-class-memaccess")
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
add_definitions(/D_GNU_SOURCE)
if (WITH_GOOGLE_BREAKPAD)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g")
endif()
if (${CMAKE_VERSION} VERSION_LESS "3.1.0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)
add_definitions(/DNOMINMAX)
add_definitions(/DHAVE_ROTR)
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-overloaded-virtual")
endif()

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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -22,15 +22,15 @@
* 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>
#include "App.h"
#include "base/io/Console.h"
#include "base/io/log/Log.h"
#include "base/kernel/Signals.h"
#include "base/io/Signals.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "proxy/Proxy.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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -22,25 +22,23 @@
* 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 "3rdparty/rapidjson/document.h"
#include "base/api/interfaces/IApiRequest.h"
#include "base/kernel/Platform.h"
#include "base/tools/Buffer.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "proxy/Counters.h"
#include "proxy/Miner.h"
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"
#include "version.h"
#include <cmath>
#include <cstring>
#include <uv.h>
static inline double normalize(double d)
{
if (!std::isnormal(d)) {
@@ -57,9 +55,7 @@ xmrig::ApiRouter::ApiRouter(Base *base) :
}
xmrig::ApiRouter::~ApiRouter()
{
}
xmrig::ApiRouter::~ApiRouter() = default;
void xmrig::ApiRouter::onRequest(IApiRequest &request)
@@ -69,7 +65,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());
}
@@ -190,42 +185,12 @@ void xmrig::ApiRouter::getMinersSummary(rapidjson::Value &reply, rapidjson::Docu
upstreams.AddMember("sleep", stats.upstreams.sleep, allocator);
upstreams.AddMember("error", stats.upstreams.error, allocator);
upstreams.AddMember("total", stats.upstreams.total, allocator);
upstreams.AddMember("ratio", normalize(stats.upstreams.ratio), allocator);
upstreams.AddMember("ratio", normalize(stats.upstreams.ratio(Counters::miners())), allocator);
reply.AddMember("upstreams", upstreams, allocator);
}
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 +208,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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,9 +26,10 @@
#define XMRIG_APIROUTER_H
#include "3rdparty/rapidjson/fwd.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/tools/Object.h"
#include "proxy/StatsData.h"
#include "rapidjson/fwd.h"
namespace xmrig {
@@ -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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,21 +26,18 @@
#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/crypto/keccak.h"
#include "base/io/Env.h"
#include "base/io/json/Json.h"
#include "base/kernel/Base.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "crypto/common/keccak.h"
#include "version.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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,22 +23,27 @@
*/
#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"
#include "base/net/http/HttpServer.h"
#include "base/net/tools/TcpServer.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/https/HttpsServer.h"
#else
# include "base/net/http/HttpServer.h"
#endif
namespace xmrig {
static const char *kAuthorization = "authorization";
static const char *kContentType = "content-type";
#ifdef _WIN32
static const char *favicon = nullptr;
@@ -49,34 +54,40 @@ static size_t faviconSize = 0;
xmrig::Httpd::Httpd(Base *base) :
m_base(base),
m_http(nullptr),
m_server(nullptr),
m_port(0)
m_base(base)
{
m_httpListener = std::make_shared<HttpListener>(this);
base->addListener(this);
}
xmrig::Httpd::~Httpd()
{
}
xmrig::Httpd::~Httpd() = default;
bool xmrig::Httpd::start()
{
const Http &config = m_base->config()->http();
const auto &config = m_base->config()->http();
if (!config.isEnabled()) {
return true;
}
m_http = new HttpServer(this);
bool tls = false;
# ifdef XMRIG_FEATURE_TLS
m_http = new HttpsServer(m_httpListener);
tls = m_http->setTls(m_base->config()->tls());
# else
m_http = new HttpServer(m_httpListener);
# endif
m_server = new TcpServer(config.host(), config.port(), m_http);
const int rc = m_server->bind();
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") BLUE_BOLD("%s:%d") " " RED_BOLD("%s"),
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CSI "1;%dm%s:%d" " " RED_BOLD("%s"),
"HTTP API",
tls ? 32 : 36,
config.host().data(),
rc < 0 ? config.port() : rc,
rc < 0 ? uv_strerror(rc) : ""
@@ -138,13 +149,13 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
# ifdef _WIN32
if (favicon != nullptr) {
HttpResponse response(data.id());
response.setHeader("Content-Type", "image/x-icon");
response.setHeader(HttpData::kContentType, "image/x-icon");
return response.end(favicon, faviconSize);
}
# endif
return HttpResponse(data.id(), 404).end();
return HttpResponse(data.id(), HTTP_STATUS_NOT_FOUND).end();
}
if (data.method > 4) {
@@ -161,7 +172,7 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end();
}
if (!data.headers.count(kContentType) || data.headers.at(kContentType) != "application/json") {
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
}
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,11 +26,13 @@
#define XMRIG_HTTPD_H
#include <stdint.h>
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/net/http/HttpListener.h"
#include "base/tools/Object.h"
#include <cstdint>
#include <memory>
namespace xmrig {
@@ -38,12 +40,15 @@ namespace xmrig {
class Base;
class HttpServer;
class HttpsServer;
class TcpServer;
class Httpd : public IBaseListener, public IHttpListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd)
Httpd(Base *base);
~Httpd() override;
@@ -57,10 +62,16 @@ protected:
private:
int auth(const HttpData &req) const;
Base *m_base;
HttpServer *m_http;
TcpServer *m_server;
uint16_t m_port;
const Base *m_base;
std::shared_ptr<IHttpListener> m_httpListener;
TcpServer *m_server = nullptr;
uint16_t m_port = 0;
# ifdef XMRIG_FEATURE_TLS
HttpsServer *m_http = nullptr;
# else
HttpServer *m_http = nullptr;
# endif
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_IAPIREQUEST_H
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {
@@ -69,21 +69,23 @@ public:
virtual ~IApiRequest() = default;
virtual bool accept() = 0;
virtual bool hasParseError() const = 0;
virtual bool isDone() const = 0;
virtual bool isNew() const = 0;
virtual bool isRestricted() const = 0;
virtual const rapidjson::Value &json() const = 0;
virtual const String &rpcMethod() const = 0;
virtual const String &url() const = 0;
virtual int version() const = 0;
virtual Method method() const = 0;
virtual rapidjson::Document &doc() = 0;
virtual rapidjson::Value &reply() = 0;
virtual RequestType type() const = 0;
virtual Source source() const = 0;
virtual void done(int status) = 0;
virtual bool accept() = 0;
virtual bool hasParseError() const = 0;
virtual bool isDone() const = 0;
virtual bool isNew() const = 0;
virtual bool isRestricted() const = 0;
virtual const rapidjson::Value &json() const = 0;
virtual const String &rpcMethod() const = 0;
virtual const String &url() const = 0;
virtual int version() const = 0;
virtual Method method() const = 0;
virtual rapidjson::Document &doc() = 0;
virtual rapidjson::Value &reply() = 0;
virtual RequestType type() const = 0;
virtual Source source() const = 0;
virtual void done(int status) = 0;
virtual void setRpcError(int code, const char *message = nullptr) = 0;
virtual void setRpcResult(rapidjson::Value &result) = 0;
};

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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,11 +23,11 @@
*/
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/requests/HttpApiRequest.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
#include "base/net/http/HttpData.h"
#include "rapidjson/error/en.h"
namespace xmrig {
@@ -53,6 +53,10 @@ static inline const char *rpcError(int code) {
return "Invalid params";
}
if (code >= HTTP_STATUS_BAD_REQUEST && code <= HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED) {
return http_status_str(static_cast<http_status>(code));
}
return "Internal error";
}
@@ -82,7 +86,7 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) :
return;
}
m_rpcMethod = Json::getString(json(), "method");
m_rpcMethod = Json::getString(m_body, "method");
if (m_rpcMethod.isEmpty()) {
done(RPC_INVALID_REQUEST);
@@ -129,6 +133,10 @@ bool xmrig::HttpApiRequest::accept()
const rapidjson::Value &xmrig::HttpApiRequest::json() const
{
if (type() == REQ_JSON_RPC) {
return Json::getValue(m_body, "params");
}
return m_body;
}
@@ -150,25 +158,14 @@ void xmrig::HttpApiRequest::done(int status)
m_res.setStatus(HTTP_STATUS_OK);
if (status != HTTP_STATUS_OK) {
if (status == HTTP_STATUS_NOT_FOUND) {
status = RPC_METHOD_NOT_FOUND;
}
Value error(kObjectType);
error.AddMember("code", status, allocator);
error.AddMember("message", StringRef(rpcError(status)), allocator);
reply().AddMember(StringRef(kError), error, allocator);
setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
}
else if (!reply().HasMember(kResult)) {
Value result(kObjectType);
result.AddMember("status", "OK", allocator);
reply().AddMember(StringRef(kResult), result, allocator);
setRpcResult(result);
}
reply().AddMember("jsonrpc", "2.0", allocator);
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(json(), kId), allocator), allocator);
}
else {
m_res.setStatus(status);
@@ -176,3 +173,38 @@ void xmrig::HttpApiRequest::done(int status)
m_res.end();
}
void xmrig::HttpApiRequest::setRpcError(int code, const char *message)
{
using namespace rapidjson;
auto &allocator = doc().GetAllocator();
Value error(kObjectType);
error.AddMember("code", code, allocator);
error.AddMember("message", message ? StringRef(message) : StringRef(rpcError(code)), allocator);
rpcDone(kError, error);
}
void xmrig::HttpApiRequest::setRpcResult(rapidjson::Value &result)
{
rpcDone(kResult, result);
}
void xmrig::HttpApiRequest::rpcDone(const char *key, rapidjson::Value &value)
{
ApiRequest::done(0);
using namespace rapidjson;
auto &allocator = doc().GetAllocator();
reply().AddMember(StringRef(key), value, allocator);
reply().AddMember("jsonrpc", "2.0", allocator);
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
m_res.setStatus(HTTP_STATUS_OK);
m_res.end();
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -53,8 +53,12 @@ protected:
const rapidjson::Value &json() const override;
Method method() const override;
void done(int status) override;
void setRpcError(int code, const char *message = nullptr) override;
void setRpcResult(rapidjson::Value &result) override;
private:
void rpcDone(const char *key, rapidjson::Value &value);
const HttpData &m_req;
HttpApiResponse m_res;
int m_parsed = 0;

View File

@@ -1,12 +1,18 @@
set(HEADERS_BASE
src/base/api/interfaces/IApiListener.h
src/base/crypto/Algorithm.h
src/base/crypto/Coin.h
src/base/crypto/keccak.h
src/base/io/Console.h
src/base/io/Env.h
src/base/io/json/Json.h
src/base/io/json/JsonChain.h
src/base/io/json/JsonRequest.h
src/base/io/log/backends/ConsoleLog.h
src/base/io/log/backends/FileLog.h
src/base/io/log/FileLogWriter.h
src/base/io/log/Log.h
src/base/io/Signals.h
src/base/io/Watcher.h
src/base/kernel/Base.h
src/base/kernel/config/BaseConfig.h
@@ -29,20 +35,26 @@ set(HEADERS_BASE
src/base/kernel/interfaces/IWatcherListener.h
src/base/kernel/Platform.h
src/base/kernel/Process.h
src/base/kernel/Signals.h
src/base/net/dns/Dns.h
src/base/net/dns/DnsRecord.h
src/base/net/http/Http.h
src/base/net/http/HttpListener.h
src/base/net/stratum/BaseClient.h
src/base/net/stratum/Client.h
src/base/net/stratum/Job.h
src/base/net/stratum/NetworkState.h
src/base/net/stratum/Pool.h
src/base/net/stratum/Pools.h
src/base/net/stratum/ProxyUrl.h
src/base/net/stratum/Socks5.h
src/base/net/stratum/strategies/FailoverStrategy.h
src/base/net/stratum/strategies/SinglePoolStrategy.h
src/base/net/stratum/strategies/StrategyProxy.h
src/base/net/stratum/SubmitResult.h
src/base/net/stratum/Url.h
src/base/net/tools/RecvBuf.h
src/base/net/tools/LineReader.h
src/base/net/tools/MemPool.h
src/base/net/tools/NetBuffer.h
src/base/net/tools/Storage.h
src/base/tools/Arguments.h
src/base/tools/Baton.h
@@ -54,13 +66,19 @@ set(HEADERS_BASE
)
set(SOURCES_BASE
src/base/crypto/Algorithm.cpp
src/base/crypto/Coin.cpp
src/base/crypto/keccak.cpp
src/base/io/Console.cpp
src/base/io/Env.cpp
src/base/io/json/Json.cpp
src/base/io/json/JsonChain.cpp
src/base/io/json/JsonRequest.cpp
src/base/io/log/backends/ConsoleLog.cpp
src/base/io/log/backends/FileLog.cpp
src/base/io/log/FileLogWriter.cpp
src/base/io/log/Log.cpp
src/base/io/Signals.cpp
src/base/io/Watcher.cpp
src/base/kernel/Base.cpp
src/base/kernel/config/BaseConfig.cpp
@@ -68,18 +86,22 @@ set(SOURCES_BASE
src/base/kernel/Entry.cpp
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp
src/base/kernel/Signals.cpp
src/base/net/dns/Dns.cpp
src/base/net/dns/DnsRecord.cpp
src/base/net/http/Http.cpp
src/base/net/stratum/BaseClient.cpp
src/base/net/stratum/Client.cpp
src/base/net/stratum/Job.cpp
src/base/net/stratum/NetworkState.cpp
src/base/net/stratum/Pool.cpp
src/base/net/stratum/Pools.cpp
src/base/net/stratum/ProxyUrl.cpp
src/base/net/stratum/Socks5.cpp
src/base/net/stratum/strategies/FailoverStrategy.cpp
src/base/net/stratum/strategies/SinglePoolStrategy.cpp
src/base/net/stratum/Url.cpp
src/base/net/tools/LineReader.cpp
src/base/net/tools/NetBuffer.cpp
src/base/tools/Arguments.cpp
src/base/tools/Buffer.cpp
src/base/tools/String.cpp
@@ -132,12 +154,12 @@ if (WITH_HTTP)
src/base/kernel/interfaces/IHttpListener.h
src/base/kernel/interfaces/IJsonReader.h
src/base/kernel/interfaces/ITcpServerListener.h
src/base/net/http/Fetch.h
src/base/net/http/HttpApiResponse.h
src/base/net/http/HttpClient.h
src/base/net/http/HttpContext.h
src/base/net/http/HttpData.h
src/base/net/http/HttpResponse.h
src/base/net/http/HttpServer.h
src/base/net/stratum/DaemonClient.h
src/base/net/stratum/SelfSelectClient.h
src/base/net/tools/TcpServer.h
@@ -149,11 +171,13 @@ if (WITH_HTTP)
src/base/api/Httpd.cpp
src/base/api/requests/ApiRequest.cpp
src/base/api/requests/HttpApiRequest.cpp
src/base/net/http/Fetch.cpp
src/base/net/http/HttpApiResponse.cpp
src/base/net/http/HttpClient.cpp
src/base/net/http/HttpContext.cpp
src/base/net/http/HttpData.cpp
src/base/net/http/HttpListener.cpp
src/base/net/http/HttpResponse.cpp
src/base/net/http/HttpServer.cpp
src/base/net/stratum/DaemonClient.cpp
src/base/net/stratum/SelfSelectClient.cpp
src/base/net/tools/TcpServer.cpp
@@ -167,3 +191,15 @@ else()
remove_definitions(/DXMRIG_FEATURE_HTTP)
remove_definitions(/DXMRIG_FEATURE_API)
endif()
if (WITH_ENV_VARS AND CMAKE_CXX_COMPILER_ID MATCHES GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
set(WITH_ENV_VARS OFF)
endif()
if (WITH_ENV_VARS)
add_definitions(/DXMRIG_FEATURE_ENV)
else()
remove_definitions(/DXMRIG_FEATURE_ENV)
endif()

View File

@@ -6,8 +6,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,11 +24,8 @@
*/
#include "crypto/common/Algorithm.h"
#include "crypto/cn/CnAlgo.h"
#include "rapidjson/document.h"
#include "base/crypto/Algorithm.h"
#include "3rdparty/rapidjson/document.h"
#include <cassert>
@@ -101,6 +98,10 @@ 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/ultra", "cn/ultra", 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,12 +113,20 @@ 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 },
{ "randomx/keva", "rx/keva", Algorithm::RX_KEVA },
{ "RandomKEVA", nullptr, Algorithm::RX_KEVA },
# endif
# ifdef XMRIG_ALGO_ARGON2
{ "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ },
# endif
# ifdef XMRIG_ALGO_ASTROBWT
{ "astrobwt", nullptr, Algorithm::ASTROBWT_DERO },
{ "astrobwt/dero", nullptr, Algorithm::ASTROBWT_DERO },
# endif
};
@@ -138,9 +147,11 @@ size_t xmrig::Algorithm::l2() const
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return 0x40000;
case RX_WOW:
case RX_KEVA:
return 0x20000;
case RX_ARQ:
@@ -159,11 +170,24 @@ size_t xmrig::Algorithm::l3() const
{
constexpr size_t oneMiB = 0x100000;
const Family f = family();
const auto f = family();
assert(f != UNKNOWN);
if (f < RANDOM_X) {
return CnAlgo<>::memory(m_id);
switch (f) {
case CN:
return oneMiB * 2;
case CN_LITE:
return oneMiB;
case CN_HEAVY:
return oneMiB * 4;
case CN_PICO:
return oneMiB / 4;
default:
break;
}
# ifdef XMRIG_ALGO_RANDOMX
@@ -171,9 +195,11 @@ size_t xmrig::Algorithm::l3() const
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return oneMiB * 2;
case RX_WOW:
case RX_KEVA:
return oneMiB;
case RX_ARQ:
@@ -200,6 +226,18 @@ size_t xmrig::Algorithm::l3() const
}
# endif
# ifdef XMRIG_ALGO_ASTROBWT
if (f == ASTROBWT) {
switch (m_id) {
case ASTROBWT_DERO:
return oneMiB * 20;
default:
break;
}
}
# endif
return 0;
}
@@ -218,6 +256,12 @@ uint32_t xmrig::Algorithm::maxIntensity() const
}
# endif
# ifdef XMRIG_ALGO_ASTROBWT
if (family() == ASTROBWT) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_CN_GPU
if (m_id == CN_GPU) {
return 1;
@@ -262,6 +306,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 +315,8 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
case RX_WOW:
case RX_LOKI:
case RX_ARQ:
case RX_SFX:
case RX_KEVA:
return RANDOM_X;
# endif
@@ -279,6 +326,11 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
return ARGON2;
# endif
# ifdef XMRIG_ALGO_ASTROBWT
case ASTROBWT_DERO:
return ASTROBWT;
# endif
default:
break;
}

View File

@@ -6,8 +6,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -30,7 +30,7 @@
#include <vector>
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {
@@ -62,13 +62,17 @@ 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).
RX_KEVA, // "rx/keva" RandomKEVA (Keva).
AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
ASTROBWT_DERO, // "astrobwt" AstroBWT (Dero)
MAX
};
@@ -79,7 +83,8 @@ public:
CN_HEAVY,
CN_PICO,
RANDOM_X,
ARGON2
ARGON2,
ASTROBWT
};
inline Algorithm() = default;

View File

@@ -6,8 +6,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,8 +24,8 @@
*/
#include "crypto/common/Coin.h"
#include "rapidjson/document.h"
#include "base/crypto/Coin.h"
#include "3rdparty/rapidjson/document.h"
#include <cstring>
@@ -50,7 +50,9 @@ static CoinName const coin_names[] = {
{ "monero", Coin::MONERO },
{ "xmr", Coin::MONERO },
{ "arqma", Coin::ARQMA },
{ "arq", Coin::ARQMA }
{ "arq", Coin::ARQMA },
{ "dero", Coin::DERO },
{ "keva", Coin::KEVA }
};
@@ -67,6 +69,12 @@ xmrig::Algorithm::Id xmrig::Coin::algorithm(uint8_t blobVersion) const
case ARQMA:
return (blobVersion >= 15) ? Algorithm::RX_ARQ : Algorithm::CN_PICO_0;
case DERO:
return (blobVersion >= 4) ? Algorithm::ASTROBWT_DERO : Algorithm::CN_0;
case KEVA:
return (blobVersion >= 11) ? Algorithm::RX_KEVA : Algorithm::CN_R;
case INVALID:
break;
}

View File

@@ -6,8 +6,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -27,8 +27,8 @@
#define XMRIG_COIN_H
#include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
#include "base/crypto/Algorithm.h"
namespace xmrig {
@@ -40,7 +40,9 @@ public:
enum Id : int {
INVALID = -1,
MONERO,
ARQMA
ARQMA,
DERO,
KEVA
};

View File

@@ -6,7 +6,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,11 +24,10 @@
*/
#include <stdint.h>
#include <memory.h>
#include "crypto/common/keccak.h"
#include "base/crypto/keccak.h"
#define HASH_DATA_AREA 136

View File

@@ -6,7 +6,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,8 +27,8 @@
#ifndef XMRIG_KECCAK_H
#define XMRIG_KECCAK_H
#include <stdint.h>
#include <string.h>
#include <cstdint>
#include <cstring>
namespace xmrig {

153
src/base/io/Env.cpp Normal file
View File

@@ -0,0 +1,153 @@
/* 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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/io/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 {
#ifdef XMRIG_FEATURE_ENV
static std::map<String, String> variables;
static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_KIND", APP_KIND });
variables.insert({ "XMRIG_HOSTNAME", Env::hostname() });
variables.insert({ "XMRIG_EXE", Process::exepath() });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
}
#endif
} // namespace xmrig
xmrig::String xmrig::Env::expand(const char *in)
{
# ifdef XMRIG_FEATURE_ENV
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();
# else
return in;
# endif
}
xmrig::String xmrig::Env::get(const String &name)
{
# ifdef XMRIG_FEATURE_ENV
if (variables.empty()) {
createVariables();
}
if (variables.count(name)) {
return variables.at(name);
}
# endif
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 {};
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -21,24 +22,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef __FreeBSD__
# include <uuid.h>
#else
# include <uuid/uuid.h>
#endif
#include "proxy/Uuid.h"
#ifndef XMRIG_ENV_H
#define XMRIG_ENV_H
void Uuid::create(char *out, size_t size)
#include "base/tools/String.h"
namespace xmrig {
class Env
{
uuid_t id;
public:
static String expand(const char *in);
static String get(const String &name);
static String hostname();
};
# ifdef __FreeBSD__
uuid_create(&id, nullptr);
uuid_to_string(&id, &out, nullptr);
# else
uuid_generate(id);
uuid_unparse_lower(id, out);
# endif
}
} /* namespace xmrig */
#endif /* XMRIG_ENV_H */

View File

@@ -26,8 +26,8 @@
#include <uv.h>
#include "base/io/Signals.h"
#include "base/kernel/interfaces/ISignalListener.h"
#include "base/kernel/Signals.h"
#include "base/tools/Handle.h"

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,10 +24,11 @@
#include "base/io/json/Json.h"
#include "rapidjson/document.h"
#include "3rdparty/rapidjson/document.h"
#include <cassert>
#include <cmath>
namespace xmrig {
@@ -39,7 +40,9 @@ static const rapidjson::Value kNullValue;
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsBool()) {
@@ -50,9 +53,17 @@ 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)
bool xmrig::Json::isEmpty(const rapidjson::Value &obj)
{
assert(obj.IsObject());
return !obj.IsObject() || obj.ObjectEmpty();
}
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
{
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsString()) {
@@ -65,7 +76,9 @@ const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key,
const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsArray()) {
@@ -78,7 +91,9 @@ const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const
const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsObject()) {
@@ -91,7 +106,9 @@ const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, cons
const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd()) {
@@ -104,7 +121,9 @@ const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const
int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt()) {
@@ -117,7 +136,9 @@ int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaul
int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt64()) {
@@ -130,7 +151,9 @@ int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int6
uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint64()) {
@@ -143,7 +166,9 @@ uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, ui
unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint()) {
@@ -154,7 +179,50 @@ 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::Json::convertOffset(std::istream &ifs, size_t offset, size_t &line, size_t &pos, std::vector<std::string> &s)
{
std::string prev_t;
std::string t;
line = 0;
pos = 0;
size_t k = 0;
while (!ifs.eof()) {
prev_t = t;
std::getline(ifs, t);
k += t.length() + 1;
++line;
if (k > offset) {
pos = offset + t.length() + 1 - k + 1;
s.clear();
if (!prev_t.empty()) {
s.emplace_back(prev_t);
}
s.emplace_back(t);
return true;
}
}
return false;
}
bool xmrig::JsonReader::isEmpty() const
{
return !m_obj.IsObject() || m_obj.ObjectEmpty();
return Json::isEmpty(m_obj);
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,8 +26,13 @@
#define XMRIG_JSON_H
#include "3rdparty/rapidjson/fwd.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "rapidjson/fwd.h"
#include <string>
#include <vector>
#include <fstream>
namespace xmrig {
@@ -37,6 +42,7 @@ class Json
{
public:
static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false);
static bool isEmpty(const rapidjson::Value &obj);
static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr);
static const rapidjson::Value &getArray(const rapidjson::Value &obj, const char *key);
static const rapidjson::Value &getObject(const rapidjson::Value &obj, const char *key);
@@ -48,6 +54,12 @@ public:
static bool get(const char *fileName, rapidjson::Document &doc);
static bool save(const char *fileName, const rapidjson::Document &doc);
static bool convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector<std::string> &s);
static rapidjson::Value normalize(double value, bool zero);
private:
static bool convertOffset(std::istream &ifs, size_t offset, size_t &line, size_t &pos, std::vector<std::string> &s);
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,10 +23,10 @@
*/
#include "base/io/json/Json.h"
#include "base/io/json/JsonChain.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "rapidjson/error/en.h"
namespace xmrig {
@@ -64,7 +64,27 @@ bool xmrig::JsonChain::addFile(const char *fileName)
}
if (doc.HasParseError()) {
LOG_ERR("%s<offset:%zu>: \"%s\"", fileName, doc.GetErrorOffset(), GetParseError_En(doc.GetParseError()));
const size_t offset = doc.GetErrorOffset();
size_t line, pos;
std::vector<std::string> s;
if (Json::convertOffset(fileName, offset, line, pos, s)) {
for (const auto& t : s) {
LOG_ERR("%s", t.c_str());
}
std::string t;
if (pos > 0) {
t.assign(pos - 1, ' ');
}
t += '^';
LOG_ERR("%s", t.c_str());
LOG_ERR("%s<line:%zu, position:%zu>: \"%s\"", fileName, line, pos, GetParseError_En(doc.GetParseError()));
}
else {
LOG_ERR("%s<offset:%zu>: \"%s\"", fileName, offset, GetParseError_En(doc.GetParseError()));
}
}
else {
LOG_ERR("unable to open \"%s\".", fileName);

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -29,9 +29,9 @@
#include <vector>
#include "3rdparty/rapidjson/document.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "base/tools/String.h"
#include "rapidjson/document.h"
namespace xmrig {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,15 +24,43 @@
#include "base/io/json/JsonRequest.h"
#include "rapidjson/document.h"
#include "3rdparty/rapidjson/document.h"
namespace xmrig {
static const char *k2_0 = "2.0";
static const char *kId = "id";
static const char *kJsonRPC = "jsonrpc";
static const char *kMethod = "method";
const char *JsonRequest::kParams = "params";
} // namespace xmrig
rapidjson::Document xmrig::JsonRequest::create(int64_t id, const char *method)
{
using namespace rapidjson;
Document doc(kObjectType);
auto &allocator = doc.GetAllocator();
doc.AddMember(StringRef(kId), id, allocator);
doc.AddMember(StringRef(kJsonRPC), StringRef(k2_0), allocator);
doc.AddMember(StringRef(kMethod), StringRef(method), allocator);
return doc;
}
void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value &params)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
doc.AddMember("id", id, allocator);
doc.AddMember("jsonrpc", "2.0", allocator);
doc.AddMember("method", rapidjson::StringRef(method), allocator);
doc.AddMember("params", params, allocator);
doc.AddMember(StringRef(kId), id, allocator);
doc.AddMember(StringRef(kJsonRPC), StringRef(k2_0), allocator);
doc.AddMember(StringRef(kMethod), StringRef(method), allocator);
doc.AddMember(StringRef(kParams), params, allocator);
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_JSONREQUEST_H
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {
@@ -35,6 +35,9 @@ namespace xmrig {
class JsonRequest
{
public:
static const char *kParams;
static rapidjson::Document create(int64_t id, const char *method);
static void create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value &params);
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -27,10 +27,10 @@
#include "base/io/json/Json.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/prettywriter.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/istreamwrapper.h"
#include "3rdparty/rapidjson/ostreamwrapper.h"
#include "3rdparty/rapidjson/prettywriter.h"
bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc)
@@ -62,3 +62,14 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
return true;
}
bool xmrig::Json::convertOffset(const char* fileName, size_t offset, size_t& line, size_t& pos, std::vector<std::string>& s)
{
std::ifstream ifs(fileName, std::ios_base::in | std::ios_base::binary);
if (!ifs.is_open()) {
return false;
}
return convertOffset(ifs, offset, line, pos, s);
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -37,10 +37,13 @@
#include "base/io/json/Json.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/prettywriter.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/istreamwrapper.h"
#include "3rdparty/rapidjson/ostreamwrapper.h"
#include "3rdparty/rapidjson/prettywriter.h"
namespace xmrig {
#if defined(_MSC_VER) || defined (__GNUC__)
@@ -60,31 +63,36 @@ static std::wstring toUtf16(const char *str)
#endif
#if defined(_MSC_VER)
# define OPEN_IFS(name) \
std::ifstream ifs(toUtf16(name), std::ios_base::in | std::ios_base::binary); \
if (!ifs.is_open()) { \
return false; \
}
#elif defined(__GNUC__)
# define OPEN_IFS(name) \
const int fd = _wopen(toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \
if (fd == -1) { \
return false; \
} \
__gnu_cxx::stdio_filebuf<char> buf(fd, std::ios_base::in | std::ios_base::binary); \
std::istream ifs(&buf);
#else
# define OPEN_IFS(name) \
std::ifstream ifs(name, std::ios_base::in | std::ios_base::binary); \
if (!ifs.is_open()) { \
return false; \
}
#endif
} // namespace xmrig
bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc)
{
OPEN_IFS(fileName)
using namespace rapidjson;
constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary;
# if defined(_MSC_VER)
std::ifstream ifs(toUtf16(fileName), mode);
if (!ifs.is_open()) {
return false;
}
# elif defined(__GNUC__)
const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY);
if (fd == -1) {
return false;
}
__gnu_cxx::stdio_filebuf<char> buf(fd, mode);
std::istream ifs(&buf);
# else
std::ifstream ifs(fileName, mode);
if (!ifs.is_open()) {
return false;
}
# endif
IStreamWrapper isw(ifs);
doc.ParseStream<kParseCommentsFlag | kParseTrailingCommasFlag>(isw);
@@ -125,3 +133,11 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
return true;
}
bool xmrig::Json::convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector<std::string> &s)
{
OPEN_IFS(fileName)
return convertOffset(ifs, offset, line, pos, s);
}

View File

@@ -0,0 +1,94 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/io/log/FileLogWriter.h"
#include "base/io/Env.h"
#include <cassert>
#include <uv.h>
namespace xmrig {
static void fsWriteCallback(uv_fs_t *req)
{
delete [] static_cast<char *>(req->data);
uv_fs_req_cleanup(req);
delete req;
}
static const char *kNewLine = "\n";
} // namespace xmrig
bool xmrig::FileLogWriter::open(const char *fileName)
{
assert(fileName != nullptr);
if (!fileName) {
return false;
}
uv_fs_t req;
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);
return isOpen();
}
bool xmrig::FileLogWriter::write(const char *data, size_t size)
{
if (!isOpen()) {
return false;
}
uv_buf_t buf = uv_buf_init(new char[size], size);
memcpy(buf.base, data, size);
auto req = new uv_fs_t;
req->data = buf.base;
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, fsWriteCallback);
return true;
}
bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
{
uv_buf_t buf[2] = {
uv_buf_init(new char[size], size),
uv_buf_init(const_cast<char *>(kNewLine), 1)
};
memcpy(buf[0].base, data, size);
auto req = new uv_fs_t;
req->data = buf[0].base;
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, -1, fsWriteCallback);
return true;
}

View File

@@ -0,0 +1,49 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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_FILELOGWRITER_H
#define XMRIG_FILELOGWRITER_H
#include <cstddef>
namespace xmrig {
class FileLogWriter
{
public:
FileLogWriter() = default;
FileLogWriter(const char *fileName) { open(fileName); }
inline bool isOpen() const { return m_file >= 0; }
bool open(const char *fileName);
bool write(const char *data, size_t size);
bool writeLine(const char *data, size_t size);
private:
int m_file = -1;
};
} /* namespace xmrig */
#endif /* XMRIG_FILELOGWRITER_H */

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -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;
}
@@ -189,15 +189,16 @@ private:
}
char m_buf[4096]{};
char m_buf[Log::kMaxBufferSize]{};
std::mutex m_mutex;
std::vector<ILogBackend*> m_backends;
};
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

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -27,6 +27,10 @@
#define XMRIG_LOG_H
#include <cstddef>
#include <cstdint>
namespace xmrig {
@@ -49,15 +53,26 @@ public:
DEBUG, // debug-level messages
};
constexpr static size_t kMaxBufferSize = 16384;
static void add(ILogBackend *backend);
static void destroy();
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 +98,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 +125,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 +134,16 @@ 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::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_VV(x, ...) if (xmrig::Log::verbose() > 1) { 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

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,44 +24,26 @@
*/
#include <string.h>
#include <uv.h>
#include "base/io/log/backends/FileLog.h"
xmrig::FileLog::FileLog(const char *fileName)
#include <cassert>
#include <cstring>
xmrig::FileLog::FileLog(const char *fileName) :
m_writer(fileName)
{
uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
uv_fs_req_cleanup(&req);
}
void xmrig::FileLog::print(int, const char *line, size_t, size_t size, bool colors)
{
if (m_file < 0 || colors) {
if (!m_writer.isOpen() || colors) {
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;
req->data = buf.base;
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite);
}
void xmrig::FileLog::onWrite(uv_fs_t *req)
{
delete [] static_cast<char *>(req->data);
uv_fs_req_cleanup(req);
delete req;
m_writer.write(line, size);
}

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Spudz76 <https://github.com/Spudz76>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -27,9 +27,7 @@
#define XMRIG_FILELOG_H
typedef struct uv_fs_s uv_fs_t;
#include "base/io/log/FileLogWriter.h"
#include "base/kernel/interfaces/ILogBackend.h"
@@ -41,14 +39,11 @@ class FileLog : public ILogBackend
public:
FileLog(const char *fileName);
protected:
void print(int level, const char *line, size_t offset, size_t size, bool colors) override;
private:
static void onWrite(uv_fs_t *req);
int m_file;
FileLogWriter m_writer;
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -27,16 +27,17 @@
#include <memory>
#include "base/kernel/Base.h"
#include "base/io/json/Json.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/backends/ConsoleLog.h"
#include "base/io/log/backends/FileLog.h"
#include "base/io/log/Log.h"
#include "base/io/Watcher.h"
#include "base/kernel/Base.h"
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/Platform.h"
#include "base/kernel/Process.h"
#include "base/net/tools/NetBuffer.h"
#include "core/config/Config.h"
#include "core/config/ConfigTransform.h"
@@ -84,6 +85,8 @@ public:
delete config;
delete watcher;
NetBuffer::destroy();
}
@@ -127,7 +130,7 @@ private:
return config.release();
}
chain.addFile(process->location(Process::ExeLocation, "config.json"));
chain.addFile(Process::location(Process::DataLocation, "config.json"));
if (read(chain, config)) {
return config.release();
@@ -176,12 +179,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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,11 +26,11 @@
#define XMRIG_BASE_H
#include "3rdparty/rapidjson/fwd.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/tools/Object.h"
#include "rapidjson/fwd.h"
namespace xmrig {

View File

@@ -79,10 +79,14 @@ static int showVersion()
printf("\nlibuv/%s\n", uv_version_string());
# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT)
# if defined(XMRIG_FEATURE_TLS)
{
# if defined(LIBRESSL_VERSION_TEXT)
printf("LibreSSL/%s\n", LIBRESSL_VERSION_TEXT + 9);
# elif defined(OPENSSL_VERSION_TEXT)
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
# endif
}
# endif
@@ -101,9 +105,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);

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -48,9 +48,7 @@ public:
}
static bool setThreadAffinity(uint64_t cpu_id);
static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent);
static void restoreTimerResolution();
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);

View File

@@ -6,8 +6,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -30,6 +30,7 @@
#include <hwloc.h>
#include <thread>
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
@@ -42,8 +43,11 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
}
if (hwloc_set_cpubind(cpu->topology(), pu->cpuset, HWLOC_CPUBIND_THREAD | HWLOC_CPUBIND_STRICT) >= 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return true;
}
return hwloc_set_cpubind(cpu->topology(), pu->cpuset, HWLOC_CPUBIND_THREAD) >= 0;
const bool result = (hwloc_set_cpubind(cpu->topology(), pu->cpuset, HWLOC_CPUBIND_THREAD) >= 0);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,15 +28,12 @@
#include <stdlib.h>
#include <sys/resource.h>
#include <uv.h>
#include <thread>
#include "base/kernel/Platform.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
char *xmrig::Platform::createUserAgent()
{
@@ -45,11 +42,6 @@ char *xmrig::Platform::createUserAgent()
char *buf = new char[max]();
int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string());
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
@@ -67,23 +59,14 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
thread_affinity_policy_data_t policy = { static_cast<integer_t>(cpu_id) };
mach_thread = pthread_mach_thread_np(pthread_self());
return thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1) == KERN_SUCCESS;
const bool result = (thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1) == KERN_SUCCESS);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}
#endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void xmrig::Platform::restoreTimerResolution()
{
}
void xmrig::Platform::setProcessPriority(int priority)
void xmrig::Platform::setProcessPriority(int)
{
}

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -37,15 +37,12 @@
#include <sys/resource.h>
#include <unistd.h>
#include <uv.h>
#include <thread>
#include "base/kernel/Platform.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
#ifdef __FreeBSD__
typedef cpuset_t cpu_set_t;
@@ -69,11 +66,6 @@ char *xmrig::Platform::createUserAgent()
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__)
@@ -92,26 +84,18 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
CPU_SET(cpu_id, &mn);
# ifndef __ANDROID__
return pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mn) == 0;
const bool result = (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mn) == 0);
# else
return sched_setaffinity(gettid(), sizeof(cpu_set_t), &mn) == 0;
const bool result = (sched_setaffinity(gettid(), sizeof(cpu_set_t), &mn) == 0);
# endif
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}
#endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void xmrig::Platform::restoreTimerResolution()
{
}
void xmrig::Platform::setProcessPriority(int priority)
void xmrig::Platform::setProcessPriority(int)
{
}

View File

@@ -4,9 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -30,23 +29,12 @@
#include "base/kernel/Platform.h"
#include "base/io/log/Log.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
#ifdef XMRIG_AMD_PROJECT
static uint32_t timerResolution = 0;
#endif
static inline OSVERSIONINFOEX winOsVersion()
{
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
using RtlGetVersionFunction = NTSTATUS (*)(LPOSVERSIONINFO);
OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
@@ -76,11 +64,6 @@ char *xmrig::Platform::createUserAgent()
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
# endif
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif _MSC_VER
@@ -94,43 +77,13 @@ char *xmrig::Platform::createUserAgent()
#ifndef XMRIG_FEATURE_HWLOC
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
if (cpu_id >= 64) {
LOG_ERR("Unable to set affinity. Windows supports only affinity up to 63.");
}
return SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0;
const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0);
Sleep(1);
return result;
}
#endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
# ifdef XMRIG_AMD_PROJECT
TIMECAPS tc;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
return 0;
}
timerResolution = std::min<uint32_t>(std::max<uint32_t>(tc.wPeriodMin, resolution), tc.wPeriodMax);
return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0;
# else
return resolution;
# endif
}
void xmrig::Platform::restoreTimerResolution()
{
# ifdef XMRIG_AMD_PROJECT
if (timerResolution) {
timeEndPeriod(timerResolution);
}
# endif
}
void xmrig::Platform::setProcessPriority(int priority)
{
if (priority == -1) {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,6 +24,7 @@
#include <ctime>
#include <string>
#include <uv.h>
@@ -31,67 +32,127 @@
#include "base/tools/Chrono.h"
static size_t location(xmrig::Process::Location location, char *buf, size_t max)
{
using namespace xmrig;
namespace xmrig {
static char pathBuf[520];
static std::string dataDir;
static std::string getPath(Process::Location location)
{
size_t size = sizeof(pathBuf);
if (location == Process::DataLocation) {
if (!dataDir.empty()) {
return dataDir;
}
location = Process::ExeLocation;
}
if (location == Process::HomeLocation) {
# if UV_VERSION_HEX >= 0x010600
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
if (location == Process::TempLocation) {
# if UV_VERSION_HEX >= 0x010900
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
size_t size = max;
if (location == Process::ExeLocation) {
return uv_exepath(buf, &size) < 0 ? 0 : size;
if (uv_exepath(pathBuf, &size) < 0) {
return {};
}
const auto path = std::string(pathBuf, size);
const auto pos = path.rfind(Process::kDirSeparator);
if (pos != std::string::npos) {
return path.substr(0, pos);
}
return path;
}
if (location == Process::CwdLocation) {
return uv_cwd(buf, &size) < 0 ? 0 : size;
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
}
return 0;
return {};
}
static void setDataDir(const char *path)
{
if (path == nullptr) {
return;
}
std::string dir = path;
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
dir.pop_back();
}
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
dataDir = dir;
}
}
} // namespace xmrig
xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
setDataDir(m_arguments.value("--data-dir", "-d"));
}
xmrig::String xmrig::Process::location(Location location, const char *fileName) const
int xmrig::Process::pid()
{
constexpr const size_t max = 520;
char *buf = new char[max]();
size_t size = ::location(location, buf, max);
if (size == 0) {
delete [] buf;
return String();
}
if (fileName == nullptr) {
return buf;
}
if (location == ExeLocation) {
char *p = strrchr(buf, kDirSeparator);
if (p == nullptr) {
delete [] buf;
return String();
}
size = static_cast<size_t>(p - buf);
}
if ((size + strlen(fileName) + 2) >= max) {
delete [] buf;
return String();
}
buf[size] = kDirSeparator;
strcpy(buf + size + 1, fileName);
return buf;
# if UV_VERSION_HEX >= 0x011200
return uv_os_getpid();
# else
return 0;
# endif
}
int xmrig::Process::ppid()
{
# if UV_VERSION_HEX >= 0x011000
return uv_os_getppid();
# else
return 0;
# endif
}
xmrig::String xmrig::Process::exepath()
{
size_t size = sizeof(pathBuf);
return uv_exepath(pathBuf, &size) < 0 ? "" : String(pathBuf, size);
}
xmrig::String xmrig::Process::location(Location location, const char *fileName)
{
auto path = getPath(location);
if (path.empty() || fileName == nullptr) {
return path.c_str();
}
return (path + kDirSeparator + fileName).c_str();
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -37,7 +37,10 @@ class Process
public:
enum Location {
ExeLocation,
CwdLocation
CwdLocation,
DataLocation,
HomeLocation,
TempLocation
};
# ifdef WIN32
@@ -48,7 +51,10 @@ public:
Process(int argc, char **argv);
String location(Location location, const char *fileName = nullptr) const;
static int pid();
static int ppid();
static String exepath();
static String location(Location location, const char *fileName = nullptr);
inline const Arguments &arguments() const { return m_arguments; }

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,10 +23,19 @@
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "base/kernel/config/BaseConfig.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "version.h"
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <uv.h>
@@ -38,84 +47,32 @@
# include "backend/cpu/Cpu.h"
#endif
#ifdef XMRIG_AMD_PROJECT
# if defined(__APPLE__)
# include <OpenCL/cl.h>
# else
# include "3rdparty/CL/cl.h"
# endif
namespace xmrig {
const char *BaseConfig::kApi = "api";
const char *BaseConfig::kApiId = "id";
const char *BaseConfig::kApiWorkerId = "worker-id";
const char *BaseConfig::kAutosave = "autosave";
const char *BaseConfig::kBackground = "background";
const char *BaseConfig::kColors = "colors";
const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
#ifdef XMRIG_FEATURE_TLS
const char *BaseConfig::kTls = "tls";
#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());
}
} // namespace xmrig
bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
@@ -126,25 +83,29 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
return false;
}
m_autoSave = reader.getBool("autosave", m_autoSave);
m_background = reader.getBool("background", m_background);
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");
m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
setPrintTime(reader.getUint("print-time", 60));
# ifdef XMRIG_FEATURE_TLS
m_tls = reader.getValue(kTls);
# endif
const rapidjson::Value &api = reader.getObject("api");
Log::setColors(reader.getBool(kColors, Log::isColors()));
setVerbose(reader.getValue(kVerbose));
const auto &api = reader.getObject(kApi);
if (api.IsObject()) {
m_apiId = Json::getString(api, "id");
m_apiWorkerId = Json::getString(api, "worker-id");
m_apiId = Json::getString(api, kApiId);
m_apiWorkerId = Json::getString(api, kApiWorkerId);
}
m_http.load(reader.getObject("http"));
m_http.load(reader.getObject(kHttp));
m_pools.load(reader);
return m_pools.active() > 0;
@@ -167,3 +128,51 @@ 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)
{
# if defined(LIBRESSL_VERSION_TEXT)
snprintf(buf, sizeof buf, "LibreSSL/%s ", LIBRESSL_VERSION_TEXT + 9);
libs += buf;
# elif 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
}
# 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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -31,7 +31,9 @@
#include "base/net/stratum/Pools.h"
struct option;
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
namespace xmrig {
@@ -43,23 +45,46 @@ class IJsonReader;
class BaseConfig : public IConfig
{
public:
BaseConfig();
static const char *kApi;
static const char *kApiId;
static const char *kApiWorkerId;
static const char *kAutosave;
static const char *kBackground;
static const char *kColors;
static const char *kDryRun;
static const char *kHttp;
static const char *kLogFile;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const Http &http() const { return m_http; }
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline uint32_t printTime() const { return m_printTime; }
# ifdef XMRIG_FEATURE_TLS
static const char *kTls;
# endif
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const String &fileName() const override { return m_fileName; }
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const Http &http() const { return m_http; }
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline uint32_t printTime() const { return m_printTime; }
# ifdef XMRIG_FEATURE_TLS
inline const TlsConfig &tls() const { return m_tls; }
# endif
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const String &fileName() const override { return m_fileName; }
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
bool read(const IJsonReader &reader, const char *fileName) override;
bool save() override;
@@ -81,10 +106,13 @@ protected:
String m_logFile;
String m_userAgent;
uint32_t m_printTime = 60;
uint32_t m_version = 0;
# ifdef XMRIG_FEATURE_TLS
TlsConfig m_tls;
# endif
private:
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }
void setVerbose(const rapidjson::Value &value);
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -33,25 +33,20 @@
#endif
#include "base/kernel/config/BaseTransform.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/Log.h"
#include "base/kernel/config/BaseTransform.h"
#include "base/kernel/config/BaseConfig.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/kernel/Process.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/Config_platform.h"
namespace xmrig
{
static const char *kAlgo = "algo";
static const char *kApi = "api";
static const char *kCoin = "coin";
static const char *kHttp = "http";
static const char *kPools = "pools";
} // namespace xmrig
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
@@ -95,26 +90,26 @@ void xmrig::BaseTransform::finalize(rapidjson::Document &doc)
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
if (m_algorithm.isValid() && doc.HasMember(kPools)) {
auto &pools = doc[kPools];
if (m_algorithm.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kAlgo)) {
pool.AddMember(StringRef(kAlgo), m_algorithm.toJSON(), allocator);
if (!pool.HasMember(Pool::kAlgo)) {
pool.AddMember(StringRef(Pool::kAlgo), m_algorithm.toJSON(), allocator);
}
}
}
if (m_coin.isValid() && doc.HasMember(kPools)) {
auto &pools = doc[kPools];
if (m_coin.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kCoin)) {
pool.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator);
if (!pool.HasMember(Pool::kCoin)) {
pool.AddMember(StringRef(Pool::kCoin), m_coin.toJSON(), allocator);
}
}
}
if (m_http) {
set(doc, kHttp, "enabled", true);
set(doc, BaseConfig::kHttp, Http::kEnabled, true);
}
}
@@ -123,20 +118,20 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
{
switch (key) {
case IConfig::AlgorithmKey: /* --algo */
if (!doc.HasMember(kPools)) {
if (!doc.HasMember(Pools::kPools)) {
m_algorithm = arg;
}
else {
return add(doc, kPools, kAlgo, arg);
return add(doc, Pools::kPools, Pool::kAlgo, arg);
}
break;
case IConfig::CoinKey: /* --coin */
if (!doc.HasMember(kPools)) {
if (!doc.HasMember(Pools::kPools)) {
m_coin = arg;
}
else {
return add(doc, kPools, kCoin, arg);
return add(doc, Pools::kPools, Pool::kCoin, arg);
}
break;
@@ -150,61 +145,87 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
char *user = new char[p - arg + 1]();
strncpy(user, arg, static_cast<size_t>(p - arg));
add<const char *>(doc, kPools, "user", user);
add(doc, kPools, "pass", p + 1);
add<const char *>(doc, Pools::kPools, Pool::kUser, user);
add(doc, Pools::kPools, Pool::kPass, p + 1);
delete [] user;
}
break;
case IConfig::UrlKey: /* --url */
{
if (!doc.HasMember(kPools)) {
doc.AddMember(rapidjson::StringRef(kPools), rapidjson::kArrayType, doc.GetAllocator());
if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
}
rapidjson::Value &array = doc[kPools];
rapidjson::Value &array = doc[Pools::kPools];
if (array.Size() == 0 || Pool(array[array.Size() - 1]).isValid()) {
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
}
set(doc, array[array.Size() - 1], "url", arg);
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
break;
}
case IConfig::UserKey: /* --user */
return add(doc, kPools, "user", arg);
return add(doc, Pools::kPools, Pool::kUser, arg);
case IConfig::PasswordKey: /* --pass */
return add(doc, kPools, "pass", arg);
return add(doc, Pools::kPools, Pool::kPass, arg);
case IConfig::RigIdKey: /* --rig-id */
return add(doc, kPools, "rig-id", arg);
return add(doc, Pools::kPools, Pool::kRigId, arg);
case IConfig::FingerprintKey: /* --tls-fingerprint */
return add(doc, kPools, "tls-fingerprint", arg);
return add(doc, Pools::kPools, Pool::kFingerprint, arg);
case IConfig::SelfSelectKey: /* --self-select */
return add(doc, kPools, "self-select", arg);
return add(doc, Pools::kPools, Pool::kSelfSelect, arg);
case IConfig::ProxyKey: /* --proxy */
return add(doc, Pools::kPools, Pool::kSOCKS5, arg);
case IConfig::LogFileKey: /* --log-file */
return set(doc, "log-file", arg);
return set(doc, BaseConfig::kLogFile, arg);
case IConfig::HttpAccessTokenKey: /* --http-access-token */
m_http = true;
return set(doc, kHttp, "access-token", arg);
return set(doc, BaseConfig::kHttp, Http::kToken, arg);
case IConfig::HttpHostKey: /* --http-host */
m_http = true;
return set(doc, kHttp, "host", arg);
return set(doc, BaseConfig::kHttp, Http::kHost, arg);
case IConfig::ApiWorkerIdKey: /* --api-worker-id */
return set(doc, kApi, "worker-id", arg);
return set(doc, BaseConfig::kApi, BaseConfig::kApiWorkerId, arg);
case IConfig::ApiIdKey: /* --api-id */
return set(doc, kApi, "id", arg);
return set(doc, BaseConfig::kApi, BaseConfig::kApiId, arg);
case IConfig::UserAgentKey: /* --user-agent */
return set(doc, "user-agent", arg);
return set(doc, BaseConfig::kUserAgent, arg);
# ifdef XMRIG_FEATURE_TLS
case IConfig::TlsCertKey: /* --tls-cert */
return set(doc, BaseConfig::kTls, TlsConfig::kCert, arg);
case IConfig::TlsCertKeyKey: /* --tls-cert-key */
return set(doc, BaseConfig::kTls, TlsConfig::kCertKey, arg);
case IConfig::TlsDHparamKey: /* --tls-dhparam */
return set(doc, BaseConfig::kTls, TlsConfig::kDhparam, arg);
case IConfig::TlsCiphersKey: /* --tls-ciphers */
return set(doc, BaseConfig::kTls, TlsConfig::kCiphers, arg);
case IConfig::TlsCipherSuitesKey: /* --tls-ciphersuites */
return set(doc, BaseConfig::kTls, TlsConfig::kCipherSuites, arg);
case IConfig::TlsProtocolsKey: /* --tls-protocols */
return set(doc, BaseConfig::kTls, TlsConfig::kProtocols, arg);
case IConfig::TlsGenKey: /* --tls-gen */
return set(doc, BaseConfig::kTls, TlsConfig::kGen, arg);
# endif
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
@@ -222,6 +243,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 */
@@ -238,40 +260,43 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
{
switch (key) {
case IConfig::BackgroundKey: /* --background */
return set(doc, "background", enable);
return set(doc, BaseConfig::kBackground, enable);
case IConfig::SyslogKey: /* --syslog */
return set(doc, "syslog", enable);
return set(doc, BaseConfig::kSyslog, enable);
case IConfig::KeepAliveKey: /* --keepalive */
return add(doc, kPools, "keepalive", enable);
return add(doc, Pools::kPools, Pool::kKeepalive, enable);
case IConfig::TlsKey: /* --tls */
return add(doc, kPools, "tls", enable);
return add(doc, Pools::kPools, Pool::kTls, enable);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */
return add(doc, kPools, "daemon", enable);
return add(doc, Pools::kPools, Pool::kDaemon, enable);
# endif
# ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */
return add<bool>(doc, kPools, "nicehash", enable);
return add<bool>(doc, Pools::kPools, Pool::kNicehash, enable);
# endif
case IConfig::ColorKey: /* --no-color */
return set(doc, "colors", enable);
return set(doc, BaseConfig::kColors, enable);
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
m_http = true;
return set(doc, kHttp, "restricted", enable);
return set(doc, BaseConfig::kHttp, Http::kRestricted, enable);
case IConfig::HttpEnabledKey: /* --http-enabled */
m_http = true;
break;
case IConfig::DryRunKey: /* --dry-run */
return set(doc, "dry-run", enable);
return set(doc, BaseConfig::kDryRun, enable);
case IConfig::VerboseKey: /* --verbose */
return set(doc, BaseConfig::kVerbose, enable);
default:
break;
@@ -283,27 +308,27 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
{
switch (key) {
case IConfig::RetriesKey: /* --retries */
return set(doc, "retries", arg);
return set(doc, Pools::kRetries, arg);
case IConfig::RetryPauseKey: /* --retry-pause */
return set(doc, "retry-pause", arg);
return set(doc, Pools::kRetryPause, arg);
case IConfig::DonateLevelKey: /* --donate-level */
return set(doc, "donate-level", arg);
return set(doc, Pools::kDonateLevel, arg);
case IConfig::ProxyDonateKey: /* --donate-over-proxy */
return set(doc, "donate-over-proxy", arg);
return set(doc, Pools::kDonateOverProxy, arg);
case IConfig::HttpPort: /* --http-port */
m_http = true;
return set(doc, kHttp, "port", arg);
return set(doc, BaseConfig::kHttp, Http::kPort, arg);
case IConfig::PrintTimeKey: /* --print-time */
return set(doc, "print-time", arg);
return set(doc, BaseConfig::kPrintTime, arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, kPools, "daemon-poll-interval", arg);
return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);
# endif
default:

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,9 +26,9 @@
#define XMRIG_BASETRANSFORM_H
#include "3rdparty/rapidjson/document.h"
#include "base/crypto/Coin.h"
#include "base/kernel/interfaces/IConfigTransform.h"
#include "crypto/common/Coin.h"
#include "rapidjson/document.h"
struct option;

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_ICLIENT_H
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
#include <functional>
@@ -39,6 +39,7 @@ class Algorithm;
class Job;
class JobResult;
class Pool;
class ProxyUrl;
class String;
@@ -79,6 +80,7 @@ public:
virtual void setAlgo(const Algorithm &algo) = 0;
virtual void setEnabled(bool enabled) = 0;
virtual void setPool(const Pool &pool) = 0;
virtual void setProxy(const ProxyUrl &proxy) = 0;
virtual void setQuiet(bool quiet) = 0;
virtual void setRetries(int retries) = 0;
virtual void setRetryPause(uint64_t ms) = 0;

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -29,7 +29,7 @@
#include <cstdint>
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,8 +26,7 @@
#define XMRIG_ICONFIG_H
#include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {
@@ -66,6 +65,7 @@ public:
UserAgentKey = 1008,
UserKey = 'u',
UserpassKey = 'O',
ProxyKey = 'x',
VerboseKey = 1100,
TlsKey = 1013,
FingerprintKey = 1014,
@@ -73,6 +73,7 @@ public:
DaemonKey = 1018,
DaemonPollKey = 1019,
SelfSelectKey = 1028,
DataDirKey = 1035,
// xmrig common
CPUPriorityKey = 1021,
@@ -89,8 +90,15 @@ public:
AssemblyKey = 1015,
RandomXInitKey = 1022,
RandomXNumaKey = 1023,
RandomXModeKey = 1029,
RandomX1GbPagesKey = 1031,
RandomXWrmsrKey = 1032,
RandomXRdmsrKey = 1033,
CPUMaxThreadsKey = 1026,
MemoryPoolKey = 1027,
YieldKey = 1030,
AstroBWTMaxSizeKey = 1034,
AstroBWTAVX2Key = 1036,
// xmrig amd
OclPlatformKey = 1400,
@@ -110,6 +118,7 @@ public:
AccessLogFileKey = 'A',
BindKey = 'b',
CustomDiffKey = 1102,
CustomDiffStatsKey = 1104,
DebugKey = 1101,
ModeKey = 'm',
PoolCoinKey = 'C',
@@ -123,8 +132,10 @@ public:
TlsCiphersKey = 1112,
TlsCipherSuitesKey = 1113,
TlsProtocolsKey = 1114,
TlsGenKey = 1117,
AlgoExtKey = 1115,
ProxyPasswordKey = 1116,
LoginFileKey = 'L',
// xmrig nvidia
CudaMaxThreadsKey = 1200,

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,8 +26,7 @@
#define XMRIG_ICONFIGTRANSFORM_H
#include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_IJSONREADER_H
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,19 +26,22 @@
#define XMRIG_ILINELISTENER_H
#include <stdint.h>
#include "base/tools/Object.h"
#include <cstdint>
namespace xmrig {
class String;
class ILineListener
{
public:
virtual ~ILineListener() = default;
XMRIG_DISABLE_COPY_MOVE(ILineListener)
ILineListener() = default;
virtual ~ILineListener() = default;
virtual void onLine(char *line, size_t size) = 0;
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_ISTRATEGY_H
#include <stdint.h>
#include <cstdint>
namespace xmrig {
@@ -35,6 +35,7 @@ namespace xmrig {
class Algorithm;
class IClient;
class JobResult;
class ProxyUrl;
class IStrategy
@@ -48,6 +49,7 @@ public:
virtual void connect() = 0;
virtual void resume() = 0;
virtual void setAlgo(const Algorithm &algo) = 0;
virtual void setProxy(const ProxyUrl &proxy) = 0;
virtual void stop() = 0;
virtual void tick(uint64_t now) = 0;
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -26,7 +26,7 @@
#define XMRIG_ISTRATEGYLISTENER_H
#include "rapidjson/fwd.h"
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,9 +23,8 @@
*/
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/dns/Dns.h"
#include "base/tools/Handle.h"
#include "base/kernel/interfaces/IDnsListener.h"
namespace xmrig {
@@ -35,10 +34,7 @@ namespace xmrig {
xmrig::Dns::Dns(IDnsListener *listener) :
m_hints(),
m_listener(listener),
m_status(0),
m_resolver(nullptr)
m_listener(listener)
{
m_key = m_storage.add(this);
@@ -134,11 +130,11 @@ void xmrig::Dns::onResolved(int status, addrinfo *res)
addrinfo *ptr = res;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
m_ipv4.push_back(ptr);
m_ipv4.emplace_back(ptr);
}
if (ptr->ai_family == AF_INET6) {
m_ipv6.push_back(ptr);
m_ipv6.emplace_back(ptr);
}
ptr = ptr->ai_next;

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -32,6 +32,7 @@
#include "base/net/dns/DnsRecord.h"
#include "base/net/tools/Storage.h"
#include "base/tools/Object.h"
#include "base/tools/String.h"
@@ -44,6 +45,8 @@ class IDnsListener;
class Dns
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns)
Dns(IDnsListener *listener);
~Dns();
@@ -62,14 +65,14 @@ private:
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
addrinfo m_hints;
addrinfo m_hints{};
IDnsListener *m_listener;
int m_status;
int m_status = 0;
std::vector<DnsRecord> m_ipv4;
std::vector<DnsRecord> m_ipv6;
String m_host;
uintptr_t m_key;
uv_getaddrinfo_t *m_resolver;
uv_getaddrinfo_t *m_resolver = nullptr;
static Storage<Dns> m_storage;
};

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -50,13 +50,14 @@ xmrig::DnsRecord::DnsRecord(const addrinfo *addr) :
sockaddr *xmrig::DnsRecord::addr(uint16_t port) const
{
if (m_type == A) {
sockaddr_in *addr = new sockaddr_in();
auto addr = new sockaddr_in();
uv_ip4_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);
}
else if (m_type == AAAA) {
sockaddr_in6 *addr = new sockaddr_in6();
if (m_type == AAAA) {
auto addr = new sockaddr_in6();
uv_ip6_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -45,7 +45,7 @@ public:
AAAA
};
inline DnsRecord() : m_type(Unknown) {}
DnsRecord() {}
DnsRecord(const addrinfo *addr);
sockaddr *addr(uint16_t port = 0) const;
@@ -55,7 +55,7 @@ public:
inline Type type() const { return m_type; }
private:
Type m_type;
Type m_type = Unknown;
String m_ip;
};

122
src/base/net/http/Fetch.cpp Normal file
View File

@@ -0,0 +1,122 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/net/http/Fetch.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/stringbuffer.h"
#include "3rdparty/rapidjson/writer.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpClient.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/https/HttpsClient.h"
#endif
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
quiet(quiet),
tls(tls),
method(method),
host(host),
path(path),
port(port)
{
assert(port > 0);
setBody(data, size, contentType);
}
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
quiet(quiet),
tls(tls),
method(method),
host(host),
path(path),
port(port)
{
assert(port > 0);
setBody(value);
}
void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *contentType)
{
if (!data) {
return;
}
assert(method != HTTP_GET && method != HTTP_HEAD);
if (method == HTTP_GET || method == HTTP_HEAD) {
return;
}
body = size ? std::string(data, size) : data;
if (contentType) {
headers.insert({ HttpData::kContentType, contentType });
}
}
void xmrig::FetchRequest::setBody(const rapidjson::Value &value)
{
assert(method != HTTP_GET && method != HTTP_HEAD);
if (method == HTTP_GET || method == HTTP_HEAD) {
return;
}
using namespace rapidjson;
StringBuffer buffer(nullptr, 512);
Writer<StringBuffer> writer(buffer);
value.Accept(writer);
setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str());
}
void xmrig::fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type)
{
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
req.tls ? "s" : "", req.host.data(), req.port, http_method_str(req.method), req.path.data(), req.body.size());
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
}
# endif
HttpClient *client;
# ifdef XMRIG_FEATURE_TLS
if (req.tls) {
client = new HttpsClient(std::move(req), listener);
}
else
# endif
{
client = new HttpClient(std::move(req), listener);
}
client->userType = type;
client->connect();
}

71
src/base/net/http/Fetch.h Normal file
View File

@@ -0,0 +1,71 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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_FETCH_H
#define XMRIG_FETCH_H
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/String.h"
#include <map>
#include <memory>
#include <string>
namespace xmrig {
class IHttpListener;
class FetchRequest
{
public:
FetchRequest() = default;
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
void setBody(const char *data, size_t size, const char *contentType = nullptr);
void setBody(const rapidjson::Value &value);
inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); }
bool quiet = false;
bool tls = false;
http_method method = HTTP_GET;
std::map<const std::string, const std::string> headers;
std::string body;
String fingerprint;
String host;
String path;
uint16_t port = 0;
};
void fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type = 0);
} // namespace xmrig
#endif // XMRIG_FETCH_H

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -23,28 +23,27 @@
*/
#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 {
static const char *kEnabled = "enabled";
static const char *kHost = "host";
static const char *kLocalhost = "127.0.0.1";
static const char *kPort = "port";
static const char *kRestricted = "restricted";
static const char *kToken = "access-token";
const char *Http::kEnabled = "enabled";
const char *Http::kHost = "host";
const char *Http::kLocalhost = "127.0.0.1";
const char *Http::kPort = "port";
const char *Http::kRestricted = "restricted";
const char *Http::kToken = "access-token";
}
xmrig::Http::Http() :
m_enabled(false),
m_restricted(true),
m_host(kLocalhost),
m_port(0)
m_host(kLocalhost)
{
}

View File

@@ -5,8 +5,8 @@
* 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>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -36,9 +36,16 @@ namespace xmrig {
class Http
{
public:
static const char *kEnabled;
static const char *kHost;
static const char *kLocalhost;
static const char *kPort;
static const char *kRestricted;
static const char *kToken;
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 +65,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

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,10 +24,11 @@
*/
#include "3rdparty/http-parser/http_parser.h"
#include "base/net/http/HttpApiResponse.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/prettywriter.h"
#include "3rdparty/rapidjson/stringbuffer.h"
#include "base/net/http/HttpData.h"
namespace xmrig {
@@ -75,7 +76,7 @@ void xmrig::HttpApiResponse::end()
return HttpResponse::end();
}
setHeader("Content-Type", "application/json");
setHeader(HttpData::kContentType, HttpData::kApplicationJson);
StringBuffer buffer(nullptr, 4096);
PrettyWriter<StringBuffer> writer(buffer);

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,8 +28,8 @@
#define XMRIG_HTTPAPIRESPONSE_H
#include "3rdparty/rapidjson/document.h"
#include "base/net/http/HttpResponse.h"
#include "rapidjson/document.h"
namespace xmrig {

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,70 +24,35 @@
*/
#include <sstream>
#include "base/net/http/HttpClient.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/io/log/Log.h"
#include "base/kernel/Platform.h"
#include "base/net/dns/Dns.h"
#include "base/net/http/HttpClient.h"
#include "base/tools/Baton.h"
#include "base/net/tools/NetBuffer.h"
#include <sstream>
namespace xmrig {
static const char *kCRLF = "\r\n";
class ClientWriteBaton : public Baton<uv_write_t>
{
public:
inline ClientWriteBaton(const std::string &header, std::string &&body) :
m_body(std::move(body)),
m_header(header)
{
bufs[0].len = m_header.size();
bufs[0].base = const_cast<char *>(m_header.c_str());
if (!m_body.empty()) {
bufs[1].len = m_body.size();
bufs[1].base = const_cast<char *>(m_body.c_str());
}
else {
bufs[1].base = nullptr;
bufs[1].len = 0;
}
}
inline size_t count() const { return bufs[1].base == nullptr ? 1 : 2; }
inline size_t size() const { return bufs[0].len + bufs[1].len; }
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<ClientWriteBaton *>(req->data); }
uv_buf_t bufs[2];
private:
std::string m_body;
std::string m_header;
};
} // namespace xmrig
xmrig::HttpClient::HttpClient(int method, const String &url, IHttpListener *listener, const char *data, size_t size) :
HttpContext(HTTP_RESPONSE, listener)
xmrig::HttpClient::HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
HttpContext(HTTP_RESPONSE, listener),
m_req(std::move(req))
{
this->method = method;
this->url = url;
if (data) {
body = size ? std::string(data, size) : data;
}
m_dns = new Dns(this);
method = m_req.method;
url = std::move(m_req.path);
body = std::move(m_req.body);
headers = std::move(m_req.headers);
m_dns = new Dns(this);
}
@@ -97,17 +62,9 @@ xmrig::HttpClient::~HttpClient()
}
bool xmrig::HttpClient::connect(const String &host, uint16_t port)
bool xmrig::HttpClient::connect()
{
m_port = port;
return m_dns->resolve(host);
}
const xmrig::String &xmrig::HttpClient::host() const
{
return m_dns->host();
return m_dns->resolve(m_req.host);
}
@@ -116,25 +73,27 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status)
this->status = status;
if (status < 0 && dns.isEmpty()) {
if (!m_quiet) {
LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), m_port, uv_strerror(status));
if (!isQuiet()) {
LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), port(), uv_strerror(status));
}
return;
}
sockaddr *addr = dns.get().addr(m_port);
sockaddr *addr = dns.get().addr(port());
auto req = new uv_connect_t;
req->data = this;
uv_tcp_connect(req, m_tcp, addr, onConnect);
delete addr;
}
void xmrig::HttpClient::handshake()
{
headers.insert({ "Host", m_dns->host().data() });
headers.insert({ "Host", host() });
headers.insert({ "Connection", "close" });
headers.insert({ "User-Agent", Platform::userAgent() });
@@ -153,7 +112,8 @@ void xmrig::HttpClient::handshake()
headers.clear();
write(ss.str());
body.insert(0, ss.str());
write(std::move(body), false);
}
@@ -165,42 +125,24 @@ void xmrig::HttpClient::read(const char *data, size_t size)
}
void xmrig::HttpClient::write(const std::string &header)
{
auto baton = new ClientWriteBaton(header, std::move(body));
uv_write(&baton->req, stream(), baton->bufs, baton->count(), ClientWriteBaton::onWrite);
}
void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
{
auto client = static_cast<HttpClient *>(req->data);
delete req;
if (!client) {
delete req;
return;
}
if (status < 0) {
if (!client->m_quiet) {
LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->m_port, uv_strerror(status));
if (!client->isQuiet()) {
LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(status));
}
delete req;
client->close(status);
return;
return client->close(status);
}
uv_read_start(client->stream(),
[](uv_handle_t *, size_t suggested_size, uv_buf_t *buf)
{
buf->base = new char[suggested_size];
# ifdef _WIN32
buf->len = static_cast<unsigned int>(suggested_size);
# else
buf->len = suggested_size;
# endif
},
uv_read_start(client->stream(), NetBuffer::onAlloc,
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
{
auto client = static_cast<HttpClient*>(tcp->data);
@@ -208,14 +150,14 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
if (nread >= 0) {
client->read(buf->base, static_cast<size_t>(nread));
} else {
if (!client->m_quiet && nread != UV_EOF) {
LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->m_port, uv_strerror(static_cast<int>(nread)));
if (!client->isQuiet() && nread != UV_EOF) {
LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(static_cast<int>(nread)));
}
client->close(static_cast<int>(nread));
}
delete [] buf->base;
NetBuffer::release(buf);
});
client->handshake();

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,8 +28,9 @@
#define XMRIG_HTTPCLIENT_H
#include "base/net/http/HttpContext.h"
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/http/Fetch.h"
#include "base/net/http/HttpContext.h"
#include "base/tools/Object.h"
@@ -44,29 +45,29 @@ class HttpClient : public HttpContext, public IDnsListener
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpClient);
HttpClient(int method, const String &url, IHttpListener *listener, const char *data = nullptr, size_t size = 0);
HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
~HttpClient() override;
inline uint16_t port() const { return m_port; }
inline void setQuiet(bool quiet) { m_quiet = quiet; }
inline bool isQuiet() const { return m_req.quiet; }
inline const char *host() const override { return m_req.host; }
inline uint16_t port() const override { return m_req.port; }
bool connect(const String &host, uint16_t port);
const String &host() const;
bool connect();
protected:
void onResolved(const Dns &dns, int status) override;
virtual void handshake();
virtual void read(const char *data, size_t size);
virtual void write(const std::string &header);
bool m_quiet = false;
protected:
inline const FetchRequest &req() const { return m_req; }
private:
static void onConnect(uv_connect_t *req, int status);
Dns *m_dns;
uint16_t m_port = 0;
FetchRequest m_req;
};

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,27 +24,62 @@
*/
#include "base/net/http/HttpContext.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/tools/Baton.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;
class HttpWriteBaton : public Baton<uv_write_t>
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpWriteBaton)
inline HttpWriteBaton(std::string &&body, HttpContext *ctx) :
m_ctx(ctx),
m_body(std::move(body))
{
m_buf = uv_buf_init(&m_body.front(), m_body.size());
}
inline ~HttpWriteBaton()
{
if (m_ctx) {
m_ctx->close();
}
}
void write(uv_stream_t *stream)
{
uv_write(&req, stream, &m_buf, 1, [](uv_write_t *req, int) { delete reinterpret_cast<HttpWriteBaton *>(req->data); });
}
private:
HttpContext *m_ctx;
std::string m_body;
uv_buf_t m_buf{};
};
} // namespace xmrig
xmrig::HttpContext::HttpContext(int parser_type, IHttpListener *listener) :
xmrig::HttpContext::HttpContext(int parser_type, const std::weak_ptr<IHttpListener> &listener) :
HttpData(SEQUENCE++),
m_wasHeaderValue(false),
m_timestamp(Chrono::steadyMSecs()),
m_listener(listener)
{
storage[id()] = this;
@@ -72,6 +107,23 @@ xmrig::HttpContext::~HttpContext()
}
void xmrig::HttpContext::write(std::string &&data, bool close)
{
if (uv_is_writable(stream()) != 1) {
return;
}
auto baton = new HttpWriteBaton(std::move(data), close ? this : nullptr);
baton->write(stream());
}
bool xmrig::HttpContext::isRequest() const
{
return m_parser->type == HTTP_REQUEST;
}
size_t xmrig::HttpContext::parse(const char *data, size_t size)
{
return http_parser_execute(m_parser, &http_settings, data, size);
@@ -96,17 +148,22 @@ 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) {
auto listener = httpListener();
if (status < 0 && listener) {
this->status = status;
m_listener->onHttpData(*this);
listener->onHttpData(*this);
}
auto it = storage.find(id());
if (it != storage.end()) {
storage.erase(it);
}
storage.erase(id());
if (!uv_is_closing(handle())) {
uv_close(handle(), [](uv_handle_t *handle) -> void { delete reinterpret_cast<HttpContext*>(handle->data); });
@@ -126,7 +183,7 @@ xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id)
void xmrig::HttpContext::closeAll()
{
for (auto kv : storage) {
for (auto &kv : storage) {
if (!uv_is_closing(kv.second->handle())) {
uv_close(kv.second->handle(), [](uv_handle_t *handle) -> void { delete reinterpret_cast<HttpContext*>(handle->data); });
}
@@ -208,9 +265,13 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
settings->on_message_complete = [](http_parser *parser) -> int
{
auto ctx = static_cast<HttpContext*>(parser->data);
ctx->m_listener->onHttpData(*ctx);
ctx->m_listener = nullptr;
auto ctx = static_cast<HttpContext*>(parser->data);
auto listener = ctx->httpListener();
if (listener) {
listener->onHttpData(*ctx);
ctx->m_listener.reset();
}
return 0;
};

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -40,6 +40,9 @@ using uv_tcp_t = struct uv_tcp_s;
#include "base/tools/Object.h"
#include <memory>
namespace xmrig {
@@ -51,14 +54,23 @@ class HttpContext : public HttpData
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpContext)
HttpContext(int parser_type, IHttpListener *listener);
virtual ~HttpContext();
HttpContext(int parser_type, const std::weak_ptr<IHttpListener> &listener);
~HttpContext() override;
inline uv_stream_t *stream() const { return reinterpret_cast<uv_stream_t *>(m_tcp); }
inline uv_handle_t *handle() const { return reinterpret_cast<uv_handle_t *>(m_tcp); }
inline const char *host() const override { return nullptr; }
inline const char *tlsFingerprint() const override { return nullptr; }
inline const char *tlsVersion() const override { return nullptr; }
inline uint16_t port() const override { return 0; }
void write(std::string &&data, bool close) override;
bool isRequest() const override;
size_t parse(const char *data, size_t size);
std::string ip() const;
std::string ip() const override;
uint64_t elapsed() const;
void close(int status = 0);
static HttpContext *get(uint64_t id);
@@ -68,17 +80,20 @@ protected:
uv_tcp_t *m_tcp;
private:
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
static int onHeaderField(http_parser *parser, const char *at, size_t length);
static int onHeaderValue(http_parser *parser, const char *at, size_t length);
static void attach(http_parser_settings *settings);
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;
std::string m_lastHeaderValue;
std::weak_ptr<IHttpListener> m_listener;
};

View File

@@ -0,0 +1,44 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/net/http/HttpData.h"
namespace xmrig {
const std::string HttpData::kApplicationJson = "application/json";
const std::string HttpData::kContentType = "Content-Type";
const std::string HttpData::kContentTypeL = "content-type";
const std::string HttpData::kTextPlain = "text/plain";
} // namespace xmrig
bool xmrig::HttpData::isJSON() const
{
if (!headers.count(kContentTypeL)) {
return false;
}
auto &type = headers.at(kContentTypeL);
return type == kApplicationJson || type == kTextPlain;
}

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,6 +28,9 @@
#define XMRIG_HTTPDATA_H
#include "base/tools/Object.h"
#include <map>
#include <string>
@@ -38,12 +41,32 @@ namespace xmrig {
class HttpData
{
public:
inline HttpData(uint64_t id) : method(0), status(0), m_id(id) {}
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpData)
inline uint64_t id() const { return m_id; }
static const std::string kApplicationJson;
static const std::string kContentType;
static const std::string kContentTypeL;
static const std::string kTextPlain;
int method;
int status;
inline HttpData(uint64_t id) : m_id(id) {}
virtual ~HttpData() = default;
inline uint64_t id() const { return m_id; }
virtual bool isRequest() const = 0;
virtual const char *host() const = 0;
virtual const char *tlsFingerprint() const = 0;
virtual const char *tlsVersion() const = 0;
virtual std::string ip() const = 0;
virtual uint16_t port() const = 0;
virtual void write(std::string &&data, bool close) = 0;
bool isJSON() const;
int method = 0;
int status = 0;
int userType = 0;
std::map<const std::string, const std::string> headers;
std::string body;
std::string url;

View File

@@ -0,0 +1,41 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/net/http/HttpListener.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpData.h"
void xmrig::HttpListener::onHttpData(const HttpData &data)
{
# ifdef APP_DEBUG
if (!data.isRequest()) {
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast<int>(data.body.size()), data.body.c_str());
}
}
# endif
m_listener->onHttpData(data);
}

View File

@@ -1,11 +1,6 @@
/* 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>
*
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -21,17 +16,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROXY_UUID_H__
#define __PROXY_UUID_H__
#ifndef XMRIG_HTTPLISTENER_H
#define XMRIG_HTTPLISTENER_H
#include <stddef.h>
#include "base/kernel/interfaces/IHttpListener.h"
class Uuid
namespace xmrig {
class HttpListener : public IHttpListener
{
public:
static void create(char *out, size_t size);
inline HttpListener(IHttpListener *listener, const char *tag = nullptr) : m_tag(tag), m_listener(listener) {}
protected:
void onHttpData(const HttpData &data) override;
private:
const char *m_tag;
IHttpListener *m_listener;
};
#endif /* __PROXY_UUID_H__ */
} /* namespace xmrig */
#endif // XMRIG_HTTPLISTENER_H

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -24,68 +24,25 @@
*/
#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 <cinttypes>
#include <cstring>
#include <sstream>
#include <uv.h>
namespace xmrig {
static const char *kCRLF = "\r\n";
static const char *kUserAgent = "user-agent";
class WriteBaton : public Baton<uv_write_t>
{
public:
inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) :
m_ctx(ctx),
m_header(ss.str())
{
bufs[0].len = m_header.size();
bufs[0].base = const_cast<char *>(m_header.c_str());
if (data) {
bufs[1].len = size;
bufs[1].base = new char[size];
memcpy(bufs[1].base, data, size);
}
else {
bufs[1].base = nullptr;
bufs[1].len = 0;
}
}
inline ~WriteBaton()
{
if (count() == 2) {
delete [] bufs[1].base;
}
m_ctx->close();
}
inline size_t count() const { return bufs[1].base == nullptr ? 1 : 2; }
inline size_t size() const { return bufs[0].len + bufs[1].len; }
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<WriteBaton *>(req->data); }
uv_buf_t bufs[2];
private:
HttpContext *m_ctx;
std::string m_header;
};
} // namespace xmrig
@@ -98,7 +55,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 +86,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);
std::string body = data ? (ss.str() + std::string(data, size)) : ss.str();
# ifndef APP_DEBUG
if (statusCode() >= 400)
@@ -138,16 +95,17 @@ 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(),
body.size(),
ctx->elapsed(),
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
);
}
uv_write(&baton->req, ctx->stream(), baton->bufs, baton->count(), WriteBaton::onWrite);
ctx->write(std::move(body), true);
}

View File

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

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,14 +28,13 @@
#include <uv.h>
#include "3rdparty/http-parser/http_parser.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/net/http/HttpContext.h"
#include "base/net/http/HttpResponse.h"
#include "base/net/http/HttpServer.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/net/http/HttpContext.h"
#include "base/net/tools/NetBuffer.h"
xmrig::HttpServer::HttpServer(IHttpListener *listener) :
xmrig::HttpServer::HttpServer(const std::shared_ptr<IHttpListener> &listener) :
m_listener(listener)
{
}
@@ -49,27 +48,17 @@ 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(),
[](uv_handle_t *, size_t suggested_size, uv_buf_t *buf)
{
buf->base = new char[suggested_size];
# ifdef _WIN32
buf->len = static_cast<unsigned int>(suggested_size);
# else
buf->len = suggested_size;
# endif
},
uv_read_start(ctx->stream(), NetBuffer::onAlloc,
[](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();
@@ -78,6 +67,6 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
ctx->close();
}
delete [] buf->base;
NetBuffer::release(buf);
});
}

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -28,11 +28,15 @@
#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"
#include <memory>
namespace xmrig {
@@ -44,14 +48,16 @@ class IHttpListener;
class HttpServer : public ITcpServerListener
{
public:
HttpServer(IHttpListener *listener);
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpServer)
HttpServer(const std::shared_ptr<IHttpListener> &listener);
~HttpServer() override;
protected:
void onConnection(uv_stream_t *stream, uint16_t port) override;
private:
IHttpListener *m_listener;
std::weak_ptr<IHttpListener> m_listener;
};

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -29,8 +29,8 @@
#include <uv.h>
#include "base/net/https/HttpsClient.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpsClient.h"
#include "base/tools/Buffer.h"
@@ -39,12 +39,8 @@
#endif
xmrig::HttpsClient::HttpsClient(int method, const String &url, IHttpListener *listener, const char *data, size_t size, const String &fingerprint) :
HttpClient(method, url, listener, data, size),
m_ready(false),
m_buf(),
m_ssl(nullptr),
m_fp(fingerprint)
xmrig::HttpsClient::HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
HttpClient(std::move(req), listener)
{
m_ctx = SSL_CTX_new(SSLv23_method());
assert(m_ctx != nullptr);
@@ -53,8 +49,8 @@ xmrig::HttpsClient::HttpsClient(int method, const String &url, IHttpListener *li
return;
}
m_writeBio = BIO_new(BIO_s_mem());
m_readBio = BIO_new(BIO_s_mem());
m_write = BIO_new(BIO_s_mem());
m_read = BIO_new(BIO_s_mem());
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
}
@@ -71,13 +67,13 @@ xmrig::HttpsClient::~HttpsClient()
}
const char *xmrig::HttpsClient::fingerprint() const
const char *xmrig::HttpsClient::tlsFingerprint() const
{
return m_ready ? m_fingerprint : nullptr;
}
const char *xmrig::HttpsClient::version() const
const char *xmrig::HttpsClient::tlsVersion() const
{
return m_ready ? SSL_get_version(m_ssl) : nullptr;
}
@@ -93,24 +89,24 @@ void xmrig::HttpsClient::handshake()
}
SSL_set_connect_state(m_ssl);
SSL_set_bio(m_ssl, m_readBio, m_writeBio);
SSL_set_tlsext_host_name(m_ssl, host().data());
SSL_set_bio(m_ssl, m_read, m_write);
SSL_set_tlsext_host_name(m_ssl, host());
SSL_do_handshake(m_ssl);
flush();
flush(false);
}
void xmrig::HttpsClient::read(const char *data, size_t size)
{
BIO_write(m_readBio, data, size);
BIO_write(m_read, data, size);
if (!SSL_is_init_finished(m_ssl)) {
const int rc = SSL_connect(m_ssl);
if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) {
flush();
flush(false);
} else if (rc == 1) {
X509 *cert = SSL_get_peer_certificate(m_ssl);
if (!verify(cert)) {
@@ -127,19 +123,25 @@ void xmrig::HttpsClient::read(const char *data, size_t size)
return;
}
int bytes_read = 0;
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
HttpClient::read(m_buf, static_cast<size_t>(bytes_read));
static char buf[16384]{};
int rc = 0;
while ((rc = SSL_read(m_ssl, buf, sizeof(buf))) > 0) {
HttpClient::read(buf, static_cast<size_t>(rc));
}
if (rc == 0) {
close(UV_EOF);
}
}
void xmrig::HttpsClient::write(const std::string &header)
void xmrig::HttpsClient::write(std::string &&data, bool close)
{
SSL_write(m_ssl, (header + body).c_str(), header.size() + body.size());
body.clear();
const std::string body = std::move(data);
SSL_write(m_ssl, body.data(), body.size());
flush();
flush(close);
}
@@ -150,12 +152,12 @@ bool xmrig::HttpsClient::verify(X509 *cert)
}
if (!verifyFingerprint(cert)) {
if (!m_quiet) {
LOG_ERR("[%s:%d] Failed to verify server certificate fingerprint", host().data(), port());
if (!isQuiet()) {
LOG_ERR("[%s:%d] Failed to verify server certificate fingerprint", host(), port());
if (strlen(m_fingerprint) == 64 && !m_fp.isNull()) {
if (strlen(m_fingerprint) == 64 && !req().fingerprint.isNull()) {
LOG_ERR("\"%s\" was given", m_fingerprint);
LOG_ERR("\"%s\" was configured", m_fp.data());
LOG_ERR("\"%s\" was configured", req().fingerprint.data());
}
}
@@ -182,27 +184,21 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert)
Buffer::toHex(md, 32, m_fingerprint);
return m_fp.isNull() || strncasecmp(m_fingerprint, m_fp.data(), 64) == 0;
return req().fingerprint.isNull() || strncasecmp(m_fingerprint, req().fingerprint.data(), 64) == 0;
}
void xmrig::HttpsClient::flush()
void xmrig::HttpsClient::flush(bool close)
{
uv_buf_t buf;
buf.len = BIO_get_mem_data(m_writeBio, &buf.base);
if (buf.len == 0) {
if (uv_is_writable(stream()) != 1) {
return;
}
bool result = false;
if (uv_is_writable(stream())) {
result = uv_try_write(stream(), &buf, 1) == static_cast<int>(buf.len);
char *data = nullptr;
const size_t size = BIO_get_mem_data(m_write, &data);
std::string body(data, size);
if (!result) {
close(UV_EIO);
}
}
(void) BIO_reset(m_write);
(void) BIO_reset(m_writeBio);
HttpContext::write(std::move(body), close);
}

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@@ -46,30 +46,29 @@ class HttpsClient : public HttpClient
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsClient)
HttpsClient(int method, const String &url, IHttpListener *listener, const char *data, size_t size, const String &fingerprint);
HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
~HttpsClient() override;
const char *fingerprint() const;
const char *version() const;
const char *tlsFingerprint() const override;
const char *tlsVersion() const override;
protected:
void handshake() override;
void read(const char *data, size_t size) override;
void write(const std::string &header) override;
private:
void write(std::string &&data, bool close) override;
bool verify(X509 *cert);
bool verifyFingerprint(X509 *cert);
void flush();
void flush(bool close);
BIO *m_readBio;
BIO *m_writeBio;
bool m_ready;
char m_buf[1024 * 2];
char m_fingerprint[32 * 2 + 8];
SSL *m_ssl;
SSL_CTX *m_ctx;
String m_fp;
BIO *m_read = nullptr;
BIO *m_write = nullptr;
bool m_ready = false;
char m_fingerprint[32 * 2 + 8]{};
SSL *m_ssl = nullptr;
SSL_CTX *m_ctx = nullptr;
};

View File

@@ -0,0 +1,99 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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/net/https/HttpsContext.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/net/tls/TlsContext.h"
#include <openssl/bio.h>
#include <uv.h>
xmrig::HttpsContext::HttpsContext(TlsContext *tls, const std::weak_ptr<IHttpListener> &listener) :
HttpContext(HTTP_REQUEST, listener),
ServerTls(tls ? tls->ctx() : nullptr)
{
if (!tls) {
m_mode = TLS_OFF;
}
}
xmrig::HttpsContext::~HttpsContext() = default;
void xmrig::HttpsContext::append(char *data, size_t size)
{
if (m_mode == TLS_AUTO) {
m_mode = isTLS(data, size) ? TLS_ON : TLS_OFF;
}
if (m_mode == TLS_ON) {
read(data, size);
}
else {
parse(data, size);
}
}
bool xmrig::HttpsContext::write(BIO *bio)
{
if (uv_is_writable(stream()) != 1) {
return false;
}
char *data = nullptr;
const size_t size = BIO_get_mem_data(bio, &data);
std::string body(data, size);
(void) BIO_reset(bio);
HttpContext::write(std::move(body), m_close);
return true;
}
void xmrig::HttpsContext::parse(char *data, size_t size)
{
if (HttpContext::parse(data, size) < size) {
close();
}
}
void xmrig::HttpsContext::shutdown()
{
close();
}
void xmrig::HttpsContext::write(std::string &&data, bool close)
{
m_close = close;
if (m_mode == TLS_ON) {
send(data.data(), data.size());
}
else {
HttpContext::write(std::move(data), close);
}
}

Some files were not shown because too many files have changed in this diff Show More