diff --git a/CHANGELOG.md b/CHANGELOG.md index 95575c3d..71d4e5b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,156 +1,156 @@ -# v2.6.0-beta2 -- Improved performance for `cryptonight v7` especially in double hash mode. -- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 disabled for internal HTTP API by default, was cause issues on some systems. -- Added short aliases for algorithm names: `cn`, `cn-lite` and `cn-heavy`. -- Fixed regressions (v2.6.0-beta1 affected) - - [#494](https://github.com/xmrig/xmrig/issues/494) Command line option `--donate-level` was broken. +# v2.6.0-beta2 +- Improved performance for `cryptonight v7` especially in double hash mode. +- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 disabled for internal HTTP API by default, was causing issues on some systems. +- Added short aliases for algorithm names: `cn`, `cn-lite` and `cn-heavy`. +- Fixed regressions (v2.6.0-beta1 affected) + - [#494](https://github.com/xmrig/xmrig/issues/494) Command line option `--donate-level` was broken. - [#502](https://github.com/xmrig/xmrig/issues/502) Build without libmicrohttpd was broken. - - Fixed nonce calculation for `--av 4` (software AES, double hash) was cause reduction of effective hashrate and rejected shares on nicehash. - -# v2.6.0-beta1 - - [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.** - - HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization. - - Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested. - - Added API endpoint `PUT /1/config` to update current config. - - Added API endpoint `GET /1/config` to get current active config. - - Added API endpoint `GET /1/threads` to get current active threads configuration. - - API endpoint `GET /` now deprecated, use `GET /1/summary` instead. - - Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API. - - Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified. - -# v2.5.2 -- [#448](https://github.com/xmrig/xmrig/issues/478) Fixed broken reconnect. - -# v2.5.1 -- [#454](https://github.com/xmrig/xmrig/issues/454) Fixed build with libmicrohttpd version below v0.9.35. -- [#456](https://github.com/xmrig/xmrig/issues/459) Verbose errors related to donation pool was not fully silenced. -- [#459](https://github.com/xmrig/xmrig/issues/459) Fixed regression (version 2.5.0 affected) with connection to **xmr.f2pool.com**. - -# v2.5.0 -- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on April 6.** -- Added full IPv6 support. -- Added protocol extension, when use the miner with xmrig-proxy 2.5+ no more need manually specify `nicehash` option. -- [#123](https://github.com/xmrig/xmrig-proxy/issues/123) Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy was parsed incorrectly. -- [#428](https://github.com/xmrig/xmrig/issues/428) Fixed regression (version 2.4.5 affected) with CPU cache size detection. - -# v2.4.5 -- [#324](https://github.com/xmrig/xmrig/pull/324) Fixed build without libmicrohttpd (CMake cache issue). -- [#341](https://github.com/xmrig/xmrig/issues/341) Fixed wrong exit code and added command line option `--dry-run`. -- [#385](https://github.com/xmrig/xmrig/pull/385) Up to 20% performance increase for non-AES CPU and fixed Intel Core 2 cache detection. - -# v2.4.4 - - Added libmicrohttpd version to --version output. - - Fixed bug in singal handler, in some cases miner wasn't shutdown properly. - - Fixed recent MSVC 2017 version detection. - - [#279](https://github.com/xmrig/xmrig/pull/279) Fixed build on some macOS versions. - -# v2.4.3 - - [#94](https://github.com/xmrig/xmrig/issues/94#issuecomment-342019257) [#216](https://github.com/xmrig/xmrig/issues/216) Added **ARMv8** and **ARMv7** support. Hardware AES supported, thanks [Imran Yusuff](https://github.com/imranyusuff). - - [#157](https://github.com/xmrig/xmrig/issues/157) [#196](https://github.com/xmrig/xmrig/issues/196) Fixed Linux compile issues. - - [#184](https://github.com/xmrig/xmrig/issues/184) Fixed cache size detection for CPUs with disabled Hyper-Threading. - - [#200](https://github.com/xmrig/xmrig/issues/200) In some cases miner was doesn't write log to stdout. - -# v2.4.2 - - [#60](https://github.com/xmrig/xmrig/issues/60) Added FreeBSD support, thanks [vcambur](https://github.com/vcambur). - - [#153](https://github.com/xmrig/xmrig/issues/153) Fixed issues with dwarfpool.com. - -# v2.4.1 - - [#147](https://github.com/xmrig/xmrig/issues/147) Fixed comparability with monero-stratum. - -# v2.4.0 - - Added [HTTP API](https://github.com/xmrig/xmrig/wiki/API). - - Added comments support in config file. - - libjansson replaced to rapidjson. - - [#98](https://github.com/xmrig/xmrig/issues/98) Ignore `keepalive` option with minergate.com and nicehash.com. - - [#101](https://github.com/xmrig/xmrig/issues/101) Fixed MSVC 2017 (15.3) compile time version detection. - - [#108](https://github.com/xmrig/xmrig/issues/108) Silently ignore invalid values for `donate-level` option. - - [#111](https://github.com/xmrig/xmrig/issues/111) Fixed build without AEON support. - -# v2.3.1 -- [#68](https://github.com/xmrig/xmrig/issues/68) Fixed compatibility with Docker containers, was nothing print on console. - -# v2.3.0 -- Added `--cpu-priority` option (0 idle, 2 normal to 5 highest). -- Added `--user-agent` option, to set custom user-agent string for pool. For example `cpuminer-multi/0.1`. -- Added `--no-huge-pages` option, to disable huge pages support. -- [#62](https://github.com/xmrig/xmrig/issues/62) Don't send the login to the dev pool. -- Force reconnect if pool block miner IP address. helps switch to backup pool. -- Fixed: failed open default config file if path contains non English characters. -- Fixed: error occurred if try use unavailable stdin or stdout, regression since version 2.2.0. -- Fixed: message about huge pages support successfully enabled on Windows was not shown in release builds. - -# v2.2.1 -- Fixed [terminal issues](https://github.com/xmrig/xmrig-proxy/issues/2#issuecomment-319914085) after exit on Linux and OS X. - -# v2.2.0 -- [#46](https://github.com/xmrig/xmrig/issues/46) Restored config file support. Now possible use multiple config files and combine with command line options also added support for default config. -- Improved colors support on Windows, now used uv_tty, legacy code removed. -- QuickEdit Mode now disabled on Windows. -- Added interactive commands in console window:: **h**ashrate, **p**ause, **r**esume. -- Fixed autoconf mode for AMD FX CPUs. - -# v2.1.0 -- [#40](https://github.com/xmrig/xmrig/issues/40) -Improved miner shutdown, fixed crash on exit for Linux and OS X. -- Fixed, login request was contain malformed JSON if username or password has some special characters for example `\`. -- [#220](https://github.com/fireice-uk/xmr-stak-cpu/pull/220) Better support for Round Robin DNS, IP address now always chosen randomly instead of stuck on first one. -- Changed donation address, new [xmrig-proxy](https://github.com/xmrig/xmrig-proxy) is coming soon. - -# v2.0.2 -- Better deal with possible duplicate jobs from pool, show warning and ignore duplicates. -- For Windows builds libuv updated to version 1.13.1 and gcc to 7.1.0. - -# v2.0.1 - - [#27](https://github.com/xmrig/xmrig/issues/27) Fixed possibility crash on 32bit systems. - -# v2.0.0 - - Option `--backup-url` removed, instead now possibility specify multiple pools for example: `-o example1.com:3333 -u user1 -p password1 -k -o example2.com:5555 -u user2 -o example3.com:4444 -u user3` - - [#15](https://github.com/xmrig/xmrig/issues/15) Added option `-l, --log-file=FILE` to write log to file. - - [#15](https://github.com/xmrig/xmrig/issues/15) Added option `-S, --syslog` to use syslog for logging, Linux only. - - [#18](https://github.com/xmrig/xmrig/issues/18) Added nice messages for accepted/rejected shares with diff and network latency. - - [#20](https://github.com/xmrig/xmrig/issues/20) Fixed `--cpu-affinity` for more than 32 threads. - - Fixed Windows XP support. - - Fixed regression, option `--no-color` was not fully disable colored output. - - Show resolved pool IP address in miner output. - -# v1.0.1 -- Fix broken software AES implementation, app has crashed if CPU not support AES-NI, only version 1.0.0 affected. - -# v1.0.0 -- Miner complete rewritten in C++ with libuv. -- This version should be fully compatible (except config file) with previos versions, many new nice features will come in next versions. -- This is still beta. If you found regression, stability or perfomance issues or have an idea for new feature please fell free to open new [issue](https://github.com/xmrig/xmrig/issues/new). -- Added new option `--print-time=N`, print hashrate report every N seconds. -- New hashrate reports, by default every 60 secons. -- Added Microsoft Visual C++ 2015 and 2017 support. -- Removed dependency on libcurl. -- To compile this version from source please switch to [dev](https://github.com/xmrig/xmrig/tree/dev) branch. - -# v0.8.2 -- Fixed L2 cache size detection for AMD CPUs (Bulldozer/Piledriver/Steamroller/Excavator architecture). - -# v0.8.2 -- Fixed L2 cache size detection for AMD CPUs (Bulldozer/Piledriver/Steamroller/Excavator architecture). -- Fixed gcc 7.1 support. - -# v0.8.1 -- Added nicehash support, detects automaticaly by pool URL, for example `cryptonight.eu.nicehash.com:3355` or manually via option `--nicehash`. - -# v0.8.0 -- Added double hash mode, also known as lower power mode. `--av=2` and `--av=4`. -- Added smart automatic CPU configuration. Default threads count now depends on size of the L3 cache of CPU. -- Added CryptoNight-Lite support for AEON `-a cryptonight-lite`. -- Added `--max-cpu-usage` option for auto CPU configuration mode. -- Added `--safe` option for adjust threads and algorithm variations to current CPU. -- No more manual steps to enable huge pages on Windows. XMRig will do it automatically. -- Removed BMI2 algorithm variation. -- Removed default pool URL. - -# v0.6.0 -- Added automatic cryptonight self test. -- New software AES algorithm variation. Will be automatically selected if cpu not support AES-NI. -- Added 32 bit builds. -- Documented [algorithm variations](https://github.com/xmrig/xmrig#algorithm-variations). - -# v0.5.0 -- Initial public release. + - Fixed nonce calculation for `--av 4` (software AES, double hash) was causing reduction of effective hashrate and rejected shares on nicehash. + +# v2.6.0-beta1 + - [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.** + - HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization. + - Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested. + - Added API endpoint `PUT /1/config` to update current config. + - Added API endpoint `GET /1/config` to get current active config. + - Added API endpoint `GET /1/threads` to get current active threads configuration. + - API endpoint `GET /` now deprecated, use `GET /1/summary` instead. + - Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API. + - Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified. + +# v2.5.2 +- [#448](https://github.com/xmrig/xmrig/issues/478) Fixed broken reconnect. + +# v2.5.1 +- [#454](https://github.com/xmrig/xmrig/issues/454) Fixed build with libmicrohttpd version below v0.9.35. +- [#456](https://github.com/xmrig/xmrig/issues/459) Verbose errors related to donation pool was not fully silenced. +- [#459](https://github.com/xmrig/xmrig/issues/459) Fixed regression (version 2.5.0 affected) with connection to **xmr.f2pool.com**. + +# v2.5.0 +- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on April 6.** +- Added full IPv6 support. +- Added protocol extension, when use the miner with xmrig-proxy 2.5+ no more need manually specify `nicehash` option. +- [#123](https://github.com/xmrig/xmrig-proxy/issues/123) Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy was parsed incorrectly. +- [#428](https://github.com/xmrig/xmrig/issues/428) Fixed regression (version 2.4.5 affected) with CPU cache size detection. + +# v2.4.5 +- [#324](https://github.com/xmrig/xmrig/pull/324) Fixed build without libmicrohttpd (CMake cache issue). +- [#341](https://github.com/xmrig/xmrig/issues/341) Fixed wrong exit code and added command line option `--dry-run`. +- [#385](https://github.com/xmrig/xmrig/pull/385) Up to 20% performance increase for non-AES CPU and fixed Intel Core 2 cache detection. + +# v2.4.4 + - Added libmicrohttpd version to --version output. + - Fixed bug in singal handler, in some cases miner wasn't shutdown properly. + - Fixed recent MSVC 2017 version detection. + - [#279](https://github.com/xmrig/xmrig/pull/279) Fixed build on some macOS versions. + +# v2.4.3 + - [#94](https://github.com/xmrig/xmrig/issues/94#issuecomment-342019257) [#216](https://github.com/xmrig/xmrig/issues/216) Added **ARMv8** and **ARMv7** support. Hardware AES supported, thanks [Imran Yusuff](https://github.com/imranyusuff). + - [#157](https://github.com/xmrig/xmrig/issues/157) [#196](https://github.com/xmrig/xmrig/issues/196) Fixed Linux compile issues. + - [#184](https://github.com/xmrig/xmrig/issues/184) Fixed cache size detection for CPUs with disabled Hyper-Threading. + - [#200](https://github.com/xmrig/xmrig/issues/200) In some cases miner was doesn't write log to stdout. + +# v2.4.2 + - [#60](https://github.com/xmrig/xmrig/issues/60) Added FreeBSD support, thanks [vcambur](https://github.com/vcambur). + - [#153](https://github.com/xmrig/xmrig/issues/153) Fixed issues with dwarfpool.com. + +# v2.4.1 + - [#147](https://github.com/xmrig/xmrig/issues/147) Fixed comparability with monero-stratum. + +# v2.4.0 + - Added [HTTP API](https://github.com/xmrig/xmrig/wiki/API). + - Added comments support in config file. + - libjansson replaced to rapidjson. + - [#98](https://github.com/xmrig/xmrig/issues/98) Ignore `keepalive` option with minergate.com and nicehash.com. + - [#101](https://github.com/xmrig/xmrig/issues/101) Fixed MSVC 2017 (15.3) compile time version detection. + - [#108](https://github.com/xmrig/xmrig/issues/108) Silently ignore invalid values for `donate-level` option. + - [#111](https://github.com/xmrig/xmrig/issues/111) Fixed build without AEON support. + +# v2.3.1 +- [#68](https://github.com/xmrig/xmrig/issues/68) Fixed compatibility with Docker containers, was nothing print on console. + +# v2.3.0 +- Added `--cpu-priority` option (0 idle, 2 normal to 5 highest). +- Added `--user-agent` option, to set custom user-agent string for pool. For example `cpuminer-multi/0.1`. +- Added `--no-huge-pages` option, to disable huge pages support. +- [#62](https://github.com/xmrig/xmrig/issues/62) Don't send the login to the dev pool. +- Force reconnect if pool block miner IP address. helps switch to backup pool. +- Fixed: failed open default config file if path contains non English characters. +- Fixed: error occurred if try use unavailable stdin or stdout, regression since version 2.2.0. +- Fixed: message about huge pages support successfully enabled on Windows was not shown in release builds. + +# v2.2.1 +- Fixed [terminal issues](https://github.com/xmrig/xmrig-proxy/issues/2#issuecomment-319914085) after exit on Linux and OS X. + +# v2.2.0 +- [#46](https://github.com/xmrig/xmrig/issues/46) Restored config file support. Now possible use multiple config files and combine with command line options also added support for default config. +- Improved colors support on Windows, now used uv_tty, legacy code removed. +- QuickEdit Mode now disabled on Windows. +- Added interactive commands in console window:: **h**ashrate, **p**ause, **r**esume. +- Fixed autoconf mode for AMD FX CPUs. + +# v2.1.0 +- [#40](https://github.com/xmrig/xmrig/issues/40) +Improved miner shutdown, fixed crash on exit for Linux and OS X. +- Fixed, login request was contain malformed JSON if username or password has some special characters for example `\`. +- [#220](https://github.com/fireice-uk/xmr-stak-cpu/pull/220) Better support for Round Robin DNS, IP address now always chosen randomly instead of stuck on first one. +- Changed donation address, new [xmrig-proxy](https://github.com/xmrig/xmrig-proxy) is coming soon. + +# v2.0.2 +- Better deal with possible duplicate jobs from pool, show warning and ignore duplicates. +- For Windows builds libuv updated to version 1.13.1 and gcc to 7.1.0. + +# v2.0.1 + - [#27](https://github.com/xmrig/xmrig/issues/27) Fixed possibility crash on 32bit systems. + +# v2.0.0 + - Option `--backup-url` removed, instead now possibility specify multiple pools for example: `-o example1.com:3333 -u user1 -p password1 -k -o example2.com:5555 -u user2 -o example3.com:4444 -u user3` + - [#15](https://github.com/xmrig/xmrig/issues/15) Added option `-l, --log-file=FILE` to write log to file. + - [#15](https://github.com/xmrig/xmrig/issues/15) Added option `-S, --syslog` to use syslog for logging, Linux only. + - [#18](https://github.com/xmrig/xmrig/issues/18) Added nice messages for accepted/rejected shares with diff and network latency. + - [#20](https://github.com/xmrig/xmrig/issues/20) Fixed `--cpu-affinity` for more than 32 threads. + - Fixed Windows XP support. + - Fixed regression, option `--no-color` was not fully disable colored output. + - Show resolved pool IP address in miner output. + +# v1.0.1 +- Fix broken software AES implementation, app has crashed if CPU not support AES-NI, only version 1.0.0 affected. + +# v1.0.0 +- Miner complete rewritten in C++ with libuv. +- This version should be fully compatible (except config file) with previos versions, many new nice features will come in next versions. +- This is still beta. If you found regression, stability or perfomance issues or have an idea for new feature please fell free to open new [issue](https://github.com/xmrig/xmrig/issues/new). +- Added new option `--print-time=N`, print hashrate report every N seconds. +- New hashrate reports, by default every 60 secons. +- Added Microsoft Visual C++ 2015 and 2017 support. +- Removed dependency on libcurl. +- To compile this version from source please switch to [dev](https://github.com/xmrig/xmrig/tree/dev) branch. + +# v0.8.2 +- Fixed L2 cache size detection for AMD CPUs (Bulldozer/Piledriver/Steamroller/Excavator architecture). + +# v0.8.2 +- Fixed L2 cache size detection for AMD CPUs (Bulldozer/Piledriver/Steamroller/Excavator architecture). +- Fixed gcc 7.1 support. + +# v0.8.1 +- Added nicehash support, detects automaticaly by pool URL, for example `cryptonight.eu.nicehash.com:3355` or manually via option `--nicehash`. + +# v0.8.0 +- Added double hash mode, also known as lower power mode. `--av=2` and `--av=4`. +- Added smart automatic CPU configuration. Default threads count now depends on size of the L3 cache of CPU. +- Added CryptoNight-Lite support for AEON `-a cryptonight-lite`. +- Added `--max-cpu-usage` option for auto CPU configuration mode. +- Added `--safe` option for adjust threads and algorithm variations to current CPU. +- No more manual steps to enable huge pages on Windows. XMRig will do it automatically. +- Removed BMI2 algorithm variation. +- Removed default pool URL. + +# v0.6.0 +- Added automatic cryptonight self test. +- New software AES algorithm variation. Will be automatically selected if cpu not support AES-NI. +- Added 32 bit builds. +- Documented [algorithm variations](https://github.com/xmrig/xmrig#algorithm-variations). + +# v0.5.0 +- Initial public release. diff --git a/CMakeLists.txt b/CMakeLists.txt index 43a7c1d4..5502405c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ set(HEADERS src/core/ConfigLoader_platform.h src/core/ConfigWatcher.cpp src/core/Controller.h + src/core/utils/c_str.h src/Cpu.h src/interfaces/IClientListener.h src/interfaces/IConfig.h @@ -44,12 +45,12 @@ set(HEADERS src/net/Job.h src/net/JobResult.h src/net/Network.h + src/net/Pool.h src/net/Storage.h src/net/strategies/DonateStrategy.h src/net/strategies/FailoverStrategy.h src/net/strategies/SinglePoolStrategy.h src/net/SubmitResult.h - src/net/Url.h src/Platform.h src/Summary.h src/version.h @@ -101,11 +102,11 @@ set(SOURCES src/net/Client.cpp src/net/Job.cpp src/net/Network.cpp + src/net/Pool.cpp src/net/strategies/DonateStrategy.cpp src/net/strategies/FailoverStrategy.cpp src/net/strategies/SinglePoolStrategy.cpp src/net/SubmitResult.cpp - src/net/Url.cpp src/Platform.cpp src/Summary.cpp src/workers/CpuThread.cpp diff --git a/src/Summary.cpp b/src/Summary.cpp index 56f3f522..5acda5c2 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -32,7 +32,7 @@ #include "Cpu.h" #include "log/Log.h" #include "Mem.h" -#include "net/Url.h" +#include "net/Pool.h" #include "Summary.h" #include "version.h" @@ -112,18 +112,18 @@ static void print_threads(xmrig::Config *config) static void print_pools(xmrig::Config *config) { - const std::vector &pools = config->pools(); + const std::vector &pools = config->pools(); for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d", + Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s", i + 1, - pools[i]->host(), - pools[i]->port()); + pools[i].url() + ); } # ifdef APP_DEBUG for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text("%s:%d, user: %s, pass: %s, ka: %d, nicehash: %d", pools[i]->host(), pools[i]->port(), pools[i]->user(), pools[i]->password(), pools[i]->keepAlive(), pools[i]->isNicehash()); + Log::i()->text("%s:%d, user: %s, pass: %s, ka: %d, nicehash: %d", pools[i].host(), pools[i].port(), pools[i].user(), pools[i].password(), pools[i].keepAlive(), pools[i].isNicehash()); } # endif } diff --git a/src/api/Httpd.cpp b/src/api/Httpd.cpp index 45c9ce07..e0901b77 100644 --- a/src/api/Httpd.cpp +++ b/src/api/Httpd.cpp @@ -33,37 +33,6 @@ #include "log/Log.h" -class UploadCtx -{ -public: - inline UploadCtx() : - m_pos(0) - {} - - - inline bool write(const char *data, size_t size) - { - if (size > (sizeof(m_data) - m_pos - 1)) { - return false; - } - - memcpy(m_data + m_pos, data, size); - - m_pos += size; - m_data[m_pos] = '\0'; - - return true; - } - - - inline const char *data() const { return m_data; } - -private: - char m_data[32768]; - size_t m_pos; -}; - - Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : m_idle(true), m_IPv6(IPv6), diff --git a/src/core/CommonConfig.cpp b/src/core/CommonConfig.cpp index 5b8a32ab..726b0e37 100644 --- a/src/core/CommonConfig.cpp +++ b/src/core/CommonConfig.cpp @@ -32,32 +32,13 @@ #include "core/CommonConfig.h" #include "donate.h" #include "log/Log.h" -#include "net/Url.h" +#include "net/Pool.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" #include "xmrig.h" -static const char *algoNames[] = { - "cryptonight", - "cryptonight-lite", - "cryptonight-heavy" -}; - - -static const char *algoNamesShort[] = { - "cn", - "cn-lite", - "cn-heavy" -}; - - -#if defined(_WIN32) && !defined(strcasecmp) -# define strcasecmp _stricmp -#endif - - xmrig::CommonConfig::CommonConfig() : m_algorithm(CRYPTONIGHT), m_adjusted(false), @@ -73,18 +54,13 @@ xmrig::CommonConfig::CommonConfig() : m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested. # endif - m_apiToken(nullptr), - m_apiWorkerId(nullptr), - m_fileName(nullptr), - m_logFile(nullptr), - m_userAgent(nullptr), m_apiPort(0), m_donateLevel(kDefaultDonateLevel), m_printTime(60), m_retries(5), m_retryPause(5) { - m_pools.push_back(new Url()); + m_pools.push_back(Pool()); # ifdef XMRIG_PROXY_PROJECT m_retries = 2; @@ -95,23 +71,6 @@ xmrig::CommonConfig::CommonConfig() : xmrig::CommonConfig::~CommonConfig() { - for (Url *url : m_pools) { - delete url; - } - - m_pools.clear(); - - free(m_fileName); - free(m_apiToken); - free(m_apiWorkerId); - free(m_logFile); - free(m_userAgent); -} - - -const char *xmrig::CommonConfig::algoName(Algo algorithm) -{ - return algoNames[algorithm]; } @@ -123,8 +82,8 @@ bool xmrig::CommonConfig::adjust() m_adjusted = true; - for (Url *url : m_pools) { - url->adjust(algorithm()); + for (Pool &pool : m_pools) { + pool.adjust(algorithm()); } return true; @@ -133,7 +92,7 @@ bool xmrig::CommonConfig::adjust() bool xmrig::CommonConfig::isValid() const { - return m_pools[0]->isValid(); + return m_pools[0].isValid() && m_algorithm != INVALID_ALGO; } @@ -149,12 +108,12 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) break; case KeepAliveKey: /* --keepalive */ - m_pools.back()->setKeepAlive(enable ? Url::kKeepAliveTimeout : 0); + m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); break; # ifndef XMRIG_PROXY_PROJECT case NicehashKey: /* --nicehash */ - m_pools.back()->setNicehash(enable); + m_pools.back().setNicehash(enable); break; # endif @@ -188,58 +147,52 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) break; case UserpassKey: /* --userpass */ - if (!m_pools.back()->setUserpass(arg)) { + if (!m_pools.back().setUserpass(arg)) { return false; } break; case UrlKey: /* --url */ - if (m_pools.size() > 1 || m_pools[0]->isValid()) { - Url *url = new Url(arg); - if (url->isValid()) { - m_pools.push_back(url); - } - else { - delete url; + if (m_pools.size() > 1 || m_pools[0].isValid()) { + Pool pool(arg); + + if (pool.isValid()) { + m_pools.push_back(std::move(pool)); } } else { - m_pools[0]->parse(arg); + m_pools[0].parse(arg); } - if (!m_pools.back()->isValid()) { + if (!m_pools.back().isValid()) { return false; } break; case UserKey: /* --user */ - m_pools.back()->setUser(arg); + m_pools.back().setUser(arg); break; case PasswordKey: /* --pass */ - m_pools.back()->setPassword(arg); + m_pools.back().setPassword(arg); break; case LogFileKey: /* --log-file */ - free(m_logFile); - m_logFile = strdup(arg); + m_logFile = arg; break; case ApiAccessTokenKey: /* --api-access-token */ - free(m_apiToken); - m_apiToken = strdup(arg); + m_apiToken = arg; break; case ApiWorkerIdKey: /* --api-worker-id */ - free(m_apiWorkerId); - m_apiWorkerId = strdup(arg); + m_apiWorkerId = arg; break; case UserAgentKey: /* --user-agent */ - free(m_userAgent); - m_userAgent = strdup(arg); + m_userAgent = arg; break; case RetriesKey: /* --retries */ @@ -286,12 +239,12 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) bool xmrig::CommonConfig::save() { - if (!m_fileName) { + if (m_fileName.isNull()) { return false; } uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName, O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); + const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); if (fd < 0) { return false; } @@ -313,15 +266,14 @@ bool xmrig::CommonConfig::save() uv_fs_close(uv_default_loop(), &req, fd, nullptr); uv_fs_req_cleanup(&req); - LOG_NOTICE("configuration saved to: \"%s\"", m_fileName); + LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); return true; } void xmrig::CommonConfig::setFileName(const char *fileName) { - free(m_fileName); - m_fileName = fileName ? strdup(fileName) : nullptr; + m_fileName = fileName; } @@ -341,11 +293,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) break; case KeepAliveKey: /* --keepalive */ - m_pools.back()->setKeepAlive(arg); + m_pools.back().setKeepAlive(arg); break; case VariantKey: /* --variant */ - m_pools.back()->setVariant(arg); + m_pools.back().setVariant(arg); break; case DonateLevelKey: /* --donate-level */ @@ -376,21 +328,5 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) void xmrig::CommonConfig::setAlgo(const char *algo) { - if (strcasecmp(algo, "cryptonight-light") == 0) { - fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n"); - - m_algorithm = CRYPTONIGHT_LITE; - return; - } - - const size_t size = sizeof(algoNames) / sizeof(algoNames[0]); - - assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0]))); - - for (size_t i = 0; i < size; i++) { - if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) { - m_algorithm = static_cast(i); - break; - } - } + m_algorithm = Pool::algorithm(algo); } diff --git a/src/core/CommonConfig.h b/src/core/CommonConfig.h index ee9c7a20..0b72b7e1 100644 --- a/src/core/CommonConfig.h +++ b/src/core/CommonConfig.h @@ -28,13 +28,12 @@ #include +#include "core/utils/c_str.h" #include "interfaces/IConfig.h" +#include "net/Pool.h" #include "xmrig.h" -class Url; - - namespace xmrig { @@ -44,20 +43,18 @@ public: CommonConfig(); ~CommonConfig(); - static const char *algoName(Algo algorithm); - inline Algo algorithm() const { return m_algorithm; } inline bool isApiIPv6() const { return m_apiIPv6; } inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isSyslog() const { return m_syslog; } - inline const char *algoName() const { return algoName(m_algorithm); } - inline const char *apiToken() const { return m_apiToken; } - inline const char *apiWorkerId() const { return m_apiWorkerId; } - inline const char *logFile() const { return m_logFile; } - inline const char *userAgent() const { return m_userAgent; } - inline const std::vector &pools() const { return m_pools; } + inline const char *algoName() const { return Pool::algoName(m_algorithm); } + inline const char *apiToken() const { return m_apiToken.data(); } + inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } + inline const char *logFile() const { return m_logFile.data(); } + inline const char *userAgent() const { return m_userAgent.data(); } + inline const std::vector &pools() const { return m_pools; } inline int apiPort() const { return m_apiPort; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } @@ -65,8 +62,8 @@ public: inline int retryPause() const { return m_retryPause; } inline void setColors(bool colors) { m_colors = colors; } - inline bool isWatch() const override { return m_watch && m_fileName; } - inline const char *fileName() const override { return m_fileName; } + inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } + inline const char *fileName() const override { return m_fileName.data(); } protected: bool adjust() override; @@ -85,17 +82,17 @@ protected: bool m_colors; bool m_syslog; bool m_watch; - char *m_apiToken; - char *m_apiWorkerId; - char *m_fileName; - char *m_logFile; - char *m_userAgent; int m_apiPort; int m_donateLevel; int m_printTime; int m_retries; int m_retryPause; - std::vector m_pools; + std::vector m_pools; + xmrig::c_str m_apiToken; + xmrig::c_str m_apiWorkerId; + xmrig::c_str m_fileName; + xmrig::c_str m_logFile; + xmrig::c_str m_userAgent; private: bool parseInt(int key, int arg); diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 6bc2dc0f..f7211250 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -30,7 +30,7 @@ #include "core/ConfigCreator.h" #include "core/ConfigLoader.h" #include "Cpu.h" -#include "net/Url.h" +#include "net/Pool.h" #include "rapidjson/document.h" #include "rapidjson/filewritestream.h" #include "rapidjson/prettywriter.h" @@ -110,22 +110,22 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const rapidjson::Value pools(rapidjson::kArrayType); - for (const Url *url : m_pools) { + for (const Pool &pool : m_pools) { rapidjson::Value obj(rapidjson::kObjectType); - obj.AddMember("url", rapidjson::StringRef(url->url()), allocator); - obj.AddMember("user", rapidjson::StringRef(url->user()), allocator); - obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator); + obj.AddMember("url", rapidjson::StringRef(pool.url()), allocator); + obj.AddMember("user", rapidjson::StringRef(pool.user()), allocator); + obj.AddMember("pass", rapidjson::StringRef(pool.password()), allocator); - if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) { - obj.AddMember("keepalive", url->keepAlive() > 0, allocator); + if (pool.keepAlive() == 0 || pool.keepAlive() == Pool::kKeepAliveTimeout) { + obj.AddMember("keepalive", pool.keepAlive() > 0, allocator); } else { - obj.AddMember("keepalive", url->keepAlive(), allocator); + obj.AddMember("keepalive", pool.keepAlive(), allocator); } - obj.AddMember("nicehash", url->isNicehash(), allocator); - obj.AddMember("variant", url->variant(), allocator); + obj.AddMember("nicehash", pool.isNicehash(), allocator); + obj.AddMember("variant", pool.variant(), allocator); pools.PushBack(obj, allocator); } @@ -279,7 +279,7 @@ bool xmrig::Config::parseInt(int key, int arg) { switch (key) { case xmrig::IConfig::ThreadsKey: /* --threads */ - if (m_threadsCount >= 0 && arg < 1024) { + if (arg >= 0 && arg < 1024) { m_threadsCount = arg; } break; diff --git a/src/core/ConfigLoader.cpp b/src/core/ConfigLoader.cpp index 1dec4eca..c84ba962 100644 --- a/src/core/ConfigLoader.cpp +++ b/src/core/ConfigLoader.cpp @@ -38,7 +38,7 @@ #include "core/ConfigWatcher.h" #include "interfaces/IConfig.h" #include "interfaces/IWatcherListener.h" -#include "net/Url.h" +#include "net/Pool.h" #include "Platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" @@ -168,7 +168,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator } if (!config->isValid()) { - fprintf(stderr, "No pool URL supplied. Exiting.\n"); + fprintf(stderr, "No valid configuration found. Exiting.\n"); delete config; return nullptr; } @@ -293,13 +293,13 @@ void xmrig::ConfigLoader::showVersion() printf("\n features:" # if defined(__i386__) || defined(_M_IX86) - " i386" + " 32-bit" # elif defined(__x86_64__) || defined(_M_AMD64) - " x86_64" + " 64-bit" # endif # if defined(__AES__) || defined(_MSC_VER) - " AES-NI" + " AES" # endif "\n"); diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 68eef639..a090fb99 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -43,7 +43,17 @@ namespace xmrig { static char const usage[] = "\ Usage: " APP_ID " [OPTIONS]\n\ Options:\n\ - -a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\ + -a, --algo=ALGO specify the algorithm to use\n\ + cryptonight\n" +#ifndef XMRIG_NO_AEON +"\ + cryptonight-lite\n" +#endif +#ifndef XMRIG_NO_SUMO +"\ + cryptonight-heavy\n" +#endif +"\ -o, --url=URL URL of mining server\n\ -O, --userpass=U:P username:password pair for mining server\n\ -u, --user=USERNAME username for mining server\n\ diff --git a/src/core/ConfigWatcher.cpp b/src/core/ConfigWatcher.cpp index b934b52b..092a0f3a 100644 --- a/src/core/ConfigWatcher.cpp +++ b/src/core/ConfigWatcher.cpp @@ -33,9 +33,9 @@ xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : - m_path(strdup(path)), m_creator(creator), - m_listener(listener) + m_listener(listener), + m_path(path) { uv_fs_event_init(uv_default_loop(), &m_fsEvent); uv_timer_init(uv_default_loop(), &m_timer); @@ -50,8 +50,6 @@ xmrig::ConfigWatcher::~ConfigWatcher() { uv_timer_stop(&m_timer); uv_fs_event_stop(&m_fsEvent); - - free(m_path); } @@ -80,10 +78,10 @@ void xmrig::ConfigWatcher::queueUpdate() void xmrig::ConfigWatcher::reload() { - LOG_WARN("\"%s\" was changed, reloading configuration", m_path); + LOG_WARN("\"%s\" was changed, reloading configuration", m_path.data()); IConfig *config = m_creator->create(); - ConfigLoader::loadFromFile(config, m_path); + ConfigLoader::loadFromFile(config, m_path.data()); if (!config->isValid()) { LOG_ERR("reloading failed"); @@ -103,5 +101,5 @@ void xmrig::ConfigWatcher::reload() void xmrig::ConfigWatcher::start() { - uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path, 0); + uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path.data(), 0); } diff --git a/src/core/ConfigWatcher.h b/src/core/ConfigWatcher.h index 74526e90..a5d25864 100644 --- a/src/core/ConfigWatcher.h +++ b/src/core/ConfigWatcher.h @@ -28,6 +28,8 @@ #include #include + +#include "core/utils/c_str.h" #include "rapidjson/fwd.h" @@ -56,11 +58,11 @@ private: void reload(); void start(); - char *m_path; IConfigCreator *m_creator; IWatcherListener *m_listener; uv_fs_event_t m_fsEvent; uv_timer_t m_timer; + xmrig::c_str m_path; }; diff --git a/src/core/utils/c_str.h b/src/core/utils/c_str.h new file mode 100644 index 00000000..9a11ade6 --- /dev/null +++ b/src/core/utils/c_str.h @@ -0,0 +1,96 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __C_STR_H__ +#define __C_STR_H__ + + +#include +#include + +#include + + +namespace xmrig { + + +/** + * @brief Simple C string wrapper. + * + * 1. I know about std:string. + * 2. For some reason I prefer don't use std:string in miner, eg because of file size of MSYS2 builds. + */ +class c_str +{ +public: + inline c_str() : m_data(nullptr) {} + inline c_str(c_str &&other) { m_data = other.m_data; other.m_data = nullptr; } + inline c_str(const c_str &other) : m_data(nullptr) { set(other.data()); } + inline c_str(const char *str) : m_data(nullptr) { set(str); } + inline ~c_str() { free(m_data); } + + + inline void set(const char *str) + { + free(m_data); + + m_data = str != nullptr ? strdup(str) : nullptr; + } + + + inline void set(char *str) + { + free(m_data); + + m_data = str; + } + + + inline bool isEqual(const char *str) const + { + return (m_data != nullptr && str != nullptr && strcmp(m_data, str)) || (m_data == nullptr && m_data == nullptr); + } + + + inline bool isNull() const { return m_data == nullptr; } + inline const char *data() const { return m_data; } + inline size_t size() const { return m_data == nullptr ? 0 : strlen(m_data); } + + + inline bool operator!=(const c_str &str) const { return !isEqual(str.data()); } + inline bool operator!=(const char *str) const { return !isEqual(str); } + inline bool operator==(const c_str &str) const { return isEqual(str.data()); } + inline bool operator==(const char *str) const { return isEqual(str); } + inline c_str &operator=(char *str) { set(str); return *this; } + inline c_str &operator=(const c_str &str) { set(str.data()); return *this; } + inline c_str &operator=(const char *str) { set(str); return *this; } + + +private: + char *m_data; +}; + + +} /* namespace xmrig */ + +#endif /* __C_STR_H__ */ diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index afccb0a7..f4764096 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -479,7 +479,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si keccak(input, (int) size, ctx->state0, 200); - VARIANT1_INIT(0); + VARIANT1_INIT(0) cn_explode_scratchpad((__m128i*) ctx->state0, (__m128i*) ctx->memory); @@ -491,15 +491,15 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si __m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]); uint64_t idx0 = h0[0] ^ h0[4]; - void* mp = (uint8_t*) l0 + (idx0 & MASK); + void* mp = ((uint8_t*) l0) + ((idx0) & MASK); + for (size_t i = 0; i < ITERATIONS; i++) { __m128i cx; if (SOFT_AES) { - cx = soft_aesenc((uint32_t*) mp, _mm_set_epi64x(ah0, al0)); - } - else { + cx = soft_aesenc((uint32_t*) mp, _mm_set_epi64x(ah0, al0)); + } else { cx = _mm_load_si128((__m128i *) mp); # ifndef XMRIG_ARMv7 cx = vreinterpretq_m128i_u8(vaesmcq_u8(vaeseq_u8(cx, vdupq_n_u8(0)))) ^ _mm_set_epi64x(ah0, al0); @@ -507,8 +507,8 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si } _mm_store_si128((__m128i *) mp, _mm_xor_si128(bx0, cx)); - VARIANT1_1(mp); - mp = (uint8_t*) l0 + ((idx0 = EXTRACT64(cx)) & MASK); + VARIANT1_1(mp); + mp = ((uint8_t*) l0) + ((idx0 = EXTRACT64(cx)) & MASK); bx0 = cx; uint64_t hi, lo, cl, ch; @@ -526,14 +526,13 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ah0 ^= ch; al0 ^= cl; - mp = (uint8_t*) l0 + (al0 & MASK); + mp = ((uint8_t*) l0) + ((al0) & MASK); if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { - int64_t n = ((int64_t*) mp)[0]; - int32_t d = ((int32_t*) mp)[2]; + int64_t n = ((int64_t*)mp)[0]; + int32_t d = ((int32_t*)mp)[2]; int64_t q = n / (d | 0x5); - - ((int64_t*) mp)[0] = n ^ q; + ((int64_t*) mp)[0] = n ^ q; } } @@ -543,7 +542,6 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output); } - template inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) { diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index d576b47a..60f0df08 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -65,6 +65,9 @@ inline size_t cn_select_memory(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_MEMORY; + + default: + break; } return 0; @@ -88,6 +91,9 @@ inline uint32_t cn_select_mask(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_MASK; + + default: + break; } return 0; @@ -111,6 +117,9 @@ inline uint32_t cn_select_iter(Algo algorithm) case CRYPTONIGHT_HEAVY: return CRYPTONIGHT_HEAVY_ITER; + + default: + break; } return 0; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 333e2191..28d3b402 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -398,8 +398,7 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp) uint8_t x = vh >> 24; static const uint16_t table = 0x7531; - const uint8_t index = (((x >> 3) & 6) | (x & 1)) << 1; - vh ^= ((table >> index) & 0x3) << 28; + vh ^= ((table >> ((((x >> 3) & 6) | (x & 1)) << 1)) & 0x3) << 28; mem_out[1] = vh; } diff --git a/src/net/Client.cpp b/src/net/Client.cpp index ec9dc863..c4387a7c 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -32,7 +32,6 @@ #include "interfaces/IClientListener.h" #include "log/Log.h" #include "net/Client.h" -#include "net/Url.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/stringbuffer.h" @@ -97,7 +96,7 @@ Client::~Client() void Client::connect() { - resolve(m_url.host()); + resolve(m_pool.host()); } @@ -106,10 +105,10 @@ void Client::connect() * * @param url */ -void Client::connect(const Url *url) +void Client::connect(const Pool &url) { - setUrl(url); - resolve(m_url.host()); + setPool(url); + connect(); } @@ -132,13 +131,13 @@ void Client::deleteLater() } -void Client::setUrl(const Url *url) +void Client::setPool(const Pool &pool) { - if (!url || !url->isValid()) { + if (!pool.isValid()) { return; } - m_url = url; + m_pool = pool; } @@ -146,7 +145,7 @@ void Client::tick(uint64_t now) { if (m_state == ConnectedState) { if (m_expire && now > m_expire) { - LOG_DEBUG_ERR("[%s:%u] timeout", m_url.host(), m_url.port()); + LOG_DEBUG_ERR("[%s] timeout", m_pool.url()); close(); } else if (m_keepAlive && now > m_keepAlive) { @@ -266,11 +265,10 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } # ifdef XMRIG_PROXY_PROJECT - Job job(m_id, m_url.variant()); + Job job(m_id, m_pool.variant()); job.setClientId(m_rpcId); - job.setCoin(m_url.coin()); # else - Job job(m_id, m_nicehash, m_url.algo(), m_url.variant()); + Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant()); # endif if (!job.setId(params["job_id"].GetString())) { @@ -307,7 +305,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } if (!m_quiet) { - LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); + LOG_WARN("[%s] duplicate job received, reconnect", m_pool.url()); } close(); @@ -323,7 +321,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) } # ifndef XMRIG_PROXY_PROJECT - m_nicehash = m_url.isNicehash(); + m_nicehash = m_pool.isNicehash(); # endif if (result.HasMember("extensions")) { @@ -351,7 +349,7 @@ int Client::resolve(const char *host) const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints); if (r) { if (!m_quiet) { - LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r)); + LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_pool.port(), uv_strerror(r)); } return 1; } @@ -362,9 +360,9 @@ int Client::resolve(const char *host) int64_t Client::send(size_t size) { - LOG_DEBUG("[%s:%u] send (%d bytes): \"%s\"", m_url.host(), m_url.port(), size, m_sendBuf); + LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); if (state() != ConnectedState || !uv_is_writable(m_stream)) { - LOG_DEBUG_ERR("[%s:%u] send failed, invalid state: %d", m_url.host(), m_url.port(), m_state); + LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); return -1; } @@ -402,7 +400,7 @@ void Client::connect(sockaddr *addr) { setState(ConnectingState); - reinterpret_cast(addr)->sin_port = htons(m_url.port()); + reinterpret_cast(addr)->sin_port = htons(m_pool.port()); delete m_socket; uv_connect_t *req = new uv_connect_t; @@ -436,9 +434,9 @@ void Client::login() doc.AddMember("method", "login", allocator); rapidjson::Value params(rapidjson::kObjectType); - params.AddMember("login", rapidjson::StringRef(m_url.user()), allocator); - params.AddMember("pass", rapidjson::StringRef(m_url.password()), allocator); - params.AddMember("agent", rapidjson::StringRef(m_agent), allocator); + params.AddMember("login", rapidjson::StringRef(m_pool.user()), allocator); + params.AddMember("pass", rapidjson::StringRef(m_pool.password()), allocator); + params.AddMember("agent", rapidjson::StringRef(m_agent), allocator); doc.AddMember("params", params, allocator); @@ -477,11 +475,11 @@ void Client::parse(char *line, size_t len) line[len - 1] = '\0'; - LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line); + LOG_DEBUG("[%s] received (%d bytes): \"%s\"", m_pool.url(), len, line); if (len < 32 || line[0] != '{') { if (!m_quiet) { - LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port()); + LOG_ERR("[%s] JSON decode failed", m_pool.url()); } return; @@ -490,7 +488,7 @@ void Client::parse(char *line, size_t len) rapidjson::Document doc; if (doc.ParseInsitu(line).HasParseError()) { if (!m_quiet) { - LOG_ERR("[%s:%u] JSON decode failed: \"%s\"", m_url.host(), m_url.port(), rapidjson::GetParseError_En(doc.GetParseError())); + LOG_ERR("[%s] JSON decode failed: \"%s\"", m_pool.url(), rapidjson::GetParseError_En(doc.GetParseError())); } return; @@ -532,7 +530,7 @@ void Client::parseNotification(const char *method, const rapidjson::Value ¶m { if (error.IsObject()) { if (!m_quiet) { - LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), error["message"].GetString(), error["code"].GetInt()); + LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), error["message"].GetString(), error["code"].GetInt()); } return; } @@ -550,7 +548,7 @@ void Client::parseNotification(const char *method, const rapidjson::Value ¶m return; } - LOG_WARN("[%s:%u] unsupported method: \"%s\"", m_url.host(), m_url.port(), method); + LOG_WARN("[%s] unsupported method: \"%s\"", m_pool.url(), method); } @@ -566,7 +564,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap m_results.erase(it); } else if (!m_quiet) { - LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), message, error["code"].GetInt()); + LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), message, error["code"].GetInt()); } if (isCriticalError(message)) { @@ -584,7 +582,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap int code = -1; if (!parseLogin(result, &code)) { if (!m_quiet) { - LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code); + LOG_ERR("[%s] login error code: %d", m_pool.url(), code); } close(); @@ -636,7 +634,7 @@ void Client::reconnect() void Client::setState(SocketState state) { - LOG_DEBUG("[%s:%u] state: %d", m_url.host(), m_url.port(), state); + LOG_DEBUG("[%s] state: %d", m_pool.url(), state); if (m_state == state) { return; @@ -650,8 +648,8 @@ void Client::startTimeout() { m_expire = 0; - if (m_url.keepAlive()) { - m_keepAlive = uv_now(uv_default_loop()) + (m_url.keepAlive() * 1000); + if (m_pool.keepAlive()) { + m_keepAlive = uv_now(uv_default_loop()) + (m_pool.keepAlive() * 1000); } } @@ -689,7 +687,7 @@ void Client::onConnect(uv_connect_t *req, int status) if (status < 0) { if (!client->m_quiet) { - LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); + LOG_ERR("[%s] connect error: \"%s\"", client->m_pool.url(), uv_strerror(status)); } delete req; @@ -717,7 +715,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) if (nread < 0) { if (nread != UV_EOF && !client->m_quiet) { - LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); + LOG_ERR("[%s] read error: \"%s\"", client->m_pool.url(), uv_strerror((int) nread)); } client->close(); @@ -777,7 +775,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) if (status < 0) { if (!client->m_quiet) { - LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); + LOG_ERR("[%s] DNS error: \"%s\"", client->m_pool.url(), uv_strerror(status)); } return client->reconnect(); @@ -801,7 +799,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) if (ipv4.empty() && ipv6.empty()) { if (!client->m_quiet) { - LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port()); + LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_pool.url()); } uv_freeaddrinfo(res); diff --git a/src/net/Client.h b/src/net/Client.h index fc0335c6..0692d38b 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -34,7 +34,7 @@ #include "net/Job.h" #include "net/Storage.h" #include "net/SubmitResult.h" -#include "net/Url.h" +#include "net/Pool.h" #include "rapidjson/fwd.h" @@ -61,18 +61,18 @@ public: bool disconnect(); int64_t submit(const JobResult &result); void connect(); - void connect(const Url *url); + void connect(const Pool &pool); void deleteLater(); - void setUrl(const Url *url); + void setPool(const Pool &pool); void tick(uint64_t now); inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } - inline const char *host() const { return m_url.host(); } + inline const char *host() const { return m_pool.host(); } inline const char *ip() const { return m_ip; } inline const Job &job() const { return m_job; } inline int id() const { return m_id; } inline SocketState state() const { return m_state; } - inline uint16_t port() const { return m_url.port(); } + inline uint16_t port() const { return m_pool.port(); } inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setRetryPause(int ms) { m_retryPause = ms; } @@ -117,6 +117,7 @@ private: int m_retryPause; int64_t m_failures; Job m_job; + Pool m_pool; size_t m_recvBufPos; SocketState m_state; std::map m_results; @@ -124,7 +125,6 @@ private: uint64_t m_jobs; uint64_t m_keepAlive; uintptr_t m_key; - Url m_url; uv_buf_t m_recvBuf; uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index a8e60efa..98ce7e8d 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -38,7 +38,6 @@ #include "net/strategies/FailoverStrategy.h" #include "net/strategies/SinglePoolStrategy.h" #include "net/SubmitResult.h" -#include "net/Url.h" #include "workers/Workers.h" #include "core/Controller.h" #include "core/Config.h" @@ -52,7 +51,7 @@ Network::Network(xmrig::Controller *controller) : Workers::setListener(this); - const std::vector &pools = controller->config()->pools(); + const std::vector &pools = controller->config()->pools(); if (pools.size() > 1) { m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this); @@ -62,7 +61,7 @@ Network::Network(xmrig::Controller *controller) : } if (controller->config()->donateLevel() > 0) { - m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front()->user(), controller->config()->algorithm(), this); + m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front().user(), controller->config()->algorithm(), this); } m_timer.data = this; diff --git a/src/net/Pool.cpp b/src/net/Pool.cpp new file mode 100644 index 00000000..4d1d7439 --- /dev/null +++ b/src/net/Pool.cpp @@ -0,0 +1,279 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include +#include +#include + + +#include "net/Pool.h" + + +#ifdef _MSC_VER +# define strncasecmp(x,y,z) _strnicmp(x,y,z) +#endif + + +static const char *algoNames[] = { + "cryptonight", +# ifndef XMRIG_NO_AEON + "cryptonight-lite", +# else + nullptr, +# endif +# ifndef XMRIG_NO_SUMO + "cryptonight-heavy" +# else + nullptr +# endif +}; + + +static const char *algoNamesShort[] = { + "cn", +# ifndef XMRIG_NO_AEON + "cn-lite", +# else + nullptr, +# endif +# ifndef XMRIG_NO_SUMO + "cn-heavy" +# else + nullptr +# endif +}; + + +Pool::Pool() : + m_nicehash(false), + m_keepAlive(0), + m_port(kDefaultPort), + m_algo(xmrig::CRYPTONIGHT), + m_variant(xmrig::VARIANT_AUTO) +{ +} + + +/** + * @brief Parse url. + * + * Valid urls: + * example.com + * example.com:3333 + * stratum+tcp://example.com + * stratum+tcp://example.com:3333 + * + * @param url + */ +Pool::Pool(const char *url) : + m_nicehash(false), + m_keepAlive(0), + m_port(kDefaultPort), + m_algo(xmrig::CRYPTONIGHT), + m_variant(xmrig::VARIANT_AUTO) +{ + parse(url); +} + + +Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, xmrig::Variant variant) : + m_nicehash(nicehash), + m_keepAlive(keepAlive), + m_port(port), + m_algo(xmrig::CRYPTONIGHT), + m_host(host), + m_password(password), + m_user(user), + m_variant(variant) +{ + const size_t size = m_host.size() + 8; + assert(size > 8); + + char *url = new char[size](); + snprintf(url, size - 1, "%s:%d", m_host.data(), m_port); + + m_url = url; +} + + +const char *Pool::algoName(xmrig::Algo algorithm) +{ + return algoNames[algorithm]; +} + + +xmrig::Algo Pool::algorithm(const char *algo) +{ +# ifndef XMRIG_NO_AEON + if (strcasecmp(algo, "cryptonight-light") == 0) { + fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n"); + + return xmrig::CRYPTONIGHT_LITE; + } +# endif + + const size_t size = sizeof(algoNames) / sizeof(algoNames[0]); + + assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0]))); + + for (size_t i = 0; i < size; i++) { + if ((algoNames[i] && strcasecmp(algo, algoNames[i]) == 0) || (algoNamesShort[i] && strcasecmp(algo, algoNamesShort[i]) == 0)) { + return static_cast(i); + } + } + + fprintf(stderr, "Unknown algorithm \"%s\" specified.\n", algo); + return xmrig::INVALID_ALGO; +} + + +bool Pool::parse(const char *url) +{ + assert(url != nullptr); + + const char *p = strstr(url, "://"); + const char *base = url; + + if (p) { + if (strncasecmp(url, "stratum+tcp://", 14)) { + return false; + } + + base = url + 14; + } + + if (!strlen(base) || *base == '/') { + return false; + } + + m_url = url; + if (base[0] == '[') { + return parseIPv6(base); + } + + const char *port = strchr(base, ':'); + if (!port) { + m_host = base; + return true; + } + + const size_t size = port++ - base + 1; + char *host = new char[size](); + memcpy(host, base, size - 1); + + m_host = host; + m_port = static_cast(strtol(port, nullptr, 10)); + + return true; +} + + +bool Pool::setUserpass(const char *userpass) +{ + const char *p = strchr(userpass, ':'); + if (!p) { + return false; + } + + char *user = new char[p - userpass + 1](); + strncpy(user, userpass, p - userpass); + + m_user = user; + m_password = p + 1; + + return true; +} + + +void Pool::adjust(xmrig::Algo algo) +{ + if (!isValid()) { + return; + } + + m_algo = algo; + + if (strstr(m_host.data(), ".nicehash.com")) { + m_keepAlive = false; + m_nicehash = true; + } + + if (strstr(m_host.data(), ".minergate.com")) { + m_keepAlive = false; + } +} + + +void Pool::setVariant(int variant) +{ + switch (variant) { + case xmrig::VARIANT_AUTO: + case xmrig::VARIANT_NONE: + case xmrig::VARIANT_V1: + m_variant = static_cast(variant); + break; + + default: + assert(false); + break; + } +} + + +bool Pool::isEqual(const Pool &other) const +{ + return (m_nicehash == other.m_nicehash + && m_keepAlive == other.m_keepAlive + && m_port == other.m_port + && m_algo == other.m_algo + && m_host == other.m_host + && m_password == other.m_password + && m_url == other.m_url + && m_user == other.m_user + && m_variant == other.m_variant); +} + + +bool Pool::parseIPv6(const char *addr) +{ + const char *end = strchr(addr, ']'); + if (!end) { + return false; + } + + const char *port = strchr(end, ':'); + if (!port) { + return false; + } + + const size_t size = end - addr; + char *host = new char[size](); + memcpy(host, addr + 1, size - 1); + + m_host = host; + m_port = static_cast(strtol(port + 1, nullptr, 10)); + + return true; +} diff --git a/src/net/Pool.h b/src/net/Pool.h new file mode 100644 index 00000000..efa3e3a7 --- /dev/null +++ b/src/net/Pool.h @@ -0,0 +1,96 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __POOL_H__ +#define __POOL_H__ + + +#include + + +#include "core/utils/c_str.h" +#include "xmrig.h" + + +class Pool +{ +public: + constexpr static const char *kDefaultPassword = "x"; + constexpr static const char *kDefaultUser = "x"; + constexpr static uint16_t kDefaultPort = 3333; + constexpr static int kKeepAliveTimeout = 60; + + Pool(); + Pool(const char *url); + Pool(const char *host, + uint16_t port, + const char *user = nullptr, + const char *password = nullptr, + int keepAlive = 0, + bool nicehash = false, + xmrig::Variant variant = xmrig::VARIANT_AUTO + ); + + static const char *algoName(xmrig::Algo algorithm); + static xmrig::Algo algorithm(const char *algo); + + inline bool isNicehash() const { return m_nicehash; } + inline bool isValid() const { return !m_host.isNull() && m_port > 0; } + inline const char *host() const { return m_host.data(); } + inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } + inline const char *url() const { return m_url.data(); } + inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } + inline int keepAlive() const { return m_keepAlive; } + inline uint16_t port() const { return m_port; } + inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } + inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setPassword(const char *password) { m_password = password; } + inline void setUser(const char *user) { m_user = user; } + inline xmrig::Algo algo() const { return m_algo; } + inline xmrig::Variant variant() const { return m_variant; } + + inline bool operator!=(const Pool &other) const { return !isEqual(other); } + inline bool operator==(const Pool &other) const { return isEqual(other); } + + bool parse(const char *url); + bool setUserpass(const char *userpass); + void adjust(xmrig::Algo algo); + void setVariant(int variant); + + bool isEqual(const Pool &other) const; + +private: + bool parseIPv6(const char *addr); + + bool m_nicehash; + int m_keepAlive; + uint16_t m_port; + xmrig::Algo m_algo; + xmrig::c_str m_host; + xmrig::c_str m_password; + xmrig::c_str m_url; + xmrig::c_str m_user; + xmrig::Variant m_variant; +}; + +#endif /* __POOL_H__ */ diff --git a/src/net/Url.cpp b/src/net/Url.cpp deleted file mode 100644 index 3d5f2cdd..00000000 --- a/src/net/Url.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include -#include -#include - - -#include "net/Url.h" -#include "xmrig.h" - - -#ifdef _MSC_VER -# define strncasecmp(x,y,z) _strnicmp(x,y,z) -#endif - - -Url::Url() : - m_nicehash(false), - m_host(nullptr), - m_password(nullptr), - m_user(nullptr), - m_algo(xmrig::CRYPTONIGHT), - m_keepAlive(0), - m_variant(xmrig::VARIANT_AUTO), - m_url(nullptr), - m_port(kDefaultPort) -{ -} - - -/** - * @brief Parse url. - * - * Valid urls: - * example.com - * example.com:3333 - * stratum+tcp://example.com - * stratum+tcp://example.com:3333 - * - * @param url - */ -Url::Url(const char *url) : - m_nicehash(false), - m_host(nullptr), - m_password(nullptr), - m_user(nullptr), - m_algo(xmrig::CRYPTONIGHT), - m_keepAlive(0), - m_variant(xmrig::VARIANT_AUTO), - m_url(nullptr), - m_port(kDefaultPort) -{ - parse(url); -} - - -Url::Url(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, int variant) : - m_nicehash(nicehash), - m_password(password ? strdup(password) : nullptr), - m_user(user ? strdup(user) : nullptr), - m_algo(xmrig::CRYPTONIGHT), - m_keepAlive(keepAlive), - m_variant(variant), - m_url(nullptr), - m_port(port) -{ - m_host = strdup(host); -} - - -Url::~Url() -{ - free(m_host); - free(m_password); - free(m_user); - - if (m_url) { - delete [] m_url; - } -} - - -bool Url::parse(const char *url) -{ - const char *p = strstr(url, "://"); - const char *base = url; - - if (p) { - if (strncasecmp(url, "stratum+tcp://", 14)) { - return false; - } - - base = url + 14; - } - - if (!strlen(base) || *base == '/') { - return false; - } - - if (base[0] == '[') { - return parseIPv6(base); - } - - const char *port = strchr(base, ':'); - if (!port) { - m_host = strdup(base); - return false; - } - - const size_t size = port++ - base + 1; - m_host = new char[size](); - memcpy(m_host, base, size - 1); - - m_port = (uint16_t) strtol(port, nullptr, 10); - return true; -} - - -bool Url::setUserpass(const char *userpass) -{ - const char *p = strchr(userpass, ':'); - if (!p) { - return false; - } - - free(m_user); - free(m_password); - - m_user = static_cast(calloc(p - userpass + 1, 1)); - strncpy(m_user, userpass, p - userpass); - m_password = strdup(p + 1); - - return true; -} - - -const char *Url::url() const -{ - if (!m_url) { - const size_t size = strlen(m_host) + 8; - m_url = new char[size]; - - snprintf(m_url, size - 1, "%s:%d", m_host, m_port); - } - - return m_url; -} - - -void Url::adjust(int algo) -{ - if (!isValid()) { - return; - } - - m_algo = algo; - - if (strstr(m_host, ".nicehash.com")) { - m_keepAlive = false; - m_nicehash = true; - } - - if (strstr(m_host, ".minergate.com")) { - m_keepAlive = false; - } -} - - -void Url::setPassword(const char *password) -{ - if (!password) { - return; - } - - free(m_password); - m_password = strdup(password); -} - - -void Url::setUser(const char *user) -{ - if (!user) { - return; - } - - free(m_user); - m_user = strdup(user); -} - - -void Url::setVariant(int variant) -{ - switch (variant) { - case xmrig::VARIANT_AUTO: - case xmrig::VARIANT_NONE: - case xmrig::VARIANT_V1: - m_variant = variant; - break; - - default: - break; - } -} - - -bool Url::operator==(const Url &other) const -{ - if (m_port != other.m_port || m_keepAlive != other.m_keepAlive || m_nicehash != other.m_nicehash) { - return false; - } - - if (strcmp(host(), other.host()) != 0 || strcmp(user(), other.user()) != 0 || strcmp(password(), other.password()) != 0) { - return false; - } - - return true; -} - - -Url &Url::operator=(const Url *other) -{ - m_keepAlive = other->m_keepAlive; - m_algo = other->m_algo; - m_variant = other->m_variant; - m_nicehash = other->m_nicehash; - m_port = other->m_port; - - free(m_host); - m_host = strdup(other->m_host); - - setPassword(other->m_password); - setUser(other->m_user); - - if (m_url) { - delete [] m_url; - m_url = nullptr; - } - - return *this; -} - - -bool Url::parseIPv6(const char *addr) -{ - const char *end = strchr(addr, ']'); - if (!end) { - return false; - } - - const char *port = strchr(end, ':'); - if (!port) { - return false; - } - - const size_t size = end - addr; - m_host = new char[size](); - memcpy(m_host, addr + 1, size - 1); - - m_port = (uint16_t) strtol(port + 1, nullptr, 10); - - return true; -} diff --git a/src/net/Url.h b/src/net/Url.h deleted file mode 100644 index 4c2c9435..00000000 --- a/src/net/Url.h +++ /dev/null @@ -1,82 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __URL_H__ -#define __URL_H__ - - -#include - - -class Url -{ -public: - constexpr static const char *kDefaultPassword = "x"; - constexpr static const char *kDefaultUser = "x"; - constexpr static uint16_t kDefaultPort = 3333; - constexpr static int kKeepAliveTimeout = 60; - - Url(); - Url(const char *url); - Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, int keepAlive = 0, bool nicehash = false, int variant = -1); - ~Url(); - - inline bool isNicehash() const { return m_nicehash; } - inline bool isValid() const { return m_host && m_port > 0; } - inline const char *host() const { return m_host; } - inline const char *password() const { return m_password ? m_password : kDefaultPassword; } - inline const char *user() const { return m_user ? m_user : kDefaultUser; } - inline int algo() const { return m_algo; } - inline int keepAlive() const { return m_keepAlive; } - inline int variant() const { return m_variant; } - inline uint16_t port() const { return m_port; } - inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } - inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } - inline void setVariant(bool monero) { m_variant = monero; } - - bool parse(const char *url); - bool setUserpass(const char *userpass); - const char *url() const; - void adjust(int algo); - void setPassword(const char *password); - void setUser(const char *user); - void setVariant(int variant); - - bool operator==(const Url &other) const; - Url &operator=(const Url *other); - -private: - bool parseIPv6(const char *addr); - - bool m_nicehash; - char *m_host; - char *m_password; - char *m_user; - int m_algo; - int m_keepAlive; - int m_variant; - mutable char *m_url; - uint16_t m_port; -}; - -#endif /* __URL_H__ */ diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index f0ec5bde..311ca424 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -60,17 +60,17 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL Job::toHex(hash, 32, userId); if (algo == xmrig::CRYPTONIGHT) { - m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true)); - m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true)); - m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false)); + m_pools.push_back(Pool(kDonatePool1, 6666, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool1, 80, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false)); } else if (algo == xmrig::CRYPTONIGHT_HEAVY) { - m_pools.push_back(new Url(kDonatePool1, 8888, userId, nullptr, false, true)); - m_pools.push_back(new Url(kDonatePool1, 8889, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool1, 8888, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool1, 8889, userId, nullptr, false, true)); } else { - m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true)); - m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool1, 5555, userId, nullptr, false, true)); + m_pools.push_back(Pool(kDonatePool1, 7777, userId, nullptr, false, true)); } m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 4ef29958..cad360b1 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -32,6 +32,7 @@ #include "interfaces/IClientListener.h" #include "interfaces/IStrategy.h" #include "interfaces/IStrategyListener.h" +#include "net/Pool.h" class Client; @@ -71,7 +72,7 @@ private: const int m_idleTime; IStrategy *m_strategy; IStrategyListener *m_listener; - std::vector m_pools; + std::vector m_pools; uv_timer_t m_timer; }; diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index dbfeb311..a4e25277 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -28,7 +28,7 @@ #include "Platform.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_quiet(quiet), m_retries(retries), m_retryPause(retryPause), @@ -36,7 +36,7 @@ FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause m_index(0), m_listener(listener) { - for (const Url *url : urls) { + for (const Pool &url : urls) { add(url); } } @@ -153,10 +153,10 @@ void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &resu } -void FailoverStrategy::add(const Url *url) +void FailoverStrategy::add(const Pool &pool) { Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); - client->setUrl(url); + client->setPool(pool); client->setRetryPause(m_retryPause * 1000); client->setQuiet(m_quiet); diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h index 8ad767ca..a48496fb 100644 --- a/src/net/strategies/FailoverStrategy.h +++ b/src/net/strategies/FailoverStrategy.h @@ -30,6 +30,7 @@ #include "interfaces/IClientListener.h" #include "interfaces/IStrategy.h" +#include "net/Pool.h" class Client; @@ -40,7 +41,7 @@ class Url; class FailoverStrategy : public IStrategy, public IClientListener { public: - FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); + FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); ~FailoverStrategy(); public: @@ -59,7 +60,7 @@ protected: void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; private: - void add(const Url *url); + void add(const Pool &pool); const bool m_quiet; const int m_retries; diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp index fc7f209e..8c113d93 100644 --- a/src/net/strategies/SinglePoolStrategy.cpp +++ b/src/net/strategies/SinglePoolStrategy.cpp @@ -28,12 +28,12 @@ #include "Platform.h" -SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet) : +SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet) : m_active(false), m_listener(listener) { m_client = new Client(0, Platform::userAgent(), this); - m_client->setUrl(url); + m_client->setPool(pool); m_client->setRetryPause(retryPause * 1000); m_client->setQuiet(quiet); } diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h index d5682cf7..ce3d0f7f 100644 --- a/src/net/strategies/SinglePoolStrategy.h +++ b/src/net/strategies/SinglePoolStrategy.h @@ -37,7 +37,7 @@ class Url; class SinglePoolStrategy : public IStrategy, public IClientListener { public: - SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false); + SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet = false); ~SinglePoolStrategy(); public: diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 7e68a990..482b4305 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -204,7 +204,7 @@ rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const auto &allocator = doc.GetAllocator(); obj.AddMember("type", "cpu", allocator); - obj.AddMember("algo", rapidjson::StringRef(CommonConfig::algoName(algorithm())), allocator); + obj.AddMember("algo", rapidjson::StringRef(Pool::algoName(algorithm())), allocator); obj.AddMember("av", m_av, allocator); obj.AddMember("low_power_mode", multiway(), allocator); obj.AddMember("affine_to_cpu", affinity(), allocator); diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index a6176743..6ba5c47f 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -144,7 +144,11 @@ bool DoubleWorker::selfTest() } # endif - return memcmp(m_hash, test_output_heavy, 64) == 0; +# ifndef XMRIG_NO_SUMO + return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, 64) == 0; +# else + return false; +# endif } diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index ca6b93a6..815b965d 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -116,7 +116,11 @@ bool SingleWorker::selfTest() } # endif +# ifndef XMRIG_NO_SUMO return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_result.result, test_output_heavy, 32) == 0; +# else + return false; +# endif } diff --git a/src/xmrig.h b/src/xmrig.h index f4ae8162..7196aee3 100644 --- a/src/xmrig.h +++ b/src/xmrig.h @@ -30,6 +30,7 @@ namespace xmrig enum Algo { + INVALID_ALGO = -1, CRYPTONIGHT, /* CryptoNight (Monero) */ CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */ CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */