├── .github └── workflows │ ├── deploy.yml │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── FindUV.cmake ├── OpenSSL.cmake ├── flags.cmake └── os.cmake ├── doc ├── CHANGELOG_OLD.md ├── STRATUM.md ├── STRATUM_EXT.md ├── gpg_keys │ └── xmrig.asc └── releases │ └── 5_0_0 │ ├── SHA256SUMS │ └── SHA256SUMS.sig ├── res ├── app.ico └── app.rc ├── scripts ├── build.openssl3.sh ├── build.uv.sh └── build_deps.sh └── src ├── 3rdparty ├── epee │ ├── LICENSE.txt │ ├── README.md │ └── span.h ├── fmt │ ├── LICENSE.rst │ ├── README.rst │ ├── chrono.h │ ├── color.h │ ├── compile.h │ ├── core.h │ ├── format-inl.h │ ├── format.cc │ ├── format.h │ ├── locale.h │ ├── os.cc │ ├── os.h │ ├── ostream.h │ ├── posix.h │ ├── printf.h │ └── ranges.h ├── getopt │ └── getopt.h ├── llhttp │ ├── LICENSE-MIT │ ├── README.md │ ├── api.c │ ├── api.h │ ├── http.c │ ├── llhttp.c │ └── llhttp.h └── rapidjson │ ├── allocators.h │ ├── cursorstreamwrapper.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ ├── en.h │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── fwd.h │ ├── internal │ ├── biginteger.h │ ├── clzll.h │ ├── diyfp.h │ ├── dtoa.h │ ├── ieee754.h │ ├── itoa.h │ ├── meta.h │ ├── pow10.h │ ├── regex.h │ ├── stack.h │ ├── strfunc.h │ ├── strtod.h │ └── swap.h │ ├── istreamwrapper.h │ ├── license.txt │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ ├── inttypes.h │ └── stdint.h │ ├── ostreamwrapper.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── readme.md │ ├── schema.h │ ├── stream.h │ ├── stringbuffer.h │ ├── uri.h │ └── writer.h ├── App.cpp ├── App.h ├── App_unix.cpp ├── App_win.cpp ├── Summary.cpp ├── Summary.h ├── api └── v1 │ ├── ApiRouter.cpp │ └── ApiRouter.h ├── base ├── api │ ├── Api.cpp │ ├── Api.h │ ├── Httpd.cpp │ ├── Httpd.h │ ├── interfaces │ │ ├── IApiListener.h │ │ └── IApiRequest.h │ └── requests │ │ ├── ApiRequest.cpp │ │ ├── ApiRequest.h │ │ ├── HttpApiRequest.cpp │ │ └── HttpApiRequest.h ├── base.cmake ├── crypto │ ├── Algorithm.cpp │ ├── Algorithm.h │ ├── Coin.cpp │ ├── Coin.h │ ├── keccak.cpp │ ├── keccak.h │ ├── sha3.cpp │ └── sha3.h ├── io │ ├── Async.cpp │ ├── Async.h │ ├── Console.cpp │ ├── Console.h │ ├── Env.cpp │ ├── Env.h │ ├── Signals.cpp │ ├── Signals.h │ ├── Watcher.cpp │ ├── Watcher.h │ ├── json │ │ ├── Json.cpp │ │ ├── Json.h │ │ ├── JsonChain.cpp │ │ ├── JsonChain.h │ │ ├── JsonRequest.cpp │ │ ├── JsonRequest.h │ │ ├── Json_unix.cpp │ │ └── Json_win.cpp │ └── log │ │ ├── FileLogWriter.cpp │ │ ├── FileLogWriter.h │ │ ├── Log.cpp │ │ ├── Log.h │ │ ├── Tags.cpp │ │ ├── Tags.h │ │ └── backends │ │ ├── ConsoleLog.cpp │ │ ├── ConsoleLog.h │ │ ├── FileLog.cpp │ │ ├── FileLog.h │ │ ├── SysLog.cpp │ │ └── SysLog.h ├── kernel │ ├── Base.cpp │ ├── Base.h │ ├── Entry.cpp │ ├── Entry.h │ ├── Platform.cpp │ ├── Platform.h │ ├── Platform_hwloc.cpp │ ├── Platform_mac.cpp │ ├── Platform_unix.cpp │ ├── Platform_win.cpp │ ├── Process.cpp │ ├── Process.h │ ├── Process_unix.cpp │ ├── Process_win.cpp │ ├── config │ │ ├── BaseConfig.cpp │ │ ├── BaseConfig.h │ │ ├── BaseTransform.cpp │ │ ├── BaseTransform.h │ │ ├── Title.cpp │ │ └── Title.h │ ├── constants.h │ └── interfaces │ │ ├── IAsyncListener.h │ │ ├── IBaseListener.h │ │ ├── IClient.h │ │ ├── IClientListener.h │ │ ├── IConfig.h │ │ ├── IConfigListener.h │ │ ├── IConfigTransform.h │ │ ├── IConsoleListener.h │ │ ├── IDnsBackend.h │ │ ├── IDnsListener.h │ │ ├── IHttpListener.h │ │ ├── IJsonReader.h │ │ ├── ILineListener.h │ │ ├── ILogBackend.h │ │ ├── ISignalListener.h │ │ ├── IStrategy.h │ │ ├── IStrategyListener.h │ │ ├── ITcpServerListener.h │ │ ├── ITimerListener.h │ │ └── IWatcherListener.h ├── net │ ├── dns │ │ ├── Dns.cpp │ │ ├── Dns.h │ │ ├── DnsConfig.cpp │ │ ├── DnsConfig.h │ │ ├── DnsRecord.cpp │ │ ├── DnsRecord.h │ │ ├── DnsRecords.cpp │ │ ├── DnsRecords.h │ │ ├── DnsRequest.h │ │ ├── DnsUvBackend.cpp │ │ └── DnsUvBackend.h │ ├── http │ │ ├── Fetch.cpp │ │ ├── Fetch.h │ │ ├── Http.cpp │ │ ├── Http.h │ │ ├── HttpApiResponse.cpp │ │ ├── HttpApiResponse.h │ │ ├── HttpClient.cpp │ │ ├── HttpClient.h │ │ ├── HttpContext.cpp │ │ ├── HttpContext.h │ │ ├── HttpData.cpp │ │ ├── HttpData.h │ │ ├── HttpListener.cpp │ │ ├── HttpListener.h │ │ ├── HttpResponse.cpp │ │ ├── HttpResponse.h │ │ ├── HttpServer.cpp │ │ └── HttpServer.h │ ├── https │ │ ├── HttpsClient.cpp │ │ ├── HttpsClient.h │ │ ├── HttpsContext.cpp │ │ ├── HttpsContext.h │ │ ├── HttpsServer.cpp │ │ └── HttpsServer.h │ ├── stratum │ │ ├── AlgoSwitch.cpp │ │ ├── AlgoSwitch.h │ │ ├── AutoClient.cpp │ │ ├── AutoClient.h │ │ ├── BaseClient.cpp │ │ ├── BaseClient.h │ │ ├── Client.cpp │ │ ├── Client.h │ │ ├── DaemonClient.cpp │ │ ├── DaemonClient.h │ │ ├── EthStratumClient.cpp │ │ ├── EthStratumClient.h │ │ ├── Job.cpp │ │ ├── Job.h │ │ ├── NetworkState.cpp │ │ ├── NetworkState.h │ │ ├── Pool.cpp │ │ ├── Pool.h │ │ ├── Pools.cpp │ │ ├── Pools.h │ │ ├── ProxyUrl.cpp │ │ ├── ProxyUrl.h │ │ ├── SelfSelectClient.cpp │ │ ├── SelfSelectClient.h │ │ ├── Socks5.cpp │ │ ├── Socks5.h │ │ ├── SubmitResult.h │ │ ├── Tls.cpp │ │ ├── Tls.h │ │ ├── Url.cpp │ │ ├── Url.h │ │ └── strategies │ │ │ ├── FailoverStrategy.cpp │ │ │ ├── FailoverStrategy.h │ │ │ ├── SinglePoolStrategy.cpp │ │ │ ├── SinglePoolStrategy.h │ │ │ └── StrategyProxy.h │ ├── tls │ │ ├── ServerTls.cpp │ │ ├── ServerTls.h │ │ ├── TlsConfig.cpp │ │ ├── TlsConfig.h │ │ ├── TlsContext.cpp │ │ ├── TlsContext.h │ │ ├── TlsGen.cpp │ │ └── TlsGen.h │ └── tools │ │ ├── LineReader.cpp │ │ ├── LineReader.h │ │ ├── MemPool.h │ │ ├── NetBuffer.cpp │ │ ├── NetBuffer.h │ │ ├── Storage.h │ │ ├── TcpServer.cpp │ │ └── TcpServer.h └── tools │ ├── Alignment.h │ ├── Arguments.cpp │ ├── Arguments.h │ ├── Baton.h │ ├── Buffer.h │ ├── Chrono.cpp │ ├── Chrono.h │ ├── Cvt.cpp │ ├── Cvt.h │ ├── Handle.h │ ├── Object.h │ ├── Span.h │ ├── String.cpp │ ├── String.h │ ├── Timer.cpp │ ├── Timer.h │ ├── bswap_64.h │ └── cryptonote │ ├── BlobReader.h │ ├── BlockTemplate.cpp │ ├── BlockTemplate.h │ ├── Signatures.cpp │ ├── Signatures.h │ ├── WalletAddress.cpp │ ├── WalletAddress.h │ ├── crypto-ops-data.c │ ├── crypto-ops.c │ ├── crypto-ops.h │ └── umul128.h ├── config.json ├── core ├── Controller.cpp ├── Controller.h └── config │ ├── Config.cpp │ ├── Config.h │ ├── ConfigTransform.cpp │ ├── ConfigTransform.h │ ├── Config_platform.h │ └── usage.h ├── donate.h ├── net ├── JobResult.cpp ├── JobResult.h └── strategies │ ├── DonateStrategy.cpp │ └── DonateStrategy.h ├── proxy ├── BindHost.cpp ├── BindHost.h ├── Counters.cpp ├── Counters.h ├── CustomDiff.cpp ├── CustomDiff.h ├── Error.cpp ├── Error.h ├── Events.cpp ├── Events.h ├── Login.cpp ├── Login.h ├── Miner.cpp ├── Miner.h ├── Miners.cpp ├── Miners.h ├── Proxy.cpp ├── Proxy.h ├── ProxyDebug.cpp ├── ProxyDebug.h ├── Server.cpp ├── Server.h ├── Stats.cpp ├── Stats.h ├── StatsData.h ├── TickingCounter.h ├── events │ ├── AcceptEvent.h │ ├── CloseEvent.h │ ├── ConnectionEvent.h │ ├── Event.cpp │ ├── Event.h │ ├── LoginEvent.h │ ├── MinerEvent.cpp │ ├── MinerEvent.h │ └── SubmitEvent.h ├── interfaces │ ├── IEvent.h │ ├── IEventListener.h │ └── ISplitter.h ├── log │ ├── AccessLog.cpp │ ├── AccessLog.h │ ├── ShareLog.cpp │ └── ShareLog.h ├── splitters │ ├── Splitter.cpp │ ├── Splitter.h │ ├── donate │ │ ├── DonateMapper.cpp │ │ ├── DonateMapper.h │ │ ├── DonateSplitter.cpp │ │ └── DonateSplitter.h │ ├── extra_nonce │ │ ├── ExtraNonceMapper.cpp │ │ ├── ExtraNonceMapper.h │ │ ├── ExtraNonceSplitter.cpp │ │ ├── ExtraNonceSplitter.h │ │ ├── ExtraNonceStorage.cpp │ │ └── ExtraNonceStorage.h │ ├── nicehash │ │ ├── NonceMapper.cpp │ │ ├── NonceMapper.h │ │ ├── NonceSplitter.cpp │ │ ├── NonceSplitter.h │ │ ├── NonceStorage.cpp │ │ └── NonceStorage.h │ └── simple │ │ ├── SimpleMapper.cpp │ │ ├── SimpleMapper.h │ │ ├── SimpleSplitter.cpp │ │ └── SimpleSplitter.h ├── tls │ ├── MinerTls.cpp │ └── MinerTls.h └── workers │ ├── Worker.cpp │ ├── Worker.h │ ├── Workers.cpp │ └── Workers.h ├── version.h └── xmrig.cpp /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | 3 | name: Test builds 4 | 5 | jobs: 6 | build_win: 7 | name: Windows build 8 | runs-on: windows-2019 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@master 12 | - name: Checkout deps 13 | run: git clone https://github.com/xmrig/xmrig-deps.git 14 | - name: Build project on Windows 15 | run: | 16 | cmake . -G "Visual Studio 16 2019" -DXMRIG_DEPS=xmrig-deps\msvc2019\x64 17 | cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin" 18 | .\MSBuild.exe /p:Configuration=Release $Env:GITHUB_WORKSPACE\xmrig-proxy.sln 19 | 20 | build_lin: 21 | name: Ubuntu build 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Prepare Ubuntu tools 25 | run: | 26 | sudo apt-get install -y git build-essential cmake libuv1-dev libssl-dev 27 | - name: Checkout code 28 | uses: actions/checkout@master 29 | - name: Build project on Ubuntu 30 | run: | 31 | cmake . 32 | make -j$(nproc) 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /CMakeLists.txt.user 3 | -------------------------------------------------------------------------------- /cmake/FindUV.cmake: -------------------------------------------------------------------------------- 1 | find_path( 2 | UV_INCLUDE_DIR 3 | NAMES uv.h 4 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 5 | PATH_SUFFIXES "include" 6 | NO_DEFAULT_PATH 7 | ) 8 | 9 | find_path(UV_INCLUDE_DIR NAMES uv.h) 10 | 11 | find_library( 12 | UV_LIBRARY 13 | NAMES libuv.a uv libuv 14 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 15 | PATH_SUFFIXES "lib" 16 | NO_DEFAULT_PATH 17 | ) 18 | 19 | find_library(UV_LIBRARY NAMES libuv.a uv libuv) 20 | 21 | set(UV_LIBRARIES ${UV_LIBRARY}) 22 | set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR}) 23 | 24 | include(FindPackageHandleStandardArgs) 25 | find_package_handle_standard_args(UV DEFAULT_MSG UV_LIBRARY UV_INCLUDE_DIR) 26 | -------------------------------------------------------------------------------- /cmake/OpenSSL.cmake: -------------------------------------------------------------------------------- 1 | if (WITH_TLS) 2 | set(OPENSSL_ROOT_DIR ${XMRIG_DEPS}) 3 | 4 | if (WIN32) 5 | set(OPENSSL_USE_STATIC_LIBS TRUE) 6 | set(OPENSSL_MSVC_STATIC_RT TRUE) 7 | 8 | set(EXTRA_LIBS ${EXTRA_LIBS} crypt32) 9 | elseif (APPLE) 10 | set(OPENSSL_USE_STATIC_LIBS TRUE) 11 | endif() 12 | 13 | find_package(OpenSSL) 14 | 15 | if (OPENSSL_FOUND) 16 | set(TLS_SOURCES 17 | src/base/net/stratum/Tls.cpp 18 | src/base/net/stratum/Tls.h 19 | src/base/net/tls/ServerTls.cpp 20 | src/base/net/tls/ServerTls.h 21 | src/base/net/tls/TlsConfig.cpp 22 | src/base/net/tls/TlsConfig.h 23 | src/base/net/tls/TlsContext.cpp 24 | src/base/net/tls/TlsContext.h 25 | src/base/net/tls/TlsGen.cpp 26 | src/base/net/tls/TlsGen.h 27 | src/proxy/tls/MinerTls.cpp 28 | src/proxy/tls/MinerTls.h 29 | ) 30 | 31 | include_directories(${OPENSSL_INCLUDE_DIR}) 32 | 33 | if (WITH_HTTP) 34 | set(TLS_SOURCES ${TLS_SOURCES} 35 | src/base/net/https/HttpsClient.cpp 36 | src/base/net/https/HttpsClient.h 37 | src/base/net/https/HttpsContext.cpp 38 | src/base/net/https/HttpsContext.h 39 | src/base/net/https/HttpsServer.cpp 40 | src/base/net/https/HttpsServer.h 41 | ) 42 | endif() 43 | else() 44 | message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") 45 | endif() 46 | 47 | add_definitions(/DXMRIG_FEATURE_TLS) 48 | else() 49 | set(TLS_SOURCES "") 50 | set(OPENSSL_LIBRARIES "") 51 | remove_definitions(/DXMRIG_FEATURE_TLS) 52 | 53 | if (WITH_HTTP) 54 | set(TLS_SOURCES ${TLS_SOURCES} 55 | src/base/net/http/HttpServer.cpp 56 | src/base/net/http/HttpServer.h 57 | ) 58 | endif() 59 | 60 | set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls") 61 | endif() 62 | -------------------------------------------------------------------------------- /cmake/flags.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 2 | set(CMAKE_CXX_EXTENSIONS OFF) 3 | set(CMAKE_CXX_STANDARD 11) 4 | 5 | set(CMAKE_C_STANDARD 99) 6 | set(CMAKE_C_STANDARD_REQUIRED ON) 7 | 8 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") 9 | set(CMAKE_BUILD_TYPE Release) 10 | endif() 11 | 12 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 13 | add_definitions(/DNDEBUG) 14 | endif() 15 | 16 | include(CheckSymbolExists) 17 | 18 | if (CMAKE_CXX_COMPILER_ID MATCHES GNU) 19 | 20 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 21 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-class-memaccess") 22 | 23 | if (WIN32) 24 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 25 | else() 26 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") 27 | endif() 28 | 29 | if (BUILD_STATIC) 30 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 31 | endif() 32 | 33 | add_definitions(/D_GNU_SOURCE) 34 | 35 | if (WITH_GOOGLE_BREAKPAD) 36 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g") 37 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g") 38 | endif() 39 | 40 | if (${CMAKE_VERSION} VERSION_LESS "3.1.0") 41 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") 42 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 43 | endif() 44 | 45 | elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) 46 | set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL") 47 | set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL") 48 | 49 | add_definitions(/D_CRT_SECURE_NO_WARNINGS) 50 | add_definitions(/D_CRT_NONSTDC_NO_WARNINGS) 51 | add_definitions(/DNOMINMAX) 52 | add_definitions(/DHAVE_ROTR) 53 | 54 | elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) 55 | 56 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 57 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-overloaded-virtual") 58 | 59 | endif() 60 | -------------------------------------------------------------------------------- /cmake/os.cmake: -------------------------------------------------------------------------------- 1 | if (WIN32) 2 | set(XMRIG_OS_WIN ON) 3 | elseif (APPLE) 4 | set(XMRIG_OS_APPLE ON) 5 | 6 | if (IOS OR CMAKE_SYSTEM_NAME STREQUAL iOS) 7 | set(XMRIG_OS_IOS ON) 8 | else() 9 | set(XMRIG_OS_MACOS ON) 10 | endif() 11 | else() 12 | set(XMRIG_OS_UNIX ON) 13 | 14 | if (ANDROID OR CMAKE_SYSTEM_NAME MATCHES "Android") 15 | set(XMRIG_OS_ANDROID ON) 16 | elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") 17 | set(XMRIG_OS_LINUX ON) 18 | elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL DragonFly) 19 | set(XMRIG_OS_FREEBSD ON) 20 | endif() 21 | endif() 22 | 23 | 24 | if (XMRIG_OS_WIN) 25 | add_definitions(/DWIN32) 26 | add_definitions(/DXMRIG_OS_WIN) 27 | elseif(XMRIG_OS_APPLE) 28 | add_definitions(/DXMRIG_OS_APPLE) 29 | 30 | if (XMRIG_OS_IOS) 31 | add_definitions(/DXMRIG_OS_IOS) 32 | else() 33 | add_definitions(/DXMRIG_OS_MACOS) 34 | endif() 35 | elseif(XMRIG_OS_UNIX) 36 | add_definitions(/DXMRIG_OS_UNIX) 37 | 38 | if (XMRIG_OS_ANDROID) 39 | add_definitions(/DXMRIG_OS_ANDROID) 40 | elseif (XMRIG_OS_LINUX) 41 | add_definitions(/DXMRIG_OS_LINUX) 42 | elseif (XMRIG_OS_FREEBSD) 43 | add_definitions(/DXMRIG_OS_FREEBSD) 44 | endif() 45 | endif() 46 | 47 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) 48 | set(XMRIG_64_BIT ON) 49 | add_definitions(-DXMRIG_64_BIT) 50 | else() 51 | set(XMRIG_64_BIT OFF) 52 | endif() 53 | -------------------------------------------------------------------------------- /doc/gpg_keys/xmrig.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | 3 | mQENBF3VSRIBCADfFjDUbq0WLGulFeSou0A+jTvweNllPyLNOn3SNCC0XLEYyEcu 4 | JiEBK80DlvR06TVr8Aw1rT5S2iH0i5Tl8DqShH2mmcN1rBp1M0Y95D89KVj3BIhE 5 | nxmgmD4N3Wgm+5FmEH4W/RpG1xdYWJx3eJhtWPdFJqpg083E2D5P30wIQem+EnTR 6 | 5YrtTZPh5cPj2KRY+UmsDE3ahmxCgP7LYgnnpZQlWBBiMV932s7MvYBPJQc1wecS 7 | 0wi1zxyS81xHc3839EkA7wueCeNo+5jha+KH66tMKsfrI2WvfPHTCPjK9v7WJc/O 8 | /eRp9d+wacn09D1L6CoRO0ers5p10GO84VhTABEBAAG0GVhNUmlnIDxzdXBwb3J0 9 | QHhtcmlnLmNvbT6JAU4EEwEIADgWIQSaxM6o5m41pcfN3BtEalNji+lECQUCXdVJ 10 | EgIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRBEalNji+lECbkQB/9nRou0 11 | tOlBwYn8xVgBu7IiDWNVETRWfrjrtdTvSahgbbo6lWgjA/vBLkjN9fISdBQ/n/Mt 12 | hNDJbEtxHHt2baJhvT8du1eWcIHHXCV/rmv+iY/hTXa1gKqHiHDJrtYSVBG3BMme 13 | 1rdsUHTiKf3t5yRHOXAfY2C+XNblKAV7mhlxQBiKxdFDIkFEQKNrHNUvnzkOqoCT 14 | 2kTZZ2tPUMQdOn1eek6zG/+C7SwcBpJnakJ8jce4yA/xZbOVKetNWO3Ufu3TE34k 15 | OdA+H4PU9+fV77XfOY8DtXeS3boUI97ei+4s/mwX/NFC0i8CPXyefxl3WRUBGDOI 16 | w//kPNQVh4HobOCeuQENBF3VSRIBCADl29WorEi+vRA/3kg9VUXtxSU6caibFS3N 17 | VXANiFRjrOmICdfrIgOSGNrYCQFsXu0Xe0udDYVX8yX6WJk+CT02Pdg0gkXiKoze 18 | KrnK15mo3xXbb2tr1o9ROPgwY/o2AwQHj0o1JhdS2cybfuRiUQRoGgBX7a9X0cTY 19 | r4ZJvOjzgAajl3ciwB3yWUmDiRlzZpO7YWESXbOhGVzyCnP5MlMEJ/fPRw9h38vK 20 | HNKLhzcRfsLpXk34ghY3SxIv4NWUfuZXFWqpSdC9JgNc5zA72lJEQcF4DHJCKl7B 21 | ddmrfsr9mdiIpo+/ZZFPPngdeZ2kvkJ2YKaZNVu2XooJARPQ8B8tABEBAAGJATYE 22 | GAEIACAWIQSaxM6o5m41pcfN3BtEalNji+lECQUCXdVJEgIbDAAKCRBEalNji+lE 23 | CdPUB/4nH1IdhHGmfko2kxdaHqQgCGLqh3pcrQXD9mBv/LYVnoHZpVRHsIDgg2Z4 24 | lQYrIRRqe69FjVxo7sA2eMIlV0GRDlUrw+HeURFpEhKPEdwFy6i/cti2MY0YxOrB 25 | TvQoRutUoMnyjM4TBJWaaqccbTsavMdLmG3JHdAkiHtUis/fUwVctmEQwN+d/J2b 26 | wJAtliqw3nXchUfdIfwHF/7hg8seUuYUaifzkazBZhVWvRkTVLVanzZ51HRfuzwD 27 | ntaa7kfYGdE+4TKOylAPh+8E6WnR19RRTpsaW0dVBgOiBTE0uc7rUv2HWS/u6RUR 28 | t7ldSBzkuDTlM2V59Iq2hXoSC6dT 29 | =cIG9 30 | -----END PGP PUBLIC KEY BLOCK----- 31 | -------------------------------------------------------------------------------- /doc/releases/5_0_0/SHA256SUMS: -------------------------------------------------------------------------------- 1 | e12d814f584cecbb6cec9c394e49989f53ae61d4079c51c7682d938a03963b96 xmrig-proxy-5.0.0-gcc-win32.zip 2 | 0a5e143c979ef163247439da3049492ecfad49355e34ae371b14a8e08529230e xmrig-proxy-5.0.0-msvc-win64.zip 3 | af7564afbb7e69aea52e6a2a945cb04caa09a993a468d5c1fdd73c3d337da05e xmrig-proxy-5.0.0-xenial-x64.tar.gz 4 | -------------------------------------------------------------------------------- /doc/releases/5_0_0/SHA256SUMS.sig: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | 3 | iQEzBAABCgAdFiEEmsTOqOZuNaXHzdwbRGpTY4vpRAkFAl3Vl4YACgkQRGpTY4vp 4 | RAlj+Qf/TeSwcQ7HoDeCk7kAVTu25gZDf/gqTyYVNPt8x4pSjc0ofxXNo/q0Yrla 5 | Dy5Ovjy0ZHJVYAC3vYdaDEaTWkZ0DVCytYDHEtsOgaA4jQm5baHGyIjREq1II8sl 6 | QU27VhiOsX39jxrV4bGJvSkgLRpljFSIlbwn8+yP+sCwPMJ4MMEoJCC60agIsZBu 7 | PsJQGVxAJ/n3nk2zvUuz/5DGqFyeOJ2MjqnLcaP6IoJ/PHxUngVi7k9qIggi6EFg 8 | Ou/M0VMNpSo9uengCKoOsidtTkoek3MXGw+eS/JVB0qNCGHaNHqj3bTRD8yk7Klv 9 | qq5hC4F84jAPPO8QHago9n4UcoYSkQ== 10 | =M0Ty 11 | -----END PGP SIGNATURE----- 12 | -------------------------------------------------------------------------------- /res/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MoneroOcean/xmrig-proxy/d5b5a30777cae7c0df5c5295f24ee03db0154524/res/app.ico -------------------------------------------------------------------------------- /res/app.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../src/version.h" 3 | 4 | 101 ICON "app.ico" 5 | 6 | VS_VERSION_INFO VERSIONINFO 7 | FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0 8 | PRODUCTVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0 9 | FILEFLAGSMASK 0x3fL 10 | #ifdef _DEBUG 11 | FILEFLAGS VS_FF_DEBUG 12 | #else 13 | FILEFLAGS 0x0L 14 | #endif 15 | FILEOS VOS__WINDOWS32 16 | FILETYPE VFT_APP 17 | FILESUBTYPE 0x0L 18 | BEGIN 19 | BLOCK "StringFileInfo" 20 | BEGIN 21 | BLOCK "000004b0" 22 | BEGIN 23 | VALUE "CompanyName", APP_SITE 24 | VALUE "FileDescription", APP_DESC 25 | VALUE "FileVersion", APP_VERSION 26 | VALUE "LegalCopyright", APP_COPYRIGHT 27 | VALUE "OriginalFilename", "xmrig-proxy.exe" 28 | VALUE "ProductName", APP_NAME 29 | VALUE "ProductVersion", APP_VERSION 30 | END 31 | END 32 | BLOCK "VarFileInfo" 33 | BEGIN 34 | VALUE "Translation", 0x0, 1200 35 | END 36 | END 37 | 38 | -------------------------------------------------------------------------------- /scripts/build.openssl3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | OPENSSL_VERSION="3.0.14" 4 | 5 | mkdir -p deps 6 | mkdir -p deps/include 7 | mkdir -p deps/lib 8 | 9 | mkdir -p build && cd build 10 | 11 | wget https://github.com/openssl/openssl/releases/download/openssl-${OPENSSL_VERSION}/openssl-${OPENSSL_VERSION}.tar.gz -O openssl-${OPENSSL_VERSION}.tar.gz 12 | tar -xzf openssl-${OPENSSL_VERSION}.tar.gz 13 | 14 | cd openssl-${OPENSSL_VERSION} 15 | ./config -no-shared -no-asm -no-zlib -no-comp -no-dgram -no-filenames -no-cms 16 | make -j$(nproc || sysctl -n hw.ncpu || sysctl -n hw.logicalcpu) 17 | cp -fr include ../../deps 18 | cp libcrypto.a ../../deps/lib 19 | cp libssl.a ../../deps/lib 20 | cd .. 21 | -------------------------------------------------------------------------------- /scripts/build.uv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | UV_VERSION="1.48.0" 4 | 5 | mkdir -p deps 6 | mkdir -p deps/include 7 | mkdir -p deps/lib 8 | 9 | mkdir -p build && cd build 10 | 11 | wget https://dist.libuv.org/dist/v${UV_VERSION}/libuv-v${UV_VERSION}.tar.gz -O v${UV_VERSION}.tar.gz 12 | tar -xzf v${UV_VERSION}.tar.gz 13 | 14 | cd libuv-v${UV_VERSION} 15 | sh autogen.sh 16 | ./configure --disable-shared 17 | make -j$(nproc || sysctl -n hw.ncpu || sysctl -n hw.logicalcpu) 18 | cp -fr include ../../deps 19 | cp .libs/libuv.a ../../deps/lib 20 | cd .. 21 | -------------------------------------------------------------------------------- /scripts/build_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | ./build.uv.sh 4 | ./build.openssl3.sh -------------------------------------------------------------------------------- /src/3rdparty/epee/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the Andrey N. Sabelnikov nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Andrey N. Sabelnikov BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /src/3rdparty/epee/README.md: -------------------------------------------------------------------------------- 1 | epee - is a small library of helpers, wrappers, tools and and so on, used to make my life easier. 2 | -------------------------------------------------------------------------------- /src/3rdparty/fmt/LICENSE.rst: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - present, Victor Zverovich 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | --- Optional exception to the license --- 23 | 24 | As an exception, if, as a result of your compiling your source code, portions 25 | of this Software are embedded into a machine-executable object form of such 26 | source code, you may redistribute such embedded portions in such object form 27 | without including the above copyright and permission notices. 28 | -------------------------------------------------------------------------------- /src/3rdparty/fmt/posix.h: -------------------------------------------------------------------------------- 1 | #include "os.h" 2 | #warning "fmt/posix.h is deprecated; use fmt/os.h instead" 3 | -------------------------------------------------------------------------------- /src/3rdparty/llhttp/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT License. 2 | 3 | Copyright Fedor Indutny, 2018. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to permit 10 | persons to whom the Software is furnished to do so, subject to the 11 | following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 19 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 | USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /src/App.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_APP_H 20 | #define XMRIG_APP_H 21 | 22 | 23 | #include "base/kernel/interfaces/IConsoleListener.h" 24 | #include "base/kernel/interfaces/ISignalListener.h" 25 | #include "base/tools/Object.h" 26 | 27 | 28 | #include 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class Console; 35 | class Controller; 36 | class Process; 37 | class Signals; 38 | 39 | 40 | class App : public IConsoleListener, public ISignalListener 41 | { 42 | public: 43 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(App) 44 | 45 | App(Process *process); 46 | ~App() override; 47 | 48 | int exec(); 49 | 50 | protected: 51 | void onConsoleCommand(char command) override; 52 | void onSignal(int signum) override; 53 | 54 | private: 55 | bool background(int &rc); 56 | void close(); 57 | 58 | std::shared_ptr m_console; 59 | std::shared_ptr m_controller; 60 | std::shared_ptr m_signals; 61 | }; 62 | 63 | 64 | } /* namespace xmrig */ 65 | 66 | 67 | #endif /* XMRIG_APP_H */ 68 | -------------------------------------------------------------------------------- /src/App_unix.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2024 SChernykh 9 | * Copyright 2016-2024 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #include "App.h" 32 | #include "base/io/log/Log.h" 33 | #include "core/Controller.h" 34 | 35 | 36 | bool xmrig::App::background(int &rc) 37 | { 38 | signal(SIGPIPE, SIG_IGN); 39 | 40 | if (!m_controller->isBackground()) { 41 | return false; 42 | } 43 | 44 | int i = fork(); 45 | if (i < 0) { 46 | rc = 1; 47 | 48 | return true; 49 | } 50 | 51 | if (i > 0) { 52 | rc = 0; 53 | 54 | return true; 55 | } 56 | 57 | if (setsid() < 0) { 58 | LOG_ERR("setsid() failed (errno = %d)", errno); 59 | } 60 | 61 | return false; 62 | } 63 | -------------------------------------------------------------------------------- /src/App_win.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | #include "App.h" 31 | #include "core/Controller.h" 32 | 33 | 34 | bool xmrig::App::background(int &) 35 | { 36 | if (!m_controller->isBackground()) { 37 | return false; 38 | } 39 | 40 | HWND hcon = GetConsoleWindow(); 41 | if (hcon) { 42 | ShowWindow(hcon, SW_HIDE); 43 | } else { 44 | HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); 45 | CloseHandle(h); 46 | FreeConsole(); 47 | } 48 | 49 | return false; 50 | } 51 | -------------------------------------------------------------------------------- /src/Summary.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_SUMMARY_H 26 | #define XMRIG_SUMMARY_H 27 | 28 | 29 | namespace xmrig { 30 | class Config; 31 | class Controller; 32 | } 33 | 34 | 35 | class Summary 36 | { 37 | public: 38 | static void print(xmrig::Controller *controller); 39 | }; 40 | 41 | 42 | #endif /* XMRIG_SUMMARY_H */ 43 | -------------------------------------------------------------------------------- /src/base/api/Httpd.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_HTTPD_H 20 | #define XMRIG_HTTPD_H 21 | 22 | 23 | #include "base/kernel/interfaces/IBaseListener.h" 24 | #include "base/net/http/HttpListener.h" 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | class Base; 31 | class HttpServer; 32 | class HttpsServer; 33 | class TcpServer; 34 | 35 | 36 | class Httpd : public IBaseListener, public IHttpListener 37 | { 38 | public: 39 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd) 40 | 41 | explicit Httpd(Base *base); 42 | ~Httpd() override; 43 | 44 | inline bool isBound() const { return m_server != nullptr; } 45 | 46 | bool start(); 47 | void stop(); 48 | 49 | protected: 50 | void onConfigChanged(Config *config, Config *previousConfig) override; 51 | void onHttpData(const HttpData &data) override; 52 | 53 | private: 54 | int auth(const HttpData &req) const; 55 | 56 | const Base *m_base; 57 | std::shared_ptr m_httpListener; 58 | TcpServer *m_server = nullptr; 59 | uint16_t m_port = 0; 60 | 61 | # ifdef XMRIG_FEATURE_TLS 62 | HttpsServer *m_http = nullptr; 63 | # else 64 | HttpServer *m_http = nullptr; 65 | # endif 66 | }; 67 | 68 | 69 | } // namespace xmrig 70 | 71 | 72 | #endif // XMRIG_HTTPD_H 73 | -------------------------------------------------------------------------------- /src/base/api/interfaces/IApiListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2021 SChernykh 3 | * Copyright 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IAPILISTENER_H 20 | #define XMRIG_IAPILISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class IApiRequest; 30 | 31 | 32 | class IApiListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(IApiListener) 36 | 37 | IApiListener() = default; 38 | virtual ~IApiListener() = default; 39 | 40 | # ifdef XMRIG_FEATURE_API 41 | virtual void onRequest(IApiRequest &request) = 0; 42 | # endif 43 | }; 44 | 45 | 46 | } /* namespace xmrig */ 47 | 48 | 49 | #endif // XMRIG_IAPILISTENER_H 50 | -------------------------------------------------------------------------------- /src/base/api/requests/ApiRequest.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include "base/api/requests/ApiRequest.h" 27 | 28 | 29 | xmrig::ApiRequest::ApiRequest(Source source, bool restricted) : 30 | m_restricted(restricted), 31 | m_source(source) 32 | { 33 | } 34 | 35 | 36 | xmrig::ApiRequest::~ApiRequest() = default; 37 | -------------------------------------------------------------------------------- /src/base/crypto/keccak.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2011 Markku-Juhani O. Saarinen 4 | * Copyright 2012-2014 pooler 5 | * Copyright 2014 Lucas Jones 6 | * Copyright 2014-2016 Wolf9466 7 | * Copyright 2016 Jay D Dee 8 | * Copyright 2017-2018 XMR-Stak , 9 | * Copyright 2018-2020 SChernykh 10 | * Copyright 2016-2020 XMRig , 11 | * 12 | * This program is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | 26 | 27 | #ifndef XMRIG_KECCAK_H 28 | #define XMRIG_KECCAK_H 29 | 30 | #include 31 | #include 32 | 33 | 34 | namespace xmrig { 35 | 36 | // compute a keccak hash (md) of given byte length from "in" 37 | void keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 38 | 39 | 40 | inline void keccak(const uint8_t *in, size_t inlen, uint8_t *md) 41 | { 42 | keccak(in, static_cast(inlen), md, 200); 43 | } 44 | 45 | 46 | inline void keccak(const char *in, size_t inlen, uint8_t *md) 47 | { 48 | keccak(reinterpret_cast(in), static_cast(inlen), md, 200); 49 | } 50 | 51 | // update the state 52 | void keccakf(uint64_t st[25], int norounds); 53 | 54 | } /* namespace xmrig */ 55 | 56 | #endif /* XMRIG_KECCAK_H */ 57 | -------------------------------------------------------------------------------- /src/base/io/Async.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2015-2020 libuv project contributors. 3 | * Copyright (c) 2020 cohcho 4 | * Copyright (c) 2018-2020 SChernykh 5 | * Copyright (c) 2016-2020 XMRig , 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef XMRIG_ASYNC_H 22 | #define XMRIG_ASYNC_H 23 | 24 | 25 | #include "base/tools/Object.h" 26 | 27 | 28 | #include 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class AsyncPrivate; 35 | class IAsyncListener; 36 | 37 | 38 | class Async 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Async) 42 | 43 | using Callback = std::function; 44 | 45 | Async(Callback callback); 46 | Async(IAsyncListener *listener); 47 | ~Async(); 48 | 49 | void send(); 50 | 51 | private: 52 | AsyncPrivate *d_ptr; 53 | }; 54 | 55 | 56 | } // namespace xmrig 57 | 58 | 59 | #endif /* XMRIG_ASYNC_H */ 60 | -------------------------------------------------------------------------------- /src/base/io/Console.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_CONSOLE_H 20 | #define XMRIG_CONSOLE_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | using uv_buf_t = struct uv_buf_t; 27 | using uv_handle_t = struct uv_handle_s; 28 | using uv_stream_t = struct uv_stream_s; 29 | using uv_tty_t = struct uv_tty_s; 30 | 31 | #ifdef XMRIG_OS_WIN 32 | using ssize_t = intptr_t; 33 | #else 34 | # include 35 | #endif 36 | 37 | 38 | namespace xmrig { 39 | 40 | 41 | class IConsoleListener; 42 | 43 | 44 | class Console 45 | { 46 | public: 47 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Console) 48 | 49 | Console(IConsoleListener *listener); 50 | ~Console(); 51 | 52 | private: 53 | static bool isSupported(); 54 | 55 | static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); 56 | static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); 57 | 58 | char m_buf[1] = { 0 }; 59 | IConsoleListener *m_listener; 60 | uv_tty_t *m_tty = nullptr; 61 | }; 62 | 63 | 64 | } /* namespace xmrig */ 65 | 66 | 67 | #endif /* XMRIG_CONSOLE_H */ 68 | -------------------------------------------------------------------------------- /src/base/io/Env.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ENV_H 20 | #define XMRIG_ENV_H 21 | 22 | 23 | #include "base/tools/String.h" 24 | 25 | 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class Env 33 | { 34 | public: 35 | static String expand(const char *in, const std::map &extra = {}); 36 | static String get(const String &name, const std::map &extra = {}); 37 | static String hostname(); 38 | }; 39 | 40 | 41 | } /* namespace xmrig */ 42 | 43 | 44 | #endif /* XMRIG_ENV_H */ 45 | -------------------------------------------------------------------------------- /src/base/io/Signals.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_SIGNALS_H 20 | #define XMRIG_SIGNALS_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | using uv_signal_t = struct uv_signal_s; 31 | 32 | 33 | namespace xmrig { 34 | 35 | 36 | class ISignalListener; 37 | 38 | 39 | class Signals 40 | { 41 | public: 42 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Signals) 43 | 44 | # ifdef SIGUSR1 45 | constexpr static const size_t kSignalsCount = 4; 46 | # else 47 | constexpr static const size_t kSignalsCount = 3; 48 | # endif 49 | 50 | Signals(ISignalListener *listener); 51 | ~Signals(); 52 | 53 | private: 54 | void close(int signum); 55 | 56 | static void onSignal(uv_signal_t *handle, int signum); 57 | 58 | ISignalListener *m_listener; 59 | uv_signal_t *m_signals[kSignalsCount]{}; 60 | }; 61 | 62 | 63 | } /* namespace xmrig */ 64 | 65 | 66 | #endif /* XMRIG_SIGNALS_H */ 67 | -------------------------------------------------------------------------------- /src/base/io/log/FileLogWriter.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_FILELOGWRITER_H 20 | #define XMRIG_FILELOGWRITER_H 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class FileLogWriter 33 | { 34 | public: 35 | FileLogWriter(); 36 | FileLogWriter(const char* fileName); 37 | 38 | ~FileLogWriter(); 39 | 40 | inline bool isOpen() const { return m_file >= 0; } 41 | inline int64_t pos() const { return m_pos; } 42 | 43 | bool open(const char *fileName); 44 | bool write(const char *data, size_t size); 45 | bool writeLine(const char *data, size_t size); 46 | 47 | private: 48 | # ifdef XMRIG_OS_WIN 49 | const char m_endl[3] = {'\r', '\n', 0}; 50 | # else 51 | const char m_endl[2] = {'\n', 0}; 52 | # endif 53 | 54 | int m_file = -1; 55 | int64_t m_pos = 0; 56 | 57 | uv_mutex_t m_buffersLock; 58 | std::vector m_buffers; 59 | 60 | uv_async_t m_flushAsync; 61 | 62 | void init(); 63 | 64 | static void on_flush(uv_async_t* async) { reinterpret_cast(async->data)->flush(); } 65 | void flush(); 66 | }; 67 | 68 | 69 | } /* namespace xmrig */ 70 | 71 | 72 | #endif /* XMRIG_FILELOGWRITER_H */ 73 | -------------------------------------------------------------------------------- /src/base/io/log/Tags.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_TAGS_H 20 | #define XMRIG_TAGS_H 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | class Tags 31 | { 32 | public: 33 | static const char *config(); 34 | static const char *network(); 35 | static const char *origin(); 36 | static const char *signal(); 37 | 38 | # ifdef XMRIG_MINER_PROJECT 39 | static const char *cpu(); 40 | static const char *miner(); 41 | # ifdef XMRIG_ALGO_RANDOMX 42 | static const char *randomx(); 43 | # endif 44 | # ifdef XMRIG_FEATURE_BENCHMARK 45 | static const char *bench(); 46 | # endif 47 | # endif 48 | 49 | # ifdef XMRIG_PROXY_PROJECT 50 | static const char *proxy(); 51 | # endif 52 | 53 | # ifdef XMRIG_FEATURE_CUDA 54 | static const char *nvidia(); 55 | # endif 56 | 57 | # ifdef XMRIG_FEATURE_OPENCL 58 | static const char *opencl(); 59 | # endif 60 | 61 | # ifdef XMRIG_FEATURE_PROFILING 62 | static const char* profiler(); 63 | # endif 64 | }; 65 | 66 | 67 | } /* namespace xmrig */ 68 | 69 | 70 | #endif /* XMRIG_TAGS_H */ 71 | -------------------------------------------------------------------------------- /src/base/io/log/backends/ConsoleLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2019 Spudz76 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_CONSOLELOG_H 21 | #define XMRIG_CONSOLELOG_H 22 | 23 | 24 | using uv_stream_t = struct uv_stream_s; 25 | using uv_tty_t = struct uv_tty_s; 26 | 27 | 28 | #include "base/kernel/interfaces/ILogBackend.h" 29 | #include "base/tools/Object.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class Title; 36 | 37 | 38 | class ConsoleLog : public ILogBackend 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE(ConsoleLog) 42 | 43 | ConsoleLog(const Title &title); 44 | ~ConsoleLog() override; 45 | 46 | protected: 47 | void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) override; 48 | 49 | private: 50 | static bool isSupported(); 51 | 52 | uv_tty_t *m_tty = nullptr; 53 | 54 | # ifdef XMRIG_OS_WIN 55 | bool isWritable() const; 56 | 57 | uv_stream_t *m_stream = nullptr; 58 | # endif 59 | }; 60 | 61 | 62 | } /* namespace xmrig */ 63 | 64 | 65 | #endif /* XMRIG_CONSOLELOG_H */ 66 | -------------------------------------------------------------------------------- /src/base/io/log/backends/FileLog.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2019 Spudz76 3 | * Copyright (c) 2018-2020 SChernykh 4 | * Copyright (c) 2016-2020 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | 21 | #include "base/io/log/backends/FileLog.h" 22 | 23 | 24 | #include 25 | #include 26 | 27 | 28 | xmrig::FileLog::FileLog(const char *fileName) : 29 | m_writer(fileName) 30 | { 31 | } 32 | 33 | 34 | void xmrig::FileLog::print(uint64_t, int, const char *line, size_t, size_t size, bool colors) 35 | { 36 | if (!m_writer.isOpen() || colors) { 37 | return; 38 | } 39 | 40 | assert(strlen(line) == size); 41 | 42 | m_writer.write(line, size); 43 | } 44 | -------------------------------------------------------------------------------- /src/base/io/log/backends/FileLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2019 Spudz76 3 | * Copyright (c) 2018-2020 SChernykh 4 | * Copyright (c) 2016-2020 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_FILELOG_H 21 | #define XMRIG_FILELOG_H 22 | 23 | 24 | #include "base/io/log/FileLogWriter.h" 25 | #include "base/kernel/interfaces/ILogBackend.h" 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | class FileLog : public ILogBackend 32 | { 33 | public: 34 | FileLog(const char *fileName); 35 | 36 | protected: 37 | void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) override; 38 | 39 | private: 40 | FileLogWriter m_writer; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif /* XMRIG_FILELOG_H */ 48 | -------------------------------------------------------------------------------- /src/base/io/log/backends/SysLog.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2019 Spudz76 3 | * Copyright (c) 2018-2020 SChernykh 4 | * Copyright (c) 2016-2020 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | 21 | #include 22 | 23 | 24 | #include "base/io/log/backends/SysLog.h" 25 | #include "version.h" 26 | 27 | 28 | xmrig::SysLog::SysLog() 29 | { 30 | openlog(APP_ID, LOG_PID, LOG_USER); 31 | } 32 | 33 | 34 | xmrig::SysLog::~SysLog() 35 | { 36 | closelog(); 37 | } 38 | 39 | 40 | void xmrig::SysLog::print(uint64_t, int level, const char *line, size_t offset, size_t, bool colors) 41 | { 42 | if (colors) { 43 | return; 44 | } 45 | 46 | syslog(level == -1 ? LOG_INFO : level, "%s", line + offset); 47 | } 48 | -------------------------------------------------------------------------------- /src/base/io/log/backends/SysLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2019 Spudz76 3 | * Copyright (c) 2018-2020 SChernykh 4 | * Copyright (c) 2016-2020 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_SYSLOG_H 21 | #define XMRIG_SYSLOG_H 22 | 23 | 24 | #include "base/kernel/interfaces/ILogBackend.h" 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | class SysLog : public ILogBackend 31 | { 32 | public: 33 | XMRIG_DISABLE_COPY_MOVE(SysLog) 34 | 35 | SysLog(); 36 | ~SysLog() override; 37 | 38 | protected: 39 | void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) override; 40 | }; 41 | 42 | 43 | } /* namespace xmrig */ 44 | 45 | 46 | #endif /* XMRIG_SYSLOG_H */ 47 | -------------------------------------------------------------------------------- /src/base/kernel/Base.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_BASE_H 20 | #define XMRIG_BASE_H 21 | 22 | 23 | #include "3rdparty/rapidjson/fwd.h" 24 | #include "base/api/interfaces/IApiListener.h" 25 | #include "base/kernel/interfaces/IConfigListener.h" 26 | #include "base/kernel/interfaces/IWatcherListener.h" 27 | #include "base/tools/Object.h" 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class Api; 34 | class BasePrivate; 35 | class Config; 36 | class IBaseListener; 37 | class Process; 38 | 39 | 40 | class Base : public IWatcherListener, public IApiListener 41 | { 42 | public: 43 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Base) 44 | 45 | Base(Process *process); 46 | ~Base() override; 47 | 48 | virtual bool isReady() const; 49 | virtual int init(); 50 | virtual void start(); 51 | virtual void stop(); 52 | 53 | Api *api() const; 54 | bool isBackground() const; 55 | bool reload(const rapidjson::Value &json); 56 | Config *config() const; 57 | void addListener(IBaseListener *listener); 58 | 59 | protected: 60 | void onFileChanged(const String &fileName) override; 61 | 62 | # ifdef XMRIG_FEATURE_API 63 | void onRequest(IApiRequest &request) override; 64 | # endif 65 | 66 | private: 67 | BasePrivate *d_ptr; 68 | }; 69 | 70 | 71 | } /* namespace xmrig */ 72 | 73 | 74 | #endif /* XMRIG_BASE_H */ 75 | -------------------------------------------------------------------------------- /src/base/kernel/Entry.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ENTRY_H 26 | #define XMRIG_ENTRY_H 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class Process; 33 | 34 | 35 | class Entry 36 | { 37 | public: 38 | enum Id { 39 | Default, 40 | Usage, 41 | Version, 42 | Topo, 43 | Platforms 44 | }; 45 | 46 | static Id get(const Process &process); 47 | static int exec(const Process &process, Id id); 48 | }; 49 | 50 | 51 | } /* namespace xmrig */ 52 | 53 | 54 | #endif /* XMRIG_ENTRY_H */ 55 | -------------------------------------------------------------------------------- /src/base/kernel/Platform.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "base/kernel/Platform.h" 20 | 21 | 22 | #include 23 | #include 24 | 25 | 26 | #ifdef XMRIG_FEATURE_TLS 27 | # include 28 | # include 29 | #endif 30 | 31 | 32 | namespace xmrig { 33 | 34 | String Platform::m_userAgent; 35 | 36 | } // namespace xmrig 37 | 38 | 39 | void xmrig::Platform::init(const char *userAgent) 40 | { 41 | # ifdef XMRIG_FEATURE_TLS 42 | SSL_library_init(); 43 | SSL_load_error_strings(); 44 | 45 | # if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER) 46 | ERR_load_BIO_strings(); 47 | ERR_load_crypto_strings(); 48 | # endif 49 | 50 | OpenSSL_add_all_digests(); 51 | # endif 52 | 53 | if (userAgent) { 54 | m_userAgent = userAgent; 55 | } 56 | else { 57 | m_userAgent = createUserAgent(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/base/kernel/Platform.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_PLATFORM_H 20 | #define XMRIG_PLATFORM_H 21 | 22 | 23 | #include 24 | 25 | 26 | #include "base/tools/String.h" 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class Platform 33 | { 34 | public: 35 | static inline bool trySetThreadAffinity(int64_t cpu_id) 36 | { 37 | if (cpu_id < 0) { 38 | return false; 39 | } 40 | 41 | return setThreadAffinity(static_cast(cpu_id)); 42 | } 43 | 44 | static bool setThreadAffinity(uint64_t cpu_id); 45 | static void init(const char *userAgent); 46 | static void setProcessPriority(int priority); 47 | static void setThreadPriority(int priority); 48 | 49 | static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; } 50 | static inline const String &userAgent() { return m_userAgent; } 51 | 52 | # ifdef XMRIG_OS_WIN 53 | static bool hasKeepalive(); 54 | # else 55 | static constexpr bool hasKeepalive() { return true; } 56 | # endif 57 | 58 | static bool isOnBatteryPower(); 59 | static uint64_t idleTime(); 60 | 61 | private: 62 | static char *createUserAgent(); 63 | 64 | static String m_userAgent; 65 | }; 66 | 67 | 68 | } // namespace xmrig 69 | 70 | 71 | #endif /* XMRIG_PLATFORM_H */ 72 | -------------------------------------------------------------------------------- /src/base/kernel/Platform_hwloc.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "base/kernel/Platform.h" 20 | #include "backend/cpu/Cpu.h" 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | #ifndef XMRIG_OS_APPLE 28 | bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) 29 | { 30 | auto topology = Cpu::info()->topology(); 31 | auto pu = hwloc_get_pu_obj_by_os_index(topology, static_cast(cpu_id)); 32 | 33 | if (pu == nullptr) { 34 | return false; 35 | } 36 | 37 | if (hwloc_set_cpubind(topology, pu->cpuset, HWLOC_CPUBIND_THREAD | HWLOC_CPUBIND_STRICT) >= 0) { 38 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 39 | return true; 40 | } 41 | 42 | const bool result = (hwloc_set_cpubind(topology, pu->cpuset, HWLOC_CPUBIND_THREAD) >= 0); 43 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 44 | 45 | return result; 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /src/base/kernel/Process.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_PROCESS_H 20 | #define XMRIG_PROCESS_H 21 | 22 | 23 | #include "base/tools/Arguments.h" 24 | 25 | 26 | #ifdef WIN32 27 | # define XMRIG_DIR_SEPARATOR "\\" 28 | #else 29 | # define XMRIG_DIR_SEPARATOR "/" 30 | #endif 31 | 32 | 33 | namespace xmrig { 34 | 35 | 36 | class Process 37 | { 38 | public: 39 | enum Location { 40 | ExeLocation, 41 | CwdLocation, 42 | DataLocation, 43 | HomeLocation, 44 | TempLocation 45 | }; 46 | 47 | Process(int argc, char **argv); 48 | 49 | static int pid(); 50 | static int ppid(); 51 | static String exepath(); 52 | static String location(Location location, const char *fileName = nullptr); 53 | 54 | inline const Arguments &arguments() const { return m_arguments; } 55 | 56 | private: 57 | Arguments m_arguments; 58 | }; 59 | 60 | 61 | } /* namespace xmrig */ 62 | 63 | 64 | #endif /* XMRIG_PROCESS_H */ 65 | -------------------------------------------------------------------------------- /src/base/kernel/Process_unix.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | 23 | 24 | #include "base/kernel/Process.h" 25 | 26 | 27 | int xmrig::Process::pid() 28 | { 29 | # if UV_VERSION_HEX >= 0x011200 30 | return uv_os_getpid(); 31 | # else 32 | return getpid(); 33 | # endif 34 | } 35 | -------------------------------------------------------------------------------- /src/base/kernel/Process_win.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | 23 | #include "base/kernel/Process.h" 24 | 25 | 26 | int xmrig::Process::pid() 27 | { 28 | # if UV_VERSION_HEX >= 0x011200 29 | return uv_os_getpid(); 30 | # else 31 | return GetCurrentProcessId(); 32 | # endif 33 | } 34 | -------------------------------------------------------------------------------- /src/base/kernel/config/Title.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "base/kernel/config/Title.h" 21 | #include "3rdparty/rapidjson/document.h" 22 | #include "base/io/Env.h" 23 | #include "version.h" 24 | 25 | 26 | xmrig::Title::Title(const rapidjson::Value &value) 27 | { 28 | if (value.IsBool()) { 29 | m_enabled = value.GetBool(); 30 | } 31 | else if (value.IsString()) { 32 | m_value = value.GetString(); 33 | } 34 | } 35 | 36 | 37 | rapidjson::Value xmrig::Title::toJSON() const 38 | { 39 | if (isEnabled() && !m_value.isNull()) { 40 | return m_value.toJSON(); 41 | } 42 | 43 | return rapidjson::Value(m_enabled); 44 | } 45 | 46 | 47 | xmrig::String xmrig::Title::value() const 48 | { 49 | if (!isEnabled()) { 50 | return {}; 51 | } 52 | 53 | if (m_value.isNull()) { 54 | return APP_NAME " " APP_VERSION; 55 | } 56 | 57 | return Env::expand(m_value); 58 | } 59 | -------------------------------------------------------------------------------- /src/base/kernel/config/Title.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_TITLE_H 20 | #define XMRIG_TITLE_H 21 | 22 | 23 | #include "3rdparty/rapidjson/fwd.h" 24 | #include "base/tools/String.h" 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | class Title 31 | { 32 | public: 33 | Title() = default; 34 | Title(const rapidjson::Value &value); 35 | 36 | inline bool isEnabled() const { return m_enabled; } 37 | 38 | rapidjson::Value toJSON() const; 39 | String value() const; 40 | 41 | private: 42 | bool m_enabled = true; 43 | String m_value; 44 | }; 45 | 46 | 47 | } // namespace xmrig 48 | 49 | 50 | #endif /* XMRIG_TITLE_H */ 51 | -------------------------------------------------------------------------------- /src/base/kernel/constants.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_CONSTANTS_H 20 | #define XMRIG_CONSTANTS_H 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | constexpr size_t XMRIG_NET_BUFFER_CHUNK_SIZE = 64 * 1024; 28 | constexpr size_t XMRIG_NET_BUFFER_INIT_CHUNKS = 4; 29 | 30 | 31 | #endif /* XMRIG_CONSTANTS_H */ 32 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IAsyncListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2020 SChernykh 3 | * Copyright 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IASYNCLISTENER_H 20 | #define XMRIG_IASYNCLISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class Async; 30 | 31 | 32 | class IAsyncListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(IAsyncListener) 36 | 37 | IAsyncListener() = default; 38 | virtual ~IAsyncListener() = default; 39 | 40 | virtual void onAsync() = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_IASYNCLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IBaseListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2021 SChernykh 3 | * Copyright 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IBASELISTENER_H 20 | #define XMRIG_IBASELISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class Config; 30 | 31 | 32 | class IBaseListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(IBaseListener) 36 | 37 | IBaseListener() = default; 38 | virtual ~IBaseListener() = default; 39 | 40 | virtual void onConfigChanged(Config *config, Config *previousConfig) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_IBASELISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IConfigListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ICONFIGLISTENER_H 26 | #define XMRIG_ICONFIGLISTENER_H 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class IConfig; 33 | 34 | 35 | class IConfigListener 36 | { 37 | public: 38 | virtual ~IConfigListener() = default; 39 | 40 | virtual void onNewConfig(IConfig *config) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_ICONFIGLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IConfigTransform.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ICONFIGTRANSFORM_H 26 | #define XMRIG_ICONFIGTRANSFORM_H 27 | 28 | 29 | #include "3rdparty/rapidjson/fwd.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class IJsonReader; 36 | class String; 37 | 38 | 39 | class IConfigTransform 40 | { 41 | public: 42 | virtual ~IConfigTransform() = default; 43 | 44 | virtual void finalize(rapidjson::Document &doc) = 0; 45 | virtual void transform(rapidjson::Document &doc, int key, const char *arg) = 0; 46 | }; 47 | 48 | 49 | } /* namespace xmrig */ 50 | 51 | 52 | #endif // XMRIG_ICONFIGTRANSFORM_H 53 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IConsoleListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ICONSOLELISTENER_H 20 | #define XMRIG_ICONSOLELISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class IConsoleListener 30 | { 31 | public: 32 | XMRIG_DISABLE_COPY_MOVE(IConsoleListener) 33 | 34 | IConsoleListener() = default; 35 | virtual ~IConsoleListener() = default; 36 | 37 | virtual void onConsoleCommand(char command) = 0; 38 | }; 39 | 40 | 41 | } /* namespace xmrig */ 42 | 43 | 44 | #endif // XMRIG_ICONSOLELISTENER_H 45 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IDnsBackend.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IDNSBACKEND_H 20 | #define XMRIG_IDNSBACKEND_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class DnsRecords; 33 | class DnsRequest; 34 | class IDnsListener; 35 | class String; 36 | 37 | 38 | class IDnsBackend 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE(IDnsBackend) 42 | 43 | IDnsBackend() = default; 44 | virtual ~IDnsBackend() = default; 45 | 46 | virtual const DnsRecords &records() const = 0; 47 | virtual std::shared_ptr resolve(const String &host, IDnsListener *listener, uint64_t ttl) = 0; 48 | }; 49 | 50 | 51 | } /* namespace xmrig */ 52 | 53 | 54 | #endif // XMRIG_IDNSBACKEND_H 55 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IDnsListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IDNSLISTENER_H 20 | #define XMRIG_IDNSLISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class DnsRecords; 30 | 31 | 32 | class IDnsListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(IDnsListener) 36 | 37 | IDnsListener() = default; 38 | virtual ~IDnsListener() = default; 39 | 40 | virtual void onResolved(const DnsRecords &records, int status, const char *error) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_IDNSLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IHttpListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_IHTTPLISTENER_H 20 | #define XMRIG_IHTTPLISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class HttpData; 30 | class HttpResponse; 31 | 32 | 33 | class IHttpListener 34 | { 35 | public: 36 | XMRIG_DISABLE_COPY_MOVE(IHttpListener) 37 | 38 | IHttpListener() = default; 39 | virtual ~IHttpListener() = default; 40 | 41 | virtual void onHttpData(const HttpData &data) = 0; 42 | }; 43 | 44 | 45 | } /* namespace xmrig */ 46 | 47 | 48 | #endif // XMRIG_IHTTPLISTENER_H 49 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/ILineListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ILINELISTENER_H 26 | #define XMRIG_ILINELISTENER_H 27 | 28 | 29 | #include "base/tools/Object.h" 30 | 31 | 32 | #include 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class ILineListener 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE(ILineListener) 42 | 43 | ILineListener() = default; 44 | virtual ~ILineListener() = default; 45 | 46 | virtual void onLine(char *line, size_t size) = 0; 47 | }; 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif // XMRIG_ILINELISTENER_H 54 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/ILogBackend.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ILOGBACKEND_H 20 | #define XMRIG_ILOGBACKEND_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class ILogBackend 34 | { 35 | public: 36 | XMRIG_DISABLE_COPY_MOVE(ILogBackend) 37 | 38 | ILogBackend() = default; 39 | virtual ~ILogBackend() = default; 40 | 41 | virtual void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) = 0; 42 | }; 43 | 44 | 45 | } /* namespace xmrig */ 46 | 47 | 48 | #endif // XMRIG_ILOGBACKEND_H 49 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/ISignalListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ISIGNALLISTENER_H 20 | #define XMRIG_ISIGNALLISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class String; 30 | 31 | 32 | class ISignalListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(ISignalListener) 36 | 37 | ISignalListener() = default; 38 | virtual ~ISignalListener() = default; 39 | 40 | virtual void onSignal(int signum) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_ISIGNALLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/ITcpServerListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ITCPSERVERLISTENER_H 26 | #define XMRIG_ITCPSERVERLISTENER_H 27 | 28 | 29 | #include 30 | 31 | 32 | typedef struct uv_stream_s uv_stream_t; 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class String; 39 | 40 | 41 | class ITcpServerListener 42 | { 43 | public: 44 | virtual ~ITcpServerListener() = default; 45 | 46 | virtual void onConnection(uv_stream_t *stream, uint16_t port) = 0; 47 | }; 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif // XMRIG_ITCPSERVERLISTENER_H 54 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/ITimerListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ITIMERLISTENER_H 20 | #define XMRIG_ITIMERLISTENER_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class Timer; 30 | 31 | 32 | class ITimerListener 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE(ITimerListener) 36 | 37 | ITimerListener() = default; 38 | virtual ~ITimerListener() = default; 39 | 40 | virtual void onTimer(const Timer *timer) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_ITIMERLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/kernel/interfaces/IWatcherListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_IWATCHERLISTENER_H 26 | #define XMRIG_IWATCHERLISTENER_H 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class String; 33 | 34 | 35 | class IWatcherListener 36 | { 37 | public: 38 | virtual ~IWatcherListener() = default; 39 | 40 | virtual void onFileChanged(const String &fileName) = 0; 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif // XMRIG_IWATCHERLISTENER_H 48 | -------------------------------------------------------------------------------- /src/base/net/dns/Dns.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "base/net/dns/Dns.h" 21 | #include "base/net/dns/DnsUvBackend.h" 22 | 23 | 24 | namespace xmrig { 25 | 26 | 27 | DnsConfig Dns::m_config; 28 | std::map > Dns::m_backends; 29 | 30 | 31 | } // namespace xmrig 32 | 33 | 34 | std::shared_ptr xmrig::Dns::resolve(const String &host, IDnsListener *listener, uint64_t ttl) 35 | { 36 | if (m_backends.find(host) == m_backends.end()) { 37 | m_backends.insert({ host, std::make_shared() }); 38 | } 39 | 40 | return m_backends.at(host)->resolve(host, listener, ttl == 0 ? m_config.ttl() : ttl); 41 | } 42 | -------------------------------------------------------------------------------- /src/base/net/dns/Dns.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_DNS_H 20 | #define XMRIG_DNS_H 21 | 22 | 23 | #include "base/net/dns/DnsConfig.h" 24 | #include "base/tools/String.h" 25 | 26 | 27 | #include 28 | #include 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class DnsConfig; 35 | class DnsRequest; 36 | class IDnsBackend; 37 | class IDnsListener; 38 | 39 | 40 | class Dns 41 | { 42 | public: 43 | inline static const DnsConfig &config() { return m_config; } 44 | inline static void set(const DnsConfig &config) { m_config = config; } 45 | 46 | static std::shared_ptr resolve(const String &host, IDnsListener *listener, uint64_t ttl = 0); 47 | 48 | private: 49 | static DnsConfig m_config; 50 | static std::map > m_backends; 51 | }; 52 | 53 | 54 | } /* namespace xmrig */ 55 | 56 | 57 | #endif /* XMRIG_DNS_H */ 58 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsConfig.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "base/net/dns/DnsConfig.h" 20 | #include "3rdparty/rapidjson/document.h" 21 | #include "base/io/json/Json.h" 22 | 23 | 24 | #include 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | const char *DnsConfig::kField = "dns"; 31 | const char *DnsConfig::kIPv6 = "ipv6"; 32 | const char *DnsConfig::kTTL = "ttl"; 33 | 34 | 35 | } // namespace xmrig 36 | 37 | 38 | xmrig::DnsConfig::DnsConfig(const rapidjson::Value &value) 39 | { 40 | m_ipv6 = Json::getBool(value, kIPv6, m_ipv6); 41 | m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U); 42 | } 43 | 44 | 45 | rapidjson::Value xmrig::DnsConfig::toJSON(rapidjson::Document &doc) const 46 | { 47 | using namespace rapidjson; 48 | 49 | auto &allocator = doc.GetAllocator(); 50 | Value obj(kObjectType); 51 | 52 | obj.AddMember(StringRef(kIPv6), m_ipv6, allocator); 53 | obj.AddMember(StringRef(kTTL), m_ttl, allocator); 54 | 55 | return obj; 56 | } 57 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsConfig.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_DNSCONFIG_H 20 | #define XMRIG_DNSCONFIG_H 21 | 22 | 23 | #include "3rdparty/rapidjson/fwd.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class DnsConfig 30 | { 31 | public: 32 | static const char *kField; 33 | static const char *kIPv6; 34 | static const char *kTTL; 35 | 36 | DnsConfig() = default; 37 | DnsConfig(const rapidjson::Value &value); 38 | 39 | inline bool isIPv6() const { return m_ipv6; } 40 | inline uint32_t ttl() const { return m_ttl * 1000U; } 41 | 42 | rapidjson::Value toJSON(rapidjson::Document &doc) const; 43 | 44 | 45 | private: 46 | bool m_ipv6 = false; 47 | uint32_t m_ttl = 30U; 48 | }; 49 | 50 | 51 | } /* namespace xmrig */ 52 | 53 | 54 | #endif /* XMRIG_DNSCONFIG_H */ 55 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsRecord.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | 23 | #include "base/net/dns/DnsRecord.h" 24 | 25 | 26 | xmrig::DnsRecord::DnsRecord(const addrinfo *addr) : 27 | m_type(addr->ai_family == AF_INET6 ? AAAA : (addr->ai_family == AF_INET ? A : Unknown)) 28 | { 29 | static_assert(sizeof(m_data) >= sizeof(sockaddr_in6), "Not enough storage for IPv6 address."); 30 | 31 | memcpy(m_data, addr->ai_addr, m_type == AAAA ? sizeof(sockaddr_in6) : sizeof(sockaddr_in)); 32 | } 33 | 34 | 35 | const sockaddr *xmrig::DnsRecord::addr(uint16_t port) const 36 | { 37 | reinterpret_cast(m_data)->sin_port = htons(port); 38 | 39 | return reinterpret_cast(m_data); 40 | } 41 | 42 | 43 | xmrig::String xmrig::DnsRecord::ip() const 44 | { 45 | char *buf = nullptr; 46 | 47 | if (m_type == AAAA) { 48 | buf = new char[45](); 49 | uv_ip6_name(reinterpret_cast(m_data), buf, 45); 50 | } 51 | else { 52 | buf = new char[16](); 53 | uv_ip4_name(reinterpret_cast(m_data), buf, 16); 54 | } 55 | 56 | return buf; 57 | } 58 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsRecord.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_DNSRECORD_H 20 | #define XMRIG_DNSRECORD_H 21 | 22 | 23 | struct addrinfo; 24 | struct sockaddr; 25 | 26 | 27 | #include "base/tools/String.h" 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class DnsRecord 34 | { 35 | public: 36 | enum Type : uint32_t { 37 | Unknown, 38 | A, 39 | AAAA 40 | }; 41 | 42 | DnsRecord() {} 43 | DnsRecord(const addrinfo *addr); 44 | 45 | const sockaddr *addr(uint16_t port = 0) const; 46 | String ip() const; 47 | 48 | inline bool isValid() const { return m_type != Unknown; } 49 | inline Type type() const { return m_type; } 50 | 51 | private: 52 | mutable uint8_t m_data[28]{}; 53 | const Type m_type = Unknown; 54 | }; 55 | 56 | 57 | } /* namespace xmrig */ 58 | 59 | 60 | #endif /* XMRIG_DNSRECORD_H */ 61 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsRecords.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_DNSRECORDS_H 20 | #define XMRIG_DNSRECORDS_H 21 | 22 | 23 | #include "base/net/dns/DnsRecord.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class DnsRecords 30 | { 31 | public: 32 | inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); } 33 | 34 | const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::Unknown) const; 35 | size_t count(DnsRecord::Type type = DnsRecord::Unknown) const; 36 | void clear(); 37 | void parse(addrinfo *res); 38 | 39 | private: 40 | std::vector m_ipv4; 41 | std::vector m_ipv6; 42 | }; 43 | 44 | 45 | } /* namespace xmrig */ 46 | 47 | 48 | #endif /* XMRIG_DNSRECORDS_H */ 49 | -------------------------------------------------------------------------------- /src/base/net/dns/DnsRequest.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_DNSREQUEST_H 20 | #define XMRIG_DNSREQUEST_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | 25 | 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class IDnsListener; 33 | 34 | 35 | class DnsRequest 36 | { 37 | public: 38 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(DnsRequest) 39 | 40 | DnsRequest(IDnsListener *listener) : listener(listener) {} 41 | ~DnsRequest() = default; 42 | 43 | IDnsListener *listener; 44 | }; 45 | 46 | 47 | } /* namespace xmrig */ 48 | 49 | 50 | #endif /* XMRIG_DNSREQUEST_H */ 51 | -------------------------------------------------------------------------------- /src/base/net/http/HttpApiResponse.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2014-2019 heapwolf 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_HTTPAPIRESPONSE_H 21 | #define XMRIG_HTTPAPIRESPONSE_H 22 | 23 | 24 | #include "3rdparty/rapidjson/document.h" 25 | #include "base/net/http/HttpResponse.h" 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | class HttpApiResponse : public HttpResponse 32 | { 33 | public: 34 | HttpApiResponse(uint64_t id); 35 | HttpApiResponse(uint64_t id, int status); 36 | 37 | inline rapidjson::Document &doc() { return m_doc; } 38 | 39 | void end(); 40 | 41 | private: 42 | rapidjson::Document m_doc; 43 | }; 44 | 45 | 46 | } // namespace xmrig 47 | 48 | 49 | #endif // XMRIG_HTTPAPIRESPONSE_H 50 | 51 | -------------------------------------------------------------------------------- /src/base/net/http/HttpListener.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "base/net/http/HttpListener.h" 21 | #include "3rdparty/llhttp/llhttp.h" 22 | #include "base/io/log/Log.h" 23 | #include "base/net/http/HttpData.h" 24 | 25 | 26 | void xmrig::HttpListener::onHttpData(const HttpData &data) 27 | { 28 | # ifdef APP_DEBUG 29 | if (!data.isRequest()) { 30 | 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"), 31 | m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), llhttp_method_name(static_cast(data.method)), data.url.data(), 32 | (data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size()); 33 | 34 | if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) { 35 | Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast(data.body.size()), data.body.c_str()); 36 | } 37 | } 38 | # endif 39 | 40 | m_listener->onHttpData(data); 41 | } 42 | -------------------------------------------------------------------------------- /src/base/net/http/HttpListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_HTTPLISTENER_H 20 | #define XMRIG_HTTPLISTENER_H 21 | 22 | 23 | #include "base/kernel/interfaces/IHttpListener.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class HttpListener : public IHttpListener 30 | { 31 | public: 32 | inline HttpListener(IHttpListener *listener, const char *tag = nullptr) : 33 | # ifdef APP_DEBUG 34 | m_tag(tag), 35 | # endif 36 | m_listener(listener) 37 | {} 38 | 39 | protected: 40 | void onHttpData(const HttpData &data) override; 41 | 42 | private: 43 | # ifdef APP_DEBUG 44 | const char *m_tag; 45 | # endif 46 | IHttpListener *m_listener; 47 | }; 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif // XMRIG_HTTPLISTENER_H 54 | -------------------------------------------------------------------------------- /src/base/net/http/HttpResponse.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2014-2019 heapwolf 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_HTTPRESPONSE_H 21 | #define XMRIG_HTTPRESPONSE_H 22 | 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class HttpResponse 33 | { 34 | public: 35 | HttpResponse(uint64_t id, int statusCode = 200); 36 | 37 | inline int statusCode() const { return m_statusCode; } 38 | inline void setHeader(const std::string &key, const std::string &value) { m_headers.insert({ key, value }); } 39 | inline void setStatus(int code) { m_statusCode = code; } 40 | 41 | bool isAlive() const; 42 | void end(const char *data = nullptr, size_t size = 0); 43 | 44 | private: 45 | const uint64_t m_id; 46 | int m_statusCode; 47 | std::map m_headers; 48 | }; 49 | 50 | 51 | } // namespace xmrig 52 | 53 | 54 | #endif // XMRIG_HTTPRESPONSE_H 55 | 56 | -------------------------------------------------------------------------------- /src/base/net/http/HttpServer.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2014-2019 heapwolf 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | 24 | 25 | #include "base/net/http/HttpServer.h" 26 | #include "3rdparty/llhttp/llhttp.h" 27 | #include "base/net/http/HttpContext.h" 28 | #include "base/net/tools/NetBuffer.h" 29 | 30 | 31 | xmrig::HttpServer::HttpServer(const std::shared_ptr &listener) : 32 | m_listener(listener) 33 | { 34 | } 35 | 36 | 37 | xmrig::HttpServer::~HttpServer() 38 | { 39 | HttpContext::closeAll(); 40 | } 41 | 42 | 43 | void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t) 44 | { 45 | auto ctx = new HttpContext(HTTP_REQUEST, m_listener); 46 | uv_accept(stream, ctx->stream()); 47 | 48 | uv_read_start(ctx->stream(), NetBuffer::onAlloc, 49 | [](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf) 50 | { 51 | auto ctx = static_cast(tcp->data); 52 | 53 | if (nread < 0 || !ctx->parse(buf->base, static_cast(nread))) { 54 | ctx->close(); 55 | } 56 | 57 | NetBuffer::release(buf); 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /src/base/net/http/HttpServer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2014-2019 heapwolf 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_HTTPSERVER_H 21 | #define XMRIG_HTTPSERVER_H 22 | 23 | 24 | #include "base/kernel/interfaces/ITcpServerListener.h" 25 | #include "base/tools/Object.h" 26 | 27 | 28 | #include 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class IHttpListener; 35 | 36 | 37 | class HttpServer : public ITcpServerListener 38 | { 39 | public: 40 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpServer) 41 | 42 | HttpServer(const std::shared_ptr &listener); 43 | ~HttpServer() override; 44 | 45 | protected: 46 | void onConnection(uv_stream_t *stream, uint16_t port) override; 47 | 48 | private: 49 | std::weak_ptr m_listener; 50 | }; 51 | 52 | 53 | } // namespace xmrig 54 | 55 | 56 | #endif // XMRIG_HTTPSERVER_H 57 | 58 | -------------------------------------------------------------------------------- /src/base/net/https/HttpsContext.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #ifndef XMRIG_HTTPSCONTEXT_H 21 | #define XMRIG_HTTPSCONTEXT_H 22 | 23 | 24 | using BIO = struct bio_st; 25 | using SSL = struct ssl_st; 26 | 27 | 28 | #include "base/net/http/HttpContext.h" 29 | #include "base/net/tls/ServerTls.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class TlsContext; 36 | 37 | 38 | class HttpsContext : public HttpContext, public ServerTls 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsContext) 42 | 43 | HttpsContext(TlsContext *tls, const std::weak_ptr &listener); 44 | ~HttpsContext() override; 45 | 46 | void append(char *data, size_t size); 47 | 48 | protected: 49 | // ServerTls 50 | bool write(BIO *bio) override; 51 | void parse(char *data, size_t size) override; 52 | void shutdown() override; 53 | 54 | // HttpContext 55 | void write(std::string &&data, bool close) override; 56 | 57 | private: 58 | enum TlsMode : uint32_t { 59 | TLS_AUTO, 60 | TLS_OFF, 61 | TLS_ON 62 | }; 63 | 64 | bool m_close = false; 65 | TlsMode m_mode = TLS_AUTO; 66 | }; 67 | 68 | 69 | } // namespace xmrig 70 | 71 | 72 | #endif // XMRIG_HTTPSCONTEXT_H 73 | 74 | -------------------------------------------------------------------------------- /src/base/net/https/HttpsServer.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | 22 | #include "base/net/https/HttpsServer.h" 23 | #include "base/net/https/HttpsContext.h" 24 | #include "base/net/tls/TlsContext.h" 25 | #include "base/net/tools/NetBuffer.h" 26 | 27 | 28 | xmrig::HttpsServer::HttpsServer(const std::shared_ptr &listener) : 29 | m_listener(listener) 30 | { 31 | } 32 | 33 | 34 | xmrig::HttpsServer::~HttpsServer() 35 | { 36 | HttpContext::closeAll(); 37 | 38 | delete m_tls; 39 | } 40 | 41 | 42 | bool xmrig::HttpsServer::setTls(const TlsConfig &config) 43 | { 44 | m_tls = TlsContext::create(config); 45 | 46 | return m_tls != nullptr; 47 | } 48 | 49 | 50 | void xmrig::HttpsServer::onConnection(uv_stream_t *stream, uint16_t) 51 | { 52 | auto ctx = new HttpsContext(m_tls, m_listener); 53 | uv_accept(stream, ctx->stream()); 54 | 55 | uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) 56 | } 57 | 58 | 59 | void xmrig::HttpsServer::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) 60 | { 61 | auto ctx = static_cast(stream->data); 62 | if (nread >= 0) { 63 | ctx->append(buf->base, static_cast(nread)); 64 | } 65 | else { 66 | ctx->close(); 67 | } 68 | 69 | NetBuffer::release(buf); 70 | } 71 | -------------------------------------------------------------------------------- /src/base/net/https/HttpsServer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_HTTPSSERVER_H 20 | #define XMRIG_HTTPSSERVER_H 21 | 22 | 23 | using uv_tcp_t = struct uv_tcp_s; 24 | 25 | struct http_parser; 26 | struct http_parser_settings; 27 | struct uv_buf_t; 28 | 29 | 30 | #include "base/kernel/interfaces/ITcpServerListener.h" 31 | #include "base/tools/Object.h" 32 | 33 | 34 | #include 35 | 36 | 37 | namespace xmrig { 38 | 39 | 40 | class IHttpListener; 41 | class TlsContext; 42 | class TlsConfig; 43 | 44 | 45 | class HttpsServer : public ITcpServerListener 46 | { 47 | public: 48 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsServer) 49 | 50 | HttpsServer(const std::shared_ptr &listener); 51 | ~HttpsServer() override; 52 | 53 | bool setTls(const TlsConfig &config); 54 | 55 | protected: 56 | void onConnection(uv_stream_t *stream, uint16_t port) override; 57 | 58 | private: 59 | static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); 60 | 61 | std::weak_ptr m_listener; 62 | TlsContext *m_tls = nullptr; 63 | }; 64 | 65 | 66 | } // namespace xmrig 67 | 68 | 69 | #endif // XMRIG_HTTPSSERVER_H 70 | 71 | -------------------------------------------------------------------------------- /src/base/net/stratum/AlgoSwitch.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2020 MoneroOcean , 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "3rdparty/rapidjson/document.h" 21 | #include "base/crypto/Algorithm.h" 22 | 23 | namespace xmrig { 24 | 25 | class Miner; 26 | 27 | class AlgoSwitch { 28 | typedef std::pair miner_algo_perf_data; 29 | typedef std::pair miner_algo_perf; 30 | typedef std::map miner_algo_perfs; 31 | uint64_t m_percent = 20; 32 | miner_algo_perfs m_miner_algo_perfs; 33 | Algorithms m_algos, m_default_algos; 34 | algo_perfs m_algo_perfs, m_default_algo_perfs; 35 | 36 | Algorithms intersection(Algorithms, Algorithms) const; 37 | algo_perfs intersection(const algo_perfs&, const algo_perfs&) const; 38 | 39 | void compute_common_miner_algo_perfs(); 40 | 41 | public: 42 | AlgoSwitch() { setDefaultAlgoSwitchAlgo(Algorithm(Algorithm::RX_0)); } 43 | void setDefaultAlgoSwitchAlgo(const Algorithm&); 44 | rapidjson::Value algos_toJSON(rapidjson::Document&) const; 45 | rapidjson::Value algo_perfs_toJSON(rapidjson::Document&) const; 46 | void set_algo_perf_same_threshold(uint64_t); 47 | bool try_miner(const Miner*, int upstream_count) const; 48 | void add_miner(const Miner*); 49 | void del_miner(const Miner*); 50 | }; 51 | 52 | } /* namespace xmrig */ 53 | -------------------------------------------------------------------------------- /src/base/net/stratum/AutoClient.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_AUTOCLIENT_H 20 | #define XMRIG_AUTOCLIENT_H 21 | 22 | 23 | #include "base/net/stratum/EthStratumClient.h" 24 | 25 | 26 | #include 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class AutoClient : public EthStratumClient 33 | { 34 | public: 35 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(AutoClient) 36 | 37 | AutoClient(int id, const char *agent, IClientListener *listener); 38 | ~AutoClient() override = default; 39 | 40 | protected: 41 | inline void login() override { Client::login(); } 42 | 43 | bool handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error) override; 44 | bool parseLogin(const rapidjson::Value &result, int *code) override; 45 | int64_t submit(const JobResult &result) override; 46 | void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error) override; 47 | 48 | private: 49 | enum Mode { 50 | DEFAULT_MODE, 51 | ETH_MODE 52 | }; 53 | 54 | Mode m_mode = DEFAULT_MODE; 55 | }; 56 | 57 | 58 | } /* namespace xmrig */ 59 | 60 | 61 | #endif /* XMRIG_AUTOCLIENT_H */ 62 | -------------------------------------------------------------------------------- /src/base/net/stratum/ProxyUrl.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2020 SChernykh 3 | * Copyright 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "base/net/stratum/ProxyUrl.h" 21 | #include "3rdparty/rapidjson/document.h" 22 | 23 | 24 | namespace xmrig { 25 | 26 | static const String kLocalhost = "127.0.0.1"; 27 | 28 | } // namespace xmrig 29 | 30 | 31 | xmrig::ProxyUrl::ProxyUrl(const rapidjson::Value &value) 32 | { 33 | m_port = 0; 34 | 35 | if (value.IsString()) { 36 | parse(value.GetString()); 37 | } 38 | else if (value.IsUint()) { 39 | m_port = value.GetUint(); 40 | } 41 | } 42 | 43 | 44 | const xmrig::String &xmrig::ProxyUrl::host() const 45 | { 46 | return m_host.isNull() && isValid() ? kLocalhost : m_host; 47 | } 48 | 49 | 50 | rapidjson::Value xmrig::ProxyUrl::toJSON(rapidjson::Document &doc) const 51 | { 52 | using namespace rapidjson; 53 | if (!isValid()) { 54 | return Value(kNullType); 55 | } 56 | 57 | if (!m_host.isNull()) { 58 | return m_url.toJSON(doc); 59 | } 60 | 61 | return Value(m_port); 62 | } 63 | -------------------------------------------------------------------------------- /src/base/net/stratum/ProxyUrl.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2020 SChernykh 3 | * Copyright 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_PROXYURL_H 20 | #define XMRIG_PROXYURL_H 21 | 22 | 23 | #include "base/net/stratum/Url.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class ProxyUrl : public Url 30 | { 31 | public: 32 | inline ProxyUrl() { m_port = 0; } 33 | 34 | ProxyUrl(const rapidjson::Value &value); 35 | 36 | inline bool isValid() const { return m_port > 0 && (m_scheme == UNSPECIFIED || m_scheme == SOCKS5); } 37 | 38 | const String &host() const; 39 | rapidjson::Value toJSON(rapidjson::Document &doc) const; 40 | }; 41 | 42 | 43 | } /* namespace xmrig */ 44 | 45 | 46 | #endif /* XMRIG_PROXYURL_H */ 47 | -------------------------------------------------------------------------------- /src/base/net/stratum/Socks5.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2020 SChernykh 3 | * Copyright 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_SOCKS5_H 20 | #define XMRIG_SOCKS5_H 21 | 22 | 23 | #include "base/net/stratum/Client.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class Client::Socks5 30 | { 31 | public: 32 | Socks5(Client *client); 33 | 34 | inline bool isReady() const { return m_state == Ready; } 35 | 36 | bool read(const char *data, size_t size); 37 | void handshake(); 38 | 39 | private: 40 | enum State { 41 | Created, 42 | SentInitialHandshake, 43 | SentFinalHandshake, 44 | Ready 45 | }; 46 | 47 | static bool isIPv4(const String &host, sockaddr_storage *addr); 48 | static bool isIPv6(const String &host, sockaddr_storage *addr); 49 | 50 | void connect(); 51 | 52 | Client *m_client; 53 | size_t m_nextSize = 0; 54 | State m_state = Created; 55 | }; 56 | 57 | 58 | } /* namespace xmrig */ 59 | 60 | 61 | #endif /* XMRIG_SOCKS5_H */ 62 | -------------------------------------------------------------------------------- /src/base/net/stratum/Tls.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018 Lee Clagett 3 | * Copyright (c) 2018-2021 SChernykh 4 | * Copyright (c) 2016-2021 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_CLIENT_TLS_H 21 | #define XMRIG_CLIENT_TLS_H 22 | 23 | 24 | using BIO = struct bio_st; 25 | using SSL = struct ssl_st; 26 | using SSL_CTX = struct ssl_ctx_st; 27 | using X509 = struct x509_st; 28 | 29 | 30 | #include "base/net/stratum/Client.h" 31 | #include "base/tools/Object.h" 32 | 33 | 34 | namespace xmrig { 35 | 36 | 37 | class Client::Tls 38 | { 39 | public: 40 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Tls) 41 | 42 | Tls(Client *client); 43 | ~Tls(); 44 | 45 | bool handshake(const char* servername); 46 | bool send(const char *data, size_t size); 47 | const char *fingerprint() const; 48 | const char *version() const; 49 | void read(const char *data, size_t size); 50 | 51 | private: 52 | bool send(); 53 | bool verify(X509 *cert); 54 | bool verifyFingerprint(X509 *cert); 55 | 56 | BIO *m_read = nullptr; 57 | BIO *m_write = nullptr; 58 | bool m_ready = false; 59 | char m_fingerprint[32 * 2 + 8]{}; 60 | Client *m_client; 61 | SSL *m_ssl = nullptr; 62 | SSL_CTX *m_ctx; 63 | }; 64 | 65 | 66 | } /* namespace xmrig */ 67 | 68 | 69 | #endif /* XMRIG_CLIENT_TLS_H */ 70 | -------------------------------------------------------------------------------- /src/base/net/tls/ServerTls.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #ifndef XMRIG_SERVERTLS_H 21 | #define XMRIG_SERVERTLS_H 22 | 23 | 24 | using BIO = struct bio_st; 25 | using SSL = struct ssl_st; 26 | using SSL_CTX = struct ssl_ctx_st; 27 | 28 | 29 | 30 | #include "base/tools/Object.h" 31 | 32 | 33 | namespace xmrig { 34 | 35 | 36 | class ServerTls 37 | { 38 | public: 39 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(ServerTls) 40 | 41 | ServerTls(SSL_CTX *ctx); 42 | virtual ~ServerTls(); 43 | 44 | static bool isHTTP(const char *data, size_t size); 45 | static bool isTLS(const char *data, size_t size); 46 | 47 | bool send(const char *data, size_t size); 48 | void read(const char *data, size_t size); 49 | 50 | protected: 51 | virtual bool write(BIO *bio) = 0; 52 | virtual void parse(char *data, size_t size) = 0; 53 | virtual void shutdown() = 0; 54 | 55 | private: 56 | void read(); 57 | 58 | BIO *m_read = nullptr; 59 | BIO *m_write = nullptr; 60 | bool m_ready = false; 61 | SSL *m_ssl = nullptr; 62 | SSL_CTX *m_ctx; 63 | }; 64 | 65 | 66 | } // namespace xmrig 67 | 68 | 69 | #endif /* XMRIG_SERVERTLS_H */ 70 | -------------------------------------------------------------------------------- /src/base/net/tls/TlsContext.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018 Lee Clagett 3 | * Copyright (c) 2018-2023 SChernykh 4 | * Copyright (c) 2016-2023 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_TLSCONTEXT_H 21 | #define XMRIG_TLSCONTEXT_H 22 | 23 | 24 | #include "base/tools/Object.h" 25 | 26 | 27 | using SSL_CTX = struct ssl_ctx_st; 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class TlsConfig; 34 | 35 | 36 | class TlsContext 37 | { 38 | public: 39 | XMRIG_DISABLE_COPY_MOVE(TlsContext) 40 | 41 | ~TlsContext(); 42 | 43 | static TlsContext *create(const TlsConfig &config); 44 | 45 | inline SSL_CTX *ctx() const { return m_ctx; } 46 | 47 | private: 48 | TlsContext() = default; 49 | 50 | bool load(const TlsConfig &config); 51 | bool setCiphers(const char *ciphers); 52 | bool setCipherSuites(const char *ciphersuites); 53 | bool setDH(const char *dhparam); 54 | void setProtocols(uint32_t protocols); 55 | 56 | SSL_CTX *m_ctx = nullptr; 57 | }; 58 | 59 | 60 | } // namespace xmrig 61 | 62 | 63 | #endif // XMRIG_TLSCONTEXT_H 64 | -------------------------------------------------------------------------------- /src/base/net/tls/TlsGen.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_TLSGEN_H 20 | #define XMRIG_TLSGEN_H 21 | 22 | 23 | #include "base/tools/Object.h" 24 | #include "base/tools/String.h" 25 | 26 | 27 | using EVP_PKEY = struct evp_pkey_st; 28 | using X509 = struct x509_st; 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class TlsGen 35 | { 36 | public: 37 | XMRIG_DISABLE_COPY_MOVE(TlsGen) 38 | 39 | TlsGen() : m_cert("cert.pem"), m_certKey("cert_key.pem") {} 40 | ~TlsGen(); 41 | 42 | inline const String &cert() const { return m_cert; } 43 | inline const String &certKey() const { return m_certKey; } 44 | 45 | void generate(const char *commonName = nullptr); 46 | 47 | private: 48 | bool generate_x509(const char *commonName); 49 | bool write(); 50 | 51 | const String m_cert; 52 | const String m_certKey; 53 | EVP_PKEY *m_pkey = nullptr; 54 | X509 *m_x509 = nullptr; 55 | }; 56 | 57 | 58 | } // namespace xmrig 59 | 60 | 61 | #endif // XMRIG_TLSGEN_H 62 | -------------------------------------------------------------------------------- /src/base/net/tools/LineReader.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2020 cohcho 3 | * Copyright (c) 2018-2020 SChernykh 4 | * Copyright (c) 2016-2020 XMRig , 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef XMRIG_LINEREADER_H 21 | #define XMRIG_LINEREADER_H 22 | 23 | 24 | #include "base/tools/Object.h" 25 | 26 | 27 | #include 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class ILineListener; 34 | 35 | 36 | class LineReader 37 | { 38 | public: 39 | XMRIG_DISABLE_COPY_MOVE(LineReader) 40 | 41 | LineReader() = default; 42 | LineReader(ILineListener *listener) : m_listener(listener) {} 43 | ~LineReader(); 44 | 45 | inline void setListener(ILineListener *listener) { m_listener = listener; } 46 | 47 | void parse(char *data, size_t size); 48 | void reset(); 49 | 50 | private: 51 | void add(const char *data, size_t size); 52 | void getline(char *data, size_t size); 53 | 54 | char *m_buf = nullptr; 55 | ILineListener *m_listener = nullptr; 56 | size_t m_pos = 0; 57 | }; 58 | 59 | 60 | } /* namespace xmrig */ 61 | 62 | 63 | #endif /* XMRIG_NETBUFFER_H */ 64 | -------------------------------------------------------------------------------- /src/base/net/tools/NetBuffer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_NETBUFFER_H 20 | #define XMRIG_NETBUFFER_H 21 | 22 | 23 | struct uv_buf_t; 24 | using uv_handle_t = struct uv_handle_s; 25 | 26 | 27 | #include 28 | 29 | 30 | namespace xmrig { 31 | 32 | 33 | class NetBuffer 34 | { 35 | public: 36 | static char *allocate(); 37 | static void destroy(); 38 | static void onAlloc(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); 39 | static void release(const char *buf); 40 | static void release(const uv_buf_t *buf); 41 | }; 42 | 43 | 44 | } /* namespace xmrig */ 45 | 46 | 47 | #endif /* XMRIG_NETBUFFER_H */ 48 | -------------------------------------------------------------------------------- /src/base/net/tools/TcpServer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_TCPSERVER_H 26 | #define XMRIG_TCPSERVER_H 27 | 28 | 29 | #include 30 | 31 | 32 | #include "base/tools/Object.h" 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class ITcpServerListener; 39 | class String; 40 | 41 | 42 | class TcpServer 43 | { 44 | public: 45 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(TcpServer) 46 | 47 | TcpServer(const String &host, uint16_t port, ITcpServerListener *listener); 48 | ~TcpServer(); 49 | 50 | int bind(); 51 | 52 | private: 53 | void create(uv_stream_t *stream, int status); 54 | 55 | static void onConnection(uv_stream_t *stream, int status); 56 | 57 | const String &m_host; 58 | int m_version = 0; 59 | ITcpServerListener *m_listener; 60 | sockaddr_storage m_addr{}; 61 | uint16_t m_port; 62 | uv_tcp_t *m_tcp; 63 | }; 64 | 65 | 66 | } /* namespace xmrig */ 67 | 68 | 69 | #endif /* XMRIG_TCPSERVER_H */ 70 | -------------------------------------------------------------------------------- /src/base/tools/Alignment.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2022 SChernykh 3 | * Copyright (c) 2016-2022 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ALIGNMENT_H 20 | #define XMRIG_ALIGNMENT_H 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | template 31 | inline T readUnaligned(const T* ptr) 32 | { 33 | static_assert(std::is_trivially_copyable::value, "T must be trivially copyable"); 34 | 35 | T result; 36 | memcpy(&result, ptr, sizeof(T)); 37 | return result; 38 | } 39 | 40 | 41 | template 42 | inline void writeUnaligned(T* ptr, T data) 43 | { 44 | static_assert(std::is_trivially_copyable::value, "T must be trivially copyable"); 45 | 46 | memcpy(ptr, &data, sizeof(T)); 47 | } 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif /* XMRIG_ALIGNMENT_H */ 54 | -------------------------------------------------------------------------------- /src/base/tools/Arguments.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_ARGUMENTS_H 20 | #define XMRIG_ARGUMENTS_H 21 | 22 | 23 | #include 24 | 25 | 26 | #include "base/tools/String.h" 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class Arguments 33 | { 34 | public: 35 | Arguments(int argc, char **argv); 36 | 37 | bool hasArg(const char *name) const; 38 | const char *value(const char *key1, const char *key2 = nullptr) const; 39 | 40 | inline char **argv() const { return m_argv; } 41 | inline const std::vector &data() const { return m_data; } 42 | inline int argc() const { return m_argc; } 43 | 44 | private: 45 | void add(const char *arg); 46 | 47 | char **m_argv; 48 | int m_argc; 49 | std::vector m_data; 50 | }; 51 | 52 | 53 | } /* namespace xmrig */ 54 | 55 | 56 | #endif /* XMRIG_ARGUMENTS_H */ 57 | -------------------------------------------------------------------------------- /src/base/tools/Baton.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_BATON_H 20 | #define XMRIG_BATON_H 21 | 22 | 23 | namespace xmrig { 24 | 25 | 26 | template 27 | class Baton 28 | { 29 | public: 30 | inline Baton() { req.data = this; } 31 | 32 | REQ req; 33 | }; 34 | 35 | 36 | } /* namespace xmrig */ 37 | 38 | 39 | #endif /* XMRIG_BATON_H */ 40 | -------------------------------------------------------------------------------- /src/base/tools/Buffer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2020 SChernykh 3 | * Copyright (c) 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_BUFFER_H 20 | #define XMRIG_BUFFER_H 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | using Buffer = std::vector; 31 | 32 | 33 | } /* namespace xmrig */ 34 | 35 | 36 | #endif /* XMRIG_BUFFER_H */ 37 | -------------------------------------------------------------------------------- /src/base/tools/Chrono.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "Chrono.h" 20 | 21 | 22 | #ifdef XMRIG_OS_WIN 23 | # include 24 | #endif 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | double Chrono::highResolutionMSecs() 31 | { 32 | # ifdef XMRIG_OS_WIN 33 | LARGE_INTEGER f, t; 34 | QueryPerformanceFrequency(&f); 35 | QueryPerformanceCounter(&t); 36 | return static_cast(t.QuadPart) * 1e3 / f.QuadPart; 37 | # else 38 | using namespace std::chrono; 39 | return static_cast(duration_cast(high_resolution_clock::now().time_since_epoch()).count()) / 1e6; 40 | # endif 41 | } 42 | 43 | 44 | } /* namespace xmrig */ 45 | -------------------------------------------------------------------------------- /src/base/tools/Chrono.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_CHRONO_H 20 | #define XMRIG_CHRONO_H 21 | 22 | 23 | #include 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | class Chrono 30 | { 31 | public: 32 | static double highResolutionMSecs(); 33 | 34 | 35 | static inline uint64_t steadyMSecs() 36 | { 37 | using namespace std::chrono; 38 | if (high_resolution_clock::is_steady) { 39 | return static_cast(time_point_cast(high_resolution_clock::now()).time_since_epoch().count()); 40 | } 41 | 42 | return static_cast(time_point_cast(steady_clock::now()).time_since_epoch().count()); 43 | } 44 | 45 | 46 | static inline uint64_t currentMSecsSinceEpoch() 47 | { 48 | using namespace std::chrono; 49 | 50 | return static_cast(time_point_cast(system_clock::now()).time_since_epoch().count()); 51 | } 52 | }; 53 | 54 | 55 | } /* namespace xmrig */ 56 | 57 | #endif /* XMRIG_CHRONO_H */ 58 | -------------------------------------------------------------------------------- /src/base/tools/Object.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2023 SChernykh 3 | * Copyright (c) 2016-2023 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_OBJECT_H 20 | #define XMRIG_OBJECT_H 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | #define XMRIG_DISABLE_COPY_MOVE(X) \ 32 | X(const X &other) = delete; \ 33 | X(X &&other) = delete; \ 34 | X &operator=(const X &other) = delete; \ 35 | X &operator=(X &&other) = delete; 36 | 37 | 38 | #define XMRIG_DISABLE_COPY_MOVE_DEFAULT(X) \ 39 | X() = delete; \ 40 | X(const X &other) = delete; \ 41 | X(X &&other) = delete; \ 42 | X &operator=(const X &other) = delete; \ 43 | X &operator=(X &&other) = delete; 44 | 45 | 46 | } // namespace xmrig 47 | 48 | 49 | #endif // XMRIG_OBJECT_H 50 | -------------------------------------------------------------------------------- /src/base/tools/Span.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_SPAN_H 20 | #define XMRIG_SPAN_H 21 | 22 | 23 | #include "3rdparty/epee/span.h" 24 | 25 | 26 | namespace xmrig { 27 | 28 | 29 | using Span = epee::span; 30 | 31 | 32 | } /* namespace xmrig */ 33 | 34 | 35 | #endif /* XMRIG_SPAN_H */ 36 | -------------------------------------------------------------------------------- /src/base/tools/Timer.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2018-2020 SChernykh 3 | * Copyright 2016-2020 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_TIMER_H 20 | #define XMRIG_TIMER_H 21 | 22 | 23 | using uv_timer_t = struct uv_timer_s; 24 | 25 | 26 | #include "base/tools/Object.h" 27 | 28 | 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class ITimerListener; 36 | 37 | 38 | class Timer 39 | { 40 | public: 41 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Timer); 42 | 43 | Timer(ITimerListener *listener); 44 | Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat); 45 | ~Timer(); 46 | 47 | inline int id() const { return m_id; } 48 | 49 | uint64_t repeat() const; 50 | void setRepeat(uint64_t repeat); 51 | void singleShot(uint64_t timeout, int id = 0); 52 | void start(uint64_t timeout, uint64_t repeat); 53 | void stop(); 54 | 55 | private: 56 | void init(); 57 | 58 | static void onTimer(uv_timer_t *handle); 59 | 60 | int m_id = 0; 61 | ITimerListener *m_listener; 62 | uv_timer_t *m_timer = nullptr; 63 | }; 64 | 65 | 66 | } /* namespace xmrig */ 67 | 68 | 69 | #endif /* XMRIG_TIMER_H */ 70 | -------------------------------------------------------------------------------- /src/base/tools/bswap_64.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_BSWAP_64_H 20 | #define XMRIG_BSWAP_64_H 21 | 22 | #ifdef _MSC_VER 23 | 24 | #include 25 | #define bswap_64(x) _byteswap_uint64(x) 26 | #define bswap_32(x) _byteswap_ulong(x) 27 | 28 | #elif defined __GNUC__ 29 | 30 | #define bswap_64(x) __builtin_bswap64(x) 31 | #define bswap_32(x) __builtin_bswap32(x) 32 | 33 | #else 34 | 35 | #include 36 | 37 | #endif 38 | 39 | #endif /* XMRIG_BSWAP_64_H */ 40 | -------------------------------------------------------------------------------- /src/base/tools/cryptonote/Signatures.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2012-2013 The Cryptonote developers 3 | * Copyright 2014-2021 The Monero Project 4 | * Copyright 2018-2021 SChernykh 5 | * Copyright 2016-2021 XMRig , 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef XMRIG_SIGNATURES_H 22 | #define XMRIG_SIGNATURES_H 23 | 24 | 25 | #include 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | void generate_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sec, uint8_t* sig); 32 | bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sig); 33 | 34 | bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation, uint8_t* view_tag); 35 | void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); 36 | bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); 37 | 38 | void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key); 39 | 40 | void generate_keys(uint8_t* pub, uint8_t* sec); 41 | bool secret_key_to_public_key(const uint8_t* sec, uint8_t* pub); 42 | 43 | } /* namespace xmrig */ 44 | 45 | 46 | #endif /* XMRIG_SIGNATURES_H */ 47 | -------------------------------------------------------------------------------- /src/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "access-log-file": null, 3 | "access-password": null, 4 | "algo-ext": true, 5 | "api": { 6 | "id": null, 7 | "worker-id": null 8 | }, 9 | "http": { 10 | "enabled": false, 11 | "host": "127.0.0.1", 12 | "port": 0, 13 | "access-token": null, 14 | "restricted": true 15 | }, 16 | "background": false, 17 | "bind": [ 18 | { 19 | "host": "0.0.0.0", 20 | "port": 3333, 21 | "tls": false 22 | }, 23 | { 24 | "host": "::", 25 | "port": 3333, 26 | "tls": false 27 | } 28 | ], 29 | "colors": true, 30 | "title": true, 31 | "custom-diff": 0, 32 | "custom-diff-stats": false, 33 | "donate-level": 0, 34 | "log-file": null, 35 | "mode": "nicehash", 36 | "pools": [ 37 | { 38 | "algo": null, 39 | "coin": null, 40 | "url": "gulf.moneroocean.stream:11024", 41 | "user": "YOUR_XMR_WALLET", 42 | "pass": "x", 43 | "rig-id": null, 44 | "keepalive": true, 45 | "enabled": true, 46 | "tls": false, 47 | "tls-fingerprint": null, 48 | "daemon": false 49 | } 50 | ], 51 | "retries": 2, 52 | "retry-pause": 1, 53 | "reuse-timeout": 0, 54 | "algo-perf-same-threshold": 50, 55 | "tls": { 56 | "enabled": true, 57 | "protocols": null, 58 | "cert": null, 59 | "cert_key": null, 60 | "ciphers": null, 61 | "ciphersuites": null, 62 | "dhparam": null 63 | }, 64 | "user-agent": null, 65 | "syslog": false, 66 | "verbose": false, 67 | "watch": true, 68 | "workers": true 69 | } -------------------------------------------------------------------------------- /src/core/config/ConfigTransform.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_CONFIGTRANSFORM_H 26 | #define XMRIG_CONFIGTRANSFORM_H 27 | 28 | 29 | #include "base/kernel/config/BaseTransform.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class ConfigTransform : public BaseTransform 36 | { 37 | public: 38 | ConfigTransform() = default; 39 | 40 | protected: 41 | void transform(rapidjson::Document &doc, int key, const char *arg) override; 42 | 43 | private: 44 | void transformBoolean(rapidjson::Document &doc, int key, bool enable); 45 | void transformUint64(rapidjson::Document &doc, int key, uint64_t arg); 46 | }; 47 | 48 | 49 | } // namespace xmrig 50 | 51 | 52 | #endif /* XMRIG_CONFIGTRANSFORM_H */ 53 | -------------------------------------------------------------------------------- /src/net/JobResult.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include "net/JobResult.h" 21 | #include "base/net/stratum/Job.h" 22 | #include "base/tools/Cvt.h" 23 | 24 | 25 | #include 26 | 27 | 28 | xmrig::JobResult::JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce) : 29 | algorithm(algorithm), 30 | nonce(nonce), 31 | result(result), 32 | sig(sig), 33 | sig_data(sig_data), 34 | view_tag(view_tag), 35 | id(id), 36 | extra_nonce(extra_nonce), 37 | jobId(jobId) 38 | { 39 | if (result && strlen(result) == 64) { 40 | uint64_t target = 0; 41 | Cvt::fromHex(reinterpret_cast(&target), sizeof(target), result + 48, 16); 42 | 43 | if (target > 0) { 44 | m_actualDiff = Job::toDiff(target); 45 | } 46 | } 47 | } 48 | 49 | 50 | bool xmrig::JobResult::isCompatible(uint8_t fixedByte) const 51 | { 52 | uint8_t n[4]; 53 | if (!Cvt::fromHex(n, sizeof(n), nonce, 8)) { 54 | return false; 55 | } 56 | 57 | return n[3] == fixedByte; 58 | } 59 | 60 | 61 | bool xmrig::JobResult::isValid() const 62 | { 63 | if (!nonce || m_actualDiff == 0) { 64 | return false; 65 | } 66 | 67 | return strlen(nonce) == 8 && !jobId.isNull(); 68 | } 69 | -------------------------------------------------------------------------------- /src/net/JobResult.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright (c) 2018-2021 SChernykh 3 | * Copyright (c) 2016-2021 XMRig , 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef XMRIG_JOBRESULT_H 20 | #define XMRIG_JOBRESULT_H 21 | 22 | 23 | #include 24 | #include 25 | 26 | 27 | #include "base/crypto/Algorithm.h" 28 | #include "base/tools/String.h" 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class JobResult 35 | { 36 | public: 37 | static constexpr uint32_t backend = 0; 38 | 39 | JobResult() = default; 40 | JobResult(int64_t id, const char *jobId, const char *nonce, const char *result, const xmrig::Algorithm &algorithm, const char* sig, const char* sig_data, uint8_t view_tag, int64_t extra_nonce); 41 | 42 | bool isCompatible(uint8_t fixedByte) const; 43 | bool isValid() const; 44 | 45 | inline uint64_t actualDiff() const { return m_actualDiff; } 46 | 47 | Algorithm algorithm; 48 | const char *nonce = nullptr; 49 | const char *result = nullptr; 50 | const char *sig = nullptr; 51 | const char *sig_data = nullptr; 52 | const uint8_t view_tag = 0; 53 | const int64_t id = 0; 54 | const int64_t extra_nonce = -1; 55 | String jobId; 56 | uint64_t diff = 0; 57 | 58 | private: 59 | uint64_t m_actualDiff = 0; 60 | }; 61 | 62 | 63 | } /* namespace xmrig */ 64 | 65 | 66 | #endif /* XMRIG_JOBRESULT_H */ 67 | -------------------------------------------------------------------------------- /src/proxy/Counters.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include "Counters.h" 26 | 27 | 28 | uint32_t Counters::m_added = 0; 29 | uint32_t Counters::m_removed = 0; 30 | uint64_t Counters::accepted = 0; 31 | uint64_t Counters::connections = 0; 32 | uint64_t Counters::expired = 0; 33 | uint64_t Counters::m_maxMiners = 0; 34 | uint64_t Counters::m_miners = 0; 35 | -------------------------------------------------------------------------------- /src/proxy/CustomDiff.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_CUSTOMDIFF_H 26 | #define XMRIG_CUSTOMDIFF_H 27 | 28 | 29 | #include "interfaces/IEventListener.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class Controller; 36 | class LoginEvent; 37 | 38 | 39 | class CustomDiff : public IEventListener 40 | { 41 | public: 42 | CustomDiff(Controller *controller); 43 | ~CustomDiff() override; 44 | 45 | protected: 46 | void onEvent(IEvent *event) override; 47 | inline void onRejectedEvent(IEvent *) override {} 48 | 49 | private: 50 | void login(LoginEvent *event); 51 | 52 | Controller *m_controller; 53 | }; 54 | 55 | 56 | } /* namespace xmrig */ 57 | 58 | 59 | #endif /* XMRIG_CUSTOMDIFF_H */ 60 | -------------------------------------------------------------------------------- /src/proxy/Error.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ERROR_H 26 | #define XMRIG_ERROR_H 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class Error 33 | { 34 | public: 35 | enum Code { 36 | NoError, 37 | BadGateway, 38 | InvalidJobId, 39 | InvalidMethod, 40 | InvalidNonce, 41 | LowDifficulty, 42 | Unauthenticated, 43 | IncompatibleAlgorithm, 44 | IncorrectAlgorithm, 45 | Forbidden, 46 | RouteNotFound 47 | }; 48 | 49 | static const char *toString(int code); 50 | }; 51 | 52 | 53 | } /* namespace xmrig */ 54 | 55 | 56 | #endif /* XMRIG_ERROR_H */ 57 | -------------------------------------------------------------------------------- /src/proxy/Events.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include "base/io/log/Log.h" 26 | #include "proxy/Events.h" 27 | 28 | 29 | namespace xmrig { 30 | 31 | bool Events::m_ready = true; 32 | std::map > Events::m_listeners; 33 | 34 | } 35 | 36 | 37 | bool xmrig::Events::exec(IEvent *event) 38 | { 39 | if (!m_ready) { 40 | LOG_ERR("failed start event %d", (int) event->type()); 41 | return false; 42 | } 43 | 44 | m_ready = false; 45 | 46 | std::vector &listeners = m_listeners[event->type()]; 47 | for (IEventListener *listener : listeners) { 48 | event->isRejected() ? listener->onRejectedEvent(event) : listener->onEvent(event); 49 | } 50 | 51 | const bool rejected = event->isRejected(); 52 | event->~IEvent(); 53 | 54 | m_ready = true; 55 | return !rejected; 56 | } 57 | 58 | 59 | void xmrig::Events::stop() 60 | { 61 | m_listeners.clear(); 62 | } 63 | 64 | 65 | void xmrig::Events::subscribe(IEvent::Type type, IEventListener *listener) 66 | { 67 | m_listeners[type].push_back(listener); 68 | } 69 | -------------------------------------------------------------------------------- /src/proxy/Events.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_EVENTS_H 26 | #define XMRIG_EVENTS_H 27 | 28 | 29 | #include 30 | #include 31 | 32 | 33 | #include "interfaces/IEvent.h" 34 | #include "interfaces/IEventListener.h" 35 | 36 | 37 | namespace xmrig { 38 | 39 | 40 | class Events 41 | { 42 | public: 43 | static bool exec(IEvent *event); 44 | static void stop(); 45 | static void subscribe(IEvent::Type type, IEventListener *listener); 46 | 47 | private: 48 | static bool m_ready; 49 | static std::map > m_listeners; 50 | }; 51 | 52 | 53 | } /* namespace xmrig */ 54 | 55 | 56 | #endif /* XMRIG_EVENTS_H */ 57 | -------------------------------------------------------------------------------- /src/proxy/Login.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_LOGIN_H 26 | #define XMRIG_LOGIN_H 27 | 28 | 29 | #include "base/tools/Object.h" 30 | #include "interfaces/IEventListener.h" 31 | 32 | 33 | namespace xmrig { 34 | 35 | 36 | class Controller; 37 | class LoginEvent; 38 | 39 | 40 | class Login : public IEventListener 41 | { 42 | public: 43 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Login) 44 | 45 | Login(Controller *controller); 46 | ~Login() override; 47 | 48 | protected: 49 | void onEvent(IEvent *event) override; 50 | inline void onRejectedEvent(IEvent *) override {} 51 | 52 | private: 53 | void login(LoginEvent *event); 54 | void reject(LoginEvent *event, const char *message); 55 | 56 | Controller *m_controller; 57 | }; 58 | 59 | 60 | } /* namespace xmrig */ 61 | 62 | 63 | #endif /* XMRIG_LOGIN_H */ 64 | -------------------------------------------------------------------------------- /src/proxy/Miners.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_MINERS_H 26 | #define XMRIG_MINERS_H 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | #include "interfaces/IEventListener.h" 35 | 36 | 37 | namespace xmrig { 38 | 39 | 40 | class Miner; 41 | 42 | 43 | class Miners : public IEventListener 44 | { 45 | public: 46 | Miners(); 47 | ~Miners() override; 48 | 49 | std::vector miners() const; 50 | 51 | protected: 52 | void onEvent(IEvent *event) override; 53 | inline void onRejectedEvent(IEvent *) override {} 54 | 55 | private: 56 | constexpr static int kTickInterval = 1 * 1000; 57 | 58 | void add(Miner *miner); 59 | void remove(Miner *miner); 60 | void tick(); 61 | 62 | std::map m_miners; 63 | uv_timer_t *m_timer; 64 | }; 65 | 66 | 67 | } /* namespace xmrig */ 68 | 69 | 70 | #endif /* XMRIG_MINERS_H */ 71 | -------------------------------------------------------------------------------- /src/proxy/ProxyDebug.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_PROXYDEBUG_H 26 | #define XMRIG_PROXYDEBUG_H 27 | 28 | 29 | #include "interfaces/IEventListener.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class ProxyDebug : public IEventListener 36 | { 37 | public: 38 | ProxyDebug(bool enabled); 39 | ~ProxyDebug() override; 40 | 41 | inline void setEnabled(bool enabled) { m_enabled = enabled; } 42 | inline void toggle() { m_enabled = !m_enabled; } 43 | 44 | protected: 45 | void onEvent(IEvent *event) override; 46 | void onRejectedEvent(IEvent *event) override; 47 | 48 | private: 49 | bool m_enabled; 50 | }; 51 | 52 | 53 | } /* namespace xmrig */ 54 | 55 | 56 | #endif /* XMRIG_PROXYDEBUG_H */ 57 | -------------------------------------------------------------------------------- /src/proxy/Server.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_SERVER_H 26 | #define XMRIG_SERVER_H 27 | 28 | 29 | #include 30 | 31 | 32 | #include "base/tools/Object.h" 33 | #include "base/tools/String.h" 34 | 35 | 36 | namespace xmrig { 37 | 38 | 39 | class BindHost; 40 | class TlsContext; 41 | 42 | 43 | class Server 44 | { 45 | public: 46 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(Server) 47 | 48 | Server(const BindHost &host, const TlsContext *ctx); 49 | ~Server(); 50 | 51 | bool bind(); 52 | 53 | private: 54 | void create(uv_stream_t *server, int status); 55 | 56 | static void onConnection(uv_stream_t *server, int status); 57 | 58 | const bool m_strictTls; 59 | const String m_host; 60 | const TlsContext *m_ctx; 61 | const uint16_t m_port; 62 | int m_version = 0; 63 | sockaddr_storage m_addr{}; 64 | uv_tcp_t *m_server; 65 | }; 66 | 67 | 68 | } /* namespace xmrig */ 69 | 70 | 71 | #endif /* XMRIG_SERVER_H */ 72 | -------------------------------------------------------------------------------- /src/proxy/events/CloseEvent.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_CLOSEEVENT_H 26 | #define XMRIG_CLOSEEVENT_H 27 | 28 | 29 | #include "proxy/events/MinerEvent.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class CloseEvent : public MinerEvent 36 | { 37 | public: 38 | static inline bool start(Miner *miner) 39 | { 40 | return exec(new (m_buf) CloseEvent(miner)); 41 | } 42 | 43 | 44 | protected: 45 | inline CloseEvent(Miner *miner) : MinerEvent(CloseType, miner) {} 46 | }; 47 | 48 | 49 | } /* namespace xmrig */ 50 | 51 | 52 | #endif /* XMRIG_CLOSEEVENT_H */ 53 | -------------------------------------------------------------------------------- /src/proxy/events/ConnectionEvent.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_CONNECTIONEVENT_H 26 | #define XMRIG_CONNECTIONEVENT_H 27 | 28 | 29 | #include "proxy/events/MinerEvent.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class ConnectionEvent : public MinerEvent 36 | { 37 | public: 38 | static inline bool start(Miner *miner, int port) 39 | { 40 | return exec(new (m_buf) ConnectionEvent(miner, port)); 41 | } 42 | 43 | inline int port() const { return m_port; } 44 | 45 | 46 | protected: 47 | inline ConnectionEvent(Miner *miner, int port) 48 | : MinerEvent(ConnectionType, miner), 49 | m_port(port) 50 | {} 51 | 52 | private: 53 | int m_port; 54 | }; 55 | 56 | 57 | } /* namespace xmrig */ 58 | 59 | 60 | #endif /* __CONNECTIONEVENT_H__ */ 61 | -------------------------------------------------------------------------------- /src/proxy/events/Event.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include "proxy/Events.h" 27 | #include "proxy/events/Event.h" 28 | 29 | 30 | char xmrig::Event::m_buf[4096]; 31 | 32 | 33 | bool xmrig::Event::exec(IEvent *event) 34 | { 35 | return Events::exec(event); 36 | } 37 | -------------------------------------------------------------------------------- /src/proxy/events/Event.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_EVENT_H 26 | #define XMRIG_EVENT_H 27 | 28 | 29 | #include 30 | 31 | 32 | #include "proxy/interfaces/IEvent.h" 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class Event : public IEvent 39 | { 40 | public: 41 | inline Event(Type type) : m_type(type) {} 42 | 43 | static bool exec(IEvent *event); 44 | 45 | inline bool isRejected() const override { return m_rejected; } 46 | inline Type type() const override { return m_type; } 47 | inline void reject() override { m_rejected = true; } 48 | 49 | inline bool start() { return exec(this); } 50 | 51 | protected: 52 | bool m_rejected = false; 53 | const Type m_type; 54 | 55 | static char m_buf[4096]; 56 | }; 57 | 58 | 59 | } /* namespace xmrig */ 60 | 61 | 62 | #endif /* XMRIG_EVENT_H */ 63 | -------------------------------------------------------------------------------- /src/proxy/events/MinerEvent.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include "proxy/events/MinerEvent.h" 27 | #include "proxy/Miner.h" 28 | 29 | 30 | static const char *kDefaultIP = "0.0.0.0"; 31 | 32 | 33 | const char *xmrig::MinerEvent::ip() const 34 | { 35 | return m_miner ? m_miner->ip() : kDefaultIP; 36 | } 37 | 38 | 39 | int32_t xmrig::MinerEvent::route() const 40 | { 41 | return m_miner ? m_miner->routeId() : -1; 42 | } 43 | -------------------------------------------------------------------------------- /src/proxy/events/MinerEvent.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_MINEREVENT_H 26 | #define XMRIG_MINEREVENT_H 27 | 28 | 29 | #include "proxy/events/Event.h" 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class Miner; 36 | 37 | 38 | class MinerEvent : public Event 39 | { 40 | public: 41 | const char *ip() const; 42 | 43 | 44 | inline Miner *miner() const { return m_miner; } 45 | 46 | 47 | protected: 48 | inline MinerEvent(Type type, Miner *miner) : Event(type), m_miner(miner) {} 49 | 50 | int32_t route() const override; 51 | 52 | 53 | private: 54 | Miner *m_miner; 55 | }; 56 | 57 | 58 | } /* namespace xmrig */ 59 | 60 | 61 | #endif /* XMRIG_MINEREVENT_H */ 62 | -------------------------------------------------------------------------------- /src/proxy/interfaces/IEvent.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_IEVENT_H 26 | #define XMRIG_IEVENT_H 27 | 28 | 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class IEvent 36 | { 37 | public: 38 | enum Type { 39 | ConnectionType, 40 | CloseType, 41 | LoginType, 42 | SubmitType, 43 | AcceptType 44 | }; 45 | 46 | virtual ~IEvent() = default; 47 | 48 | virtual bool isRejected() const = 0; 49 | virtual int32_t route() const = 0; 50 | virtual Type type() const = 0; 51 | virtual void reject() = 0; 52 | }; 53 | 54 | 55 | } /* namespace xmrig */ 56 | 57 | 58 | #endif // XMRIG_IEVENT_H 59 | -------------------------------------------------------------------------------- /src/proxy/interfaces/IEventListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_IEVENTLISTENER_H 26 | #define XMRIG_IEVENTLISTENER_H 27 | 28 | 29 | namespace xmrig { 30 | 31 | 32 | class IEvent; 33 | 34 | 35 | class IEventListener 36 | { 37 | public: 38 | virtual ~IEventListener() = default; 39 | 40 | virtual void onEvent(IEvent *event) = 0; 41 | virtual void onRejectedEvent(IEvent *event) = 0; 42 | }; 43 | 44 | 45 | } /* namespace xmrig */ 46 | 47 | 48 | #endif // XMRIG_IEVENTLISTENER_H 49 | -------------------------------------------------------------------------------- /src/proxy/log/AccessLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_ACCESSLOG_H 26 | #define XMRIG_ACCESSLOG_H 27 | 28 | 29 | #include "base/io/log/FileLogWriter.h" 30 | #include "base/tools/Object.h" 31 | #include "proxy/interfaces/IEventListener.h" 32 | 33 | 34 | namespace xmrig { 35 | 36 | 37 | class Controller; 38 | 39 | 40 | class AccessLog : public IEventListener 41 | { 42 | public: 43 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(AccessLog) 44 | 45 | AccessLog(Controller *controller); 46 | ~AccessLog() override; 47 | 48 | protected: 49 | void onEvent(IEvent *event) override; 50 | void onRejectedEvent(IEvent *event) override; 51 | 52 | private: 53 | void write(const char *fmt, ...); 54 | 55 | FileLogWriter m_writer; 56 | }; 57 | 58 | 59 | } /* namespace xmrig */ 60 | 61 | 62 | #endif /* XMRIG_ACCESSLOG_H */ 63 | -------------------------------------------------------------------------------- /src/proxy/log/ShareLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_SHARELOG_H 26 | #define XMRIG_SHARELOG_H 27 | 28 | 29 | #include "base/tools/Object.h" 30 | #include "proxy/interfaces/IEventListener.h" 31 | 32 | 33 | namespace xmrig { 34 | 35 | 36 | class AcceptEvent; 37 | class Controller; 38 | class Stats; 39 | 40 | 41 | class ShareLog : public IEventListener 42 | { 43 | public: 44 | XMRIG_DISABLE_COPY_MOVE_DEFAULT(ShareLog) 45 | 46 | ShareLog(Controller *controller, Stats *stats); 47 | ~ShareLog() override; 48 | 49 | protected: 50 | void onEvent(IEvent *event) override; 51 | void onRejectedEvent(IEvent *event) override; 52 | 53 | private: 54 | void accept(const AcceptEvent *event); 55 | void reject(const AcceptEvent *event); 56 | 57 | Stats *m_stats; 58 | Controller *m_controller; 59 | }; 60 | 61 | 62 | } /* namespace xmrig */ 63 | 64 | 65 | #endif /* XMRIG_SHARELOG_H */ 66 | -------------------------------------------------------------------------------- /src/proxy/splitters/Splitter.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include "core/Controller.h" 27 | #include "proxy/splitters/Splitter.h" 28 | 29 | 30 | xmrig::Splitter::Splitter(Controller *controller) : 31 | m_controller(controller) 32 | { 33 | controller->addListener(this); 34 | } 35 | -------------------------------------------------------------------------------- /src/proxy/splitters/Splitter.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2019 SChernykh 9 | * Copyright 2016-2019 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_SPLITTER_H 26 | #define XMRIG_SPLITTER_H 27 | 28 | 29 | #include "base/kernel/interfaces/IBaseListener.h" 30 | #include "proxy/interfaces/IEventListener.h" 31 | #include "proxy/interfaces/ISplitter.h" 32 | 33 | 34 | namespace xmrig { 35 | 36 | 37 | class Controller; 38 | 39 | 40 | class Splitter : public IEventListener, public ISplitter, public IBaseListener 41 | { 42 | public: 43 | Splitter(Controller *controller); 44 | 45 | protected: 46 | Controller *m_controller; 47 | }; 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif /* XMRIG_SPLITTER_H */ 54 | -------------------------------------------------------------------------------- /src/proxy/tls/MinerTls.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2018-2020 SChernykh 10 | * Copyright 2016-2020 XMRig , 11 | * 12 | * This program is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | 26 | 27 | #include "proxy/tls/MinerTls.h" 28 | 29 | 30 | xmrig::Miner::Tls::Tls(SSL_CTX *ctx, Miner *miner) : 31 | ServerTls(ctx), 32 | m_miner(miner) 33 | { 34 | } 35 | 36 | 37 | bool xmrig::Miner::Tls::write(BIO *bio) 38 | { 39 | return m_miner->send(bio); 40 | } 41 | 42 | 43 | void xmrig::Miner::Tls::parse(char *data, size_t size) 44 | { 45 | m_miner->m_reader.parse(data, size); 46 | } 47 | 48 | 49 | void xmrig::Miner::Tls::shutdown() 50 | { 51 | m_miner->close(); 52 | } 53 | -------------------------------------------------------------------------------- /src/proxy/tls/MinerTls.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018-2020 SChernykh 9 | * Copyright 2016-2020 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef XMRIG_MINER_TLS_H 26 | #define XMRIG_MINER_TLS_H 27 | 28 | 29 | #include "base/net/tls/ServerTls.h" 30 | #include "proxy/Miner.h" 31 | 32 | 33 | class xmrig::Miner::Tls : public ServerTls 34 | { 35 | public: 36 | Tls(SSL_CTX *ctx, Miner *miner); 37 | 38 | protected: 39 | bool write(BIO *bio) override; 40 | void parse(char *data, size_t size) override; 41 | void shutdown() override; 42 | 43 | private: 44 | Miner *m_miner; 45 | }; 46 | 47 | 48 | #endif /* XMRIG_MINER_TLS_H */ 49 | --------------------------------------------------------------------------------