1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-08 08:23:34 -05:00

Compare commits

...

167 Commits

Author SHA1 Message Date
XMRig
177e0c9c26 v2.15.0-beta 2019-03-24 02:35:51 +07:00
xmrig
a891d2a590 Update CHANGELOG.md 2019-03-24 02:34:54 +07:00
XMRig
cf7df3f629 v2.15.0-evo 2019-03-20 11:55:15 +07:00
XMRig
453443a2f1 Merge branch 'feature-donate-over-proxy' into evo 2019-03-20 11:53:18 +07:00
XMRig
8d61a47040 Fix uv_tty_reset_mode on Linux. 2019-03-19 22:13:43 +07:00
XMRig
4c95136e6a Implemented donate over proxy. 2019-03-19 21:31:54 +07:00
XMRig
0907d1eb0c Added "donate-over-proxy" option. 2019-03-19 00:16:30 +07:00
XMRig
55686c7d57 Use new Timer inside DonateStrategy. 2019-03-18 13:40:56 +07:00
XMRig
9a6a5a94b5 Add class Timer. 2019-03-18 02:36:17 +07:00
XMRig
bbf0d11a51 Sync changes. 2019-03-17 16:03:45 +07:00
XMRig
c94c0210f7 Fix copy. 2019-03-16 13:32:00 +07:00
XMRig
1b9fbf1132 Fix compile issues. 2019-03-16 13:10:04 +07:00
XMRig
0d86e53a32 Move files. 2019-03-16 02:07:26 +07:00
XMRig
ba68fb6c53 Added real graceful exit. 2019-03-16 00:44:15 +07:00
XMRig
1e62943010 Fix memory leak. 2019-03-15 18:54:45 +07:00
XMRig
af3655c27e Add classes Dns, DnsRecord, IDnsListener. 2019-03-15 18:14:25 +07:00
XMRig
3094741c64 Remove file SubmitResult.cpp. 2019-03-15 12:54:00 +07:00
XMRig
f5077cadbd Added class RecvBuf. 2019-03-15 03:44:02 +07:00
XMRig
9808fbe396 Added class Buffer. 2019-03-15 02:25:38 +07:00
XMRig
8c362411ef Removed class Id. 2019-03-15 02:03:01 +07:00
XMRig
ba01f2a9c4 Rename files. 2019-03-15 01:50:35 +07:00
XMRig
be5d609856 Client refactoring. 2019-03-15 01:06:10 +07:00
XMRig
d57b41c673 Sync changes. 2019-03-14 18:42:27 +07:00
xmrig
fb62ee938a Merge pull request #987 from SChernykh/dev
Unified ASM functions signature
2019-03-14 13:39:30 +07:00
SChernykh
1bb8f77b52 Unified ASM functions signature 2019-03-13 22:00:44 +01:00
XMRig
5d9ebb0b91 v2.14.2-dev 2019-03-07 17:51:54 +07:00
XMRig
d4f6eaa371 Merge branch 'master' into dev 2019-03-07 17:51:17 +07:00
xmrig
08ef94486b Update CHANGELOG.md 2019-03-07 15:16:42 +07:00
XMRig
1042f23dd5 v2.14.1 2019-03-07 15:02:55 +07:00
XMRig
80a7aa2497 #975 Fixed crash on Linux if used double thread. 2019-03-07 14:52:40 +07:00
XMRig
5cd48f483e v2.14.0 2019-03-06 19:12:15 +07:00
XMRig
8aa4c8f19b Merge branch 'dev' 2019-03-06 19:11:35 +07:00
xmrig
c8b1f176e7 Update CHANGELOG.md 2019-03-06 17:58:24 +07:00
XMRig
31e40943d0 Add algo-switch for ZLS. 2019-03-06 13:05:13 +07:00
xmrig
538c8fc9e1 Merge pull request #971 from SChernykh/dev
Algo switch at Graft fork
2019-03-06 00:12:12 +07:00
SChernykh
fb3129c67d Algo switch at Graft fork 2019-03-05 18:05:19 +01:00
XMRig
6a77a27e7f Fix algorithm negotiation (recently added algorithms was missing). 2019-03-05 23:44:16 +07:00
XMRig
0bbeafde65 Added "cn/zls" (Zelerius) and "cn/double" (X-CASH) algorithms. 2019-03-05 18:29:13 +07:00
XMRig
6052da3c43 #951 Fix AVX detection. 2019-03-05 15:03:43 +07:00
XMRig
8800219cf4 Include ConfigLoader_default.h only if embedded enabled. 2019-03-05 13:10:22 +07:00
XMRig
7ed840016a Merge branch 'pr969' into dev 2019-03-05 02:12:34 +07:00
XMRig
21d9ad6dbc Fix MSYS2 build. 2019-03-05 02:11:34 +07:00
SChernykh
154806ac74 CryptoNight v8 ReverseWaltz (+asm code and all test vectors)
Co-Authored-By: Vitalius Parubochyi <eddragonwolf@users.noreply.github.com>
2019-03-04 19:57:33 +01:00
xmrig
10eb579270 Merge pull request #968 from SChernykh/dev
Optimized cn/r asm code
2019-03-04 23:54:50 +07:00
SChernykh
123e7cf0b8 Merge remote-tracking branch 'upstream/dev' into dev 2019-03-04 17:43:22 +01:00
SChernykh
9f2d821970 Optimized cn/r asm code
Average over 100 block heights:
Coffee Lake +0.1%
Ryzen +0.4%
Sandy Bridge +1.5%
2019-03-04 17:39:49 +01:00
XMRig
18a9803e5e Removed unnecessary ASM files duplicates for MSYS2. 2019-03-04 14:40:22 +07:00
XMRig
f2574c2a41 Use machine friendly test data for cn/r and cn/wow algorithms. 2019-03-04 00:42:17 +07:00
XMRig
4ebfc135e0 Build whole CryptonightR_gen.cpp only if ASM used. 2019-03-03 17:33:27 +07:00
XMRig
d135bdd87e #957 Added optional embedded JSON config support. 2019-03-02 13:12:38 +07:00
XMRig
bde77ebab4 Sync changes. 2019-03-01 22:59:34 +07:00
XMRig
a261fe8c75 #952 Add missing header. 2019-03-01 22:23:02 +07:00
XMRig
b1700d270a v2.13.2-dev 2019-03-01 22:00:23 +07:00
XMRig
26e4859740 Merge branch 'master' into dev 2019-03-01 21:59:39 +07:00
xmrig
9685496ce0 Merge pull request #958 from osensei/fix-arm-user-agent
Properly report ARM architecture on user agent.
2019-02-28 11:03:40 +07:00
osensei
7e83fb306e Properly report ARM architecture on user agent. 2019-02-27 19:21:17 -03:00
XMRig
fc1bbbba6e v2.13.1 2019-02-25 21:23:59 +07:00
xmrig
d6788e4c46 Update CHANGELOG.md 2019-02-25 21:13:24 +07:00
XMRig
3ab7c8344e Merge branch 'dev' 2019-02-25 21:07:27 +07:00
xmrig
9155e6a2a0 Merge pull request #946 from SChernykh/feature-softaes
Optimized soft AES implementations
2019-02-25 16:11:49 +07:00
XMRig
948f23c7d9 Small code cleanups. 2019-02-25 15:54:21 +07:00
SChernykh
d4d0c69b5d Fixed compilation error in Linux 2019-02-24 20:23:52 +01:00
SChernykh
488cec09dd Optimized soft AES implementations
cn-pico: +6.7%
cn/half: +6.2%
cn/2: +4.3%
cn-heavy: +9.1%
cn/wow, cn/r: 2.4-2.6 times faster
2019-02-24 20:04:09 +01:00
XMRig
a5dcd6dd1f v2.13.1-dev 2019-02-23 10:00:20 +07:00
XMRig
d9066dc817 Merge branch 'master' into dev 2019-02-23 09:59:42 +07:00
XMRig
cac240104e Sync changes with AMD miner. 2019-02-21 19:03:53 +07:00
XMRig
eec5ca5535 v2.13.0 2019-02-21 17:37:05 +07:00
XMRig
060655fc6c Merge branch 'dev' 2019-02-21 17:36:36 +07:00
xmrig
5bd2b8fd3f Update CHANGELOG.md 2019-02-21 16:58:42 +07:00
XMRig
ac58ece16e Allow expired shares. 2019-02-21 14:20:23 +07:00
XMRig
a0553264a4 Merge branch 'dev' of github.com:xmrig/xmrig into dev 2019-02-20 09:10:07 +07:00
XMRig
1c16cfedfc v2.13.0-dev 2019-02-20 09:07:39 +07:00
XMRig
1ea34b31a1 #932 Fixed "cn-pico/trtl" performance. 2019-02-19 11:26:19 +07:00
XMRig
55c8ac6736 Merge branch 'evo' into dev 2019-02-19 10:12:42 +07:00
XMRig
601453bff6 Expired shares not allowed for cn/r. 2019-02-19 09:57:21 +07:00
XMRig
1bd51dcf2e Fixed msvc2015/msys2 build & code cleanup. 2019-02-19 09:15:06 +07:00
XMRig
41feb756bf Merge branch 'feature-cn4' of https://github.com/SChernykh/xmrig into evo 2019-02-19 08:15:36 +07:00
XMRig
3393ea346b Removed unused code. 2019-02-19 07:49:39 +07:00
XMRig
84f85b4200 Sync changes. 2019-02-18 19:02:40 +07:00
SChernykh
415600b8c9 Use public name CryptonightR for Monero's variant 4 2019-02-18 08:03:41 +01:00
XMRig
b7c17cf1a0 Fixed Linux build. 2019-02-18 12:39:52 +07:00
XMRig
de975adb8a Revert variant into summary output. 2019-02-18 08:14:42 +07:00
SChernykh
764767d317 Support for Cryptonight variant 4 (Monero) 2019-02-17 18:17:14 +01:00
XMRig
9c088eabc2 Implemented dynamic pool reload. 2019-02-17 19:29:33 +07:00
XMRig
7c789a0d3c Added "enabled" field to pools. 2019-02-17 15:55:05 +07:00
XMRig
bdff4064a2 Create pools directly from JSON objects. 2019-02-17 15:43:55 +07:00
XMRig
3a0fdcac6f Create network strategies in Pools class. 2019-02-17 11:25:25 +07:00
XMRig
ee4f6e28f0 * [WIP] More unification in Pools class. 2019-02-17 10:51:32 +07:00
XMRig
f6699b5929 [WIP] Use unified Pools class. 2019-02-17 08:53:37 +07:00
XMRig
ee667144e8 Move network classes into xmrig namespace. 2019-02-17 06:59:19 +07:00
XMRig
dbdcc14672 Move Pool.h/Pool.cpp. 2019-02-16 09:56:08 +07:00
XMRig
4f188a2cd8 Add Signals class. 2019-02-15 14:21:40 +07:00
XMRig
70d6e0e62c Use early exit for --help and --version options. 2019-02-15 09:11:18 +07:00
XMRig
14e7c82512 Prevent config reload after initial save. 2019-02-15 07:06:48 +07:00
XMRig
f4d2dec628 Added classes Process and Arguments. 2019-02-15 05:42:46 +07:00
XMRig
0450c31449 Rewritten watch feature. 2019-02-15 04:59:20 +07:00
XMRig
b368ffacdb Added class Json. 2019-02-14 18:14:38 +07:00
XMRig
2df204f8a8 v2.12.1-dev 2019-02-14 06:00:42 +07:00
XMRig
d554f1c12a Merge branch 'master' into dev 2019-02-14 06:00:12 +07:00
XMRig
ca5fb6e8f0 v2.12.0 2019-02-13 09:28:06 +07:00
XMRig
7f5ac83050 Merge branch 'dev' 2019-02-13 09:27:10 +07:00
xmrig
3688cd9b6c Update CHANGELOG.md 2019-02-13 09:17:30 +07:00
XMRig
33a3ae59bd Removed "cn/r" alias and fixed build without ASM. 2019-02-13 00:18:40 +07:00
XMRig
8cf56438f6 Merge branch 'feature-cn-wow' into dev 2019-02-12 04:47:09 +07:00
XMRig
4a781cee8b Expired shares prohibited for cn/wow. 2019-02-12 03:15:36 +07:00
XMRig
8d316c17f0 Add block version check for pools without algorithm negotiation. 2019-02-11 07:07:09 +07:00
XMRig
42e0d35207 Show height only if it specified by pool. 2019-02-11 06:22:20 +07:00
XMRig
a6813ef4f5 Temporary added "cn/r" alias for test pool. 2019-02-11 05:46:43 +07:00
SChernykh
36ce144d35 Fixed ARM code 2019-02-10 16:04:24 +01:00
SChernykh
65dab8371b Removed unused variable 2019-02-10 15:46:55 +01:00
SChernykh
c2e15e2b86 Fixed ARM compilation 2019-02-10 15:34:31 +01:00
SChernykh
e3f2c38fff CryptonightR support for Wownero 2019-02-10 15:21:17 +01:00
XMRig
73852f44c6 v2.11.1-dev 2019-02-10 01:30:54 +07:00
XMRig
01428acc65 Merge branch 'master' into dev 2019-02-10 01:30:12 +07:00
XMRig
9dd223d5b1 v2.11.0 2019-02-09 22:06:38 +07:00
XMRig
c27c577c5e Merge branch 'dev' 2019-02-09 22:06:10 +07:00
xmrig
a1fec1c797 Update CHANGELOG.md 2019-02-09 16:36:28 +07:00
XMRig
a5f77eb16a #925 Fixed self test on recent macOS. 2019-02-09 03:48:24 +07:00
XMRig
5b3ad39a9e v2.11.0-dev 2019-02-08 17:25:09 +07:00
XMRig
1a2aaf210c Sync changes. 2019-02-08 16:55:21 +07:00
XMRig
a6a0fb965a Fixed self test, cn/gpu not support multihash mode. 2019-02-06 01:27:50 +07:00
XMRig
aabdff2cc9 Fixed floating-point rounding, resolved conflict between cn/2 and cn/gpu. Thanks @SChernykh. 2019-02-06 00:38:55 +07:00
XMRig
3f8898f228 Sync changes. 2019-02-05 18:47:54 +07:00
XMRig
ab60add9d5 #749 Use HWCAP to detect AES feature on ARMv8, thanks @lhirlimann. 2019-02-04 03:03:10 +07:00
XMRig
7e4858db2a Allow override ARM arch detection and support for ARMv8 without crypto extension. 2019-02-04 02:23:05 +07:00
XMRig
885a2cab21 Merge branch 'feature-cn-gpu' into dev 2019-02-04 00:14:14 +07:00
XMRig
3337f5ac43 Fix ARM builds with clang. 2019-02-03 20:43:49 +07:00
XMRig
5f113a47cf Fix typo. 2019-02-03 20:34:24 +07:00
XMRig
f4170ec7bc Add ARM support for cn/gpu. 2019-02-03 20:28:13 +07:00
XMRig
e9069a381e Disable cn/gpu for 32bit builds. 2019-02-03 16:49:17 +07:00
XMRig
ca18622ad0 Disable -Ofast for gcc and cn/gpu. 2019-02-03 16:00:06 +07:00
XMRig
eac6a97a2e Fix Linux build. 2019-02-03 14:48:11 +07:00
XMRig
bd4bc9ba4d Added reference implementation for cn/gpu (cn-gpu). 2019-02-03 14:44:23 +07:00
XMRig
7605c4241f v2.10.1-dev 2019-02-02 01:33:25 +07:00
XMRig
bb583afcff Merge branch 'master' into dev 2019-02-02 01:32:52 +07:00
xmrig
5a2cf85b6c Update CHANGELOG.md 2019-01-23 19:44:14 +07:00
xmrig
80de5766ac Update CHANGELOG.md 2019-01-23 19:39:55 +07:00
XMRig
2c0183dcef v2.10.0 2019-01-23 19:31:45 +07:00
XMRig
8a90fc699e Merge branch 'dev' 2019-01-23 19:29:54 +07:00
XMRig
b1816005fd Sync changes with proxy. 2019-01-21 19:16:49 +07:00
XMRig
f478fa843d Better fix for memory allocation, thanks @SChernykh. 2019-01-21 17:27:45 +07:00
XMRig
046c345f65 Fix memory allocation. 2019-01-21 01:44:15 +07:00
XMRig
9692f92c6b New default value for max-cpu-usage option is 100 (instead of 75) also this option now deprecated. 2019-01-21 00:37:36 +07:00
XMRig
bc26d2ede6 #904 Add ASM implementation. 2019-01-21 00:32:24 +07:00
XMRig
36b01f136f #904 Initial support for "cn-pico/trtl". 2019-01-20 19:52:44 +07:00
XMRig
ca43d155d8 v2.9.5-dev 2019-01-20 15:13:01 +07:00
XMRig
e04d0f504c Merge branch 'master' into dev 2019-01-20 15:12:26 +07:00
XMRig
acca8f79cf v2.9.4 2019-01-19 23:55:30 +07:00
XMRig
2c38f693d7 Merge branch 'dev' 2019-01-19 23:54:50 +07:00
xmrig
4faa95b460 Update CHANGELOG.md 2019-01-19 23:53:39 +07:00
xmrig
5f9ebdf149 Merge pull request #915 from SChernykh/dev
Make JIT memory read-only after patching is done
2019-01-19 17:55:54 +07:00
SChernykh
31a571dc70 Make JIT memory read-only after patching is done 2019-01-19 11:22:54 +01:00
XMRig
897ff83dcd #913 Increase max blob size for MSR secor upgrade. 2019-01-18 21:44:44 +07:00
XMRig
a63794ccd6 v2.9.4-dev 2019-01-17 20:43:25 +07:00
XMRig
b15e605614 Merge branch 'master' into dev 2019-01-17 20:41:52 +07:00
XMRig
18335392a1 Merge branch 'master' of github.com:xmrig/xmrig 2019-01-17 12:22:00 +07:00
XMRig
b1c22da6a1 v2.9.3 2019-01-17 12:21:39 +07:00
xmrig
b95ff65eae Update CHANGELOG.md 2019-01-17 12:20:37 +07:00
xmrig
005a09cd98 Merge pull request #912 from SChernykh/master
Correct FP rounding mode for cn/half
2019-01-17 12:12:03 +07:00
SChernykh
e0f5066ded Correct FP rounding mode for cn/half 2019-01-17 00:49:48 +01:00
XMRig
2b15bcbb4f Don't use __builtin___clear_cache on FreeBSD. 2019-01-16 17:53:47 +07:00
xmrig
db646d5d2d Merge pull request #910 from ehaupt/patch-1
FreeBSD needs pthread
2019-01-16 17:50:53 +07:00
Emanuel Haupt
b58e20dde4 FreeBSD needs pthread
FreeBSD needs the pthread linker flag.
2019-01-16 10:55:45 +01:00
XMRig
b11e772acc v2.9.2 2019-01-16 09:17:35 +07:00
xmrig
d1bc03351b Merge pull request #907 from SChernykh/master
Fixed crash in patchCode() on Linux
2019-01-16 09:09:51 +07:00
SChernykh
d1f551da2c Fixed compilation error on Windows 2019-01-16 00:24:34 +01:00
SChernykh
6425c53d61 Fixed crash in patchCode() on Linux 2019-01-16 00:09:00 +01:00
185 changed files with 19647 additions and 2382 deletions

View File

@@ -1,3 +1,52 @@
# v2.15.0-beta
- [#314](https://github.com/xmrig/xmrig-proxy/issues/314) Added donate over proxy feature.
- Added new option `donate-over-proxy`.
- Added real graceful exit.
# v2.14.1
* [#975](https://github.com/xmrig/xmrig/issues/975) Fixed crash on Linux if double thread mode used.
# v2.14.0
- **[#969](https://github.com/xmrig/xmrig/pull/969) Added new algorithm `cryptonight/rwz`, short alias `cn/rwz` (also known as CryptoNight ReverseWaltz), for upcoming [Graft](https://www.graft.network/) fork.**
- **[#931](https://github.com/xmrig/xmrig/issues/931) Added new algorithm `cryptonight/zls`, short alias `cn/zls` for [Zelerius Network](https://zelerius.org) fork.**
- **[#940](https://github.com/xmrig/xmrig/issues/940) Added new algorithm `cryptonight/double`, short alias `cn/double` (also known as CryptoNight HeavyX), for [X-CASH](https://x-cash.org/).**
- [#951](https://github.com/xmrig/xmrig/issues/951#issuecomment-469581529) Fixed crash if AVX was disabled on OS level.
- [#952](https://github.com/xmrig/xmrig/issues/952) Fixed compile error on some Linux.
- [#957](https://github.com/xmrig/xmrig/issues/957#issuecomment-468890667) Added support for embedded config.
- [#958](https://github.com/xmrig/xmrig/pull/958) Fixed incorrect user agent on ARM platforms.
- [#968](https://github.com/xmrig/xmrig/pull/968) Optimized `cn/r` algorithm performance.
# v2.13.1
- [#946](https://github.com/xmrig/xmrig/pull/946) Optimized software AES implementations for CPUs without hardware AES support. `cn/r`, `cn/wow` up to 2.6 times faster, 4-9% improvements for other algorithms.
# v2.13.0
- **[#938](https://github.com/xmrig/xmrig/issues/938) Added support for new algorithm `cryptonight/r`, short alias `cn/r` (also known as CryptoNightR or CryptoNight variant 4), for upcoming [Monero](https://www.getmonero.org/) fork on March 9, thanks [@SChernykh](https://github.com/SChernykh).**
- [#939](https://github.com/xmrig/xmrig/issues/939) Added support for dynamic (runtime) pools reload.
- [#932](https://github.com/xmrig/xmrig/issues/932) Fixed `cn-pico` hashrate drop, regression since v2.11.0.
# v2.12.0
- [#929](https://github.com/xmrig/xmrig/pull/929) Added support for new algorithm `cryptonight/wow`, short alias `cn/wow` (also known as CryptonightR), for upcoming [Wownero](http://wownero.org) fork on February 14.
# v2.11.0
- [#928](https://github.com/xmrig/xmrig/issues/928) Added support for new algorithm `cryptonight/gpu`, short alias `cn/gpu` (original name `cryptonight-gpu`), for upcoming [Ryo currency](https://ryo-currency.com) fork on February 14.
- [#749](https://github.com/xmrig/xmrig/issues/749) Added support for detect hardware AES in runtime on ARMv8 platforms.
- [#292](https://github.com/xmrig/xmrig/issues/292) Fixed build on ARMv8 platforms if compiler not support hardware AES.
# v2.10.0
- [#904](https://github.com/xmrig/xmrig/issues/904) Added new algorithm `cn-pico/trtl` (aliases `cryptonight-turtle`, `cn-trtl`) for upcoming TurtleCoin (TRTL) fork.
- Default value for option `max-cpu-usage` changed to `100` also this option now deprecated.
# v2.9.4
- [#913](https://github.com/xmrig/xmrig/issues/913) Fixed Masari (MSR) support (this update required for upcoming fork).
- [#915](https://github.com/xmrig/xmrig/pull/915) Improved security, JIT memory now read-only after patching.
# v2.9.3
- [#909](https://github.com/xmrig/xmrig/issues/909) Fixed compile errors on FreeBSD.
- [#912](https://github.com/xmrig/xmrig/pull/912) Fixed, C++ implementation of `cn/half` was produce up to 13% of invalid hashes.
# v2.9.2
- [#907](https://github.com/xmrig/xmrig/pull/907) Fixed crash on Linux.
# v2.9.1 # v2.9.1
- Restored compatibility with https://stellite.hashvault.pro. - Restored compatibility with https://stellite.hashvault.pro.

View File

@@ -1,56 +1,47 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
project(xmrig) project(xmrig)
option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_AEON "CryptoNight-Lite support" ON)
option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON)
option(WITH_HTTPD "HTTP REST API" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON)
option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_CN_GPU "CryptoNight-GPU support" ON)
option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_HTTPD "HTTP REST API" ON)
option(WITH_ASM "Enable ASM PoW implementations" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF)
option(BUILD_STATIC "Build static binary" OFF) option(WITH_TLS "Enable OpenSSL support" ON)
option(WITH_ASM "Enable ASM PoW implementations" ON)
option(BUILD_STATIC "Build static binary" OFF)
option(ARM_TARGET "Force use specific ARM target 8 or 7" 0)
option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF)
include (CheckIncludeFile) include (CheckIncludeFile)
include (cmake/cpu.cmake) include (cmake/cpu.cmake)
include (src/base/base.cmake)
set(HEADERS set(HEADERS
"${HEADERS_BASE}"
src/api/NetworkState.h src/api/NetworkState.h
src/App.h src/App.h
src/base/tools/String.h
src/common/config/CommonConfig.h src/common/config/CommonConfig.h
src/common/config/ConfigLoader.h src/common/config/ConfigLoader.h
src/common/config/ConfigWatcher.h src/common/config/ConfigWatcher.h
src/common/Console.h
src/common/cpu/Cpu.h src/common/cpu/Cpu.h
src/common/crypto/Algorithm.h src/common/crypto/Algorithm.h
src/common/crypto/keccak.h src/common/crypto/keccak.h
src/common/interfaces/IClientListener.h
src/common/interfaces/IConfig.h src/common/interfaces/IConfig.h
src/common/interfaces/IConfigCreator.h src/common/interfaces/IConfigCreator.h
src/common/interfaces/IConsoleListener.h
src/common/interfaces/IControllerListener.h src/common/interfaces/IControllerListener.h
src/common/interfaces/ICpuInfo.h src/common/interfaces/ICpuInfo.h
src/common/interfaces/ILogBackend.h src/common/interfaces/ILogBackend.h
src/common/interfaces/IStrategy.h
src/common/interfaces/IStrategyListener.h
src/common/interfaces/IWatcherListener.h
src/common/log/BasicLog.h src/common/log/BasicLog.h
src/common/log/ConsoleLog.h src/common/log/ConsoleLog.h
src/common/log/FileLog.h src/common/log/FileLog.h
src/common/log/Log.h src/common/log/Log.h
src/common/net/Client.h
src/common/net/Id.h
src/common/net/Job.h
src/common/net/Pool.h
src/common/net/Storage.h
src/common/net/strategies/FailoverStrategy.h
src/common/net/strategies/SinglePoolStrategy.h
src/common/net/SubmitResult.h
src/common/Platform.h src/common/Platform.h
src/common/utils/c_str.h
src/common/utils/mm_malloc.h src/common/utils/mm_malloc.h
src/common/xmrig.h src/common/xmrig.h
src/core/ConfigLoader_default.h
src/core/ConfigLoader_platform.h src/core/ConfigLoader_platform.h
src/core/Controller.h src/core/Controller.h
src/interfaces/IJobResultListener.h src/interfaces/IJobResultListener.h
@@ -63,7 +54,7 @@ set(HEADERS
src/Summary.h src/Summary.h
src/version.h src/version.h
src/workers/CpuThread.h src/workers/CpuThread.h
src/workers/Handle.h src/workers/ThreadHandle.h
src/workers/Hashrate.h src/workers/Hashrate.h
src/workers/MultiWorker.h src/workers/MultiWorker.h
src/workers/Worker.h src/workers/Worker.h
@@ -83,6 +74,7 @@ set(HEADERS_CRYPTO
src/crypto/hash.h src/crypto/hash.h
src/crypto/skein_port.h src/crypto/skein_port.h
src/crypto/soft_aes.h src/crypto/soft_aes.h
src/crypto/asm/CryptonightR_template.h
) )
if (XMRIG_ARM) if (XMRIG_ARM)
@@ -92,25 +84,18 @@ else()
endif() endif()
set(SOURCES set(SOURCES
"${SOURCES_BASE}"
src/api/NetworkState.cpp src/api/NetworkState.cpp
src/App.cpp src/App.cpp
src/base/tools/String.cpp
src/common/config/CommonConfig.cpp src/common/config/CommonConfig.cpp
src/common/config/ConfigLoader.cpp src/common/config/ConfigLoader.cpp
src/common/config/ConfigWatcher.cpp src/common/config/ConfigWatcher.cpp
src/common/Console.cpp
src/common/crypto/Algorithm.cpp src/common/crypto/Algorithm.cpp
src/common/crypto/keccak.cpp src/common/crypto/keccak.cpp
src/common/log/BasicLog.cpp src/common/log/BasicLog.cpp
src/common/log/ConsoleLog.cpp src/common/log/ConsoleLog.cpp
src/common/log/FileLog.cpp src/common/log/FileLog.cpp
src/common/log/Log.cpp src/common/log/Log.cpp
src/common/net/Client.cpp
src/common/net/Job.cpp
src/common/net/Pool.cpp
src/common/net/strategies/FailoverStrategy.cpp
src/common/net/strategies/SinglePoolStrategy.cpp
src/common/net/SubmitResult.cpp
src/common/Platform.cpp src/common/Platform.cpp
src/core/Config.cpp src/core/Config.cpp
src/core/Controller.cpp src/core/Controller.cpp
@@ -119,7 +104,7 @@ set(SOURCES
src/net/strategies/DonateStrategy.cpp src/net/strategies/DonateStrategy.cpp
src/Summary.cpp src/Summary.cpp
src/workers/CpuThread.cpp src/workers/CpuThread.cpp
src/workers/Handle.cpp src/workers/ThreadHandle.cpp
src/workers/Hashrate.cpp src/workers/Hashrate.cpp
src/workers/MultiWorker.cpp src/workers/MultiWorker.cpp
src/workers/Worker.cpp src/workers/Worker.cpp
@@ -136,6 +121,7 @@ set(SOURCES_CRYPTO
if (WIN32) if (WIN32)
set(SOURCES_OS set(SOURCES_OS
"${SOURCES_OS}"
res/app.rc res/app.rc
src/App_win.cpp src/App_win.cpp
src/common/Platform_win.cpp src/common/Platform_win.cpp
@@ -146,19 +132,21 @@ if (WIN32)
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv) set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
elseif (APPLE) elseif (APPLE)
set(SOURCES_OS set(SOURCES_OS
"${SOURCES_OS}"
src/App_unix.cpp src/App_unix.cpp
src/common/Platform_mac.cpp src/common/Platform_mac.cpp
src/Mem_unix.cpp src/Mem_unix.cpp
) )
else() else()
set(SOURCES_OS set(SOURCES_OS
"${SOURCES_OS}"
src/App_unix.cpp src/App_unix.cpp
src/common/Platform_unix.cpp src/common/Platform_unix.cpp
src/Mem_unix.cpp src/Mem_unix.cpp
) )
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(EXTRA_LIBS kvm) set(EXTRA_LIBS kvm pthread)
else() else()
set(EXTRA_LIBS pthread rt dl) set(EXTRA_LIBS pthread rt dl)
endif() endif()
@@ -199,6 +187,7 @@ endif()
include(cmake/OpenSSL.cmake) include(cmake/OpenSSL.cmake)
include(cmake/asm.cmake) include(cmake/asm.cmake)
include(cmake/cn-gpu.cmake)
CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H) CHECK_INCLUDE_FILE (syslog.h HAVE_SYSLOG_H)
if (HAVE_SYSLOG_H) if (HAVE_SYSLOG_H)
@@ -218,6 +207,14 @@ if (NOT WITH_IPBC)
add_definitions(/DXMRIG_NO_IPBC) add_definitions(/DXMRIG_NO_IPBC)
endif() endif()
if (NOT WITH_CN_PICO)
add_definitions(/DXMRIG_NO_CN_PICO)
endif()
if (WITH_EMBEDDED_CONFIG)
add_definitions(/DXMRIG_FEATURE_EMBEDDED_CONFIG)
endif()
if (WITH_HTTPD) if (WITH_HTTPD)
find_package(MHD) find_package(MHD)
@@ -257,5 +254,5 @@ if (WITH_DEBUG_LOG)
add_definitions(/DAPP_DEBUG) add_definitions(/DAPP_DEBUG)
endif() endif()
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES}) add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES} ${CN_GPU_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})

View File

@@ -11,14 +11,18 @@ if (WITH_TLS)
find_package(OpenSSL) find_package(OpenSSL)
if (OPENSSL_FOUND) if (OPENSSL_FOUND)
set(TLS_SOURCES src/common/net/Tls.h src/common/net/Tls.cpp) set(TLS_SOURCES src/base/net/stratum/Tls.h src/base/net/stratum/Tls.cpp)
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
else() else()
message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support") message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support")
endif() endif()
add_definitions(/DXMRIG_FEATURE_TLS)
remove_definitions(/DXMRIG_NO_TLS)
else() else()
set(TLS_SOURCES "") set(TLS_SOURCES "")
set(OPENSSL_LIBRARIES "") set(OPENSSL_LIBRARIES "")
remove_definitions(/DXMRIG_FEATURE_TLS)
add_definitions(/DXMRIG_NO_TLS) add_definitions(/DXMRIG_NO_TLS)
set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls") set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls")

View File

@@ -5,26 +5,38 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
enable_language(ASM_MASM) enable_language(ASM_MASM)
if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141) if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141)
set(XMRIG_ASM_FILE "src/crypto/asm/cn_main_loop.asm") set(XMRIG_ASM_FILES
"src/crypto/asm/cn_main_loop.asm"
"src/crypto/asm/CryptonightR_template.asm"
)
else() else()
set(XMRIG_ASM_FILE "src/crypto/asm/win64/cn_main_loop.asm") set(XMRIG_ASM_FILES
"src/crypto/asm/win64/cn_main_loop.asm"
"src/crypto/asm/win64/CryptonightR_template.asm"
)
endif() endif()
set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY ASM_MASM) set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY ASM_MASM)
else() else()
enable_language(ASM) enable_language(ASM)
if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU)
set(XMRIG_ASM_FILE "src/crypto/asm/win64/cn_main_loop.S") set(XMRIG_ASM_FILES
"src/crypto/asm/win64/cn_main_loop.S"
"src/crypto/asm/CryptonightR_template.S"
)
else() else()
set(XMRIG_ASM_FILE "src/crypto/asm/cn_main_loop.S") set(XMRIG_ASM_FILES
"src/crypto/asm/cn_main_loop.S"
"src/crypto/asm/CryptonightR_template.S"
)
endif() endif()
set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY C) set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY C)
endif() endif()
add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILE}) add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES})
set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp) set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp src/crypto/CryptonightR_gen.cpp)
set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C)
else() else()
set(XMRIG_ASM_SOURCES "") set(XMRIG_ASM_SOURCES "")

23
cmake/cn-gpu.cmake Normal file
View File

@@ -0,0 +1,23 @@
if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8)
if (XMRIG_ARM)
set(CN_GPU_SOURCES src/crypto/cn_gpu_arm.cpp)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3")
endif()
else()
set(CN_GPU_SOURCES src/crypto/cn_gpu_avx.cpp src/crypto/cn_gpu_ssse3.cpp)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-O3 -mavx2")
set_source_files_properties(src/crypto/cn_gpu_ssse3.cpp PROPERTIES COMPILE_FLAGS "-O3")
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
endif()
endif()
else()
set(CN_GPU_SOURCES "")
add_definitions(/DXMRIG_NO_CN_GPU)
endif()

View File

@@ -7,19 +7,37 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
add_definitions(/DRAPIDJSON_SSE2) add_definitions(/DRAPIDJSON_SSE2)
endif() endif()
if (NOT ARM_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64)$") if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8-a)$")
set(XMRIG_ARM ON) set(ARM_TARGET 8)
set(XMRIG_ARMv8 ON) elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$")
set(WITH_LIBCPUID OFF) set(ARM_TARGET 7)
endif()
add_definitions(/DXMRIG_ARM) endif()
add_definitions(/DXMRIG_ARMv8)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$") if (ARM_TARGET AND ARM_TARGET GREATER 6)
set(XMRIG_ARM ON) set(XMRIG_ARM ON)
set(XMRIG_ARMv7 ON) set(WITH_LIBCPUID OFF)
set(WITH_LIBCPUID OFF) add_definitions(/DXMRIG_ARM)
add_definitions(/DXMRIG_ARM) message(STATUS "Use ARM_TARGET=${ARM_TARGET} (${CMAKE_SYSTEM_PROCESSOR})")
add_definitions(/DXMRIG_ARMv7)
include(CheckCXXCompilerFlag)
if (ARM_TARGET EQUAL 8)
set(XMRIG_ARMv8 ON)
add_definitions(/DXMRIG_ARMv8)
CHECK_CXX_COMPILER_FLAG(-march=armv8-a+crypto XMRIG_ARM_CRYPTO)
if (XMRIG_ARM_CRYPTO)
add_definitions(/DXMRIG_ARM_CRYPTO)
set(ARM8_CXX_FLAGS "-march=armv8-a+crypto")
else()
set(ARM8_CXX_FLAGS "-march=armv8-a")
endif()
elseif (ARM_TARGET EQUAL 7)
set(XMRIG_ARMv7 ON)
add_definitions(/DXMRIG_ARMv7)
endif()
endif() endif()

View File

@@ -19,8 +19,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s")
if (XMRIG_ARMv8) if (XMRIG_ARMv8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto -flax-vector-conversions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions")
elseif (XMRIG_ARMv7) elseif (XMRIG_ARMv7)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions")
@@ -60,8 +60,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
if (XMRIG_ARMv8) if (XMRIG_ARMv8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS}")
elseif (XMRIG_ARMv7) elseif (XMRIG_ARMv7)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}")

View File

@@ -5,7 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -28,7 +30,8 @@
#include "api/Api.h" #include "api/Api.h"
#include "App.h" #include "App.h"
#include "common/Console.h" #include "base/io/Console.h"
#include "base/kernel/Signals.h"
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "common/Platform.h" #include "common/Platform.h"
@@ -47,35 +50,25 @@
#endif #endif
App *App::m_self = nullptr; xmrig::App::App(Process *process) :
App::App(int argc, char **argv) :
m_console(nullptr), m_console(nullptr),
m_httpd(nullptr) m_httpd(nullptr),
m_signals(nullptr)
{ {
m_self = this; m_controller = new Controller(process);
if (m_controller->init() != 0) {
m_controller = new xmrig::Controller();
if (m_controller->init(argc, argv) != 0) {
return; return;
} }
if (!m_controller->config()->isBackground()) { if (!m_controller->config()->isBackground()) {
m_console = new Console(this); m_console = new Console(this);
} }
uv_signal_init(uv_default_loop(), &m_sigHUP);
uv_signal_init(uv_default_loop(), &m_sigINT);
uv_signal_init(uv_default_loop(), &m_sigTERM);
} }
App::~App() xmrig::App::~App()
{ {
uv_tty_reset_mode(); delete m_signals;
delete m_console; delete m_console;
delete m_controller; delete m_controller;
@@ -85,19 +78,13 @@ App::~App()
} }
int App::exec() int xmrig::App::exec()
{ {
if (m_controller->isDone()) {
return 0;
}
if (!m_controller->isReady()) { if (!m_controller->isReady()) {
return 2; return 2;
} }
uv_signal_start(&m_sigHUP, App::onSignal, SIGHUP); m_signals = new Signals(this);
uv_signal_start(&m_sigINT, App::onSignal, SIGINT);
uv_signal_start(&m_sigTERM, App::onSignal, SIGTERM);
background(); background();
@@ -107,7 +94,6 @@ int App::exec()
if (m_controller->config()->isDryRun()) { if (m_controller->config()->isDryRun()) {
LOG_NOTICE("OK"); LOG_NOTICE("OK");
release();
return 0; return 0;
} }
@@ -134,12 +120,11 @@ int App::exec()
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_loop_close(uv_default_loop()); uv_loop_close(uv_default_loop());
release();
return r; return r;
} }
void App::onConsoleCommand(char command) void xmrig::App::onConsoleCommand(char command)
{ {
switch (command) { switch (command) {
case 'h': case 'h':
@@ -174,21 +159,7 @@ void App::onConsoleCommand(char command)
} }
void App::close() void xmrig::App::onSignal(int signum)
{
m_controller->network()->stop();
Workers::stop();
uv_stop(uv_default_loop());
}
void App::release()
{
}
void App::onSignal(uv_signal_t *handle, int signum)
{ {
switch (signum) switch (signum)
{ {
@@ -205,9 +176,23 @@ void App::onSignal(uv_signal_t *handle, int signum)
break; break;
default: default:
break; return;
} }
uv_signal_stop(handle); close();
m_self->close(); }
void xmrig::App::close()
{
# ifndef XMRIG_NO_HTTPD
m_httpd->stop();
# endif
m_signals->stop();
m_console->stop();
m_controller->stop();
Workers::stop();
Log::release();
} }

View File

@@ -5,7 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,54 +23,49 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __APP_H__ #ifndef XMRIG_APP_H
#define __APP_H__ #define XMRIG_APP_H
#include <uv.h> #include "base/kernel/interfaces/IConsoleListener.h"
#include "base/kernel/interfaces/ISignalListener.h"
#include "common/interfaces/IConsoleListener.h"
class Console;
class Httpd;
class Network;
class Options;
namespace xmrig { namespace xmrig {
class Controller;
}
class App : public IConsoleListener class Console;
class Controller;
class Httpd;
class Network;
class Process;
class Signals;
class App : public IConsoleListener, public ISignalListener
{ {
public: public:
App(int argc, char **argv); App(Process *process);
~App(); ~App() override;
int exec(); int exec();
protected: protected:
void onConsoleCommand(char command) override; void onConsoleCommand(char command) override;
void onSignal(int signum) override;
private: private:
void background(); void background();
void close(); void close();
void release();
static void onSignal(uv_signal_t *handle, int signum); Console *m_console;
Controller *m_controller;
static App *m_self; Httpd *m_httpd;
Signals *m_signals;
Console *m_console;
Httpd *m_httpd;
uv_signal_t m_sigHUP;
uv_signal_t m_sigINT;
uv_signal_t m_sigTERM;
xmrig::Controller *m_controller;
}; };
#endif /* __APP_H__ */ } /* namespace xmrig */
#endif /* XMRIG_APP_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -34,7 +35,7 @@
#include "core/Controller.h" #include "core/Controller.h"
void App::background() void xmrig::App::background()
{ {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -31,7 +32,7 @@
#include "core/Config.h" #include "core/Config.h"
void App::background() void xmrig::App::background()
{ {
if (!m_controller->config()->isBackground()) { if (!m_controller->config()->isBackground()) {
return; return;

View File

@@ -34,7 +34,6 @@ bool Mem::m_enabled = true;
int Mem::m_flags = 0; int Mem::m_flags = 0;
MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
{ {
using namespace xmrig; using namespace xmrig;
@@ -42,11 +41,9 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
MemInfo info; MemInfo info;
info.size = cn_select_memory(algorithm) * count; info.size = cn_select_memory(algorithm) * count;
# ifndef XMRIG_NO_AEON constexpr const size_t align_size = 2 * 1024 * 1024;
info.size += info.size % cn_select_memory<CRYPTONIGHT>(); info.size = ((info.size + align_size - 1) / align_size) * align_size;
# endif info.pages = info.size / align_size;
info.pages = info.size / cn_select_memory<CRYPTONIGHT>();
allocate(info, m_enabled); allocate(info, m_enabled);
@@ -54,6 +51,14 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096)); cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096));
c->memory = info.memory + (i * cn_select_memory(algorithm)); c->memory = info.memory + (i * cn_select_memory(algorithm));
uint8_t* p = reinterpret_cast<uint8_t*>(allocateExecutableMemory(0x4000));
c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(p);
c->generated_code_double = reinterpret_cast<cn_mainloop_fun_ms_abi>(p + 0x2000);
c->generated_code_data.variant = xmrig::VARIANT_MAX;
c->generated_code_data.height = (uint64_t)(-1);
c->generated_code_double_data = c->generated_code_data;
ctx[i] = c; ctx[i] = c;
} }

View File

@@ -61,6 +61,7 @@ public:
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info); static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
static void *allocateExecutableMemory(size_t size); static void *allocateExecutableMemory(size_t size);
static void protectExecutableMemory(void *p, size_t size);
static void flushInstructionCache(void *p, size_t size); static void flushInstructionCache(void *p, size_t size);
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }

View File

@@ -100,7 +100,15 @@ void *Mem::allocateExecutableMemory(size_t size)
} }
void Mem::protectExecutableMemory(void *p, size_t size)
{
mprotect(p, size, PROT_READ | PROT_EXEC);
}
void Mem::flushInstructionCache(void *p, size_t size) void Mem::flushInstructionCache(void *p, size_t size)
{ {
# ifndef __FreeBSD__
__builtin___clear_cache(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + size); __builtin___clear_cache(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + size);
# endif
} }

View File

@@ -191,6 +191,13 @@ void *Mem::allocateExecutableMemory(size_t size)
} }
void Mem::protectExecutableMemory(void *p, size_t size)
{
DWORD oldProtect;
VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect);
}
void Mem::flushInstructionCache(void *p, size_t size) void Mem::flushInstructionCache(void *p, size_t size)
{ {
::FlushInstructionCache(GetCurrentProcess(), p, size); ::FlushInstructionCache(GetCurrentProcess(), p, size);

View File

@@ -4,9 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -28,9 +28,9 @@
#include <uv.h> #include <uv.h>
#include "base/net/stratum/Pool.h"
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "common/net/Pool.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "crypto/Asm.h" #include "crypto/Asm.h"
@@ -59,11 +59,11 @@ inline static const char *asmName(xmrig::Assembly assembly, bool colors)
static void print_memory(xmrig::Config *config) { static void print_memory(xmrig::Config *config) {
# ifdef _WIN32 # ifdef _WIN32
if (config->isColors()) { if (config->isColors()) {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
"HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable");
} }
else { else {
Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); xmrig::Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable");
} }
# endif # endif
} }
@@ -74,18 +74,25 @@ static void print_cpu(xmrig::Config *config)
using namespace xmrig; using namespace xmrig;
if (config->isColors()) { if (config->isColors()) {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES", Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES %sAVX2",
"CPU", "CPU",
Cpu::info()->brand(), Cpu::info()->brand(),
Cpu::info()->sockets(), Cpu::info()->sockets(),
Cpu::info()->isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", Cpu::info()->isX64() ? "\x1B[1;32m" : "\x1B[1;31m-",
Cpu::info()->hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); Cpu::info()->hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-",
Cpu::info()->hasAVX2() ? "\x1B[1;32m" : "\x1B[1;31m-");
# ifndef XMRIG_NO_LIBCPUID # ifndef XMRIG_NO_LIBCPUID
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%.1f MB/%.1f MB"), "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0);
# endif # endif
} }
else { else {
Log::i()->text(" * %-13s%s (%d) %sx64 %sAES", "CPU", Cpu::info()->brand(), Cpu::info()->sockets(), Cpu::info()->isX64() ? "" : "-", Cpu::info()->hasAES() ? "" : "-"); Log::i()->text(" * %-13s%s (%d) %sx64 %sAES %sAVX2",
"CPU",
Cpu::info()->brand(),
Cpu::info()->sockets(),
Cpu::info()->isX64() ? "" : "-",
Cpu::info()->hasAES() ? "" : "-",
Cpu::info()->hasAVX2() ? "" : "-");
# ifndef XMRIG_NO_LIBCPUID # ifndef XMRIG_NO_LIBCPUID
Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0); Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0);
# endif # endif
@@ -101,35 +108,35 @@ static void print_threads(xmrig::Config *config)
snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity());
} }
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s")
: " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s",
"THREADS", "THREADS",
config->threadsCount(), config->threadsCount(),
config->algorithm().name(), config->algorithm().name(),
config->algoVariant(), config->algoVariant(),
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "",
config->donateLevel(), config->pools().donateLevel(),
buf); buf);
} }
else { else {
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%")
: " * %-13s%d, %s, %sdonate=%d%%", : " * %-13s%d, %s, %sdonate=%d%%",
"THREADS", "THREADS",
config->threadsCount(), config->threadsCount(),
config->algorithm().name(), config->algorithm().name(),
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "",
config->donateLevel()); config->pools().donateLevel());
} }
# ifndef XMRIG_NO_ASM # ifndef XMRIG_NO_ASM
if (config->assembly() == xmrig::ASM_AUTO) { if (config->assembly() == xmrig::ASM_AUTO) {
const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly(); const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly();
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s")
: " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors())); : " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors()));
} }
else { else {
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors()));
} }
# endif # endif
} }
@@ -138,12 +145,12 @@ static void print_threads(xmrig::Config *config)
static void print_commands(xmrig::Config *config) static void print_commands(xmrig::Config *config)
{ {
if (config->isColors()) { if (config->isColors()) {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
MAGENTA_BOLD("p") WHITE_BOLD("ause, ") MAGENTA_BOLD("p") WHITE_BOLD("ause, ")
MAGENTA_BOLD("r") WHITE_BOLD("esume")); MAGENTA_BOLD("r") WHITE_BOLD("esume"));
} }
else { else {
Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); xmrig::Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
} }
} }

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -62,7 +63,7 @@ void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
} }
void Api::tick(const NetworkState &network) void Api::tick(const xmrig::NetworkState &network)
{ {
if (!m_router) { if (!m_router) {
return; return;

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __API_H__ #ifndef XMRIG_API_H
#define __API_H__ #define XMRIG_API_H
#include <uv.h> #include <uv.h>
@@ -30,13 +31,13 @@
class ApiRouter; class ApiRouter;
class Hashrate; class Hashrate;
class NetworkState;
namespace xmrig { namespace xmrig {
class Controller; class Controller;
class HttpReply; class HttpReply;
class HttpRequest; class HttpRequest;
class NetworkState;
} }
@@ -47,10 +48,10 @@ public:
static void release(); static void release();
static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
static void tick(const NetworkState &results); static void tick(const xmrig::NetworkState &results);
private: private:
static ApiRouter *m_router; static ApiRouter *m_router;
}; };
#endif /* __API_H__ */ #endif /* XMRIG_API_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -33,11 +34,11 @@
#include "api/ApiRouter.h" #include "api/ApiRouter.h"
#include "base/tools/Buffer.h"
#include "common/api/HttpReply.h" #include "common/api/HttpReply.h"
#include "common/api/HttpRequest.h" #include "common/api/HttpRequest.h"
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "common/crypto/keccak.h" #include "common/crypto/keccak.h"
#include "common/net/Job.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
@@ -119,7 +120,7 @@ void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
} }
void ApiRouter::tick(const NetworkState &network) void ApiRouter::tick(const xmrig::NetworkState &network)
{ {
m_network = network; m_network = network;
} }
@@ -133,7 +134,7 @@ void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousCo
void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const
{ {
rapidjson::StringBuffer buffer(0, 4096); rapidjson::StringBuffer buffer(nullptr, 4096);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer); rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
writer.SetMaxDecimalPlaces(10); writer.SetMaxDecimalPlaces(10);
doc.Accept(writer); doc.Accept(writer);
@@ -173,7 +174,7 @@ void ApiRouter::genId(const char *id)
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND));
xmrig::keccak(input, inSize, hash); xmrig::keccak(input, inSize, hash);
Job::toHex(hash, 8, m_id); xmrig::Buffer::toHex(hash, 8, m_id);
delete [] input; delete [] input;
break; break;
@@ -253,7 +254,7 @@ void ApiRouter::getMiner(rapidjson::Document &doc) const
doc.AddMember("cpu", cpu, allocator); doc.AddMember("cpu", cpu, allocator);
doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator); doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator);
doc.AddMember("hugepages", Workers::hugePages() > 0, allocator); doc.AddMember("hugepages", Workers::hugePages() > 0, allocator);
doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator); doc.AddMember("donate_level", m_controller->config()->pools().donateLevel(), allocator);
} }
@@ -292,13 +293,16 @@ void ApiRouter::getThreads(rapidjson::Document &doc) const
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads(); const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
rapidjson::Value list(rapidjson::kArrayType); rapidjson::Value list(rapidjson::kArrayType);
size_t i = 0;
for (const xmrig::IThread *thread : threads) { for (const xmrig::IThread *thread : threads) {
rapidjson::Value value = thread->toAPI(doc); rapidjson::Value value = thread->toAPI(doc);
rapidjson::Value hashrate(rapidjson::kArrayType); rapidjson::Value hashrate(rapidjson::kArrayType);
hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::ShortInterval)), allocator); hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::MediumInterval)), allocator); hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
hashrate.PushBack(normalize(hr->calc(thread->index(), Hashrate::LargeInterval)), allocator); hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
i++;
value.AddMember("hashrate", hashrate, allocator); value.AddMember("hashrate", hashrate, allocator);
list.PushBack(value, allocator); list.PushBack(value, allocator);

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __APIROUTER_H__ #ifndef XMRIG_APIROUTER_H
#define __APIROUTER_H__ #define XMRIG_APIROUTER_H
#include "api/NetworkState.h" #include "api/NetworkState.h"
@@ -44,12 +45,12 @@ class ApiRouter : public xmrig::IControllerListener
{ {
public: public:
ApiRouter(xmrig::Controller *controller); ApiRouter(xmrig::Controller *controller);
~ApiRouter(); ~ApiRouter() override;
void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const; void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const;
void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
void tick(const NetworkState &results); void tick(const xmrig::NetworkState &results);
protected: protected:
void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override; void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override;
@@ -68,8 +69,8 @@ private:
char m_id[32]; char m_id[32];
char m_workerId[128]; char m_workerId[128];
NetworkState m_network; xmrig::NetworkState m_network;
xmrig::Controller *m_controller; xmrig::Controller *m_controller;
}; };
#endif /* __APIROUTER_H__ */ #endif /* XMRIG_APIROUTER_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -29,10 +30,11 @@
#include "api/NetworkState.h" #include "api/NetworkState.h"
#include "common/net/SubmitResult.h" #include "base/net/stratum/SubmitResult.h"
#include "base/tools/Chrono.h"
NetworkState::NetworkState() : xmrig::NetworkState::NetworkState() :
diff(0), diff(0),
accepted(0), accepted(0),
failures(0), failures(0),
@@ -44,13 +46,7 @@ NetworkState::NetworkState() :
} }
int NetworkState::connectionTime() const uint32_t xmrig::NetworkState::avgTime() const
{
return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0;
}
uint32_t NetworkState::avgTime() const
{ {
if (m_latency.empty()) { if (m_latency.empty()) {
return 0; return 0;
@@ -60,7 +56,7 @@ uint32_t NetworkState::avgTime() const
} }
uint32_t NetworkState::latency() const uint32_t xmrig::NetworkState::latency() const
{ {
const size_t calls = m_latency.size(); const size_t calls = m_latency.size();
if (calls == 0) { if (calls == 0) {
@@ -74,7 +70,13 @@ uint32_t NetworkState::latency() const
} }
void NetworkState::add(const SubmitResult &result, const char *error) uint64_t xmrig::NetworkState::connectionTime() const
{
return m_active ? ((Chrono::steadyMSecs() - m_connectionTime) / 1000) : 0;
}
void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
{ {
if (error) { if (error) {
rejected++; rejected++;
@@ -94,16 +96,16 @@ void NetworkState::add(const SubmitResult &result, const char *error)
} }
void NetworkState::setPool(const char *host, int port, const char *ip) void xmrig::NetworkState::setPool(const char *host, int port, const char *ip)
{ {
snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port); snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port);
m_active = true; m_active = true;
m_connectionTime = uv_now(uv_default_loop()); m_connectionTime = Chrono::steadyMSecs();
} }
void NetworkState::stop() void xmrig::NetworkState::stop()
{ {
m_active = false; m_active = false;
diff = 0; diff = 0;

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,14 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __NETWORKSTATE_H__ #ifndef XMRIG_NETWORKSTATE_H
#define __NETWORKSTATE_H__ #define XMRIG_NETWORKSTATE_H
#include <array> #include <array>
#include <vector> #include <vector>
namespace xmrig {
class SubmitResult; class SubmitResult;
@@ -37,9 +41,9 @@ class NetworkState
public: public:
NetworkState(); NetworkState();
int connectionTime() const;
uint32_t avgTime() const; uint32_t avgTime() const;
uint32_t latency() const; uint32_t latency() const;
uint64_t connectionTime() const;
void add(const SubmitResult &result, const char *error); void add(const SubmitResult &result, const char *error);
void setPool(const char *host, int port, const char *ip); void setPool(const char *host, int port, const char *ip);
void stop(); void stop();
@@ -58,4 +62,8 @@ private:
uint64_t m_connectionTime; uint64_t m_connectionTime;
}; };
#endif /* __NETWORKSTATE_H__ */
} /* namespace xmrig */
#endif /* XMRIG_NETWORKSTATE_H */

63
src/base/base.cmake Normal file
View File

@@ -0,0 +1,63 @@
set(HEADERS_BASE
src/base/io/Console.h
src/base/io/Json.h
src/base/io/Watcher.h
src/base/kernel/Entry.h
src/base/kernel/interfaces/IClientListener.h
src/base/kernel/interfaces/IConfigListener.h
src/base/kernel/interfaces/IConsoleListener.h
src/base/kernel/interfaces/IDnsListener.h
src/base/kernel/interfaces/ILineListener.h
src/base/kernel/interfaces/ISignalListener.h
src/base/kernel/interfaces/IStrategy.h
src/base/kernel/interfaces/IStrategyListener.h
src/base/kernel/interfaces/ITimerListener.h
src/base/kernel/interfaces/IWatcherListener.h
src/base/kernel/Process.h
src/base/kernel/Signals.h
src/base/net/dns/Dns.h
src/base/net/dns/DnsRecord.h
src/base/net/stratum/Client.h
src/base/net/stratum/Job.h
src/base/net/stratum/Pool.h
src/base/net/stratum/Pools.h
src/base/net/stratum/strategies/FailoverStrategy.h
src/base/net/stratum/strategies/SinglePoolStrategy.h
src/base/net/stratum/SubmitResult.h
src/base/net/tools/RecvBuf.h
src/base/net/tools/Storage.h
src/base/tools/Arguments.h
src/base/tools/Buffer.h
src/base/tools/Chrono.h
src/base/tools/Handle.h
src/base/tools/String.h
src/base/tools/Timer.h
)
set(SOURCES_BASE
src/base/io/Console.cpp
src/base/io/Json.cpp
src/base/io/Watcher.cpp
src/base/kernel/Entry.cpp
src/base/kernel/Process.cpp
src/base/kernel/Signals.cpp
src/base/net/dns/Dns.cpp
src/base/net/dns/DnsRecord.cpp
src/base/net/stratum/Client.cpp
src/base/net/stratum/Job.cpp
src/base/net/stratum/Pool.cpp
src/base/net/stratum/Pools.cpp
src/base/net/stratum/strategies/FailoverStrategy.cpp
src/base/net/stratum/strategies/SinglePoolStrategy.cpp
src/base/tools/Arguments.cpp
src/base/tools/Buffer.cpp
src/base/tools/String.cpp
src/base/tools/Timer.cpp
)
if (WIN32)
set(SOURCES_OS src/base/io/Json_win.cpp)
else()
set(SOURCES_OS src/base/io/Json_unix.cpp)
endif()

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -22,26 +23,44 @@
*/ */
#include "common/Console.h" #include "base/io/Console.h"
#include "interfaces/IConsoleListener.h" #include "base/kernel/interfaces/IConsoleListener.h"
#include "base/tools/Handle.h"
Console::Console(IConsoleListener *listener) xmrig::Console::Console(IConsoleListener *listener)
: m_listener(listener) : m_listener(listener)
{ {
m_tty.data = this; m_tty = new uv_tty_t;
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
if (!uv_is_readable(reinterpret_cast<uv_stream_t*>(&m_tty))) { m_tty->data = this;
uv_tty_init(uv_default_loop(), m_tty, 0, 1);
if (!uv_is_readable(reinterpret_cast<uv_stream_t*>(m_tty))) {
return; return;
} }
uv_tty_set_mode(&m_tty, UV_TTY_MODE_RAW); uv_tty_set_mode(m_tty, UV_TTY_MODE_RAW);
uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), Console::onAllocBuffer, Console::onRead); uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), Console::onAllocBuffer, Console::onRead);
} }
void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) xmrig::Console::~Console()
{
stop();
}
void xmrig::Console::stop()
{
uv_tty_reset_mode();
Handle::close(m_tty);
m_tty = nullptr;
}
void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
{ {
auto console = static_cast<Console*>(handle->data); auto console = static_cast<Console*>(handle->data);
buf->len = 1; buf->len = 1;
@@ -49,7 +68,7 @@ void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
} }
void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) void xmrig::Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
{ {
if (nread < 0) { if (nread < 0) {
return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr); return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,13 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __CONSOLE_H__ #ifndef XMRIG_CONSOLE_H
#define __CONSOLE_H__ #define XMRIG_CONSOLE_H
#include <uv.h> #include <uv.h>
namespace xmrig {
class IConsoleListener; class IConsoleListener;
@@ -35,6 +40,9 @@ class Console
{ {
public: public:
Console(IConsoleListener *listener); Console(IConsoleListener *listener);
~Console();
void stop();
private: private:
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
@@ -42,8 +50,11 @@ private:
char m_buf[1]; char m_buf[1];
IConsoleListener *m_listener; IConsoleListener *m_listener;
uv_tty_t m_tty; uv_tty_t *m_tty;
}; };
#endif /* __CONSOLE_H__ */ } /* namespace xmrig */
#endif /* XMRIG_CONSOLE_H */

93
src/base/io/Json.cpp Normal file
View File

@@ -0,0 +1,93 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/Json.h"
#include "rapidjson/document.h"
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsBool()) {
return i->value.GetBool();
}
return defaultValue;
}
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsString()) {
return i->value.GetString();
}
return defaultValue;
}
int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt()) {
return i->value.GetInt();
}
return defaultValue;
}
int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt64()) {
return i->value.GetInt64();
}
return defaultValue;
}
uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint64()) {
return i->value.GetUint64();
}
return defaultValue;
}
unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue)
{
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint()) {
return i->value.GetUint();
}
return defaultValue;
}

53
src/base/io/Json.h Normal file
View File

@@ -0,0 +1,53 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_JSON_H
#define XMRIG_JSON_H
#include "rapidjson/fwd.h"
namespace xmrig {
class Json
{
public:
static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false);
static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr);
static int getInt(const rapidjson::Value &obj, const char *key, int defaultValue = 0);
static int64_t getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue = 0);
static uint64_t getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue = 0);
static unsigned getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue = 0);
static bool get(const char *fileName, rapidjson::Document &doc);
static bool save(const char *fileName, const rapidjson::Document &doc);
};
} /* namespace xmrig */
#endif /* XMRIG_JSON_H */

62
src/base/io/Json_unix.cpp Normal file
View File

@@ -0,0 +1,62 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fstream>
#include "base/io/Json.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/prettywriter.h"
bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc)
{
std::ifstream ifs(fileName, std::ios_base::in | std::ios_base::binary);
if (!ifs.is_open()) {
return false;
}
rapidjson::IStreamWrapper isw(ifs);
doc.ParseStream<rapidjson::kParseCommentsFlag | rapidjson::kParseTrailingCommasFlag>(isw);
return !doc.HasParseError() && doc.IsObject();
}
bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
{
std::ofstream ofs(fileName, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
if (!ofs.is_open()) {
return false;
}
rapidjson::OStreamWrapper osw(ofs);
rapidjson::PrettyWriter<rapidjson::OStreamWrapper> writer(osw);
doc.Accept(writer);
return true;
}

124
src/base/io/Json_win.cpp Normal file
View File

@@ -0,0 +1,124 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#ifdef __GNUC__
# include <fcntl.h>
# include <ext/stdio_filebuf.h>
#endif
#include <fstream>
#include "base/io/Json.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/ostreamwrapper.h"
#include "rapidjson/prettywriter.h"
#if defined(_MSC_VER) || defined (__GNUC__)
static std::wstring toUtf16(const char *str)
{
const int size = static_cast<int>(strlen(str));
std::wstring ret;
int len = MultiByteToWideChar(CP_UTF8, 0, str, size, nullptr, 0);
if (len > 0) {
ret.resize(static_cast<size_t>(len));
MultiByteToWideChar(CP_UTF8, 0, str, size, &ret[0], len);
}
return ret;
}
#endif
bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc)
{
using namespace rapidjson;
constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary;
# if defined(_MSC_VER)
std::ifstream ifs(toUtf16(fileName), mode);
if (!ifs.is_open()) {
return false;
}
# elif defined(__GNUC__)
const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY);
if (fd == -1) {
return false;
}
__gnu_cxx::stdio_filebuf<char> buf(fd, mode);
std::istream ifs(&buf);
# else
std::ifstream ifs(fileName, mode);
if (!ifs.is_open()) {
return false;
}
# endif
IStreamWrapper isw(ifs);
doc.ParseStream<kParseCommentsFlag | kParseTrailingCommasFlag>(isw);
return !doc.HasParseError() && doc.IsObject();
}
bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
{
using namespace rapidjson;
constexpr const std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary | std::ios_base::trunc;
# if defined(_MSC_VER)
std::ofstream ofs(toUtf16(fileName), mode);
if (!ofs.is_open()) {
return false;
}
# elif defined(__GNUC__)
const int fd = _wopen(toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_TRUNC);
if (fd == -1) {
return false;
}
__gnu_cxx::stdio_filebuf<char> buf(fd, mode);
std::ostream ofs(&buf);
# else
std::ofstream ofs(fileName, mode);
if (!ofs.is_open()) {
return false;
}
# endif
OStreamWrapper osw(ofs);
PrettyWriter<OStreamWrapper> writer(osw);
doc.Accept(writer);
return true;
}

88
src/base/io/Watcher.cpp Normal file
View File

@@ -0,0 +1,88 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/io/Watcher.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) :
m_listener(listener),
m_path(path)
{
m_timer = new Timer(this);
m_fsEvent = new uv_fs_event_t;
m_fsEvent->data = this;
uv_fs_event_init(uv_default_loop(), m_fsEvent);
start();
}
xmrig::Watcher::~Watcher()
{
delete m_timer;
Handle::close(m_fsEvent);
}
void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int, int)
{
if (!filename) {
return;
}
static_cast<Watcher *>(handle->data)->queueUpdate();
}
void xmrig::Watcher::queueUpdate()
{
m_timer->stop();
m_timer->start(kDelay, 0);
}
void xmrig::Watcher::reload()
{
m_listener->onFileChanged(m_path);
# ifndef _WIN32
uv_fs_event_stop(m_fsEvent);
start();
# endif
}
void xmrig::Watcher::start()
{
uv_fs_event_start(m_fsEvent, xmrig::Watcher::onFsEvent, m_path, 0);
}

71
src/base/io/Watcher.h Normal file
View File

@@ -0,0 +1,71 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_WATCHER_H
#define XMRIG_WATCHER_H
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/tools/String.h"
typedef struct uv_fs_event_s uv_fs_event_t;
namespace xmrig {
class IWatcherListener;
class Timer;
class Watcher : public ITimerListener
{
public:
Watcher(const String &path, IWatcherListener *listener);
~Watcher() override;
protected:
inline void onTimer(const Timer *) override { reload(); }
private:
constexpr static int kDelay = 500;
static void onFsEvent(uv_fs_event_t *handle, const char *filename, int events, int status);
void queueUpdate();
void reload();
void start();
IWatcherListener *m_listener;
String m_path;
Timer *m_timer;
uv_fs_event_t *m_fsEvent;
};
} /* namespace xmrig */
#endif /* XMRIG_WATCHER_H */

121
src/base/kernel/Entry.cpp Normal file
View File

@@ -0,0 +1,121 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <uv.h>
#ifndef XMRIG_NO_HTTPD
# include <microhttpd.h>
#endif
#ifndef XMRIG_NO_TLS
# include <openssl/opensslv.h>
#endif
#include "base/kernel/Entry.h"
#include "base/kernel/Process.h"
#include "core/usage.h"
#include "version.h"
static int showVersion()
{
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
# if defined(__clang__)
" with clang " __clang_version__);
# elif defined(__GNUC__)
" with GCC");
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER)
" with MSVC");
printf(" %d", MSVC_VERSION);
# else
);
# endif
printf("\n features:"
# if defined(__i386__) || defined(_M_IX86)
" 32-bit"
# elif defined(__x86_64__) || defined(_M_AMD64)
" 64-bit"
# endif
# if defined(__AES__) || defined(_MSC_VER)
" AES"
# endif
"\n");
printf("\nlibuv/%s\n", uv_version_string());
# ifndef XMRIG_NO_HTTPD
printf("microhttpd/%s\n", MHD_get_version());
# endif
# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT)
{
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
}
# endif
return 0;
}
xmrig::Entry::Id xmrig::Entry::get(const Process &process)
{
const Arguments &args = process.arguments();
if (args.hasArg("-h") || args.hasArg("--help")) {
return Usage;
}
if (args.hasArg("-V") || args.hasArg("--version")) {
return Version;
}
return Default;
}
int xmrig::Entry::exec(const Process &, Id id)
{
switch (id) {
case Usage:
printf(usage);
return 0;
case Version:
return showVersion();
default:
break;
}
return 1;
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,29 +22,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SUBMITRESULT_H__ #ifndef XMRIG_ENTRY_H
#define __SUBMITRESULT_H__ #define XMRIG_ENTRY_H
#include <uv.h> namespace xmrig {
class SubmitResult class Process;
class Entry
{ {
public: public:
inline SubmitResult() : reqId(0), seq(0), diff(0), actualDiff(0), elapsed(0), start(0) {} enum Id {
SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId = 0); Default,
Usage,
Version
};
void done(); static Id get(const Process &process);
static int exec(const Process &process, Id id);
int64_t reqId;
int64_t seq;
uint32_t diff;
uint64_t actualDiff;
uint64_t elapsed;
private:
uint64_t start;
}; };
#endif /* __SUBMITRESULT_H__ */
} /* namespace xmrig */
#endif /* XMRIG_ENTRY_H */

102
src/base/kernel/Process.cpp Normal file
View File

@@ -0,0 +1,102 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include <time.h>
#include "base/kernel/Process.h"
#include "base/tools/Chrono.h"
static size_t location(xmrig::Process::Location location, char *buf, size_t max)
{
using namespace xmrig;
size_t size = max;
if (location == Process::ExeLocation) {
return uv_exepath(buf, &size) < 0 ? 0 : size;
}
if (location == Process::CwdLocation) {
return uv_cwd(buf, &size) < 0 ? 0 : size;
}
return 0;
}
xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
}
xmrig::Process::~Process()
{
}
xmrig::String xmrig::Process::location(Location location, const char *fileName) const
{
constexpr const size_t max = 520;
char *buf = new char[max]();
size_t size = ::location(location, buf, max);
if (size == 0) {
delete [] buf;
return String();
}
if (fileName == nullptr) {
return buf;
}
if (location == ExeLocation) {
char *p = strrchr(buf, kDirSeparator);
if (p == nullptr) {
delete [] buf;
return String();
}
size = static_cast<size_t>(p - buf);
}
if ((size + strlen(fileName) + 2) >= max) {
delete [] buf;
return String();
}
buf[size] = kDirSeparator;
strcpy(buf + size + 1, fileName);
return buf;
}

64
src/base/kernel/Process.h Normal file
View File

@@ -0,0 +1,64 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_PROCESS_H
#define XMRIG_PROCESS_H
#include "base/tools/Arguments.h"
namespace xmrig {
class Process
{
public:
enum Location {
ExeLocation,
CwdLocation
};
# ifdef WIN32
constexpr const static char kDirSeparator = '\\';
# else
constexpr const static char kDirSeparator = '/';
# endif
Process(int argc, char **argv);
~Process();
String location(Location location, const char *fileName = nullptr) const;
inline const Arguments &arguments() const { return m_arguments; }
private:
Arguments m_arguments;
};
} /* namespace xmrig */
#endif /* XMRIG_PROCESS_H */

View File

@@ -0,0 +1,74 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/kernel/interfaces/ISignalListener.h"
#include "base/kernel/Signals.h"
#include "base/tools/Handle.h"
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
xmrig::Signals::Signals(ISignalListener *listener)
: m_listener(listener)
{
for (size_t i = 0; i < kSignalsCount; ++i) {
uv_signal_t *signal = new uv_signal_t;
signal->data = this;
m_signals[i] = signal;
uv_signal_init(uv_default_loop(), signal);
uv_signal_start(signal, Signals::onSignal, signums[i]);
}
}
xmrig::Signals::~Signals()
{
stop();
}
void xmrig::Signals::stop()
{
if (!m_signals[0]) {
return;
}
for (size_t i = 0; i < kSignalsCount; ++i) {
Handle::close(m_signals[i]);
m_signals[i] = nullptr;
}
}
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
{
static_cast<Signals *>(handle->data)->m_listener->onSignal(signum);
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,35 +22,43 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef XMRIG_TIMESTAMP_H #ifndef XMRIG_SIGNALS_H
#define XMRIG_TIMESTAMP_H #define XMRIG_SIGNALS_H
#include <chrono> #include <stddef.h>
typedef struct uv_signal_s uv_signal_t;
namespace xmrig { namespace xmrig {
static inline int64_t steadyTimestamp() class ISignalListener;
class Signals
{ {
using namespace std::chrono; public:
if (high_resolution_clock::is_steady) { constexpr static const size_t kSignalsCount = 3;
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
}
return time_point_cast<milliseconds>(steady_clock::now()).time_since_epoch().count(); Signals(ISignalListener *listener);
} ~Signals();
void stop();
static inline int64_t currentMSecsSinceEpoch() private:
{ void close(int signum);
using namespace std::chrono;
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count(); static void onSignal(uv_signal_t *handle, int signum);
}
ISignalListener *m_listener;
uv_signal_t *m_signals[kSignalsCount];
};
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* XMRIG_TIMESTAMP_H */
#endif /* XMRIG_SIGNALS_H */

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,13 +22,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ICLIENTLISTENER_H__ #ifndef XMRIG_ICLIENTLISTENER_H
#define __ICLIENTLISTENER_H__ #define XMRIG_ICLIENTLISTENER_H
#include <stdint.h> #include <stdint.h>
#include "rapidjson/fwd.h"
namespace xmrig {
class Client; class Client;
class Job; class Job;
class SubmitResult; class SubmitResult;
@@ -36,13 +43,17 @@ class SubmitResult;
class IClientListener class IClientListener
{ {
public: public:
virtual ~IClientListener() {} virtual ~IClientListener() = default;
virtual void onClose(Client *client, int failures) = 0; virtual void onClose(Client *client, int failures) = 0;
virtual void onJobReceived(Client *client, const Job &job) = 0; virtual void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) = 0;
virtual void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value &params) = 0;
virtual void onLoginSuccess(Client *client) = 0; virtual void onLoginSuccess(Client *client) = 0;
virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0;
}; };
#endif // __ICLIENTLISTENER_H__ } /* namespace xmrig */
#endif // XMRIG_ICLIENTLISTENER_H

View File

@@ -0,0 +1,47 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ICONFIGLISTENER_H
#define XMRIG_ICONFIGLISTENER_H
namespace xmrig {
class IConfig;
class IConfigListener
{
public:
virtual ~IConfigListener() = default;
virtual void onNewConfig(IConfig *config) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_ICONFIGLISTENER_H

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,19 +22,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef XMRIG_C_STR_H #ifndef XMRIG_ICONSOLELISTENER_H
#define XMRIG_C_STR_H #define XMRIG_ICONSOLELISTENER_H
#include "base/tools/String.h"
namespace xmrig { namespace xmrig {
typedef String c_str; class IConsoleListener
{
public:
virtual ~IConsoleListener() = default;
virtual void onConsoleCommand(char command) = 0;
};
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* XMRIG_C_STR_H */
#endif // XMRIG_ICONSOLELISTENER_H

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,25 +22,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef XMRIG_IDNSLISTENER_H
#include <uv.h> #define XMRIG_IDNSLISTENER_H
#include "common/net/SubmitResult.h" namespace xmrig {
SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : class Dns;
reqId(reqId),
seq(seq),
diff(diff), class IDnsListener
actualDiff(actualDiff),
elapsed(0)
{ {
start = uv_hrtime(); public:
} virtual ~IDnsListener() = default;
virtual void onResolved(const Dns &dns, int status) = 0;
};
void SubmitResult::done() } /* namespace xmrig */
{
elapsed = (uv_hrtime() - start) / 1000000;
} #endif // XMRIG_IDNSLISTENER_H

View File

@@ -0,0 +1,50 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ILINELISTENER_H
#define XMRIG_ILINELISTENER_H
#include <stdint.h>
namespace xmrig {
class String;
class ILineListener
{
public:
virtual ~ILineListener() = default;
virtual void onLine(char *line, size_t size) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_ILINELISTENER_H

View File

@@ -0,0 +1,47 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ISIGNALLISTENER_H
#define XMRIG_ISIGNALLISTENER_H
namespace xmrig {
class String;
class ISignalListener
{
public:
virtual ~ISignalListener() = default;
virtual void onSignal(int signum) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_ISIGNALLISTENER_H

View File

@@ -0,0 +1,59 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ISTRATEGY_H
#define XMRIG_ISTRATEGY_H
#include <stdint.h>
namespace xmrig {
class Algorithm;
class Client;
class JobResult;
class IStrategy
{
public:
virtual ~IStrategy() = default;
virtual bool isActive() const = 0;
virtual Client *client() const = 0;
virtual int64_t submit(const JobResult &result) = 0;
virtual void connect() = 0;
virtual void resume() = 0;
virtual void setAlgo(const Algorithm &algo) = 0;
virtual void stop() = 0;
virtual void tick(uint64_t now) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_ISTRATEGY_H

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,13 +22,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ISTRATEGYLISTENER_H__ #ifndef XMRIG_ISTRATEGYLISTENER_H
#define __ISTRATEGYLISTENER_H__ #define XMRIG_ISTRATEGYLISTENER_H
#include <stdint.h> #include <stdint.h>
namespace xmrig {
class Client; class Client;
class IStrategy; class IStrategy;
class Job; class Job;
@@ -37,7 +41,7 @@ class SubmitResult;
class IStrategyListener class IStrategyListener
{ {
public: public:
virtual ~IStrategyListener() {} virtual ~IStrategyListener() = default;
virtual void onActive(IStrategy *strategy, Client *client) = 0; virtual void onActive(IStrategy *strategy, Client *client) = 0;
virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0; virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0;
@@ -46,4 +50,7 @@ public:
}; };
#endif // __ISTRATEGYLISTENER_H__ } /* namespace xmrig */
#endif // XMRIG_ISTRATEGYLISTENER_H

View File

@@ -0,0 +1,47 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ITIMERLISTENER_H
#define XMRIG_ITIMERLISTENER_H
namespace xmrig {
class Timer;
class ITimerListener
{
public:
virtual ~ITimerListener() = default;
virtual void onTimer(const Timer *timer) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_ITIMERLISTENER_H

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,26 +22,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __IWATCHERLISTENER_H__ #ifndef XMRIG_IWATCHERLISTENER_H
#define __IWATCHERLISTENER_H__ #define XMRIG_IWATCHERLISTENER_H
namespace xmrig { namespace xmrig {
class IConfig; class String;
class IWatcherListener class IWatcherListener
{ {
public: public:
virtual ~IWatcherListener() {} virtual ~IWatcherListener() = default;
virtual void onNewConfig(IConfig *config) = 0; virtual void onFileChanged(const String &fileName) = 0;
}; };
} /* namespace xmrig */ } /* namespace xmrig */
#endif // __IWATCHERLISTENER_H__ #endif // XMRIG_IWATCHERLISTENER_H

158
src/base/net/dns/Dns.cpp Normal file
View File

@@ -0,0 +1,158 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/dns/Dns.h"
#include "base/tools/Handle.h"
namespace xmrig {
Storage<Dns> Dns::m_storage;
static const DnsRecord defaultRecord;
}
xmrig::Dns::Dns(IDnsListener *listener) :
m_hints(),
m_listener(listener),
m_status(0)
{
m_key = m_storage.add(this);
m_resolver = new uv_getaddrinfo_t;
m_resolver->data = m_storage.ptr(m_key);
m_hints.ai_family = AF_UNSPEC;
m_hints.ai_socktype = SOCK_STREAM;
m_hints.ai_protocol = IPPROTO_TCP;
}
xmrig::Dns::~Dns()
{
m_storage.release(m_key);
Handle::close(m_resolver);
}
bool xmrig::Dns::resolve(const String &host)
{
if (m_host != host) {
m_host = host;
clear();
}
m_status = uv_getaddrinfo(uv_default_loop(), m_resolver, Dns::onResolved, m_host.data(), nullptr, &m_hints);
return m_status == 0;
}
const char *xmrig::Dns::error() const
{
return uv_strerror(m_status);
}
const xmrig::DnsRecord &xmrig::Dns::get(DnsRecord::Type prefered) const
{
if (count() == 0) {
return defaultRecord;
}
const size_t ipv4 = m_ipv4.size();
const size_t ipv6 = m_ipv6.size();
if (ipv6 && (prefered == DnsRecord::AAAA || !ipv4)) {
return m_ipv6[ipv6 == 1 ? 0 : static_cast<size_t>(rand()) % ipv6];
}
if (ipv4) {
return m_ipv4[ipv4 == 1 ? 0 : static_cast<size_t>(rand()) % ipv4];
}
return defaultRecord;
}
size_t xmrig::Dns::count(DnsRecord::Type type) const
{
if (type == DnsRecord::A) {
return m_ipv4.size();
}
if (type == DnsRecord::AAAA) {
return m_ipv6.size();
}
return m_ipv4.size() + m_ipv6.size();
}
void xmrig::Dns::clear()
{
m_ipv4.clear();
m_ipv6.clear();
}
void xmrig::Dns::onResolved(int status, addrinfo *res)
{
m_status = status;
if (m_status < 0) {
return m_listener->onResolved(*this, status);
}
clear();
addrinfo *ptr = res;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
m_ipv4.push_back(ptr);
}
if (ptr->ai_family == AF_INET6) {
m_ipv6.push_back(ptr);
}
ptr = ptr->ai_next;
}
m_listener->onResolved(*this, status);
}
void xmrig::Dns::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
{
Dns *dns = m_storage.get(req->data);
if (dns) {
dns->onResolved(status, res);
}
uv_freeaddrinfo(res);
}

80
src/base/net/dns/Dns.h Normal file
View File

@@ -0,0 +1,80 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNS_H
#define XMRIG_DNS_H
#include <vector>
#include <uv.h>
#include "base/net/dns/DnsRecord.h"
#include "base/net/tools/Storage.h"
#include "base/tools/String.h"
namespace xmrig {
class IDnsListener;
class Dns
{
public:
Dns(IDnsListener *listener);
~Dns();
inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); }
inline int status() const { return m_status; }
bool resolve(const String &host);
const char *error() const;
const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::A) const;
size_t count(DnsRecord::Type type = DnsRecord::Unknown) const;
private:
void clear();
void onResolved(int status, addrinfo *res);
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
addrinfo m_hints;
IDnsListener *m_listener;
int m_status;
std::vector<DnsRecord> m_ipv4;
std::vector<DnsRecord> m_ipv6;
String m_host;
uintptr_t m_key;
uv_getaddrinfo_t *m_resolver;
static Storage<Dns> m_storage;
};
} /* namespace xmrig */
#endif /* XMRIG_DNS_H */

View File

@@ -0,0 +1,66 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/net/dns/DnsRecord.h"
xmrig::DnsRecord::DnsRecord(const addrinfo *addr) :
m_type(addr->ai_family == AF_INET6 ? AAAA : A)
{
char *buf = nullptr;
if (m_type == AAAA) {
buf = new char[45]();
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(addr->ai_addr), buf, 45);
}
else {
buf = new char[16]();
uv_ip4_name(reinterpret_cast<sockaddr_in*>(addr->ai_addr), buf, 16);
}
m_ip = buf;
}
sockaddr *xmrig::DnsRecord::addr(uint16_t port) const
{
if (m_type == A) {
sockaddr_in *addr = new sockaddr_in();
uv_ip4_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);
}
else if (m_type == AAAA) {
sockaddr_in6 *addr = new sockaddr_in6();
uv_ip6_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);
}
return nullptr;
}

View File

@@ -0,0 +1,66 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNSRECORD_H
#define XMRIG_DNSRECORD_H
struct addrinfo;
struct sockaddr;
#include "base/tools/String.h"
namespace xmrig {
class DnsRecord
{
public:
enum Type {
Unknown,
A,
AAAA
};
inline DnsRecord() : m_type(Unknown) {}
DnsRecord(const addrinfo *addr);
sockaddr *addr(uint16_t port = 0) const;
inline bool isValid() const { return m_type != Unknown; }
inline const String &ip() const { return m_ip; }
inline Type type() const { return m_type; }
private:
Type m_type;
String m_ip;
};
} /* namespace xmrig */
#endif /* XMRIG_DNSRECORD_H */

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -32,13 +33,16 @@
#ifndef XMRIG_NO_TLS #ifndef XMRIG_NO_TLS
# include <openssl/ssl.h> # include <openssl/ssl.h>
# include <openssl/err.h> # include <openssl/err.h>
# include "common/net/Tls.h" # include "base/net/stratum/Tls.h"
#endif #endif
#include "common/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
#include "base/net/dns/Dns.h"
#include "base/net/stratum/Client.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "common/net/Client.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
@@ -51,8 +55,12 @@
#endif #endif
namespace xmrig {
int64_t Client::m_sequence = 1; int64_t Client::m_sequence = 1;
xmrig::Storage<Client> Client::m_storage; Storage<Client> Client::m_storage;
} /* namespace xmrig */
#ifdef APP_DEBUG #ifdef APP_DEBUG
@@ -66,18 +74,16 @@ static const char *states[] = {
#endif #endif
Client::Client(int id, const char *agent, IClientListener *listener) : xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
m_enabled(true),
m_ipv6(false), m_ipv6(false),
m_nicehash(false),
m_quiet(false), m_quiet(false),
m_agent(agent), m_agent(agent),
m_listener(listener), m_listener(listener),
m_extensions(0),
m_id(id), m_id(id),
m_retries(5), m_retries(5),
m_retryPause(5000), m_retryPause(5000),
m_failures(0), m_failures(0),
m_recvBufPos(0),
m_state(UnconnectedState), m_state(UnconnectedState),
m_tls(nullptr), m_tls(nullptr),
m_expire(0), m_expire(0),
@@ -88,28 +94,18 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
m_socket(nullptr) m_socket(nullptr)
{ {
m_key = m_storage.add(this); m_key = m_storage.add(this);
m_dns = new Dns(this);
memset(m_ip, 0, sizeof(m_ip));
memset(&m_hints, 0, sizeof(m_hints));
m_resolver.data = m_storage.ptr(m_key);
m_hints.ai_family = AF_UNSPEC;
m_hints.ai_socktype = SOCK_STREAM;
m_hints.ai_protocol = IPPROTO_TCP;
m_recvBuf.base = m_buf;
m_recvBuf.len = sizeof(m_buf);
} }
Client::~Client() xmrig::Client::~Client()
{ {
delete m_dns;
delete m_socket; delete m_socket;
} }
void Client::connect() void xmrig::Client::connect()
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (m_pool.isTLS()) { if (m_pool.isTLS()) {
@@ -126,14 +122,14 @@ void Client::connect()
* *
* @param url * @param url
*/ */
void Client::connect(const Pool &url) void xmrig::Client::connect(const Pool &url)
{ {
setPool(url); setPool(url);
connect(); connect();
} }
void Client::deleteLater() void xmrig::Client::deleteLater()
{ {
if (!m_listener) { if (!m_listener) {
return; return;
@@ -148,7 +144,7 @@ void Client::deleteLater()
void Client::setPool(const Pool &pool) void xmrig::Client::setPool(const Pool &pool)
{ {
if (!pool.isValid()) { if (!pool.isValid()) {
return; return;
@@ -158,11 +154,11 @@ void Client::setPool(const Pool &pool)
} }
void Client::tick(uint64_t now) void xmrig::Client::tick(uint64_t now)
{ {
if (m_state == ConnectedState) { if (m_state == ConnectedState) {
if (m_expire && now > m_expire) { if (m_expire && now > m_expire) {
LOG_DEBUG_ERR("[%s] timeout", m_pool.url()); LOG_DEBUG_ERR("[%s] timeout", url());
close(); close();
} }
else if (m_keepAlive && now > m_keepAlive) { else if (m_keepAlive && now > m_keepAlive) {
@@ -176,7 +172,7 @@ void Client::tick(uint64_t now)
} }
bool Client::disconnect() bool xmrig::Client::disconnect()
{ {
m_keepAlive = 0; m_keepAlive = 0;
m_expire = 0; m_expire = 0;
@@ -186,7 +182,17 @@ bool Client::disconnect()
} }
const char *Client::tlsFingerprint() const bool xmrig::Client::isTLS() const
{
# ifndef XMRIG_NO_TLS
return m_pool.isTLS() && m_tls;
# else
return false;
# endif
}
const char *xmrig::Client::tlsFingerprint() const
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (isTLS() && m_pool.fingerprint() == nullptr) { if (isTLS() && m_pool.fingerprint() == nullptr) {
@@ -198,7 +204,7 @@ const char *Client::tlsFingerprint() const
} }
const char *Client::tlsVersion() const const char *xmrig::Client::tlsVersion() const
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (isTLS()) { if (isTLS()) {
@@ -210,7 +216,7 @@ const char *Client::tlsVersion() const
} }
int64_t Client::submit(const JobResult &result) int64_t xmrig::Client::submit(const JobResult &result)
{ {
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
if (result.clientId != m_rpcId) { if (result.clientId != m_rpcId) {
@@ -227,10 +233,10 @@ int64_t Client::submit(const JobResult &result)
char *nonce = m_sendBuf; char *nonce = m_sendBuf;
char *data = m_sendBuf + 16; char *data = m_sendBuf + 16;
Job::toHex(reinterpret_cast<const unsigned char*>(&result.nonce), 4, nonce); Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
nonce[8] = '\0'; nonce[8] = '\0';
Job::toHex(result.result, 32, data); Buffer::toHex(result.result, 32, data);
data[64] = '\0'; data[64] = '\0';
# endif # endif
@@ -247,7 +253,7 @@ int64_t Client::submit(const JobResult &result)
params.AddMember("nonce", StringRef(nonce), allocator); params.AddMember("nonce", StringRef(nonce), allocator);
params.AddMember("result", StringRef(data), allocator); params.AddMember("result", StringRef(data), allocator);
if (m_extensions & AlgoExt) { if (has<EXT_ALGO>() && result.algorithm.isValid()) {
params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator); params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator);
} }
@@ -263,7 +269,37 @@ int64_t Client::submit(const JobResult &result)
} }
bool Client::close() void xmrig::Client::onResolved(const Dns &dns, int status)
{
assert(m_listener != nullptr);
if (!m_listener) {
return reconnect();
}
if (status < 0 && dns.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("[%s] DNS error: \"%s\"", url(), uv_strerror(status));
}
return reconnect();
}
if (dns.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", url());
}
return reconnect();
}
const DnsRecord &record = dns.get();
m_ip = record.ip();
connect(record.addr(m_pool.port()));
}
bool xmrig::Client::close()
{ {
if (m_state == ClosingState) { if (m_state == ClosingState) {
return m_socket != nullptr; return m_socket != nullptr;
@@ -283,7 +319,7 @@ bool Client::close()
} }
bool Client::isCriticalError(const char *message) bool xmrig::Client::isCriticalError(const char *message)
{ {
if (!message) { if (!message) {
return false; return false;
@@ -305,24 +341,14 @@ bool Client::isCriticalError(const char *message)
} }
bool Client::isTLS() const bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
{
# ifndef XMRIG_NO_TLS
return m_pool.isTLS() && m_tls;
# else
return false;
# endif
}
bool Client::parseJob(const rapidjson::Value &params, int *code)
{ {
if (!params.IsObject()) { if (!params.IsObject()) {
*code = 2; *code = 2;
return false; return false;
} }
Job job(m_id, m_nicehash, m_pool.algorithm(), m_rpcId); Job job(m_id, has<EXT_NICEHASH>(), m_pool.algorithm(), m_rpcId);
if (!job.setId(params["job_id"].GetString())) { if (!job.setId(params["job_id"].GetString())) {
*code = 3; *code = 3;
@@ -354,6 +380,14 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
} }
} }
if (params.HasMember("height")) {
const rapidjson::Value &variant = params["height"];
if (variant.IsUint64()) {
job.setHeight(variant.GetUint64());
}
}
if (!verifyAlgorithm(job.algorithm())) { if (!verifyAlgorithm(job.algorithm())) {
*code = 6; *code = 6;
@@ -374,7 +408,7 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
} }
if (!isQuiet()) { if (!isQuiet()) {
LOG_WARN("[%s] duplicate job received, reconnect", m_pool.url()); LOG_WARN("[%s] duplicate job received, reconnect", url());
} }
close(); close();
@@ -382,18 +416,15 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
} }
bool Client::parseLogin(const rapidjson::Value &result, int *code) bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code)
{ {
if (!m_rpcId.setId(result["id"].GetString())) { m_rpcId = result["id"].GetString();
if (m_rpcId.isNull()) {
*code = 1; *code = 1;
return false; return false;
} }
m_nicehash = m_pool.isNicehash(); parseExtensions(result);
if (result.HasMember("extensions")) {
parseExtensions(result["extensions"]);
}
const bool rc = parseJob(result["job"], code); const bool rc = parseJob(result["job"], code);
m_jobs = 0; m_jobs = 0;
@@ -402,7 +433,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code)
} }
bool Client::send(BIO *bio) bool xmrig::Client::send(BIO *bio)
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
uv_buf_t buf; uv_buf_t buf;
@@ -412,7 +443,7 @@ bool Client::send(BIO *bio)
return true; return true;
} }
LOG_DEBUG("[%s] TLS send (%d bytes)", m_pool.url(), static_cast<int>(buf.len)); LOG_DEBUG("[%s] TLS send (%d bytes)", url(), static_cast<int>(buf.len));
bool result = false; bool result = false;
if (state() == ConnectedState && uv_is_writable(m_stream)) { if (state() == ConnectedState && uv_is_writable(m_stream)) {
@@ -423,7 +454,7 @@ bool Client::send(BIO *bio)
} }
} }
else { else {
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
} }
(void) BIO_reset(bio); (void) BIO_reset(bio);
@@ -435,10 +466,10 @@ bool Client::send(BIO *bio)
} }
bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const
{ {
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
if (m_pool.algorithm().variant() == xmrig::VARIANT_AUTO || m_id == -1) { if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) {
return true; return true;
} }
# endif # endif
@@ -462,22 +493,22 @@ bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const
} }
int Client::resolve(const char *host) int xmrig::Client::resolve(const String &host)
{ {
setState(HostLookupState); setState(HostLookupState);
m_expire = 0; m_expire = 0;
m_recvBufPos = 0; m_recvBuf.reset();
if (m_failures == -1) { if (m_failures == -1) {
m_failures = 0; m_failures = 0;
} }
const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints); if (!m_dns->resolve(host)) {
if (r) {
if (!isQuiet()) { if (!isQuiet()) {
LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_pool.port(), uv_strerror(r)); LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host.data(), m_pool.port(), uv_strerror(m_dns->status()));
} }
return 1; return 1;
} }
@@ -485,17 +516,17 @@ int Client::resolve(const char *host)
} }
int64_t Client::send(const rapidjson::Document &doc) int64_t xmrig::Client::send(const rapidjson::Document &doc)
{ {
using namespace rapidjson; using namespace rapidjson;
StringBuffer buffer(0, 512); StringBuffer buffer(nullptr, 512);
Writer<StringBuffer> writer(buffer); Writer<StringBuffer> writer(buffer);
doc.Accept(writer); doc.Accept(writer);
const size_t size = buffer.GetSize(); const size_t size = buffer.GetSize();
if (size > (sizeof(m_sendBuf) - 2)) { if (size > (sizeof(m_sendBuf) - 2)) {
LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", m_pool.url(), size, (sizeof(m_sendBuf) - 2)); LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2));
close(); close();
return -1; return -1;
} }
@@ -508,9 +539,9 @@ int64_t Client::send(const rapidjson::Document &doc)
} }
int64_t Client::send(size_t size) int64_t xmrig::Client::send(size_t size)
{ {
LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); LOG_DEBUG("[%s] send (%d bytes): \"%s\"", url(), size, m_sendBuf);
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (isTLS()) { if (isTLS()) {
@@ -522,7 +553,7 @@ int64_t Client::send(size_t size)
# endif # endif
{ {
if (state() != ConnectedState || !uv_is_writable(m_stream)) { if (state() != ConnectedState || !uv_is_writable(m_stream)) {
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state); LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
return -1; return -1;
} }
@@ -534,30 +565,12 @@ int64_t Client::send(size_t size)
} }
} }
m_expire = uv_now(uv_default_loop()) + kResponseTimeout; m_expire = Chrono::steadyMSecs() + kResponseTimeout;
return m_sequence++; return m_sequence++;
} }
void Client::connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6) void xmrig::Client::connect(sockaddr *addr)
{
addrinfo *addr = nullptr;
m_ipv6 = ipv4.empty() && !ipv6.empty();
if (m_ipv6) {
addr = ipv6[ipv6.size() == 1 ? 0 : rand() % ipv6.size()];
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(addr->ai_addr), m_ip, 45);
}
else {
addr = ipv4[ipv4.size() == 1 ? 0 : rand() % ipv4.size()];
uv_ip4_name(reinterpret_cast<sockaddr_in*>(addr->ai_addr), m_ip, 16);
}
connect(addr->ai_addr);
}
void Client::connect(sockaddr *addr)
{ {
setState(ConnectingState); setState(ConnectingState);
@@ -577,14 +590,16 @@ void Client::connect(sockaddr *addr)
# endif # endif
uv_tcp_connect(req, m_socket, reinterpret_cast<const sockaddr*>(addr), Client::onConnect); uv_tcp_connect(req, m_socket, reinterpret_cast<const sockaddr*>(addr), Client::onConnect);
delete addr;
} }
void Client::handshake() void xmrig::Client::handshake()
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (isTLS()) { if (isTLS()) {
m_expire = uv_now(uv_default_loop()) + kResponseTimeout; m_expire = Chrono::steadyMSecs() + kResponseTimeout;
m_tls->handshake(); m_tls->handshake();
} }
@@ -596,7 +611,7 @@ void Client::handshake()
} }
void Client::login() void xmrig::Client::login()
{ {
using namespace rapidjson; using namespace rapidjson;
m_results.clear(); m_results.clear();
@@ -609,12 +624,12 @@ void Client::login()
doc.AddMember("method", "login", allocator); doc.AddMember("method", "login", allocator);
Value params(kObjectType); Value params(kObjectType);
params.AddMember("login", StringRef(m_pool.user()), allocator); params.AddMember("login", m_pool.user().toJSON(), allocator);
params.AddMember("pass", StringRef(m_pool.password()), allocator); params.AddMember("pass", m_pool.password().toJSON(), allocator);
params.AddMember("agent", StringRef(m_agent), allocator); params.AddMember("agent", StringRef(m_agent), allocator);
if (m_pool.rigId()) { if (!m_pool.rigId().isNull()) {
params.AddMember("rigid", StringRef(m_pool.rigId()), allocator); params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
} }
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
@@ -630,13 +645,15 @@ void Client::login()
params.AddMember("algo", algo, allocator); params.AddMember("algo", algo, allocator);
} }
m_listener->onLogin(this, doc, params);
doc.AddMember("params", params, allocator); doc.AddMember("params", params, allocator);
send(doc); send(doc);
} }
void Client::onClose() void xmrig::Client::onClose()
{ {
delete m_socket; delete m_socket;
@@ -655,17 +672,15 @@ void Client::onClose()
} }
void Client::parse(char *line, size_t len) void xmrig::Client::parse(char *line, size_t len)
{ {
startTimeout(); startTimeout();
line[len - 1] = '\0'; LOG_DEBUG("[%s] received (%d bytes): \"%s\"", url(), len, line);
LOG_DEBUG("[%s] received (%d bytes): \"%s\"", m_pool.url(), len, line);
if (len < 32 || line[0] != '{') { if (len < 32 || line[0] != '{') {
if (!isQuiet()) { if (!isQuiet()) {
LOG_ERR("[%s] JSON decode failed", m_pool.url()); LOG_ERR("[%s] JSON decode failed", url());
} }
return; return;
@@ -674,7 +689,7 @@ void Client::parse(char *line, size_t len)
rapidjson::Document doc; rapidjson::Document doc;
if (doc.ParseInsitu(line).HasParseError()) { if (doc.ParseInsitu(line).HasParseError()) {
if (!isQuiet()) { if (!isQuiet()) {
LOG_ERR("[%s] JSON decode failed: \"%s\"", m_pool.url(), rapidjson::GetParseError_En(doc.GetParseError())); LOG_ERR("[%s] JSON decode failed: \"%s\"", url(), rapidjson::GetParseError_En(doc.GetParseError()));
} }
return; return;
@@ -694,38 +709,52 @@ void Client::parse(char *line, size_t len)
} }
void Client::parseExtensions(const rapidjson::Value &value) void xmrig::Client::parseExtensions(const rapidjson::Value &result)
{ {
m_extensions = 0; m_extensions.reset();
if (!value.IsArray()) { if (!result.HasMember("extensions")) {
return; return;
} }
for (const rapidjson::Value &ext : value.GetArray()) { const rapidjson::Value &extensions = result["extensions"];
if (!extensions.IsArray()) {
return;
}
for (const rapidjson::Value &ext : extensions.GetArray()) {
if (!ext.IsString()) { if (!ext.IsString()) {
continue; continue;
} }
if (strcmp(ext.GetString(), "algo") == 0) { const char *name = ext.GetString();
m_extensions |= AlgoExt;
continue;
}
if (strcmp(ext.GetString(), "nicehash") == 0) { if (strcmp(name, "algo") == 0) {
m_extensions |= NicehashExt; setExtension(EXT_ALGO, true);
m_nicehash = true;
continue;
} }
else if (strcmp(name, "nicehash") == 0) {
setExtension(EXT_NICEHASH, true);
}
else if (strcmp(name, "connect") == 0) {
setExtension(EXT_CONNECT, true);
}
else if (strcmp(name, "keepalive") == 0) {
setExtension(EXT_KEEPALIVE, true);
}
# ifdef XMRIG_FEATURE_TLS
else if (strcmp(name, "tls") == 0) {
setExtension(EXT_TLS, true);
}
# endif
} }
} }
void Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error) void xmrig::Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{ {
if (error.IsObject()) { if (error.IsObject()) {
if (!isQuiet()) { if (!isQuiet()) {
LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), error["message"].GetString(), error["code"].GetInt()); LOG_ERR("[%s] error: \"%s\", code: %d", url(), error["message"].GetString(), error["code"].GetInt());
} }
return; return;
} }
@@ -737,17 +766,17 @@ void Client::parseNotification(const char *method, const rapidjson::Value &param
if (strcmp(method, "job") == 0) { if (strcmp(method, "job") == 0) {
int code = -1; int code = -1;
if (parseJob(params, &code)) { if (parseJob(params, &code)) {
m_listener->onJobReceived(this, m_job); m_listener->onJobReceived(this, m_job, params);
} }
return; return;
} }
LOG_WARN("[%s] unsupported method: \"%s\"", m_pool.url(), method); LOG_WARN("[%s] unsupported method: \"%s\"", url(), method);
} }
void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error) void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{ {
if (error.IsObject()) { if (error.IsObject()) {
const char *message = error["message"].GetString(); const char *message = error["message"].GetString();
@@ -759,7 +788,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
m_results.erase(it); m_results.erase(it);
} }
else if (!isQuiet()) { else if (!isQuiet()) {
LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), message, error["code"].GetInt()); LOG_ERR("[%s] error: \"%s\", code: %d", url(), message, error["code"].GetInt());
} }
if (isCriticalError(message)) { if (isCriticalError(message)) {
@@ -777,7 +806,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
int code = -1; int code = -1;
if (!parseLogin(result, &code)) { if (!parseLogin(result, &code)) {
if (!isQuiet()) { if (!isQuiet()) {
LOG_ERR("[%s] login error code: %d", m_pool.url(), code); LOG_ERR("[%s] login error code: %d", url(), code);
} }
close(); close();
@@ -786,7 +815,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
m_failures = 0; m_failures = 0;
m_listener->onLoginSuccess(this); m_listener->onLoginSuccess(this);
m_listener->onJobReceived(this, m_job); m_listener->onJobReceived(this, m_job, result["job"]);
return; return;
} }
@@ -799,42 +828,52 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
} }
void Client::ping() void xmrig::Client::ping()
{ {
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
} }
void Client::read() void xmrig::Client::read(ssize_t nread)
{ {
char* end; const size_t size = static_cast<size_t>(nread);
char* start = m_recvBuf.base;
size_t remaining = m_recvBufPos;
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) { if (nread > 0 && size > m_recvBuf.available()) {
end++; nread = UV_ENOBUFS;
size_t len = end - start;
parse(start, len);
remaining -= len;
start = end;
} }
if (remaining == 0) { if (nread < 0) {
m_recvBufPos = 0; if (!isQuiet()) {
LOG_ERR("[%s] read error: \"%s\"", url(), uv_strerror(static_cast<int>(nread)));
}
close();
return; return;
} }
if (start == m_recvBuf.base) { assert(m_listener != nullptr);
return; if (!m_listener) {
return reconnect();
} }
memcpy(m_recvBuf.base, start, remaining); m_recvBuf.nread(size);
m_recvBufPos = remaining;
# ifndef XMRIG_NO_TLS
if (isTLS()) {
LOG_DEBUG("[%s] TLS received (%d bytes)", url(), static_cast<int>(nread));
m_tls->read(m_recvBuf.base(), m_recvBuf.pos());
m_recvBuf.reset();
}
else
# endif
{
m_recvBuf.getline(this);
}
} }
void Client::reconnect() void xmrig::Client::reconnect()
{ {
if (!m_listener) { if (!m_listener) {
m_storage.remove(m_key); m_storage.remove(m_key);
@@ -851,15 +890,15 @@ void Client::reconnect()
setState(ConnectingState); setState(ConnectingState);
m_failures++; m_failures++;
m_listener->onClose(this, (int) m_failures); m_listener->onClose(this, static_cast<int>(m_failures));
m_expire = uv_now(uv_default_loop()) + m_retryPause; m_expire = Chrono::steadyMSecs() + m_retryPause;
} }
void Client::setState(SocketState state) void xmrig::Client::setState(SocketState state)
{ {
LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]); LOG_DEBUG("[%s] state: \"%s\"", url(), states[state]);
if (m_state == state) { if (m_state == state) {
return; return;
@@ -869,29 +908,36 @@ void Client::setState(SocketState state)
} }
void Client::startTimeout() void xmrig::Client::startTimeout()
{ {
m_expire = 0; m_expire = 0;
if (m_pool.keepAlive()) { if (has<EXT_KEEPALIVE>()) {
m_keepAlive = uv_now(uv_default_loop()) + (m_pool.keepAlive() * 1000); const uint64_t ms = static_cast<uint64_t>(m_pool.keepAlive() > 0 ? m_pool.keepAlive() : Pool::kKeepAliveTimeout) * 1000;
m_keepAlive = Chrono::steadyMSecs() + ms;
} }
} }
void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) void xmrig::Client::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
{ {
auto client = getClient(handle->data); auto client = getClient(handle->data);
if (!client) { if (!client) {
return; return;
} }
buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; buf->base = client->m_recvBuf.current();
buf->len = client->m_recvBuf.len - client->m_recvBufPos;
# ifdef _WIN32
buf->len = static_cast<ULONG>(client->m_recvBuf.available());
# else
buf->len = client->m_recvBuf.available();
# endif
} }
void Client::onClose(uv_handle_t *handle) void xmrig::Client::onClose(uv_handle_t *handle)
{ {
auto client = getClient(handle->data); auto client = getClient(handle->data);
if (!client) { if (!client) {
@@ -902,7 +948,7 @@ void Client::onClose(uv_handle_t *handle)
} }
void Client::onConnect(uv_connect_t *req, int status) void xmrig::Client::onConnect(uv_connect_t *req, int status)
{ {
auto client = getClient(req->data); auto client = getClient(req->data);
if (!client) { if (!client) {
@@ -912,7 +958,7 @@ void Client::onConnect(uv_connect_t *req, int status)
if (status < 0) { if (status < 0) {
if (!client->isQuiet()) { if (!client->isQuiet()) {
LOG_ERR("[%s] connect error: \"%s\"", client->m_pool.url(), uv_strerror(status)); LOG_ERR("[%s] connect error: \"%s\"", client->url(), uv_strerror(status));
} }
delete req; delete req;
@@ -931,94 +977,10 @@ void Client::onConnect(uv_connect_t *req, int status)
} }
void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *)
{ {
auto client = getClient(stream->data); auto client = getClient(stream->data);
if (!client) { if (client) {
return; client->read(nread);
}
if (nread < 0) {
if (!client->isQuiet()) {
LOG_ERR("[%s] read error: \"%s\"", client->m_pool.url(), uv_strerror((int) nread));
}
client->close();
return;
}
if ((size_t) nread > (sizeof(m_buf) - 8 - client->m_recvBufPos)) {
client->close();
return;
}
assert(client->m_listener != nullptr);
if (!client->m_listener) {
return client->reconnect();
}
client->m_recvBufPos += nread;
# ifndef XMRIG_NO_TLS
if (client->isTLS()) {
LOG_DEBUG("[%s] TLS received (%d bytes)", client->m_pool.url(), static_cast<int>(nread));
client->m_tls->read(client->m_recvBuf.base, client->m_recvBufPos);
client->m_recvBufPos = 0;
}
else
# endif
{
client->read();
} }
} }
void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
{
auto client = getClient(req->data);
if (!client) {
return;
}
assert(client->m_listener != nullptr);
if (!client->m_listener) {
return client->reconnect();
}
if (status < 0) {
if (!client->isQuiet()) {
LOG_ERR("[%s] DNS error: \"%s\"", client->m_pool.url(), uv_strerror(status));
}
return client->reconnect();
}
addrinfo *ptr = res;
std::vector<addrinfo*> ipv4;
std::vector<addrinfo*> ipv6;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
ipv4.push_back(ptr);
}
if (ptr->ai_family == AF_INET6) {
ipv6.push_back(ptr);
}
ptr = ptr->ai_next;
}
if (ipv4.empty() && ipv6.empty()) {
if (!client->isQuiet()) {
LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_pool.url());
}
uv_freeaddrinfo(res);
return client->reconnect();
}
client->connect(ipv4, ipv6);
uv_freeaddrinfo(res);
}

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -25,28 +26,34 @@
#define XMRIG_CLIENT_H #define XMRIG_CLIENT_H
#include <bitset>
#include <map> #include <map>
#include <uv.h> #include <uv.h>
#include <vector> #include <vector>
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/kernel/interfaces/ILineListener.h"
#include "base/net/stratum/Job.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/net/tools/RecvBuf.h"
#include "base/net/tools/Storage.h"
#include "common/crypto/Algorithm.h" #include "common/crypto/Algorithm.h"
#include "common/net/Id.h"
#include "common/net/Job.h"
#include "common/net/Pool.h"
#include "common/net/Storage.h" typedef struct bio_st BIO;
#include "common/net/SubmitResult.h"
#include "rapidjson/fwd.h"
namespace xmrig {
class IClientListener; class IClientListener;
class JobResult; class JobResult;
typedef struct bio_st BIO; class Client : public IDnsListener, public ILineListener
class Client
{ {
public: public:
enum SocketState { enum SocketState {
@@ -57,6 +64,15 @@ public:
ClosingState ClosingState
}; };
enum Extension {
EXT_ALGO,
EXT_NICEHASH,
EXT_CONNECT,
EXT_TLS,
EXT_KEEPALIVE,
EXT_MAX
};
constexpr static int kResponseTimeout = 20 * 1000; constexpr static int kResponseTimeout = 20 * 1000;
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
@@ -66,9 +82,10 @@ public:
# endif # endif
Client(int id, const char *agent, IClientListener *listener); Client(int id, const char *agent, IClientListener *listener);
~Client(); ~Client() override;
bool disconnect(); bool disconnect();
bool isTLS() const;
const char *tlsFingerprint() const; const char *tlsFingerprint() const;
const char *tlsVersion() const; const char *tlsVersion() const;
int64_t submit(const JobResult &result); int64_t submit(const JobResult &result);
@@ -78,95 +95,102 @@ public:
void setPool(const Pool &pool); void setPool(const Pool &pool);
void tick(uint64_t now); void tick(uint64_t now);
inline bool isEnabled() const { return m_enabled; }
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
inline const char *host() const { return m_pool.host(); } inline const char *host() const { return m_pool.host(); }
inline const char *ip() const { return m_ip; } inline const char *ip() const { return m_ip; }
inline const Job &job() const { return m_job; } inline const Job &job() const { return m_job; }
inline const Pool &pool() const { return m_pool; }
inline int id() const { return m_id; } inline int id() const { return m_id; }
inline SocketState state() const { return m_state; } inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_pool.port(); } inline uint16_t port() const { return m_pool.port(); }
inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } inline void setAlgo(const Algorithm &algo) { m_pool.setAlgo(algo); }
inline void setEnabled(bool enabled) { m_enabled = enabled; }
inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setQuiet(bool quiet) { m_quiet = quiet; }
inline void setRetries(int retries) { m_retries = retries; } inline void setRetries(int retries) { m_retries = retries; }
inline void setRetryPause(int ms) { m_retryPause = ms; } inline void setRetryPause(int ms) { m_retryPause = ms; }
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
protected:
inline void onLine(char *line, size_t size) override { parse(line, size); }
void onResolved(const Dns &dns, int status) override;
private: private:
class Tls; class Tls;
enum Extensions {
NicehashExt = 1,
AlgoExt = 2
};
bool close(); bool close();
bool isCriticalError(const char *message); bool isCriticalError(const char *message);
bool isTLS() const;
bool parseJob(const rapidjson::Value &params, int *code); bool parseJob(const rapidjson::Value &params, int *code);
bool parseLogin(const rapidjson::Value &result, int *code); bool parseLogin(const rapidjson::Value &result, int *code);
bool send(BIO *bio); bool send(BIO *bio);
bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const; bool verifyAlgorithm(const Algorithm &algorithm) const;
int resolve(const char *host); int resolve(const String &host);
int64_t send(const rapidjson::Document &doc); int64_t send(const rapidjson::Document &doc);
int64_t send(size_t size); int64_t send(size_t size);
void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
void connect(sockaddr *addr); void connect(sockaddr *addr);
void handshake(); void handshake();
void login(); void login();
void onClose(); void onClose();
void parse(char *line, size_t len); void parse(char *line, size_t len);
void parseExtensions(const rapidjson::Value &value); void parseExtensions(const rapidjson::Value &result);
void parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error); void parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error);
void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error);
void ping(); void ping();
void read(); void read(ssize_t nread);
void reconnect(); void reconnect();
void setState(SocketState state); void setState(SocketState state);
void startTimeout(); void startTimeout();
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; } inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
inline const char *url() const { return m_pool.url(); }
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
static void onClose(uv_handle_t *handle); static void onClose(uv_handle_t *handle);
static void onConnect(uv_connect_t *req, int status); static void onConnect(uv_connect_t *req, int status);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
static void onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res);
static inline Client *getClient(void *data) { return m_storage.get(data); } static inline Client *getClient(void *data) { return m_storage.get(data); }
addrinfo m_hints; bool m_enabled;
bool m_ipv6; bool m_ipv6;
bool m_nicehash;
bool m_quiet; bool m_quiet;
char m_buf[kInputBufferSize];
char m_ip[46];
char m_sendBuf[2048]; char m_sendBuf[2048];
const char *m_agent; const char *m_agent;
Dns *m_dns;
IClientListener *m_listener; IClientListener *m_listener;
int m_extensions;
int m_id; int m_id;
int m_retries; int m_retries;
int m_retryPause; int m_retryPause;
int64_t m_failures; int64_t m_failures;
Job m_job; Job m_job;
Pool m_pool; Pool m_pool;
size_t m_recvBufPos; RecvBuf<kInputBufferSize> m_recvBuf;
SocketState m_state; SocketState m_state;
std::bitset<EXT_MAX> m_extensions;
std::map<int64_t, SubmitResult> m_results; std::map<int64_t, SubmitResult> m_results;
String m_ip;
String m_rpcId;
Tls *m_tls; Tls *m_tls;
uint64_t m_expire; uint64_t m_expire;
uint64_t m_jobs; uint64_t m_jobs;
uint64_t m_keepAlive; uint64_t m_keepAlive;
uintptr_t m_key; uintptr_t m_key;
uv_buf_t m_recvBuf;
uv_getaddrinfo_t m_resolver;
uv_stream_t *m_stream; uv_stream_t *m_stream;
uv_tcp_t *m_socket; uv_tcp_t *m_socket;
xmrig::Id m_rpcId;
static int64_t m_sequence; static int64_t m_sequence;
static xmrig::Storage<Client> m_storage; static Storage<Client> m_storage;
}; };
template<> inline bool Client::has<Client::EXT_NICEHASH>() const noexcept { return m_extensions.test(EXT_NICEHASH) || m_pool.isNicehash(); }
template<> inline bool Client::has<Client::EXT_KEEPALIVE>() const noexcept { return m_extensions.test(EXT_KEEPALIVE) || m_pool.keepAlive() > 0; }
} /* namespace xmrig */
#endif /* XMRIG_CLIENT_H */ #endif /* XMRIG_CLIENT_H */

View File

@@ -28,76 +28,52 @@
#include <string.h> #include <string.h>
#include "common/net/Job.h" #include "base/net/stratum/Job.h"
#include "base/tools/Buffer.h"
static inline unsigned char hf_hex2bin(char c, bool &err) xmrig::Job::Job() :
{
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'f') {
return c - 'a' + 0xA;
}
else if (c >= 'A' && c <= 'F') {
return c - 'A' + 0xA;
}
err = true;
return 0;
}
static inline char hf_bin2hex(unsigned char c)
{
if (c <= 0x9) {
return '0' + c;
}
return 'a' - 0xA + c;
}
Job::Job() :
m_autoVariant(false), m_autoVariant(false),
m_nicehash(false), m_nicehash(false),
m_poolId(-2), m_poolId(-2),
m_threadId(-1), m_threadId(-1),
m_size(0), m_size(0),
m_diff(0), m_diff(0),
m_height(0),
m_target(0), m_target(0),
m_blob() m_blob()
{ {
} }
Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) : xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId) :
m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO), m_algorithm(algorithm),
m_autoVariant(algorithm.variant() == VARIANT_AUTO),
m_nicehash(nicehash), m_nicehash(nicehash),
m_poolId(poolId), m_poolId(poolId),
m_threadId(-1), m_threadId(-1),
m_size(0), m_size(0),
m_clientId(clientId),
m_diff(0), m_diff(0),
m_height(0),
m_target(0), m_target(0),
m_blob(), m_blob()
m_algorithm(algorithm),
m_clientId(clientId)
{ {
} }
Job::~Job() xmrig::Job::~Job()
{ {
} }
bool Job::isEqual(const Job &other) const bool xmrig::Job::isEqual(const Job &other) const
{ {
return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
} }
bool Job::setBlob(const char *blob) bool xmrig::Job::setBlob(const char *blob)
{ {
if (!blob) { if (!blob) {
return false; return false;
@@ -113,7 +89,7 @@ bool Job::setBlob(const char *blob)
return false; return false;
} }
if (!fromHex(blob, (int) m_size * 2, m_blob)) { if (!Buffer::fromHex(blob, m_size * 2, m_blob)) {
return false; return false;
} }
@@ -126,11 +102,20 @@ bool Job::setBlob(const char *blob)
} }
if (!m_algorithm.isForced()) { if (!m_algorithm.isForced()) {
if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] >= 9) { if (m_algorithm.variant() == VARIANT_XTL && m_blob[0] >= 9) {
m_algorithm.setVariant(xmrig::VARIANT_HALF); m_algorithm.setVariant(VARIANT_HALF);
} }
else if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] >= 8) { else if (m_algorithm.variant() == VARIANT_MSR && m_blob[0] >= 8) {
m_algorithm.setVariant(xmrig::VARIANT_HALF); m_algorithm.setVariant(VARIANT_HALF);
}
else if (m_algorithm.variant() == VARIANT_WOW && m_blob[0] < 11) {
m_algorithm.setVariant(VARIANT_2);
}
else if (m_algorithm.variant() == VARIANT_RWZ && m_blob[0] < 12) {
m_algorithm.setVariant(VARIANT_2);
}
else if (m_algorithm.variant() == VARIANT_ZLS && m_blob[0] < 8) {
m_algorithm.setVariant(VARIANT_2);
} }
} }
@@ -143,7 +128,7 @@ bool Job::setBlob(const char *blob)
} }
bool Job::setTarget(const char *target) bool xmrig::Job::setTarget(const char *target)
{ {
if (!target) { if (!target) {
return false; return false;
@@ -156,7 +141,7 @@ bool Job::setTarget(const char *target)
char str[8]; char str[8];
memcpy(str, target, len); memcpy(str, target, len);
if (!fromHex(str, 8, reinterpret_cast<unsigned char*>(&tmp)) || tmp == 0) { if (!Buffer::fromHex(str, 8, reinterpret_cast<uint8_t *>(&tmp)) || tmp == 0) {
return false; return false;
} }
@@ -167,7 +152,7 @@ bool Job::setTarget(const char *target)
char str[16]; char str[16];
memcpy(str, target, len); memcpy(str, target, len);
if (!fromHex(str, 16, reinterpret_cast<unsigned char*>(&m_target)) || m_target == 0) { if (!Buffer::fromHex(str, 16, reinterpret_cast<uint8_t *>(&m_target)) || m_target == 0) {
return false; return false;
} }
} }
@@ -185,7 +170,7 @@ bool Job::setTarget(const char *target)
} }
void Job::setAlgorithm(const char *algo) void xmrig::Job::setAlgorithm(const char *algo)
{ {
m_algorithm.parseAlgorithm(algo); m_algorithm.parseAlgorithm(algo);
@@ -195,47 +180,17 @@ void Job::setAlgorithm(const char *algo)
} }
bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) void xmrig::Job::setHeight(uint64_t height)
{ {
bool error = false; m_height = height;
for (unsigned int i = 0; i < len; i += 2) {
out[i / 2] = (hf_hex2bin(in[i], error) << 4) | hf_hex2bin(in[i + 1], error);
if (error) {
return false;
}
}
return true;
} }
void Job::toHex(const unsigned char* in, unsigned int len, char* out) xmrig::Variant xmrig::Job::variant() const
{ {
for (unsigned int i = 0; i < len; i++) {
out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4);
out[i * 2 + 1] = hf_bin2hex(in[i] & 0x0F);
}
}
#ifdef APP_DEBUG
char *Job::toHex(const unsigned char* in, unsigned int len)
{
char *out = new char[len * 2 + 1]();
toHex(in, len, out);
return out;
}
#endif
xmrig::Variant Job::variant() const
{
using namespace xmrig;
switch (m_algorithm.algo()) { switch (m_algorithm.algo()) {
case CRYPTONIGHT: case CRYPTONIGHT:
return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; return (m_blob[0] >= 10) ? VARIANT_4 : ((m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1);
case CRYPTONIGHT_LITE: case CRYPTONIGHT_LITE:
return VARIANT_1; return VARIANT_1;

View File

@@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -31,38 +31,48 @@
#include <stdint.h> #include <stdint.h>
#include "base/tools/String.h"
#include "common/crypto/Algorithm.h" #include "common/crypto/Algorithm.h"
#include "common/net/Id.h"
namespace xmrig {
class Job class Job
{ {
public: public:
// Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
// SECOR increase requirements for blob size: https://github.com/xmrig/xmrig/issues/913
static constexpr const size_t kMaxBlobSize = 128;
Job(); Job();
Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId);
~Job(); ~Job();
bool isEqual(const Job &other) const; bool isEqual(const Job &other) const;
bool setBlob(const char *blob); bool setBlob(const char *blob);
bool setTarget(const char *target); bool setTarget(const char *target);
void setAlgorithm(const char *algo); void setAlgorithm(const char *algo);
void setHeight(uint64_t height);
inline bool isNicehash() const { return m_nicehash; } inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool isValid() const { return m_size > 0 && m_diff > 0; }
inline bool setId(const char *id) { return m_id.setId(id); } inline bool setId(const char *id) { return m_id = id; }
inline const Algorithm &algorithm() const { return m_algorithm; }
inline const String &clientId() const { return m_clientId; }
inline const String &id() const { return m_id; }
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); } inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
inline const uint8_t *blob() const { return m_blob; } inline const uint8_t *blob() const { return m_blob; }
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
inline const xmrig::Id &clientId() const { return m_clientId; }
inline const xmrig::Id &id() const { return m_id; }
inline int poolId() const { return m_poolId; } inline int poolId() const { return m_poolId; }
inline int threadId() const { return m_threadId; } inline int threadId() const { return m_threadId; }
inline size_t size() const { return m_size; } inline size_t size() const { return m_size; }
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); } inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
inline uint32_t diff() const { return static_cast<uint32_t>(m_diff); } inline uint32_t diff() const { return static_cast<uint32_t>(m_diff); }
inline uint64_t height() const { return m_height; }
inline uint64_t target() const { return m_target; } inline uint64_t target() const { return m_target; }
inline uint8_t fixedByte() const { return *(m_blob + 42); }
inline void reset() { m_size = 0; m_diff = 0; } inline void reset() { m_size = 0; m_diff = 0; }
inline void setClientId(const xmrig::Id &id) { m_clientId = id; } inline void setClientId(const String &id) { m_clientId = id; }
inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setThreadId(int threadId) { m_threadId = threadId; }
inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); }
@@ -70,40 +80,40 @@ public:
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; } inline char *rawBlob() { return m_rawBlob; }
inline const char *rawBlob() const { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; } inline const char *rawTarget() const { return m_rawTarget; }
# endif # endif
static bool fromHex(const char* in, unsigned int len, unsigned char* out);
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); } static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; } static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
static void toHex(const unsigned char* in, unsigned int len, char* out);
# ifdef APP_DEBUG
static char *toHex(const unsigned char* in, unsigned int len);
# endif
inline bool operator==(const Job &other) const { return isEqual(other); } inline bool operator==(const Job &other) const { return isEqual(other); }
inline bool operator!=(const Job &other) const { return !isEqual(other); } inline bool operator!=(const Job &other) const { return !isEqual(other); }
private: private:
xmrig::Variant variant() const; Variant variant() const;
Algorithm m_algorithm;
bool m_autoVariant; bool m_autoVariant;
bool m_nicehash; bool m_nicehash;
int m_poolId; int m_poolId;
int m_threadId; int m_threadId;
size_t m_size; size_t m_size;
String m_clientId;
String m_id;
uint64_t m_diff; uint64_t m_diff;
uint64_t m_height;
uint64_t m_target; uint64_t m_target;
uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. uint8_t m_blob[kMaxBlobSize];
xmrig::Algorithm m_algorithm;
xmrig::Id m_clientId;
xmrig::Id m_id;
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
char m_rawBlob[176]; char m_rawBlob[kMaxBlobSize * 2 + 8];
char m_rawTarget[24]; char m_rawTarget[24];
# endif # endif
}; };
} /* namespace xmrig */
#endif /* XMRIG_JOB_H */ #endif /* XMRIG_JOB_H */

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -29,7 +29,8 @@
#include <stdio.h> #include <stdio.h>
#include "common/net/Pool.h" #include "base/io/Json.h"
#include "base/net/stratum/Pool.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
@@ -44,7 +45,27 @@
#endif #endif
Pool::Pool() : namespace xmrig {
static const char *kEnabled = "enabled";
static const char *kFingerprint = "tls-fingerprint";
static const char *kKeepalive = "keepalive";
static const char *kNicehash = "nicehash";
static const char *kPass = "pass";
static const char *kRigId = "rig-id";
static const char *kTls = "tls";
static const char *kUrl = "url";
static const char *kUser = "user";
static const char *kVariant = "variant";
const String Pool::kDefaultPassword = "x";
const String Pool::kDefaultUser = "x";
}
xmrig::Pool::Pool() :
m_enabled(true),
m_nicehash(false), m_nicehash(false),
m_tls(false), m_tls(false),
m_keepAlive(0), m_keepAlive(0),
@@ -64,7 +85,8 @@ Pool::Pool() :
* *
* @param url * @param url
*/ */
Pool::Pool(const char *url) : xmrig::Pool::Pool(const char *url) :
m_enabled(true),
m_nicehash(false), m_nicehash(false),
m_tls(false), m_tls(false),
m_keepAlive(0), m_keepAlive(0),
@@ -74,14 +96,53 @@ Pool::Pool(const char *url) :
} }
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : xmrig::Pool::Pool(const rapidjson::Value &object) :
m_enabled(true),
m_nicehash(false),
m_tls(false),
m_keepAlive(0),
m_port(kDefaultPort)
{
if (!parse(Json::getString(object, kUrl))) {
return;
}
setUser(Json::getString(object, kUser));
setPassword(Json::getString(object, kPass));
setRigId(Json::getString(object, kRigId));
setNicehash(Json::getBool(object, kNicehash));
const rapidjson::Value &keepalive = object[kKeepalive];
if (keepalive.IsInt()) {
setKeepAlive(keepalive.GetInt());
}
else if (keepalive.IsBool()) {
setKeepAlive(keepalive.GetBool());
}
const rapidjson::Value &variant = object[kVariant];
if (variant.IsString()) {
algorithm().parseVariant(variant.GetString());
}
else if (variant.IsInt()) {
algorithm().parseVariant(variant.GetInt());
}
m_enabled = Json::getBool(object, kEnabled, true);
m_tls = Json::getBool(object, kTls);
m_fingerprint = Json::getString(object, kFingerprint);
}
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) :
m_enabled(true),
m_nicehash(nicehash), m_nicehash(nicehash),
m_tls(tls), m_tls(tls),
m_keepAlive(keepAlive), m_keepAlive(keepAlive),
m_port(port),
m_host(host), m_host(host),
m_password(password), m_password(password),
m_user(user) m_user(user),
m_port(port)
{ {
const size_t size = m_host.size() + 8; const size_t size = m_host.size() + 8;
assert(size > 8); assert(size > 8);
@@ -93,7 +154,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
} }
bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const
{ {
if (m_algorithms.empty()) { if (m_algorithms.empty()) {
return true; return true;
@@ -106,8 +167,8 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
} }
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT && m_algorithm.variant() == xmrig::VARIANT_XTL) { if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT) {
return true; return m_algorithm.variant() == xmrig::VARIANT_RWZ || m_algorithm.variant() == xmrig::VARIANT_ZLS;
} }
# endif # endif
@@ -115,9 +176,22 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
} }
bool Pool::isEqual(const Pool &other) const bool xmrig::Pool::isEnabled() const
{
# ifdef XMRIG_NO_TLS
if (isTLS()) {
return false;
}
# endif
return m_enabled && isValid() && algorithm().isValid();
}
bool xmrig::Pool::isEqual(const Pool &other) const
{ {
return (m_nicehash == other.m_nicehash return (m_nicehash == other.m_nicehash
&& m_enabled == other.m_enabled
&& m_tls == other.m_tls && m_tls == other.m_tls
&& m_keepAlive == other.m_keepAlive && m_keepAlive == other.m_keepAlive
&& m_port == other.m_port && m_port == other.m_port
@@ -131,7 +205,7 @@ bool Pool::isEqual(const Pool &other) const
} }
bool Pool::parse(const char *url) bool xmrig::Pool::parse(const char *url)
{ {
assert(url != nullptr); assert(url != nullptr);
@@ -167,7 +241,7 @@ bool Pool::parse(const char *url)
return true; return true;
} }
const size_t size = port++ - base + 1; const size_t size = static_cast<size_t>(port++ - base + 1);
char *host = new char[size](); char *host = new char[size]();
memcpy(host, base, size - 1); memcpy(host, base, size - 1);
@@ -178,7 +252,7 @@ bool Pool::parse(const char *url)
} }
bool Pool::setUserpass(const char *userpass) bool xmrig::Pool::setUserpass(const char *userpass)
{ {
const char *p = strchr(userpass, ':'); const char *p = strchr(userpass, ':');
if (!p) { if (!p) {
@@ -186,7 +260,7 @@ bool Pool::setUserpass(const char *userpass)
} }
char *user = new char[p - userpass + 1](); char *user = new char[p - userpass + 1]();
strncpy(user, userpass, p - userpass); strncpy(user, userpass, static_cast<size_t>(p - userpass));
m_user = user; m_user = user;
m_password = p + 1; m_password = p + 1;
@@ -195,7 +269,7 @@ bool Pool::setUserpass(const char *userpass)
} }
rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
{ {
using namespace rapidjson; using namespace rapidjson;
@@ -203,43 +277,47 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
Value obj(kObjectType); Value obj(kObjectType);
obj.AddMember("url", StringRef(url()), allocator); obj.AddMember(StringRef(kUrl), m_url.toJSON(), allocator);
obj.AddMember("user", StringRef(user()), allocator); obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator);
obj.AddMember("pass", StringRef(password()), allocator); obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator);
obj.AddMember("rig-id", rigId() ? Value(StringRef(rigId())).Move() : Value(kNullType).Move(), allocator); obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator);
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
obj.AddMember("nicehash", isNicehash(), allocator); obj.AddMember(StringRef(kNicehash), isNicehash(), allocator);
# endif # endif
if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) { if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) {
obj.AddMember("keepalive", m_keepAlive > 0, allocator); obj.AddMember(StringRef(kKeepalive), m_keepAlive > 0, allocator);
} }
else { else {
obj.AddMember("keepalive", m_keepAlive, allocator); obj.AddMember(StringRef(kKeepalive), m_keepAlive, allocator);
} }
switch (m_algorithm.variant()) { switch (m_algorithm.variant()) {
case xmrig::VARIANT_AUTO: case VARIANT_AUTO:
case xmrig::VARIANT_0: case VARIANT_0:
case xmrig::VARIANT_1: case VARIANT_1:
case xmrig::VARIANT_2: obj.AddMember(StringRef(kVariant), m_algorithm.variant(), allocator);
obj.AddMember("variant", m_algorithm.variant(), allocator); break;
case VARIANT_2:
obj.AddMember(StringRef(kVariant), 2, allocator);
break; break;
default: default:
obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator); obj.AddMember(StringRef(kVariant), StringRef(m_algorithm.variantName()), allocator);
break; break;
} }
obj.AddMember("tls", isTLS(), allocator); obj.AddMember(StringRef(kEnabled), m_enabled, allocator);
obj.AddMember("tls-fingerprint", fingerprint() ? Value(StringRef(fingerprint())).Move() : Value(kNullType).Move(), allocator); obj.AddMember(StringRef(kTls), isTLS(), allocator);
obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator);
return obj; return obj;
} }
void Pool::adjust(const xmrig::Algorithm &algorithm) void xmrig::Pool::adjust(const Algorithm &algorithm)
{ {
if (!isValid()) { if (!isValid()) {
return; return;
@@ -254,7 +332,7 @@ void Pool::adjust(const xmrig::Algorithm &algorithm)
} }
void Pool::setAlgo(const xmrig::Algorithm &algorithm) void xmrig::Pool::setAlgo(const xmrig::Algorithm &algorithm)
{ {
m_algorithm = algorithm; m_algorithm = algorithm;
@@ -263,7 +341,7 @@ void Pool::setAlgo(const xmrig::Algorithm &algorithm)
#ifdef APP_DEBUG #ifdef APP_DEBUG
void Pool::print() const void xmrig::Pool::print() const
{ {
LOG_NOTICE("url: %s", m_url.data()); LOG_NOTICE("url: %s", m_url.data());
LOG_DEBUG ("host: %s", m_host.data()); LOG_DEBUG ("host: %s", m_host.data());
@@ -278,7 +356,7 @@ void Pool::print() const
#endif #endif
bool Pool::parseIPv6(const char *addr) bool xmrig::Pool::parseIPv6(const char *addr)
{ {
const char *end = strchr(addr, ']'); const char *end = strchr(addr, ']');
if (!end) { if (!end) {
@@ -290,7 +368,7 @@ bool Pool::parseIPv6(const char *addr)
return false; return false;
} }
const size_t size = end - addr; const size_t size = static_cast<size_t>(end - addr);
char *host = new char[size](); char *host = new char[size]();
memcpy(host, addr + 1, size - 1); memcpy(host, addr + 1, size - 1);
@@ -301,7 +379,7 @@ bool Pool::parseIPv6(const char *addr)
} }
void Pool::addVariant(xmrig::Variant variant) void xmrig::Pool::addVariant(xmrig::Variant variant)
{ {
const xmrig::Algorithm algorithm(m_algorithm.algo(), variant); const xmrig::Algorithm algorithm(m_algorithm.algo(), variant);
if (!algorithm.isValid() || m_algorithm == algorithm) { if (!algorithm.isValid() || m_algorithm == algorithm) {
@@ -312,7 +390,7 @@ void Pool::addVariant(xmrig::Variant variant)
} }
void Pool::adjustVariant(const xmrig::Variant variantHint) void xmrig::Pool::adjustVariant(const xmrig::Variant variantHint)
{ {
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
using namespace xmrig; using namespace xmrig;
@@ -398,7 +476,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint)
} }
void Pool::rebuild() void xmrig::Pool::rebuild()
{ {
m_algorithms.clear(); m_algorithms.clear();
@@ -409,16 +487,22 @@ void Pool::rebuild()
m_algorithms.push_back(m_algorithm); m_algorithms.push_back(m_algorithm);
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
addVariant(xmrig::VARIANT_2); addVariant(VARIANT_4);
addVariant(xmrig::VARIANT_1); addVariant(VARIANT_WOW);
addVariant(xmrig::VARIANT_0); addVariant(VARIANT_2);
addVariant(xmrig::VARIANT_HALF); addVariant(VARIANT_1);
addVariant(xmrig::VARIANT_XTL); addVariant(VARIANT_0);
addVariant(xmrig::VARIANT_TUBE); addVariant(VARIANT_HALF);
addVariant(xmrig::VARIANT_MSR); addVariant(VARIANT_XTL);
addVariant(xmrig::VARIANT_XHV); addVariant(VARIANT_TUBE);
addVariant(xmrig::VARIANT_XAO); addVariant(VARIANT_MSR);
addVariant(xmrig::VARIANT_RTO); addVariant(VARIANT_XHV);
addVariant(xmrig::VARIANT_AUTO); addVariant(VARIANT_XAO);
addVariant(VARIANT_RTO);
addVariant(VARIANT_GPU);
addVariant(VARIANT_RWZ);
addVariant(VARIANT_ZLS);
addVariant(VARIANT_DOUBLE);
addVariant(VARIANT_AUTO);
# endif # endif
} }

View File

@@ -5,7 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -29,21 +29,26 @@
#include <vector> #include <vector>
#include "base/tools/String.h"
#include "common/crypto/Algorithm.h" #include "common/crypto/Algorithm.h"
#include "common/utils/c_str.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
namespace xmrig {
class Pool class Pool
{ {
public: public:
constexpr static const char *kDefaultPassword = "x"; static const String kDefaultPassword;
constexpr static const char *kDefaultUser = "x"; static const String kDefaultUser;
constexpr static uint16_t kDefaultPort = 3333; constexpr static uint16_t kDefaultPort = 3333;
constexpr static int kKeepAliveTimeout = 60; constexpr static int kKeepAliveTimeout = 60;
Pool(); Pool();
Pool(const char *url); Pool(const char *url);
Pool(const rapidjson::Value &object);
Pool(const char *host, Pool(const char *host,
uint16_t port, uint16_t port,
const char *user = nullptr, const char *user = nullptr,
@@ -53,38 +58,40 @@ public:
bool tls = false bool tls = false
); );
inline Algorithm &algorithm() { return m_algorithm; }
inline bool isNicehash() const { return m_nicehash; } inline bool isNicehash() const { return m_nicehash; }
inline bool isTLS() const { return m_tls; } inline bool isTLS() const { return m_tls; }
inline bool isValid() const { return !m_host.isNull() && m_port > 0; } inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
inline const char *fingerprint() const { return m_fingerprint.data(); } inline const Algorithm &algorithm() const { return m_algorithm; }
inline const char *host() const { return m_host.data(); } inline const Algorithms &algorithms() const { return m_algorithms; }
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } inline const String &fingerprint() const { return m_fingerprint; }
inline const char *rigId() const { return m_rigId.data(); } inline const String &host() const { return m_host; }
inline const char *url() const { return m_url.data(); } inline const String &password() const { return !m_password.isNull() ? m_password : kDefaultPassword; }
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } inline const String &rigId() const { return m_rigId; }
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } inline const String &url() const { return m_url; }
inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } inline const String &user() const { return !m_user.isNull() ? m_user : kDefaultUser; }
inline int keepAlive() const { return m_keepAlive; } inline int keepAlive() const { return m_keepAlive; }
inline uint16_t port() const { return m_port; } inline uint16_t port() const { return m_port; }
inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; }
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); }
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
inline void setPassword(const char *password) { m_password = password; } inline void setPassword(const char *password) { m_password = password; }
inline void setRigId(const char *rigId) { m_rigId = rigId; } inline void setRigId(const char *rigId) { m_rigId = rigId; }
inline void setTLS(bool tls) { m_tls = tls; } inline void setTLS(bool tls) { m_tls = tls; }
inline void setUser(const char *user) { m_user = user; } inline void setUser(const char *user) { m_user = user; }
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator!=(const Pool &other) const { return !isEqual(other); }
inline bool operator==(const Pool &other) const { return isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); }
bool isCompatible(const xmrig::Algorithm &algorithm) const; bool isCompatible(const Algorithm &algorithm) const;
bool isEnabled() const;
bool isEqual(const Pool &other) const; bool isEqual(const Pool &other) const;
bool parse(const char *url); bool parse(const char *url);
bool setUserpass(const char *userpass); bool setUserpass(const char *userpass);
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
void adjust(const xmrig::Algorithm &algorithm); void adjust(const Algorithm &algorithm);
void setAlgo(const xmrig::Algorithm &algorithm); void setAlgo(const Algorithm &algorithm);
# ifdef APP_DEBUG # ifdef APP_DEBUG
void print() const; void print() const;
@@ -92,25 +99,27 @@ public:
private: private:
bool parseIPv6(const char *addr); bool parseIPv6(const char *addr);
void addVariant(xmrig::Variant variant); void addVariant(Variant variant);
void adjustVariant(const xmrig::Variant variantHint); void adjustVariant(const Variant variantHint);
void rebuild(); void rebuild();
Algorithm m_algorithm;
Algorithms m_algorithms;
bool m_enabled;
bool m_nicehash; bool m_nicehash;
bool m_tls; bool m_tls;
int m_keepAlive; int m_keepAlive;
String m_fingerprint;
String m_host;
String m_password;
String m_rigId;
String m_url;
String m_user;
uint16_t m_port; uint16_t m_port;
xmrig::Algorithm m_algorithm;
xmrig::Algorithms m_algorithms;
xmrig::c_str m_fingerprint;
xmrig::c_str m_host;
xmrig::c_str m_password;
xmrig::c_str m_rigId;
xmrig::c_str m_url;
xmrig::c_str m_user;
}; };
typedef std::vector<Pool> Pools; } /* namespace xmrig */
#endif /* XMRIG_POOL_H */ #endif /* XMRIG_POOL_H */

View File

@@ -0,0 +1,229 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/Pools.h"
#include "base/net/stratum/strategies/FailoverStrategy.h"
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
#include "common/log/Log.h"
#include "donate.h"
#include "rapidjson/document.h"
xmrig::Pools::Pools() :
m_donateLevel(kDefaultDonateLevel),
m_retries(5),
m_retryPause(5),
m_proxyDonate(PROXY_DONATE_AUTO)
{
# ifdef XMRIG_PROXY_PROJECT
m_retries = 2;
m_retryPause = 1;
# endif
}
xmrig::Pool &xmrig::Pools::current()
{
if (m_data.empty()) {
m_data.push_back(Pool());
}
return m_data.back();
}
bool xmrig::Pools::isEqual(const Pools &other) const
{
if (m_data.size() != other.m_data.size() || m_retries != other.m_retries || m_retryPause != other.m_retryPause) {
return false;
}
return std::equal(m_data.begin(), m_data.end(), other.m_data.begin());
}
bool xmrig::Pools::setUrl(const char *url)
{
if (m_data.empty() || m_data.back().isValid()) {
Pool pool(url);
if (pool.isValid()) {
m_data.push_back(std::move(pool));
return true;
}
return false;
}
current().parse(url);
return m_data.back().isValid();
}
xmrig::IStrategy *xmrig::Pools::createStrategy(IStrategyListener *listener) const
{
if (active() == 1) {
for (const Pool &pool : m_data) {
if (pool.isEnabled()) {
return new SinglePoolStrategy(pool, retryPause(), retries(), listener);
}
}
}
FailoverStrategy *strategy = new FailoverStrategy(retryPause(), retries(), listener);
for (const Pool &pool : m_data) {
if (pool.isEnabled()) {
strategy->add(pool);
}
}
return strategy;
}
rapidjson::Value xmrig::Pools::toJSON(rapidjson::Document &doc) const
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
Value pools(kArrayType);
for (const Pool &pool : m_data) {
pools.PushBack(pool.toJSON(doc), allocator);
}
return pools;
}
size_t xmrig::Pools::active() const
{
size_t count = 0;
for (const Pool &pool : m_data) {
if (pool.isEnabled()) {
count++;
}
}
return count;
}
void xmrig::Pools::adjust(const Algorithm &algorithm)
{
for (Pool &pool : m_data) {
pool.adjust(algorithm);
}
}
void xmrig::Pools::load(const rapidjson::Value &pools)
{
m_data.clear();
for (const rapidjson::Value &value : pools.GetArray()) {
if (!value.IsObject()) {
continue;
}
Pool pool(value);
if (pool.isValid()) {
m_data.push_back(std::move(pool));
}
}
}
void xmrig::Pools::print() const
{
size_t i = 1;
for (const Pool &pool : m_data) {
if (Log::colors) {
const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31;
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"),
i,
color,
pool.url().data(),
pool.algorithm().variantName()
);
}
else {
Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s",
i,
pool.isEnabled() ? "" : "-",
pool.url().data(),
pool.algorithm().variantName(),
pool.isTLS() ? "TLS" : ""
);
}
i++;
}
# ifdef APP_DEBUG
LOG_NOTICE("POOLS --------------------------------------------------------------------");
for (const Pool &pool : m_data) {
pool.print();
}
LOG_NOTICE("--------------------------------------------------------------------------");
# endif
}
void xmrig::Pools::setDonateLevel(int level)
{
if (level >= kMinimumDonateLevel && level <= 99) {
m_donateLevel = level;
}
}
void xmrig::Pools::setProxyDonate(int value)
{
switch (value) {
case PROXY_DONATE_NONE:
case PROXY_DONATE_AUTO:
case PROXY_DONATE_ALWAYS:
m_proxyDonate = static_cast<ProxyDonate>(value);
}
}
void xmrig::Pools::setRetries(int retries)
{
if (retries > 0 && retries <= 1000) {
m_retries = retries;
}
}
void xmrig::Pools::setRetryPause(int retryPause)
{
if (retryPause > 0 && retryPause <= 3600) {
m_retryPause = retryPause;
}
}

View File

@@ -0,0 +1,100 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_POOLS_H
#define XMRIG_POOLS_H
#include <vector>
#include "base/net/stratum/Pool.h"
namespace xmrig {
class IStrategy;
class IStrategyListener;
class Pools
{
public:
enum ProxyDonate {
PROXY_DONATE_NONE,
PROXY_DONATE_AUTO,
PROXY_DONATE_ALWAYS
};
Pools();
inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); }
inline const std::vector<Pool> &data() const { return m_data; }
inline int donateLevel() const { return m_donateLevel; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
inline void setKeepAlive(bool enable) { current().setKeepAlive(enable); }
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
inline void setNicehash(bool enable) { current().setNicehash(enable); }
inline void setPassword(const char *password) { current().setPassword(password); }
inline void setRigId(const char *rigId) { current().setRigId(rigId); }
inline void setTLS(bool enable) { current().setTLS(enable); }
inline void setUser(const char *user) { current().setUser(user); }
inline void setVariant(const char *variant) { current().algorithm().parseVariant(variant); }
inline void setVariant(int variant) { current().algorithm().parseVariant(variant); }
inline bool operator!=(const Pools &other) const { return !isEqual(other); }
inline bool operator==(const Pools &other) const { return isEqual(other); }
bool isEqual(const Pools &other) const;
bool setUrl(const char *url);
IStrategy *createStrategy(IStrategyListener *listener) const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t active() const;
void adjust(const Algorithm &algorithm);
void load(const rapidjson::Value &pools);
void print() const;
void setDonateLevel(int level);
void setProxyDonate(int value);
void setRetries(int retries);
void setRetryPause(int retryPause);
private:
Pool &current();
int m_donateLevel;
int m_retries;
int m_retryPause;
ProxyDonate m_proxyDonate;
std::vector<Pool> m_data;
};
} /* namespace xmrig */
#endif /* XMRIG_POOLS_H */

View File

@@ -0,0 +1,72 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_SUBMITRESULT_H
#define XMRIG_SUBMITRESULT_H
#include "base/tools/Chrono.h"
namespace xmrig {
class SubmitResult
{
public:
inline SubmitResult() :
reqId(0),
seq(0),
diff(0),
actualDiff(0),
elapsed(0),
m_start(0)
{}
inline SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId = 0) :
reqId(reqId),
seq(seq),
diff(diff),
actualDiff(actualDiff),
elapsed(0),
m_start(Chrono::steadyMSecs())
{}
inline void done() { elapsed = Chrono::steadyMSecs() - m_start; }
int64_t reqId;
int64_t seq;
uint32_t diff;
uint64_t actualDiff;
uint64_t elapsed;
private:
uint64_t m_start;
};
} /* namespace xmrig */
#endif /* XMRIG_SUBMITRESULT_H */

View File

@@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -27,8 +27,9 @@
#include <assert.h> #include <assert.h>
#include "common/net/Client.h" #include "base/net/stratum/Client.h"
#include "common/net/Tls.h" #include "base/net/stratum/Tls.h"
#include "base/tools/Buffer.h"
#include "common/log/Log.h" #include "common/log/Log.h"
@@ -37,7 +38,7 @@
#endif #endif
Client::Tls::Tls(Client *client) : xmrig::Client::Tls::Tls(Client *client) :
m_ready(false), m_ready(false),
m_buf(), m_buf(),
m_fingerprint(), m_fingerprint(),
@@ -57,7 +58,7 @@ Client::Tls::Tls(Client *client) :
} }
Client::Tls::~Tls() xmrig::Client::Tls::~Tls()
{ {
if (m_ctx) { if (m_ctx) {
SSL_CTX_free(m_ctx); SSL_CTX_free(m_ctx);
@@ -69,7 +70,7 @@ Client::Tls::~Tls()
} }
bool Client::Tls::handshake() bool xmrig::Client::Tls::handshake()
{ {
m_ssl = SSL_new(m_ctx); m_ssl = SSL_new(m_ctx);
assert(m_ssl != nullptr); assert(m_ssl != nullptr);
@@ -86,7 +87,7 @@ bool Client::Tls::handshake()
} }
bool Client::Tls::send(const char *data, size_t size) bool xmrig::Client::Tls::send(const char *data, size_t size)
{ {
SSL_write(m_ssl, data, size); SSL_write(m_ssl, data, size);
@@ -94,19 +95,19 @@ bool Client::Tls::send(const char *data, size_t size)
} }
const char *Client::Tls::fingerprint() const const char *xmrig::Client::Tls::fingerprint() const
{ {
return m_ready ? m_fingerprint : nullptr; return m_ready ? m_fingerprint : nullptr;
} }
const char *Client::Tls::version() const const char *xmrig::Client::Tls::version() const
{ {
return m_ready ? SSL_get_version(m_ssl) : nullptr; return m_ready ? SSL_get_version(m_ssl) : nullptr;
} }
void Client::Tls::read(const char *data, size_t size) void xmrig::Client::Tls::read(const char *data, size_t size)
{ {
BIO_write(m_readBio, data, size); BIO_write(m_readBio, data, size);
@@ -134,27 +135,28 @@ void Client::Tls::read(const char *data, size_t size)
int bytes_read = 0; int bytes_read = 0;
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) { while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
m_client->parse(m_buf, bytes_read); m_buf[bytes_read - 1] = '\0';
m_client->parse(m_buf, static_cast<size_t>(bytes_read));
} }
} }
bool Client::Tls::send() bool xmrig::Client::Tls::send()
{ {
return m_client->send(m_writeBio); return m_client->send(m_writeBio);
} }
bool Client::Tls::verify(X509 *cert) bool xmrig::Client::Tls::verify(X509 *cert)
{ {
if (cert == nullptr) { if (cert == nullptr) {
LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); LOG_ERR("[%s] Failed to get server certificate", m_client->url());
return false; return false;
} }
if (!verifyFingerprint(cert)) { if (!verifyFingerprint(cert)) {
LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->m_pool.url()); LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->url());
const char *fingerprint = m_client->m_pool.fingerprint(); const char *fingerprint = m_client->m_pool.fingerprint();
if (strlen(m_fingerprint) == 64 && fingerprint != nullptr) { if (strlen(m_fingerprint) == 64 && fingerprint != nullptr) {
@@ -169,7 +171,7 @@ bool Client::Tls::verify(X509 *cert)
} }
bool Client::Tls::verifyFingerprint(X509 *cert) bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
{ {
const EVP_MD *digest = EVP_get_digestbyname("sha256"); const EVP_MD *digest = EVP_get_digestbyname("sha256");
if (digest == nullptr) { if (digest == nullptr) {
@@ -183,7 +185,7 @@ bool Client::Tls::verifyFingerprint(X509 *cert)
return false; return false;
} }
Job::toHex(md, 32, m_fingerprint); Buffer::toHex(md, 32, m_fingerprint);
const char *fingerprint = m_client->m_pool.fingerprint(); const char *fingerprint = m_client->m_pool.fingerprint();
return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0; return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0;

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -28,7 +29,10 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include "common/net/Client.h" #include "base/net/stratum/Client.h"
namespace xmrig {
class Client::Tls class Client::Tls
@@ -59,4 +63,7 @@ private:
}; };
} /* namespace xmrig */
#endif /* XMRIG_CLIENT_TLS_H */ #endif /* XMRIG_CLIENT_TLS_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -22,27 +23,38 @@
*/ */
#include "common/interfaces/IStrategyListener.h" #include "base/kernel/interfaces/IStrategyListener.h"
#include "common/net/Client.h" #include "base/net/stratum/Client.h"
#include "common/net/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/FailoverStrategy.h"
#include "common/Platform.h" #include "common/Platform.h"
FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : xmrig::FailoverStrategy::FailoverStrategy(const std::vector<Pool> &pools, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_quiet(quiet), m_quiet(quiet),
m_retries(retries), m_retries(retries),
m_retryPause(retryPause), m_retryPause(retryPause),
m_active(-1), m_active(-1),
m_index(0), m_listener(listener),
m_listener(listener) m_index(0)
{ {
for (const Pool &url : urls) { for (const Pool &pool : pools) {
add(url); add(pool);
} }
} }
FailoverStrategy::~FailoverStrategy() xmrig::FailoverStrategy::FailoverStrategy(int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_quiet(quiet),
m_retries(retries),
m_retryPause(retryPause),
m_active(-1),
m_listener(listener),
m_index(0)
{
}
xmrig::FailoverStrategy::~FailoverStrategy()
{ {
for (Client *client : m_pools) { for (Client *client : m_pools) {
client->deleteLater(); client->deleteLater();
@@ -50,33 +62,53 @@ FailoverStrategy::~FailoverStrategy()
} }
int64_t FailoverStrategy::submit(const JobResult &result) void xmrig::FailoverStrategy::add(const Pool &pool)
{
Client *client = new Client(static_cast<int>(m_pools.size()), Platform::userAgent(), this);
client->setPool(pool);
client->setRetries(m_retries);
client->setRetryPause(m_retryPause * 1000);
client->setQuiet(m_quiet);
m_pools.push_back(client);
}
int64_t xmrig::FailoverStrategy::submit(const JobResult &result)
{ {
if (m_active == -1) { if (m_active == -1) {
return -1; return -1;
} }
return m_pools[m_active]->submit(result); return active()->submit(result);
} }
void FailoverStrategy::connect() void xmrig::FailoverStrategy::connect()
{ {
m_pools[m_index]->connect(); m_pools[m_index]->connect();
} }
void FailoverStrategy::resume() void xmrig::FailoverStrategy::resume()
{ {
if (!isActive()) { if (!isActive()) {
return; return;
} }
m_listener->onJob(this, m_pools[m_active], m_pools[m_active]->job()); m_listener->onJob(this, active(), active()->job());
} }
void FailoverStrategy::stop() void xmrig::FailoverStrategy::setAlgo(const xmrig::Algorithm &algo)
{
for (Client *client : m_pools) {
client->setAlgo(algo);
}
}
void xmrig::FailoverStrategy::stop()
{ {
for (size_t i = 0; i < m_pools.size(); ++i) { for (size_t i = 0; i < m_pools.size(); ++i) {
m_pools[i]->disconnect(); m_pools[i]->disconnect();
@@ -89,7 +121,7 @@ void FailoverStrategy::stop()
} }
void FailoverStrategy::tick(uint64_t now) void xmrig::FailoverStrategy::tick(uint64_t now)
{ {
for (Client *client : m_pools) { for (Client *client : m_pools) {
client->tick(now); client->tick(now);
@@ -97,7 +129,7 @@ void FailoverStrategy::tick(uint64_t now)
} }
void FailoverStrategy::onClose(Client *client, int failures) void xmrig::FailoverStrategy::onClose(Client *client, int failures)
{ {
if (failures == -1) { if (failures == -1) {
return; return;
@@ -112,13 +144,13 @@ void FailoverStrategy::onClose(Client *client, int failures)
return; return;
} }
if (m_index == client->id() && (m_pools.size() - m_index) > 1) { if (m_index == static_cast<size_t>(client->id()) && (m_pools.size() - m_index) > 1) {
m_pools[++m_index]->connect(); m_pools[++m_index]->connect();
} }
} }
void FailoverStrategy::onJobReceived(Client *client, const Job &job) void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
{ {
if (m_active == client->id()) { if (m_active == client->id()) {
m_listener->onJob(this, client, job); m_listener->onJob(this, client, job);
@@ -126,7 +158,7 @@ void FailoverStrategy::onJobReceived(Client *client, const Job &job)
} }
void FailoverStrategy::onLoginSuccess(Client *client) void xmrig::FailoverStrategy::onLoginSuccess(Client *client)
{ {
int active = m_active; int active = m_active;
@@ -147,19 +179,7 @@ void FailoverStrategy::onLoginSuccess(Client *client)
} }
void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void xmrig::FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
{ {
m_listener->onResultAccepted(this, client, result, error); m_listener->onResultAccepted(this, client, result, error);
} }
void FailoverStrategy::add(const Pool &pool)
{
Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
client->setPool(pool);
client->setRetries(m_retries);
client->setRetryPause(m_retryPause * 1000);
client->setQuiet(m_quiet);
m_pools.push_back(client);
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,54 +22,64 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __FAILOVERSTRATEGY_H__ #ifndef XMRIG_FAILOVERSTRATEGY_H
#define __FAILOVERSTRATEGY_H__ #define XMRIG_FAILOVERSTRATEGY_H
#include <vector> #include <vector>
#include "common/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
#include "common/interfaces/IStrategy.h" #include "base/kernel/interfaces/IStrategy.h"
#include "common/net/Pool.h" #include "base/net/stratum/Pool.h"
namespace xmrig {
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Url;
class FailoverStrategy : public IStrategy, public IClientListener class FailoverStrategy : public IStrategy, public IClientListener
{ {
public: public:
FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); FailoverStrategy(const std::vector<Pool> &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~FailoverStrategy(); FailoverStrategy(int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~FailoverStrategy() override;
public: void add(const Pool &pool);
inline bool isActive() const override { return m_active >= 0; }
protected:
inline bool isActive() const override { return m_active >= 0; }
inline Client *client() const override { return active(); }
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
protected:
void onClose(Client *client, int failures) override; void onClose(Client *client, int failures) override;
void onJobReceived(Client *client, const Job &job) override; void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) override;
void onLoginSuccess(Client *client) override; void onLoginSuccess(Client *client) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
private: private:
void add(const Pool &pool); inline Client *active() const { return m_pools[static_cast<size_t>(m_active)]; }
const bool m_quiet; const bool m_quiet;
const int m_retries; const int m_retries;
const int m_retryPause; const int m_retryPause;
int m_active; int m_active;
int m_index;
IStrategyListener *m_listener; IStrategyListener *m_listener;
size_t m_index;
std::vector<Client*> m_pools; std::vector<Client*> m_pools;
}; };
#endif /* __FAILOVERSTRATEGY_H__ */
} /* namespace xmrig */
#endif /* XMRIG_FAILOVERSTRATEGY_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -22,13 +23,13 @@
*/ */
#include "common/interfaces/IStrategyListener.h" #include "base/kernel/interfaces/IStrategyListener.h"
#include "common/net/Client.h" #include "base/net/stratum/Client.h"
#include "common/net/strategies/SinglePoolStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h"
#include "common/Platform.h" #include "common/Platform.h"
SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : xmrig::SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_active(false), m_active(false),
m_listener(listener) m_listener(listener)
{ {
@@ -40,25 +41,25 @@ SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int ret
} }
SinglePoolStrategy::~SinglePoolStrategy() xmrig::SinglePoolStrategy::~SinglePoolStrategy()
{ {
m_client->deleteLater(); m_client->deleteLater();
} }
int64_t SinglePoolStrategy::submit(const JobResult &result) int64_t xmrig::SinglePoolStrategy::submit(const JobResult &result)
{ {
return m_client->submit(result); return m_client->submit(result);
} }
void SinglePoolStrategy::connect() void xmrig::SinglePoolStrategy::connect()
{ {
m_client->connect(); m_client->connect();
} }
void SinglePoolStrategy::resume() void xmrig::SinglePoolStrategy::resume()
{ {
if (!isActive()) { if (!isActive()) {
return; return;
@@ -68,19 +69,25 @@ void SinglePoolStrategy::resume()
} }
void SinglePoolStrategy::stop() void xmrig::SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo)
{
m_client->setAlgo(algo);
}
void xmrig::SinglePoolStrategy::stop()
{ {
m_client->disconnect(); m_client->disconnect();
} }
void SinglePoolStrategy::tick(uint64_t now) void xmrig::SinglePoolStrategy::tick(uint64_t now)
{ {
m_client->tick(now); m_client->tick(now);
} }
void SinglePoolStrategy::onClose(Client *client, int failures) void xmrig::SinglePoolStrategy::onClose(Client *, int)
{ {
if (!isActive()) { if (!isActive()) {
return; return;
@@ -91,20 +98,20 @@ void SinglePoolStrategy::onClose(Client *client, int failures)
} }
void SinglePoolStrategy::onJobReceived(Client *client, const Job &job) void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
{ {
m_listener->onJob(this, client, job); m_listener->onJob(this, client, job);
} }
void SinglePoolStrategy::onLoginSuccess(Client *client) void xmrig::SinglePoolStrategy::onLoginSuccess(Client *client)
{ {
m_active = true; m_active = true;
m_listener->onActive(this, client); m_listener->onActive(this, client);
} }
void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void xmrig::SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
{ {
m_listener->onResultAccepted(this, client, result, error); m_listener->onResultAccepted(this, client, result, error);
} }

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,37 +22,42 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SINGLEPOOLSTRATEGY_H__ #ifndef XMRIG_SINGLEPOOLSTRATEGY_H
#define __SINGLEPOOLSTRATEGY_H__ #define XMRIG_SINGLEPOOLSTRATEGY_H
#include "common/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
#include "common/interfaces/IStrategy.h" #include "base/kernel/interfaces/IStrategy.h"
namespace xmrig {
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Url; class Pool;
class SinglePoolStrategy : public IStrategy, public IClientListener class SinglePoolStrategy : public IStrategy, public IClientListener
{ {
public: public:
SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~SinglePoolStrategy(); ~SinglePoolStrategy() override;
public: protected:
inline bool isActive() const override { return m_active; } inline bool isActive() const override { return m_active; }
inline Client *client() const override { return m_client; }
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
protected:
void onClose(Client *client, int failures) override; void onClose(Client *client, int failures) override;
void onJobReceived(Client *client, const Job &job) override; void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) override;
void onLoginSuccess(Client *client) override; void onLoginSuccess(Client *client) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
@@ -61,4 +67,8 @@ private:
IStrategyListener *m_listener; IStrategyListener *m_listener;
}; };
#endif /* __SINGLEPOOLSTRATEGY_H__ */
} /* namespace xmrig */
#endif /* XMRIG_SINGLEPOOLSTRATEGY_H */

View File

@@ -0,0 +1,99 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_RECVBUF_H
#define XMRIG_RECVBUF_H
#include <string.h>
#include "base/kernel/interfaces/ILineListener.h"
namespace xmrig {
template<size_t N>
class RecvBuf
{
public:
inline RecvBuf() :
m_buf(),
m_pos(0)
{
}
inline char *base() { return m_buf; }
inline char *current() { return m_buf + m_pos; }
inline const char *base() const { return m_buf; }
inline const char *current() const { return m_buf + m_pos; }
inline size_t available() const { return N - m_pos; }
inline size_t pos() const { return m_pos; }
inline void nread(size_t size) { m_pos += size; }
inline void reset() { m_pos = 0; }
constexpr inline size_t size() const { return N; }
inline void getline(ILineListener *listener)
{
char *end;
char *start = m_buf;
size_t remaining = m_pos;
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
*end = '\0';
end++;
const size_t len = static_cast<size_t>(end - start);
listener->onLine(start, len - 1);
remaining -= len;
start = end;
}
if (remaining == 0) {
m_pos = 0;
return;
}
if (start == m_buf) {
return;
}
memcpy(m_buf, start, remaining);
m_pos = remaining;
}
private:
char m_buf[N];
size_t m_pos;
};
} /* namespace xmrig */
#endif /* XMRIG_RECVBUF_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __STORAGE_H__ #ifndef XMRIG_STORAGE_H
#define __STORAGE_H__ #define XMRIG_STORAGE_H
#include <assert.h> #include <assert.h>
@@ -53,11 +54,10 @@ public:
inline static void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); } inline static void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
inline TYPE *get(void *id) const { return get(reinterpret_cast<uintptr_t>(id)); } inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
inline TYPE *get(uintptr_t id) const inline TYPE *get(uintptr_t id) const
{ {
assert(m_data.count(id) > 0); assert(m_data.count(id) > 0);
if (m_data.count(id) == 0) { if (m_data.count(id) == 0) {
return nullptr; return nullptr;
} }
@@ -66,20 +66,22 @@ public:
} }
inline void remove(void *id) { remove(reinterpret_cast<uintptr_t>(id)); } inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); }
inline void remove(uintptr_t id) inline void remove(uintptr_t id) { delete release(id); }
inline TYPE *release(const void *id) { release(reinterpret_cast<uintptr_t>(id)); }
inline TYPE *release(uintptr_t id)
{ {
TYPE *obj = get(id); TYPE *obj = get(id);
if (obj == nullptr) { if (obj != nullptr) {
return; auto it = m_data.find(id);
if (it != m_data.end()) {
m_data.erase(it);
}
} }
auto it = m_data.find(id); return obj;
if (it != m_data.end()) {
m_data.erase(it);
}
delete obj;
} }
@@ -92,4 +94,4 @@ private:
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* __STORAGE_H__ */ #endif /* XMRIG_STORAGE_H */

View File

@@ -0,0 +1,76 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <uv.h>
#include "base/tools/Arguments.h"
xmrig::Arguments::Arguments(int argc, char **argv) :
m_argv(argv),
m_argc(argc)
{
uv_setup_args(argc, argv);
for (size_t i = 0; i < static_cast<size_t>(argc); ++i) {
add(argv[i]);
}
}
bool xmrig::Arguments::hasArg(const char *name) const
{
if (m_argc == 1) {
return false;
}
return std::find(m_data.begin() + 1, m_data.end(), name) != m_data.end();
}
void xmrig::Arguments::add(const char *arg)
{
if (arg == nullptr) {
return;
}
const size_t size = strlen(arg);
if (size > 4 && arg[0] == '-' && arg[1] == '-') {
const char *p = strstr(arg, "=");
if (p) {
const size_t keySize = static_cast<size_t>(p - arg);
m_data.push_back(String(arg, keySize));
m_data.push_back(arg + keySize + 1);
return;
}
}
m_data.push_back(arg);
}

View File

@@ -0,0 +1,61 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ARGUMENTS_H
#define XMRIG_ARGUMENTS_H
#include <vector>
#include "base/tools/String.h"
namespace xmrig {
class Arguments
{
public:
Arguments(int argc, char **argv);
bool hasArg(const char *name) const;
inline char **argv() const { return m_argv; }
inline const std::vector<String> &data() const { return m_data; }
inline int argc() const { return m_argc; }
private:
void add(const char *arg);
char **m_argv;
int m_argc;
std::vector<String> m_data;
};
} /* namespace xmrig */
#endif /* XMRIG_ARGUMENTS_H */

201
src/base/tools/Buffer.cpp Normal file
View File

@@ -0,0 +1,201 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/tools/Buffer.h"
static inline uint8_t hf_hex2bin(uint8_t c, bool &err)
{
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'f') {
return c - 'a' + 0xA;
}
else if (c >= 'A' && c <= 'F') {
return c - 'A' + 0xA;
}
err = true;
return 0;
}
static inline uint8_t hf_bin2hex(uint8_t c)
{
if (c <= 0x9) {
return '0' + c;
}
return 'a' - 0xA + c;
}
xmrig::Buffer::Buffer() :
m_data(nullptr),
m_size(0)
{
}
xmrig::Buffer::Buffer(Buffer &&other) :
m_data(other.m_data),
m_size(other.m_size)
{
other.m_data = nullptr;
other.m_size = 0;
}
xmrig::Buffer::Buffer(const Buffer &other)
{
copy(other.data(), other.size());
}
xmrig::Buffer::Buffer(const char *data, size_t size)
{
copy(data, size);
}
xmrig::Buffer::Buffer(size_t size) :
m_size(size)
{
m_data = new char[size]();
}
xmrig::Buffer::~Buffer()
{
delete [] m_data;
}
void xmrig::Buffer::from(const char *data, size_t size)
{
if (m_size > 0) {
if (m_size == size) {
memcpy(m_data, data, m_size);
return;
}
delete [] m_data;
}
copy(data, size);
}
xmrig::Buffer xmrig::Buffer::allocUnsafe(size_t size)
{
Buffer buf;
buf.m_size = size;
buf.m_data = new char[size];
return buf;
}
bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out)
{
bool error = false;
for (size_t i = 0; i < size; i += 2) {
out[i / 2] = static_cast<uint8_t>((hf_hex2bin(in[i], error) << 4) | hf_hex2bin(in[i + 1], error));
if (error) {
return false;
}
}
return true;
}
xmrig::Buffer xmrig::Buffer::fromHex(const char *data, size_t size)
{
if (data == nullptr || size % 2 != 0) {
return Buffer();
}
Buffer buf(size / 2);
fromHex(data, size, buf.data());
return buf;
}
void xmrig::Buffer::toHex(const uint8_t *in, size_t size, uint8_t *out)
{
for (size_t i = 0; i < size; i++) {
out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4);
out[i * 2 + 1] = hf_bin2hex(in[i] & 0x0F);
}
}
xmrig::String xmrig::Buffer::toHex(const uint8_t *in, size_t size)
{
return Buffer(reinterpret_cast<const char *>(in), size).toHex();
}
xmrig::String xmrig::Buffer::toHex() const
{
if (m_size == 0) {
return String();
}
char *buf = new char[m_size * 2 + 1];
buf[m_size * 2] = '\0';
toHex(m_data, m_size, buf);
return String(buf);
}
void xmrig::Buffer::copy(const char *data, size_t size)
{
m_data = new char[size];
m_size = size;
memcpy(m_data, data, m_size);
}
void xmrig::Buffer::move(Buffer &&other)
{
if (m_size > 0) {
delete [] m_data;
}
m_data = other.m_data;
m_size = other.m_size;
other.m_data = nullptr;
other.m_size = 0;
}

88
src/base/tools/Buffer.h Normal file
View File

@@ -0,0 +1,88 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_BUFFER_H
#define XMRIG_BUFFER_H
#include "base/tools/String.h"
namespace xmrig {
class Buffer
{
public:
Buffer();
Buffer(Buffer &&other);
Buffer(const Buffer &other);
Buffer(const char *data, size_t size);
Buffer(size_t size);
~Buffer();
inline char *data() { return m_data; }
inline const char *data() const { return m_data; }
inline size_t size() const { return m_size; }
inline void from(const Buffer &other) { from(other.data(), other.size()); }
void from(const char *data, size_t size);
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
static Buffer allocUnsafe(size_t size);
static inline Buffer alloc(size_t size) { return Buffer(size); }
inline static bool fromHex(const char *in, size_t size, char *out) { return fromHex(reinterpret_cast<const uint8_t *>(in), size, reinterpret_cast<uint8_t *>(out)); }
inline static bool fromHex(const char *in, size_t size, uint8_t *out) { return fromHex(reinterpret_cast<const uint8_t *>(in), size, out); }
inline static Buffer fromHex(const char *data) { return fromHex(data, strlen(data)); }
inline static Buffer fromHex(const String &str) { return fromHex(str.data(), str.size()); }
inline static void toHex(const char *in, size_t size, char *out) { return toHex(reinterpret_cast<const uint8_t *>(in), size, reinterpret_cast<uint8_t *>(out)); }
inline static void toHex(const uint8_t *in, size_t size, char *out) { return toHex(in, size, reinterpret_cast<uint8_t *>(out)); }
static bool fromHex(const uint8_t *in, size_t size, uint8_t *out);
static Buffer fromHex(const char *data, size_t size);
static String toHex(const uint8_t *in, size_t size);
static void toHex(const uint8_t *in, size_t size, uint8_t *out);
String toHex() const;
private:
void copy(const char *data, size_t size);
void move(Buffer &&other);
char *m_data;
size_t m_size;
};
} /* namespace xmrig */
#endif /* XMRIG_BUFFER_H */

60
src/base/tools/Chrono.h Normal file
View File

@@ -0,0 +1,60 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CHRONO_H
#define XMRIG_CHRONO_H
#include <chrono>
namespace xmrig {
class Chrono
{
public:
static inline uint64_t steadyMSecs()
{
using namespace std::chrono;
if (high_resolution_clock::is_steady) {
return static_cast<uint64_t>(time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count());
}
return static_cast<uint64_t>(time_point_cast<milliseconds>(steady_clock::now()).time_since_epoch().count());
}
static inline uint64_t currentMSecsSinceEpoch()
{
using namespace std::chrono;
return static_cast<uint64_t>(time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count());
}
};
} /* namespace xmrig */
#endif /* XMRIG_CHRONO_H */

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -21,78 +22,82 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef XMRIG_ID_H #ifndef XMRIG_HANDLE_H
#define XMRIG_ID_H #define XMRIG_HANDLE_H
#include <string.h> #include <uv.h>
namespace xmrig { namespace xmrig {
class Id class Handle
{ {
public: public:
inline Id() : template<typename T>
m_data() static inline void close(T handle)
{ {
if (handle) {
deleteLater(handle);
}
} }
inline Id(const char *id, size_t sizeFix = 0) template<typename T>
static inline void deleteLater(T handle)
{ {
setId(id, sizeFix); if (uv_is_closing(reinterpret_cast<uv_handle_t *>(handle))) {
} return;
inline bool operator==(const Id &other) const
{
return memcmp(m_data, other.m_data, sizeof(m_data)) == 0;
}
inline bool operator!=(const Id &other) const
{
return memcmp(m_data, other.m_data, sizeof(m_data)) != 0;
}
Id &operator=(const Id &other)
{
memcpy(m_data, other.m_data, sizeof(m_data));
return *this;
}
inline bool setId(const char *id, size_t sizeFix = 0)
{
memset(m_data, 0, sizeof(m_data));
if (!id) {
return false;
} }
const size_t size = strlen(id); uv_close(reinterpret_cast<uv_handle_t *>(handle), [](uv_handle_t *handle) { delete handle; });
if (size >= sizeof(m_data)) {
return false;
}
memcpy(m_data, id, size - sizeFix);
return true;
} }
inline const char *data() const { return m_data; }
inline bool isValid() const { return *m_data != '\0'; }
private:
char m_data[64];
}; };
template<>
inline void Handle::close(uv_timer_t *handle)
{
if (handle) {
uv_timer_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_signal_t *handle)
{
if (handle) {
uv_signal_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_getaddrinfo_t *handle)
{
if (handle) {
uv_cancel(reinterpret_cast<uv_req_t *>(handle));
delete handle;
}
}
template<>
inline void Handle::close(uv_fs_event_t *handle)
{
if (handle) {
uv_fs_event_stop(handle);
deleteLater(handle);
}
}
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* XMRIG_ID_H */ #endif /* XMRIG_HANDLE_H */

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -178,14 +179,10 @@ void xmrig::String::copy(const char *str)
void xmrig::String::copy(const String &other) void xmrig::String::copy(const String &other)
{ {
if (m_size > 0) { if (m_size > 0 && m_size == other.m_size) {
if (m_size == other.m_size) { memcpy(m_data, other.m_data, m_size + 1);
memcpy(m_data, other.m_data, m_size + 1);
return; return;
}
delete [] m_data;
} }
delete [] m_data; delete [] m_data;

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by

91
src/base/tools/Timer.cpp Normal file
View File

@@ -0,0 +1,91 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Timer::Timer(ITimerListener *listener) :
m_listener(listener),
m_timer(nullptr)
{
init();
}
xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) :
m_listener(listener),
m_timer(nullptr)
{
init();
start(timeout, repeat);
}
xmrig::Timer::~Timer()
{
Handle::close(m_timer);
}
uint64_t xmrig::Timer::repeat() const
{
return uv_timer_get_repeat(m_timer);
}
void xmrig::Timer::setRepeat(uint64_t repeat)
{
uv_timer_set_repeat(m_timer, repeat);
}
void xmrig::Timer::start(uint64_t timeout, uint64_t repeat)
{
uv_timer_start(m_timer, onTimer, timeout, repeat);
}
void xmrig::Timer::stop()
{
uv_timer_stop(m_timer);
}
void xmrig::Timer::init()
{
m_timer = new uv_timer_t;
m_timer->data = this;
uv_timer_init(uv_default_loop(), m_timer);
}
void xmrig::Timer::onTimer(uv_timer_t *handle)
{
const Timer *timer = static_cast<Timer *>(handle->data);
timer->m_listener->onTimer(timer);
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,28 +22,45 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ISTRATEGY_H__ #ifndef XMRIG_TIMER_H
#define __ISTRATEGY_H__ #define XMRIG_TIMER_H
#include <stdint.h> #include <stdint.h>
class JobResult; typedef struct uv_timer_s uv_timer_t;
class IStrategy namespace xmrig {
class ITimerListener;
class Timer
{ {
public: public:
virtual ~IStrategy() {} Timer(ITimerListener *listener);
Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat);
~Timer();
virtual bool isActive() const = 0; uint64_t repeat() const;
virtual int64_t submit(const JobResult &result) = 0; void setRepeat(uint64_t repeat);
virtual void connect() = 0; void start(uint64_t timeout, uint64_t repeat);
virtual void resume() = 0; void stop();
virtual void stop() = 0;
virtual void tick(uint64_t now) = 0; private:
void init();
static void onTimer(uv_timer_t *handle);
ITimerListener *m_listener;
uv_timer_t *m_timer;
}; };
#endif // __ISTRATEGY_H__ } /* namespace xmrig */
#endif /* XMRIG_TIMER_H */

View File

@@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -36,40 +36,9 @@
#include "Platform.h" #include "Platform.h"
char Platform::m_defaultConfigName[520] = { 0 };
xmrig::String Platform::m_userAgent; xmrig::String Platform::m_userAgent;
const char *Platform::defaultConfigName()
{
size_t size = 520;
if (*m_defaultConfigName) {
return m_defaultConfigName;
}
if (uv_exepath(m_defaultConfigName, &size) < 0) {
return nullptr;
}
if (size < 500) {
# ifdef WIN32
char *p = strrchr(m_defaultConfigName, '\\');
# else
char *p = strrchr(m_defaultConfigName, '/');
# endif
if (p) {
strcpy(p + 1, "config.json");
return m_defaultConfigName;
}
}
*m_defaultConfigName = '\0';
return nullptr;
}
void Platform::init(const char *userAgent) void Platform::init(const char *userAgent)
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS

View File

@@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -36,19 +36,17 @@ class Platform
{ {
public: public:
static bool setThreadAffinity(uint64_t cpu_id); static bool setThreadAffinity(uint64_t cpu_id);
static const char *defaultConfigName();
static uint32_t setTimerResolution(uint32_t resolution); static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent); static void init(const char *userAgent);
static void restoreTimerResolution(); static void restoreTimerResolution();
static void setProcessPriority(int priority); static void setProcessPriority(int priority);
static void setThreadPriority(int priority); static void setThreadPriority(int priority);
static inline const char *userAgent() { return m_userAgent.data(); } static inline const char *userAgent() { return m_userAgent; }
private: private:
static char *createUserAgent(); static char *createUserAgent();
static char m_defaultConfigName[520];
static xmrig::String m_userAgent; static xmrig::String m_userAgent;
}; };

View File

@@ -61,6 +61,10 @@ char *Platform::createUserAgent()
# if defined(__x86_64__) # if defined(__x86_64__)
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string()); length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
# elif defined(__aarch64__)
length += snprintf(buf + length, max - length, "aarch64) libuv/%s", uv_version_string());
# elif defined(__arm__)
length += snprintf(buf + length, max - length, "arm) libuv/%s", uv_version_string());
# else # else
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif # endif

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -27,13 +28,15 @@
#include "api/Api.h" #include "api/Api.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
#include "common/api/Httpd.h" #include "common/api/Httpd.h"
#include "common/api/HttpReply.h" #include "common/api/HttpReply.h"
#include "common/api/HttpRequest.h" #include "common/api/HttpRequest.h"
#include "common/log/Log.h" #include "common/log/Log.h"
Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) : xmrig::Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
m_idle(true), m_idle(true),
m_IPv6(IPv6), m_IPv6(IPv6),
m_restricted(restricted), m_restricted(restricted),
@@ -41,14 +44,13 @@ Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
m_port(port), m_port(port),
m_daemon(nullptr) m_daemon(nullptr)
{ {
uv_timer_init(uv_default_loop(), &m_timer); m_timer = new Timer(this);
m_timer.data = this;
} }
Httpd::~Httpd() xmrig::Httpd::~Httpd()
{ {
uv_timer_stop(&m_timer); stop();
if (m_daemon) { if (m_daemon) {
MHD_stop_daemon(m_daemon); MHD_stop_daemon(m_daemon);
@@ -58,7 +60,7 @@ Httpd::~Httpd()
} }
bool Httpd::start() bool xmrig::Httpd::start()
{ {
if (!m_port) { if (!m_port) {
return false; return false;
@@ -82,16 +84,23 @@ bool Httpd::start()
} }
# if MHD_VERSION >= 0x00093900 # if MHD_VERSION >= 0x00093900
uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval); m_timer->start(kIdleInterval, kIdleInterval);
# else # else
uv_timer_start(&m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval); m_timer->start(kActiveInterval, kActiveInterval);
# endif # endif
return true; return true;
} }
int Httpd::process(xmrig::HttpRequest &req) void xmrig::Httpd::stop()
{
delete m_timer;
m_timer = nullptr;
}
int xmrig::Httpd::process(HttpRequest &req)
{ {
xmrig::HttpReply reply; xmrig::HttpReply reply;
if (!req.process(m_accessToken, m_restricted, reply)) { if (!req.process(m_accessToken, m_restricted, reply)) {
@@ -108,27 +117,27 @@ int Httpd::process(xmrig::HttpRequest &req)
} }
void Httpd::run() void xmrig::Httpd::run()
{ {
MHD_run(m_daemon); MHD_run(m_daemon);
# if MHD_VERSION >= 0x00093900 # if MHD_VERSION >= 0x00093900
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS); const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
if (m_idle && info->num_connections) { if (m_idle && info->num_connections) {
uv_timer_set_repeat(&m_timer, kActiveInterval); m_timer->setRepeat(kActiveInterval);
m_idle = false; m_idle = false;
} }
else if (!m_idle && !info->num_connections) { else if (!m_idle && !info->num_connections) {
uv_timer_set_repeat(&m_timer, kIdleInterval); m_timer->setRepeat(kIdleInterval);
m_idle = true; m_idle = true;
} }
# endif # endif
} }
int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls) int xmrig::Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *, const char *uploadData, size_t *uploadSize, void **con_cls)
{ {
xmrig::HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls); HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls);
if (req.method() == xmrig::HttpRequest::Options) { if (req.method() == xmrig::HttpRequest::Options) {
return req.end(MHD_HTTP_OK, nullptr); return req.end(MHD_HTTP_OK, nullptr);
@@ -140,9 +149,3 @@ int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url
return static_cast<Httpd*>(cls)->process(req); return static_cast<Httpd*>(cls)->process(req);
} }
void Httpd::onTimer(uv_timer_t *handle)
{
static_cast<Httpd*>(handle->data)->run();
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,11 +22,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __HTTPD_H__ #ifndef XMRIG_HTTPD_H
#define __HTTPD_H__ #define XMRIG_HTTPD_H
#include <uv.h> #include <stddef.h>
#include "base/kernel/interfaces/ITimerListener.h"
struct MHD_Connection; struct MHD_Connection;
@@ -33,30 +37,33 @@ struct MHD_Daemon;
struct MHD_Response; struct MHD_Response;
class UploadCtx;
namespace xmrig { namespace xmrig {
class HttpRequest;
}
class Httpd class HttpRequest;
class Timer;
class Httpd : public ITimerListener
{ {
public: public:
Httpd(int port, const char *accessToken, bool IPv6, bool restricted); Httpd(int port, const char *accessToken, bool IPv6, bool restricted);
~Httpd(); ~Httpd() override;
bool start(); bool start();
void stop();
protected:
void onTimer(const Timer *) override { run(); }
private: private:
constexpr static const int kIdleInterval = 200; constexpr static const int kIdleInterval = 200;
constexpr static const int kActiveInterval = 25; constexpr static const int kActiveInterval = 25;
int process(xmrig::HttpRequest &req); int process(HttpRequest &req);
void run(); void run();
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls); static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls);
static void onTimer(uv_timer_t *handle);
bool m_idle; bool m_idle;
bool m_IPv6; bool m_IPv6;
@@ -64,7 +71,11 @@ private:
const char *m_accessToken; const char *m_accessToken;
const int m_port; const int m_port;
MHD_Daemon *m_daemon; MHD_Daemon *m_daemon;
uv_timer_t m_timer; Timer *m_timer;
}; };
#endif /* __HTTPD_H__ */
} /* namespace xmrig */
#endif /* XMRIG_HTTPD_H */

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -53,9 +54,9 @@
#endif #endif
#include "base/io/Json.h"
#include "common/config/CommonConfig.h" #include "common/config/CommonConfig.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "donate.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/filewritestream.h" #include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h" #include "rapidjson/prettywriter.h"
@@ -69,29 +70,19 @@ xmrig::CommonConfig::CommonConfig() :
m_apiRestricted(true), m_apiRestricted(true),
m_autoSave(true), m_autoSave(true),
m_background(false), m_background(false),
m_colors(true),
m_dryRun(false), m_dryRun(false),
m_syslog(false), m_syslog(false),
# ifdef XMRIG_PROXY_PROJECT
m_watch(true), m_watch(true),
# else
m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested.
# endif
m_apiPort(0), m_apiPort(0),
m_donateLevel(kDefaultDonateLevel),
m_printTime(60), m_printTime(60),
m_retries(5),
m_retryPause(5),
m_state(NoneState) m_state(NoneState)
{ {
m_pools.push_back(Pool()); }
# ifdef XMRIG_PROXY_PROJECT
m_retries = 2; bool xmrig::CommonConfig::isColors() const
m_retryPause = 1; {
# endif return Log::colors;
} }
@@ -111,32 +102,7 @@ void xmrig::CommonConfig::printAPI()
void xmrig::CommonConfig::printPools() void xmrig::CommonConfig::printPools()
{ {
for (size_t i = 0; i < m_activePools.size(); ++i) { m_pools.print();
if (!isColors()) {
Log::i()->text(" * POOL #%-7zu%s variant=%s, TLS=%d",
i + 1,
m_activePools[i].url(),
m_activePools[i].algorithm().variantName(),
static_cast<int>(m_activePools[i].isTLS())
);
}
else {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"),
i + 1,
m_activePools[i].isTLS() ? 32 : 36,
m_activePools[i].url(),
m_activePools[i].algorithm().variantName()
);
}
}
# ifdef APP_DEBUG
LOG_NOTICE("POOLS --------------------------------------------------------------------");
for (const Pool &pool : m_activePools) {
pool.print();
}
LOG_NOTICE("--------------------------------------------------------------------------");
# endif
} }
@@ -203,31 +169,15 @@ bool xmrig::CommonConfig::save()
return false; return false;
} }
uv_fs_t req;
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;
}
uv_fs_req_cleanup(&req);
rapidjson::Document doc; rapidjson::Document doc;
getJSON(doc); getJSON(doc);
FILE *fp = fdopen(fd, "w"); if (Json::save(m_fileName, doc)) {
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data());
return true;
}
char buf[4096]; return false;
rapidjson::FileWriteStream os(fp, buf, sizeof(buf));
rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os);
doc.Accept(writer);
fflush(fp);
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
uv_fs_req_cleanup(&req);
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data());
return true;
} }
@@ -245,23 +195,9 @@ bool xmrig::CommonConfig::finalize()
return false; return false;
} }
for (Pool &pool : m_pools) { m_pools.adjust(m_algorithm);
pool.adjust(m_algorithm);
if (pool.isValid() && pool.algorithm().isValid()) { if (!m_pools.active()) {
# ifdef XMRIG_NO_TLS
if (pool.isTLS()) {
continue;
}
# endif
m_activePools.push_back(std::move(pool));
}
}
m_pools.clear();
if (m_activePools.empty()) {
m_state = ErrorState; m_state = ErrorState;
return false; return false;
} }
@@ -283,21 +219,21 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
break; break;
case KeepAliveKey: /* --keepalive */ case KeepAliveKey: /* --keepalive */
currentPool().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); m_pools.setKeepAlive(enable);
break; break;
case TlsKey: /* --tls */ case TlsKey: /* --tls */
currentPool().setTLS(enable); m_pools.setTLS(enable);
break; break;
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
case NicehashKey: /* --nicehash */ case NicehashKey: /* --nicehash */
currentPool().setNicehash(enable); m_pools.setNicehash(enable);
break; break;
# endif # endif
case ColorKey: /* --no-color */ case ColorKey: /* --no-color */
m_colors = enable; Log::colors = enable;
break; break;
case WatchKey: /* watch */ case WatchKey: /* watch */
@@ -336,50 +272,29 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
break; break;
case UserpassKey: /* --userpass */ case UserpassKey: /* --userpass */
if (!currentPool().setUserpass(arg)) { return m_pools.setUserpass(arg);
return false;
}
break;
case UrlKey: /* --url */ case UrlKey: /* --url */
fixup(); return m_pools.setUrl(arg);
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);
}
if (!m_pools.back().isValid()) {
return false;
}
break;
case UserKey: /* --user */ case UserKey: /* --user */
currentPool().setUser(arg); m_pools.setUser(arg);
break; break;
case PasswordKey: /* --pass */ case PasswordKey: /* --pass */
currentPool().setPassword(arg); m_pools.setPassword(arg);
break; break;
case RigIdKey: /* --rig-id */ case RigIdKey: /* --rig-id */
currentPool().setRigId(arg); m_pools.setRigId(arg);
break; break;
case FingerprintKey: /* --tls-fingerprint */ case FingerprintKey: /* --tls-fingerprint */
currentPool().setFingerprint(arg); m_pools.setFingerprint(arg);
break; break;
case VariantKey: /* --variant */ case VariantKey: /* --variant */
currentPool().algorithm().parseVariant(arg); m_pools.setVariant(arg);
break; break;
case LogFileKey: /* --log-file */ case LogFileKey: /* --log-file */
@@ -445,6 +360,15 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg)
} }
void xmrig::CommonConfig::parseJSON(const rapidjson::Document &doc)
{
const rapidjson::Value &pools = doc["pools"];
if (pools.IsArray()) {
m_pools.load(pools);
}
}
void xmrig::CommonConfig::setFileName(const char *fileName) void xmrig::CommonConfig::setFileName(const char *fileName)
{ {
m_fileName = fileName; m_fileName = fileName;
@@ -455,29 +379,27 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
{ {
switch (key) { switch (key) {
case RetriesKey: /* --retries */ case RetriesKey: /* --retries */
if (arg > 0 && arg <= 1000) { m_pools.setRetries(arg);
m_retries = arg;
}
break; break;
case RetryPauseKey: /* --retry-pause */ case RetryPauseKey: /* --retry-pause */
if (arg > 0 && arg <= 3600) { m_pools.setRetryPause(arg);
m_retryPause = arg;
}
break; break;
case KeepAliveKey: /* --keepalive */ case KeepAliveKey: /* --keepalive */
currentPool().setKeepAlive(arg); m_pools.setKeepAlive(arg);
break; break;
case VariantKey: /* --variant */ case VariantKey: /* --variant */
currentPool().algorithm().parseVariant(arg); m_pools.setVariant(arg);
break; break;
case DonateLevelKey: /* --donate-level */ case DonateLevelKey: /* --donate-level */
if (arg >= kMinimumDonateLevel && arg <= 99) { m_pools.setDonateLevel(arg);
m_donateLevel = arg; break;
}
case ProxyDonateKey: /* --donate-over-proxy */
m_pools.setProxyDonate(arg);
break; break;
case ApiPort: /* --api-port */ case ApiPort: /* --api-port */
@@ -498,30 +420,3 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
return true; return true;
} }
Pool &xmrig::CommonConfig::currentPool()
{
fixup();
return m_pools.back();
}
void xmrig::CommonConfig::fixup()
{
if (m_state == NoneState) {
return;
}
if (m_pools.empty()) {
if (!m_activePools.empty()) {
std::swap(m_pools, m_activePools);
}
else {
m_pools.push_back(Pool());
}
m_state = NoneState;
}
}

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -25,12 +26,9 @@
#define XMRIG_COMMONCONFIG_H #define XMRIG_COMMONCONFIG_H
#include <vector> #include "base/net/stratum/Pools.h"
#include "base/tools/String.h"
#include "common/interfaces/IConfig.h" #include "common/interfaces/IConfig.h"
#include "common/net/Pool.h"
#include "common/utils/c_str.h"
#include "common/xmrig.h" #include "common/xmrig.h"
@@ -46,7 +44,6 @@ public:
inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isApiRestricted() const { return m_apiRestricted; }
inline bool isAutoSave() const { return m_autoSave; } inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; } inline bool isBackground() const { return m_background; }
inline bool isColors() const { return m_colors; }
inline bool isDryRun() const { return m_dryRun; } inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; } inline bool isSyslog() const { return m_syslog; }
inline const char *apiId() const { return m_apiId.data(); } inline const char *apiId() const { return m_apiId.data(); }
@@ -54,20 +51,17 @@ public:
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
inline const char *logFile() const { return m_logFile.data(); } inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); } inline const char *userAgent() const { return m_userAgent.data(); }
inline const std::vector<Pool> &pools() const { return m_activePools; } inline const Pools &pools() const { return m_pools; }
inline int apiPort() const { return m_apiPort; } inline int apiPort() const { return m_apiPort; }
inline int donateLevel() const { return m_donateLevel; }
inline int printTime() const { return m_printTime; } inline int printTime() const { return m_printTime; }
inline int retries() const { return m_retries; }
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.isNull(); } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const Algorithm &algorithm() const override { return m_algorithm; } inline const Algorithm &algorithm() const override { return m_algorithm; }
inline const char *fileName() const override { return m_fileName.data(); } inline const String &fileName() const override { return m_fileName; }
bool save() override; bool save() override;
bool isColors() const;
void printAPI(); void printAPI();
void printPools(); void printPools();
void printVersions(); void printVersions();
@@ -83,6 +77,7 @@ protected:
bool parseBoolean(int key, bool enable) override; bool parseBoolean(int key, bool enable) override;
bool parseString(int key, const char *arg) override; bool parseString(int key, const char *arg) override;
bool parseUint64(int key, uint64_t arg) override; bool parseUint64(int key, uint64_t arg) override;
void parseJSON(const rapidjson::Document &doc) override;
void setFileName(const char *fileName) override; void setFileName(const char *fileName) override;
Algorithm m_algorithm; Algorithm m_algorithm;
@@ -91,29 +86,22 @@ protected:
bool m_apiRestricted; bool m_apiRestricted;
bool m_autoSave; bool m_autoSave;
bool m_background; bool m_background;
bool m_colors;
bool m_dryRun; bool m_dryRun;
bool m_syslog; bool m_syslog;
bool m_watch; bool m_watch;
int m_apiPort; int m_apiPort;
int m_donateLevel;
int m_printTime; int m_printTime;
int m_retries; Pools m_pools;
int m_retryPause;
State m_state; State m_state;
std::vector<Pool> m_activePools; String m_apiId;
std::vector<Pool> m_pools; String m_apiToken;
xmrig::c_str m_apiId; String m_apiWorkerId;
xmrig::c_str m_apiToken; String m_fileName;
xmrig::c_str m_apiWorkerId; String m_logFile;
xmrig::c_str m_fileName; String m_userAgent;
xmrig::c_str m_logFile;
xmrig::c_str m_userAgent;
private: private:
bool parseInt(int key, int arg); bool parseInt(int key, int arg);
Pool &currentPool();
void fixup();
}; };

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -22,6 +23,7 @@
*/ */
#include <assert.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <uv.h> #include <uv.h>
@@ -37,23 +39,28 @@
#endif #endif
#include "base/io/Json.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "base/kernel/Process.h"
#include "common/config/ConfigLoader.h" #include "common/config/ConfigLoader.h"
#include "common/config/ConfigWatcher.h" #include "common/config/ConfigWatcher.h"
#include "common/interfaces/IConfig.h" #include "common/interfaces/IConfig.h"
#include "common/interfaces/IWatcherListener.h"
#include "common/net/Pool.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "core/ConfigCreator.h" #include "core/ConfigCreator.h"
#include "core/ConfigLoader_platform.h" #include "core/ConfigLoader_platform.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
#include "rapidjson/filereadstream.h" #include "rapidjson/fwd.h"
#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG
# include "core/ConfigLoader_default.h"
#endif
bool xmrig::ConfigLoader::m_done = false;
xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr;
xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr; xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr;
xmrig::IWatcherListener *xmrig::ConfigLoader::m_listener = nullptr; xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr;
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
@@ -76,8 +83,9 @@ bool xmrig::ConfigLoader::loadFromFile(xmrig::IConfig *config, const char *fileN
bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const char *json) bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const char *json)
{ {
rapidjson::Document doc; using namespace rapidjson;
doc.Parse(json); Document doc;
doc.Parse<kParseCommentsFlag | kParseTrailingCommasFlag>(json);
if (doc.HasParseError() || !doc.IsObject()) { if (doc.HasParseError() || !doc.IsObject()) {
return false; return false;
@@ -93,19 +101,6 @@ bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson::
parseJSON(config, &config_options[i], doc); parseJSON(config, &config_options[i], doc);
} }
const rapidjson::Value &pools = doc["pools"];
if (pools.IsArray()) {
for (const rapidjson::Value &value : pools.GetArray()) {
if (!value.IsObject()) {
continue;
}
for (size_t i = 0; i < ARRAY_SIZE(pool_options); i++) {
parseJSON(config, &pool_options[i], value);
}
}
}
const rapidjson::Value &api = doc["api"]; const rapidjson::Value &api = doc["api"];
if (api.IsObject()) { if (api.IsObject()) {
for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) { for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) {
@@ -142,16 +137,31 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json)
} }
xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener) bool xmrig::ConfigLoader::watch(IConfig *config)
{
if (!config->isWatch()) {
return false;
}
assert(m_watcher == nullptr);
m_watcher = new xmrig::ConfigWatcher(config->fileName(), m_creator, m_listener);
return true;
}
xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener)
{ {
m_creator = creator; m_creator = creator;
m_listener = listener; m_listener = listener;
xmrig::IConfig *config = m_creator->create(); xmrig::IConfig *config = m_creator->create();
int key; int key;
int argc = process->arguments().argc();
char **argv = process->arguments().argv();
while (1) { while (1) {
key = getopt_long(argc, argv, short_options, options, NULL); key = getopt_long(argc, argv, short_options, options, nullptr);
if (key < 0) { if (key < 0) {
break; break;
} }
@@ -172,9 +182,18 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
delete config; delete config;
config = m_creator->create(); config = m_creator->create();
loadFromFile(config, Platform::defaultConfigName()); loadFromFile(config, process->location(Process::ExeLocation, "config.json"));
} }
# ifdef XMRIG_FEATURE_EMBEDDED_CONFIG
if (!config->finalize()) {
delete config;
config = m_creator->create();
loadFromJSON(config, default_config);
}
# endif
if (!config->finalize()) { if (!config->finalize()) {
if (!config->algorithm().isValid()) { if (!config->algorithm().isValid()) {
fprintf(stderr, "No valid algorithm specified. Exiting.\n"); fprintf(stderr, "No valid algorithm specified. Exiting.\n");
@@ -187,10 +206,6 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
return nullptr; return nullptr;
} }
if (config->isWatch()) {
m_watcher = new xmrig::ConfigWatcher(config->fileName(), creator, listener);
}
return config; return config;
} }
@@ -207,53 +222,28 @@ void xmrig::ConfigLoader::release()
bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc) bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc)
{ {
uv_fs_t req; if (Json::get(fileName, doc)) {
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr); return true;
if (fd < 0) {
fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd));
return false;
} }
uv_fs_req_cleanup(&req);
FILE *fp = fdopen(fd, "rb");
char buf[8192];
rapidjson::FileReadStream is(fp, buf, sizeof(buf));
doc.ParseStream(is);
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
uv_fs_req_cleanup(&req);
if (doc.HasParseError()) { if (doc.HasParseError()) {
printf("%s<%d>: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError())); printf("%s<offset:%zu>: \"%s\"\n", fileName, doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
return false; }
else {
fprintf(stderr, "unable to open \"%s\".\n", fileName);
} }
return doc.IsObject(); return false;
} }
bool xmrig::ConfigLoader::parseArg(xmrig::IConfig *config, int key, const char *arg) bool xmrig::ConfigLoader::parseArg(xmrig::IConfig *config, int key, const char *arg)
{ {
switch (key) { if (key == xmrig::IConfig::ConfigKey) {
case xmrig::IConfig::VersionKey: /* --version */ return loadFromFile(config, arg);
showVersion();
return false;
case xmrig::IConfig::HelpKey: /* --help */
showUsage();
return false;
case xmrig::IConfig::ConfigKey: /* --config */
loadFromFile(config, arg);
break;
default:
return config->parseString(key, arg);;
} }
return true; return config->parseString(key, arg);
} }
@@ -280,56 +270,3 @@ void xmrig::ConfigLoader::parseJSON(xmrig::IConfig *config, const struct option
config->parseBoolean(option->val, value.IsTrue()); config->parseBoolean(option->val, value.IsTrue());
} }
} }
void xmrig::ConfigLoader::showUsage()
{
m_done = true;
printf(usage);
}
void xmrig::ConfigLoader::showVersion()
{
m_done = true;
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
# if defined(__clang__)
" with clang " __clang_version__);
# elif defined(__GNUC__)
" with GCC");
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER)
" with MSVC");
printf(" %d", MSVC_VERSION);
# else
);
# endif
printf("\n features:"
# if defined(__i386__) || defined(_M_IX86)
" 32-bit"
# elif defined(__x86_64__) || defined(_M_AMD64)
" 64-bit"
# endif
# if defined(__AES__) || defined(_MSC_VER)
" AES"
# endif
"\n");
printf("\nlibuv/%s\n", uv_version_string());
# ifndef XMRIG_NO_HTTPD
printf("microhttpd/%s\n", MHD_get_version());
# endif
# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT)
{
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
}
# endif
}

View File

@@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -39,8 +40,9 @@ namespace xmrig {
class ConfigWatcher; class ConfigWatcher;
class IConfigCreator; class IConfigCreator;
class IWatcherListener; class IConfigListener;
class IConfig; class IConfig;
class Process;
class ConfigLoader class ConfigLoader
@@ -50,22 +52,18 @@ public:
static bool loadFromJSON(IConfig *config, const char *json); static bool loadFromJSON(IConfig *config, const char *json);
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
static bool reload(IConfig *oldConfig, const char *json); static bool reload(IConfig *oldConfig, const char *json);
static IConfig *load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener); static bool watch(IConfig *config);
static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener);
static void release(); static void release();
static inline bool isDone() { return m_done; }
private: private:
static bool getJSON(const char *fileName, rapidjson::Document &doc); static bool getJSON(const char *fileName, rapidjson::Document &doc);
static bool parseArg(IConfig *config, int key, const char *arg); static bool parseArg(IConfig *config, int key, const char *arg);
static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object); static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object);
static void showUsage();
static void showVersion();
static bool m_done;
static ConfigWatcher *m_watcher; static ConfigWatcher *m_watcher;
static IConfigCreator *m_creator; static IConfigCreator *m_creator;
static IWatcherListener *m_listener; static IConfigListener *m_listener;
}; };

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -22,66 +23,35 @@
*/ */
#include <stdio.h> #include "base/io/Watcher.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "common/config/ConfigLoader.h" #include "common/config/ConfigLoader.h"
#include "common/config/ConfigWatcher.h" #include "common/config/ConfigWatcher.h"
#include "common/interfaces/IWatcherListener.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/ConfigCreator.h" #include "core/ConfigCreator.h"
xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : xmrig::ConfigWatcher::ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener) :
m_creator(creator), m_creator(creator),
m_listener(listener), m_listener(listener)
m_path(path)
{ {
uv_fs_event_init(uv_default_loop(), &m_fsEvent); m_watcher = new Watcher(path, this);
uv_timer_init(uv_default_loop(), &m_timer);
m_fsEvent.data = m_timer.data = this;
start();
} }
xmrig::ConfigWatcher::~ConfigWatcher() xmrig::ConfigWatcher::~ConfigWatcher()
{ {
uv_timer_stop(&m_timer); delete m_watcher;
uv_fs_event_stop(&m_fsEvent);
} }
void xmrig::ConfigWatcher::onTimer(uv_timer_t* handle)
void xmrig::ConfigWatcher::onFileChanged(const String &fileName)
{ {
static_cast<xmrig::ConfigWatcher *>(handle->data)->reload(); LOG_WARN("\"%s\" was changed, reloading configuration", fileName.data());
}
void xmrig::ConfigWatcher::onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status)
{
if (!filename) {
return;
}
static_cast<xmrig::ConfigWatcher *>(handle->data)->queueUpdate();
}
void xmrig::ConfigWatcher::queueUpdate()
{
uv_timer_stop(&m_timer);
uv_timer_start(&m_timer, xmrig::ConfigWatcher::onTimer, kDelay, 0);
}
void xmrig::ConfigWatcher::reload()
{
LOG_WARN("\"%s\" was changed, reloading configuration", m_path.data());
IConfig *config = m_creator->create(); IConfig *config = m_creator->create();
ConfigLoader::loadFromFile(config, m_path.data()); ConfigLoader::loadFromFile(config, fileName);
if (!config->finalize()) { if (!config->finalize()) {
LOG_ERR("reloading failed"); LOG_ERR("reloading failed");
@@ -91,15 +61,4 @@ void xmrig::ConfigWatcher::reload()
} }
m_listener->onNewConfig(config); m_listener->onNewConfig(config);
# ifndef _WIN32
uv_fs_event_stop(&m_fsEvent);
start();
# endif
}
void xmrig::ConfigWatcher::start()
{
uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path.data(), 0);
} }

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,15 +22,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __CONFIGWATCHER_H__ #ifndef XMRIG_CONFIGWATCHER_H
#define __CONFIGWATCHER_H__ #define XMRIG_CONFIGWATCHER_H
#include <stdint.h> #include "base/kernel/interfaces/IWatcherListener.h"
#include <uv.h> #include "base/tools/String.h"
#include "common/utils/c_str.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
@@ -40,29 +38,23 @@ namespace xmrig {
class IConfigCreator; class IConfigCreator;
class IWatcherListener; class IConfigListener;
class Watcher;
class ConfigWatcher class ConfigWatcher : public IWatcherListener
{ {
public: public:
ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener); ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener);
~ConfigWatcher(); ~ConfigWatcher() override;
protected:
void onFileChanged(const String &fileName) override;
private: private:
constexpr static int kDelay = 500;
static void onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status);
static void onTimer(uv_timer_t* handle);
void queueUpdate();
void reload();
void start();
IConfigCreator *m_creator; IConfigCreator *m_creator;
IWatcherListener *m_listener; IConfigListener *m_listener;
uv_fs_event_t m_fsEvent; Watcher *m_watcher;
uv_timer_t m_timer;
xmrig::c_str m_path;
}; };

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -35,6 +36,14 @@
# define bit_AES (1 << 25) # define bit_AES (1 << 25)
#endif #endif
#ifndef bit_OSXSAVE
# define bit_OSXSAVE (1 << 27)
#endif
#ifndef bit_AVX2
# define bit_AVX2 (1 << 5)
#endif
#include "common/cpu/BasicCpuInfo.h" #include "common/cpu/BasicCpuInfo.h"
@@ -93,9 +102,28 @@ static inline bool has_aes_ni()
} }
static inline bool has_avx2()
{
int32_t cpu_info[4] = { 0 };
cpuid(EXTENDED_FEATURES, cpu_info);
return (cpu_info[EBX_Reg] & bit_AVX2) != 0;
}
static inline bool has_ossave()
{
int32_t cpu_info[4] = { 0 };
cpuid(PROCESSOR_INFO, cpu_info);
return (cpu_info[ECX_Reg] & bit_OSXSAVE) != 0;
}
xmrig::BasicCpuInfo::BasicCpuInfo() : xmrig::BasicCpuInfo::BasicCpuInfo() :
m_assembly(ASM_NONE), m_assembly(ASM_NONE),
m_aes(has_aes_ni()), m_aes(has_aes_ni()),
m_avx2(has_avx2() && has_ossave()),
m_brand(), m_brand(),
m_threads(std::thread::hardware_concurrency()) m_threads(std::thread::hardware_concurrency())
{ {

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -41,6 +42,7 @@ protected:
inline Assembly assembly() const override { return m_assembly; } inline Assembly assembly() const override { return m_assembly; }
inline bool hasAES() const override { return m_aes; } inline bool hasAES() const override { return m_aes; }
inline bool hasAVX2() const override { return m_avx2; }
inline bool isSupported() const override { return true; } inline bool isSupported() const override { return true; }
inline const char *brand() const override { return m_brand; } inline const char *brand() const override { return m_brand; }
inline int32_t cores() const override { return -1; } inline int32_t cores() const override { return -1; }
@@ -59,6 +61,7 @@ protected:
private: private:
Assembly m_assembly; Assembly m_assembly;
bool m_aes; bool m_aes;
bool m_avx2;
char m_brand[64]; char m_brand[64];
int32_t m_threads; int32_t m_threads;
}; };

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -24,19 +25,29 @@
#include <string.h> #include <string.h>
#include <thread> #include <thread>
#if __ARM_FEATURE_CRYPTO
# include <sys/auxv.h>
# include <asm/hwcap.h>
#endif
#include "common/cpu/BasicCpuInfo.h" #include "common/cpu/BasicCpuInfo.h"
xmrig::BasicCpuInfo::BasicCpuInfo() : xmrig::BasicCpuInfo::BasicCpuInfo() :
m_aes(false), m_aes(false),
m_avx2(false),
m_brand(), m_brand(),
m_threads(std::thread::hardware_concurrency()) m_threads(std::thread::hardware_concurrency())
{ {
memcpy(m_brand, "Unknown", 7); # ifdef XMRIG_ARMv8
memcpy(m_brand, "ARMv8", 5);
# else
memcpy(m_brand, "ARMv7", 5);
# endif
# if __ARM_FEATURE_CRYPTO # if __ARM_FEATURE_CRYPTO
m_aes = true; m_aes = getauxval(AT_HWCAP) & HWCAP_AES;
# endif # endif
} }

View File

@@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@@ -54,16 +54,21 @@ struct AlgoData
static AlgoData const algorithms[] = { static AlgoData const algorithms[] = {
{ "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO }, { "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO },
{ "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 },
{ "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
{ "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
{ "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, { "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR },
{ "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, { "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO },
{ "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO }, { "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO },
{ "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 }, { "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
{ "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF },
{ "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF },
{ "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW },
{ "cryptonight/r", "cn/r", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 },
{ "cryptonight/rwz", "cn/rwz", xmrig::CRYPTONIGHT, xmrig::VARIANT_RWZ },
{ "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS },
{ "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE },
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
@@ -78,6 +83,18 @@ static AlgoData const algorithms[] = {
{ "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV },
{ "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, { "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE },
# endif # endif
# ifndef XMRIG_NO_CN_PICO
{ "cryptonight-pico/trtl", "cn-pico/trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight-pico", "cn-pico", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight-turtle", "cn-trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight-ultralite", "cn-ultralite", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight_turtle", "cn_turtle", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
# endif
# ifndef XMRIG_NO_CN_GPU
{ "cryptonight/gpu", "cn/gpu", xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU },
# endif
}; };
@@ -97,6 +114,9 @@ static AlgoData const xmrStakAlgorithms[] = {
{ "cryptonight_masari", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR }, { "cryptonight_masari", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR },
{ "cryptonight-bittube2", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, // bittube-miner { "cryptonight-bittube2", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, // bittube-miner
{ "cryptonight_alloy", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, // xmr-stak-alloy { "cryptonight_alloy", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO }, // xmr-stak-alloy
{ "cryptonight_turtle", nullptr, xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight_gpu", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU },
{ "cryptonight_r", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_4 },
}; };
#endif #endif
@@ -111,7 +131,14 @@ static const char *variants[] = {
"xao", "xao",
"rto", "rto",
"2", "2",
"half" "half",
"trtl",
"gpu",
"wow",
"r",
"rwz",
"zls",
"double"
}; };
@@ -225,6 +252,10 @@ void xmrig::Algorithm::parseVariant(int variant)
void xmrig::Algorithm::setAlgo(Algo algo) void xmrig::Algorithm::setAlgo(Algo algo)
{ {
m_algo = algo; m_algo = algo;
if (m_algo == CRYPTONIGHT_PICO && m_variant == VARIANT_AUTO) {
m_variant = xmrig::VARIANT_TRTL;
}
} }

View File

@@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify

View File

@@ -4,7 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2018 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -31,6 +33,9 @@
namespace xmrig { namespace xmrig {
class String;
class IConfig class IConfig
{ {
public: public:
@@ -47,7 +52,6 @@ public:
ColorKey = 1002, ColorKey = 1002,
ConfigKey = 'c', ConfigKey = 'c',
DonateLevelKey = 1003, DonateLevelKey = 1003,
HelpKey = 'h',
KeepAliveKey = 'k', KeepAliveKey = 'k',
LogFileKey = 'l', LogFileKey = 'l',
PasswordKey = 'p', PasswordKey = 'p',
@@ -61,11 +65,11 @@ public:
UserpassKey = 'O', UserpassKey = 'O',
VariantKey = 1010, VariantKey = 1010,
VerboseKey = 1100, VerboseKey = 1100,
VersionKey = 'V',
WatchKey = 1105, WatchKey = 1105,
TlsKey = 1013, TlsKey = 1013,
FingerprintKey = 1014, FingerprintKey = 1014,
AutoSaveKey = 1016, AutoSaveKey = 1016,
ProxyDonateKey = 1017,
// xmrig common // xmrig common
CPUPriorityKey = 1021, CPUPriorityKey = 1021,
@@ -114,6 +118,8 @@ public:
TlsCiphersKey = 1112, TlsCiphersKey = 1112,
TlsCipherSuitesKey = 1113, TlsCipherSuitesKey = 1113,
TlsProtocolsKey = 1114, TlsProtocolsKey = 1114,
AlgoExtKey = 1115,
ProxyPasswordKey = 1116,
// xmrig nvidia // xmrig nvidia
CudaMaxThreadsKey = 1200, CudaMaxThreadsKey = 1200,
@@ -125,7 +131,7 @@ public:
CudaMaxUsageKey = 1206, CudaMaxUsageKey = 1206,
}; };
virtual ~IConfig() {} virtual ~IConfig() = default;
virtual bool finalize() = 0; virtual bool finalize() = 0;
virtual bool isWatch() const = 0; virtual bool isWatch() const = 0;
@@ -134,7 +140,7 @@ public:
virtual bool parseUint64(int key, uint64_t arg) = 0; virtual bool parseUint64(int key, uint64_t arg) = 0;
virtual bool save() = 0; virtual bool save() = 0;
virtual const Algorithm &algorithm() const = 0; virtual const Algorithm &algorithm() const = 0;
virtual const char *fileName() const = 0; virtual const String &fileName() const = 0;
virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void getJSON(rapidjson::Document &doc) const = 0;
virtual void parseJSON(const rapidjson::Document &doc) = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0;
virtual void setFileName(const char *fileName) = 0; virtual void setFileName(const char *fileName) = 0;

View File

@@ -4,7 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2018 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -20,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ICONFIGCREATOR_H__ #ifndef XMRIG_ICONFIGCREATOR_H
#define __ICONFIGCREATOR_H__ #define XMRIG_ICONFIGCREATOR_H
namespace xmrig { namespace xmrig {
@@ -33,7 +35,7 @@ class IConfig;
class IConfigCreator class IConfigCreator
{ {
public: public:
virtual ~IConfigCreator() {} virtual ~IConfigCreator() = default;
virtual IConfig *create() const = 0; virtual IConfig *create() const = 0;
}; };
@@ -42,4 +44,4 @@ public:
} /* namespace xmrig */ } /* namespace xmrig */
#endif // __ICONFIGCREATOR_H__ #endif // XMRIG_ICONFIGCREATOR_H

View File

@@ -1,37 +0,0 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ICONSOLELISTENER_H__
#define __ICONSOLELISTENER_H__
class IConsoleListener
{
public:
virtual ~IConsoleListener() {}
virtual void onConsoleCommand(char command) = 0;
};
#endif // __ICONSOLELISTENER_H__

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -34,7 +35,7 @@ class Config;
class IControllerListener class IControllerListener
{ {
public: public:
virtual ~IControllerListener() {} virtual ~IControllerListener() = default;
virtual void onConfigChanged(Config *config, Config *previousConfig) = 0; virtual void onConfigChanged(Config *config, Config *previousConfig) = 0;
}; };

View File

@@ -4,7 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2018 XMRig <support@xmrig.com> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -40,6 +42,7 @@ public:
virtual ~ICpuInfo() {} virtual ~ICpuInfo() {}
virtual bool hasAES() const = 0; virtual bool hasAES() const = 0;
virtual bool hasAVX2() const = 0;
virtual bool isSupported() const = 0; virtual bool isSupported() const = 0;
virtual bool isX64() const = 0; virtual bool isX64() const = 0;
virtual const char *brand() const = 0; virtual const char *brand() const = 0;

View File

@@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,14 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ILOGBACKEND_H__ #ifndef XMRIG_ILOGBACKEND_H
#define __ILOGBACKEND_H__ #define XMRIG_ILOGBACKEND_H
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
namespace xmrig {
class ILogBackend class ILogBackend
{ {
public: public:
@@ -46,11 +50,14 @@ public:
constexpr static const size_t kBufferSize = 512; constexpr static const size_t kBufferSize = 512;
# endif # endif
virtual ~ILogBackend() {} virtual ~ILogBackend() = default;
virtual void message(Level level, const char* fmt, va_list args) = 0; virtual void message(Level level, const char* fmt, va_list args) = 0;
virtual void text(const char* fmt, va_list args) = 0; virtual void text(const char* fmt, va_list args) = 0;
}; };
#endif // __ILOGBACKEND_H__ } /* namespace xmrig */
#endif // XMRIG_ILOGBACKEND_H

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