mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-07 16:05:05 -05:00
Compare commits
618 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d8e8c92ab | ||
|
|
651009e1b9 | ||
|
|
1d4bc030fb | ||
|
|
809efb4700 | ||
|
|
10165da53e | ||
|
|
51b92f66cf | ||
|
|
ff4d54dc4c | ||
|
|
699269bbae | ||
|
|
9137f59ec1 | ||
|
|
f9f7ef26b8 | ||
|
|
32c3d4b9f6 | ||
|
|
54a1c614f7 | ||
|
|
cf7ce13986 | ||
|
|
356fd04b0f | ||
|
|
5a4720cf4a | ||
|
|
c0e2a15614 | ||
|
|
1f77b049e3 | ||
|
|
29373c4226 | ||
|
|
fb62ee938a | ||
|
|
1bb8f77b52 | ||
|
|
5d9ebb0b91 | ||
|
|
d4f6eaa371 | ||
|
|
08ef94486b | ||
|
|
1042f23dd5 | ||
|
|
80a7aa2497 | ||
|
|
5cd48f483e | ||
|
|
8aa4c8f19b | ||
|
|
c8b1f176e7 | ||
|
|
31e40943d0 | ||
|
|
538c8fc9e1 | ||
|
|
fb3129c67d | ||
|
|
6a77a27e7f | ||
|
|
0bbeafde65 | ||
|
|
6052da3c43 | ||
|
|
8800219cf4 | ||
|
|
7ed840016a | ||
|
|
21d9ad6dbc | ||
|
|
154806ac74 | ||
|
|
10eb579270 | ||
|
|
123e7cf0b8 | ||
|
|
9f2d821970 | ||
|
|
18a9803e5e | ||
|
|
f2574c2a41 | ||
|
|
4ebfc135e0 | ||
|
|
d135bdd87e | ||
|
|
bde77ebab4 | ||
|
|
a261fe8c75 | ||
|
|
b1700d270a | ||
|
|
26e4859740 | ||
|
|
9685496ce0 | ||
|
|
7e83fb306e | ||
|
|
fc1bbbba6e | ||
|
|
d6788e4c46 | ||
|
|
3ab7c8344e | ||
|
|
9155e6a2a0 | ||
|
|
948f23c7d9 | ||
|
|
d4d0c69b5d | ||
|
|
488cec09dd | ||
|
|
a5dcd6dd1f | ||
|
|
d9066dc817 | ||
|
|
cac240104e | ||
|
|
eec5ca5535 | ||
|
|
060655fc6c | ||
|
|
5bd2b8fd3f | ||
|
|
ac58ece16e | ||
|
|
a0553264a4 | ||
|
|
1c16cfedfc | ||
|
|
1ea34b31a1 | ||
|
|
55c8ac6736 | ||
|
|
601453bff6 | ||
|
|
1bd51dcf2e | ||
|
|
41feb756bf | ||
|
|
3393ea346b | ||
|
|
84f85b4200 | ||
|
|
415600b8c9 | ||
|
|
b7c17cf1a0 | ||
|
|
de975adb8a | ||
|
|
764767d317 | ||
|
|
9c088eabc2 | ||
|
|
7c789a0d3c | ||
|
|
bdff4064a2 | ||
|
|
3a0fdcac6f | ||
|
|
ee4f6e28f0 | ||
|
|
f6699b5929 | ||
|
|
ee667144e8 | ||
|
|
dbdcc14672 | ||
|
|
4f188a2cd8 | ||
|
|
70d6e0e62c | ||
|
|
14e7c82512 | ||
|
|
f4d2dec628 | ||
|
|
0450c31449 | ||
|
|
b368ffacdb | ||
|
|
2df204f8a8 | ||
|
|
d554f1c12a | ||
|
|
ca5fb6e8f0 | ||
|
|
7f5ac83050 | ||
|
|
3688cd9b6c | ||
|
|
33a3ae59bd | ||
|
|
8cf56438f6 | ||
|
|
4a781cee8b | ||
|
|
8d316c17f0 | ||
|
|
42e0d35207 | ||
|
|
a6813ef4f5 | ||
|
|
36ce144d35 | ||
|
|
65dab8371b | ||
|
|
c2e15e2b86 | ||
|
|
e3f2c38fff | ||
|
|
73852f44c6 | ||
|
|
01428acc65 | ||
|
|
9dd223d5b1 | ||
|
|
c27c577c5e | ||
|
|
a1fec1c797 | ||
|
|
a5f77eb16a | ||
|
|
5b3ad39a9e | ||
|
|
1a2aaf210c | ||
|
|
a6a0fb965a | ||
|
|
aabdff2cc9 | ||
|
|
3f8898f228 | ||
|
|
ab60add9d5 | ||
|
|
7e4858db2a | ||
|
|
885a2cab21 | ||
|
|
3337f5ac43 | ||
|
|
5f113a47cf | ||
|
|
f4170ec7bc | ||
|
|
e9069a381e | ||
|
|
ca18622ad0 | ||
|
|
eac6a97a2e | ||
|
|
bd4bc9ba4d | ||
|
|
7605c4241f | ||
|
|
bb583afcff | ||
|
|
5a2cf85b6c | ||
|
|
80de5766ac | ||
|
|
2c0183dcef | ||
|
|
8a90fc699e | ||
|
|
b1816005fd | ||
|
|
f478fa843d | ||
|
|
046c345f65 | ||
|
|
9692f92c6b | ||
|
|
bc26d2ede6 | ||
|
|
36b01f136f | ||
|
|
ca43d155d8 | ||
|
|
e04d0f504c | ||
|
|
acca8f79cf | ||
|
|
2c38f693d7 | ||
|
|
4faa95b460 | ||
|
|
5f9ebdf149 | ||
|
|
31a571dc70 | ||
|
|
897ff83dcd | ||
|
|
a63794ccd6 | ||
|
|
b15e605614 | ||
|
|
18335392a1 | ||
|
|
b1c22da6a1 | ||
|
|
b95ff65eae | ||
|
|
005a09cd98 | ||
|
|
e0f5066ded | ||
|
|
2b15bcbb4f | ||
|
|
db646d5d2d | ||
|
|
b58e20dde4 | ||
|
|
b11e772acc | ||
|
|
d1bc03351b | ||
|
|
d1f551da2c | ||
|
|
6425c53d61 | ||
|
|
118e547175 | ||
|
|
d696daf5af | ||
|
|
ac60d9426c | ||
|
|
209796a07e | ||
|
|
a1f19305f4 | ||
|
|
dd3243aa70 | ||
|
|
09893bfd36 | ||
|
|
a98c475a3c | ||
|
|
59b147b6fb | ||
|
|
17f28667b3 | ||
|
|
63a62e7ea0 | ||
|
|
56cacbd5bc | ||
|
|
8b9d5cff91 | ||
|
|
eede1b4881 | ||
|
|
492449e9fb | ||
|
|
b43336582d | ||
|
|
67863a427d | ||
|
|
1382857c83 | ||
|
|
84c2cadc50 | ||
|
|
16b4fd0ff5 | ||
|
|
cfe3995aa8 | ||
|
|
5382216725 | ||
|
|
c06f77b9e9 | ||
|
|
0c930e277b | ||
|
|
2a2712ab90 | ||
|
|
9f6f599d78 | ||
|
|
a76243a65e | ||
|
|
16babcc6bc | ||
|
|
3d60b3cc62 | ||
|
|
acd042c234 | ||
|
|
a2e384df58 | ||
|
|
735180ac04 | ||
|
|
06a84499d7 | ||
|
|
caa70a1e9d | ||
|
|
deb832c9c6 | ||
|
|
d7feb2719e | ||
|
|
4b91978af6 | ||
|
|
7e078f2d07 | ||
|
|
2b0b71b9f6 | ||
|
|
938e652c45 | ||
|
|
20bd22ea22 | ||
|
|
c7c9d20b8b | ||
|
|
dd6aeb26e8 | ||
|
|
ba0df6e973 | ||
|
|
a0f48adf5c | ||
|
|
2b0cac5d4d | ||
|
|
afeaabdca4 | ||
|
|
6b584a78b2 | ||
|
|
4bf248f513 | ||
|
|
93b54f8f44 | ||
|
|
dd7c776ff4 | ||
|
|
ff3ae25d16 | ||
|
|
bdc16df418 | ||
|
|
9ef59366ba | ||
|
|
dda8157a7b | ||
|
|
023062b2f1 | ||
|
|
ad92c3b025 | ||
|
|
8f3d405b34 | ||
|
|
20268d5291 | ||
|
|
152c4f2f1b | ||
|
|
c2f6c70044 | ||
|
|
9a70f0e564 | ||
|
|
0efd995b9b | ||
|
|
a33fbe32c6 | ||
|
|
dc6d6bd539 | ||
|
|
880747d0e0 | ||
|
|
dc67352ac5 | ||
|
|
cb87c244c3 | ||
|
|
ae25c01d36 | ||
|
|
fa38d97192 | ||
|
|
9a173ce91e | ||
|
|
fbba3d1be6 | ||
|
|
782a91f7e6 | ||
|
|
52e871b810 | ||
|
|
143da8380e | ||
|
|
a63677e255 | ||
|
|
850150dc00 | ||
|
|
0d197f8906 | ||
|
|
03b4e160ec | ||
|
|
18dc19b1e8 | ||
|
|
0d9db273a0 | ||
|
|
1a3de05096 | ||
|
|
c9928a873d | ||
|
|
ebcdac7d13 | ||
|
|
f4a867b70f | ||
|
|
c2fcf23855 | ||
|
|
ba65a34a01 | ||
|
|
f163aad38c | ||
|
|
dd27c42293 | ||
|
|
0c20d7a125 | ||
|
|
c9fd8061c2 | ||
|
|
ee4d980955 | ||
|
|
1f609c7ebd | ||
|
|
cf76d9254a | ||
|
|
d8ca5ef205 | ||
|
|
30791de5bc | ||
|
|
3a7e8647bb | ||
|
|
f1a1e0814c | ||
|
|
feb1a758c1 | ||
|
|
0adad68471 | ||
|
|
dc76879188 | ||
|
|
bcd27ca259 | ||
|
|
4c4e0593a7 | ||
|
|
2189fe94ed | ||
|
|
a2d2c0418d | ||
|
|
1059189e2c | ||
|
|
7da9e7a599 | ||
|
|
bc9130ded3 | ||
|
|
2f3939396e | ||
|
|
14ac7b556e | ||
|
|
812cd9760f | ||
|
|
93216a51f4 | ||
|
|
357fbac62b | ||
|
|
0bc9016124 | ||
|
|
310ad7fa37 | ||
|
|
23914e9a9f | ||
|
|
bb3990a076 | ||
|
|
a27dfa8b70 | ||
|
|
a3873930a0 | ||
|
|
b948474d01 | ||
|
|
85946b0c40 | ||
|
|
075565e6fa | ||
|
|
eef4d9b102 | ||
|
|
f11aad515b | ||
|
|
85b829a1e3 | ||
|
|
73fca9114e | ||
|
|
57479cef8c | ||
|
|
ea1658c818 | ||
|
|
7c4b718789 | ||
|
|
f151c7131d | ||
|
|
36a562e1f1 | ||
|
|
dd8590e6c8 | ||
|
|
f7b029eb05 | ||
|
|
e8d6514bd3 | ||
|
|
95092bfadb | ||
|
|
08e791b60d | ||
|
|
6b7030cd6f | ||
|
|
b736f0a558 | ||
|
|
807b2e9d6e | ||
|
|
034d2f0c08 | ||
|
|
4a39321d74 | ||
|
|
0041e9f0c1 | ||
|
|
969a26fb5d | ||
|
|
dac12a122f | ||
|
|
2702b6ffc8 | ||
|
|
25bac30862 | ||
|
|
a8de81a51b | ||
|
|
b719bbfefc | ||
|
|
de6ee749fe | ||
|
|
33d9094cdc | ||
|
|
63fed427f4 | ||
|
|
ae89ca0a5f | ||
|
|
25dce61369 | ||
|
|
8cb7483b2c | ||
|
|
1e2fde0df1 | ||
|
|
859515315c | ||
|
|
7f169e391d | ||
|
|
6a7a7ada2e | ||
|
|
21b2e2ca1e | ||
|
|
1d31f1b0b8 | ||
|
|
dab4239aca | ||
|
|
8908c2c027 | ||
|
|
974cb4162a | ||
|
|
dba78717fa | ||
|
|
48a214c3f1 | ||
|
|
e320b2e928 | ||
|
|
1748a7bd57 | ||
|
|
6cf24936df | ||
|
|
651637d637 | ||
|
|
26ee5028e1 | ||
|
|
d900a6d9dd | ||
|
|
5d6a622b18 | ||
|
|
009bd1a507 | ||
|
|
34a3454784 | ||
|
|
14f0e8658c | ||
|
|
6dda4ad41c | ||
|
|
2b3f7f43ce | ||
|
|
5019493332 | ||
|
|
0086020b5c | ||
|
|
adc6adb6d5 | ||
|
|
8ab9f0f860 | ||
|
|
19f409a85b | ||
|
|
6a4f817693 | ||
|
|
4cd7af3da1 | ||
|
|
d7d3fec058 | ||
|
|
8d61df7cc9 | ||
|
|
b383a382eb | ||
|
|
bee1285e3a | ||
|
|
c89889cc57 | ||
|
|
a1c5afa383 | ||
|
|
a00024cf51 | ||
|
|
a5325d9021 | ||
|
|
719b1cb90f | ||
|
|
8530e6c4a5 | ||
|
|
6605e1f6f2 | ||
|
|
1f1bdcde51 | ||
|
|
298cf37121 | ||
|
|
c4a2dcc1fb | ||
|
|
dfe20e116b | ||
|
|
68e953345f | ||
|
|
b98d44ce10 | ||
|
|
734c0dbce1 | ||
|
|
1ab0829ab3 | ||
|
|
3da5823905 | ||
|
|
b533644f3f | ||
|
|
7badca3aa5 | ||
|
|
3ca7f3eece | ||
|
|
9c23186172 | ||
|
|
2b0309e159 | ||
|
|
be232fa1f2 | ||
|
|
3df99fbced | ||
|
|
85f9bd97f1 | ||
|
|
2ddac1ce68 | ||
|
|
41e8c4f887 | ||
|
|
bc2660f509 | ||
|
|
230962230f | ||
|
|
a9cc5c5258 | ||
|
|
ba5f92c6dd | ||
|
|
ca149d2eed | ||
|
|
b9fec2fcc4 | ||
|
|
6d40f2dd1a | ||
|
|
54c3cd5494 | ||
|
|
fe7cfddd29 | ||
|
|
8d9025f2ca | ||
|
|
38874fbb0a | ||
|
|
90a09f20b3 | ||
|
|
7365e0486b | ||
|
|
593056113c | ||
|
|
c48e0821c5 | ||
|
|
259a1774ca | ||
|
|
888d80240d | ||
|
|
45e8a0525c | ||
|
|
f9dbd7bc78 | ||
|
|
274992e50d | ||
|
|
8fe264bbd7 | ||
|
|
36a612af9a | ||
|
|
98e7308597 | ||
|
|
2d22f2aeff | ||
|
|
a9178bd468 | ||
|
|
78e2c12202 | ||
|
|
2d2e60a197 | ||
|
|
3f85b11e12 | ||
|
|
91dd5fe68a | ||
|
|
fe1649a2c1 | ||
|
|
9be897eb6b | ||
|
|
14576f599c | ||
|
|
e119f7f402 | ||
|
|
ad94e9a7d2 | ||
|
|
bc67216f7f | ||
|
|
0814c28998 | ||
|
|
d04a1fcb8f | ||
|
|
c0a72edf9a | ||
|
|
c221bf09f6 | ||
|
|
b32ec5342e | ||
|
|
9e3f2ae9f9 | ||
|
|
dba1acd302 | ||
|
|
f8bf48a522 | ||
|
|
f0158ae505 | ||
|
|
6de83dddd6 | ||
|
|
e2d85d78a7 | ||
|
|
6b4f2d0a91 | ||
|
|
8716f362f8 | ||
|
|
9125b6c251 | ||
|
|
4b71b7aa29 | ||
|
|
c81401ab2d | ||
|
|
c44b299750 | ||
|
|
9ce9147dad | ||
|
|
c1800094d0 | ||
|
|
a6b698d4eb | ||
|
|
51422f4b1e | ||
|
|
f197f6b1eb | ||
|
|
01c8245846 | ||
|
|
b13640e4a1 | ||
|
|
a73ad9b089 | ||
|
|
1ebaf677e0 | ||
|
|
36ef254c73 | ||
|
|
ad7545d149 | ||
|
|
3924a16048 | ||
|
|
0bfd409bdf | ||
|
|
916ff33058 | ||
|
|
30903686bd | ||
|
|
82e1138158 | ||
|
|
ccbb78d4e9 | ||
|
|
5b664f3681 | ||
|
|
77207eaaae | ||
|
|
de83cfd53c | ||
|
|
eb56c2b56e | ||
|
|
bb2faaddc0 | ||
|
|
1c2b5acb2c | ||
|
|
89c095f79e | ||
|
|
dff7636701 | ||
|
|
3b83fa530c | ||
|
|
bca087f111 | ||
|
|
ae647699a4 | ||
|
|
3a67ee6d11 | ||
|
|
c227e3c7b4 | ||
|
|
6a1c52b904 | ||
|
|
7003559c74 | ||
|
|
6b710ff3b3 | ||
|
|
4e8ef7c6ed | ||
|
|
26e1b14020 | ||
|
|
d4123b8fa6 | ||
|
|
dd6bc339bf | ||
|
|
7d5a97137d | ||
|
|
5c6ec587ac | ||
|
|
d7c5630509 | ||
|
|
c1bc6acd26 | ||
|
|
903b243308 | ||
|
|
72cd6d168e | ||
|
|
6c970612bf | ||
|
|
a042cbf885 | ||
|
|
44d56393db | ||
|
|
edd47b12a8 | ||
|
|
6e51b4191e | ||
|
|
8d4d1a3285 | ||
|
|
341557c34e | ||
|
|
af0a6fdf20 | ||
|
|
7f5d7cf7dd | ||
|
|
aac7b0404a | ||
|
|
aad19f1a35 | ||
|
|
872148c35c | ||
|
|
d24babb96e | ||
|
|
9fe863b5d7 | ||
|
|
f1bc06473f | ||
|
|
bab6a63822 | ||
|
|
1bd05d136b | ||
|
|
ec08550fd9 | ||
|
|
6f4ed5f66d | ||
|
|
f852996f97 | ||
|
|
38da8ef86c | ||
|
|
dd7f70d6e8 | ||
|
|
89608ade3b | ||
|
|
f8f89a0946 | ||
|
|
e99928aa44 | ||
|
|
1011fd4891 | ||
|
|
673a1291e1 | ||
|
|
8aa73318c8 | ||
|
|
04a95e3aa8 | ||
|
|
ff68840220 | ||
|
|
f2625b7ff5 | ||
|
|
4440d3edd5 | ||
|
|
efa21b2531 | ||
|
|
2de5d92d3a | ||
|
|
2e320d28d9 | ||
|
|
e58429a044 | ||
|
|
ed5bf3420c | ||
|
|
a7cf34d2eb | ||
|
|
de5016dda8 | ||
|
|
1cf1d616c6 | ||
|
|
c46c019c83 | ||
|
|
a2f747fb0c | ||
|
|
38c39321d0 | ||
|
|
7ab81ef19a | ||
|
|
2e503f7f8c | ||
|
|
3d41629170 | ||
|
|
7959cf39fa | ||
|
|
d48921bfc8 | ||
|
|
04c02d4add | ||
|
|
2c2b3d2f36 | ||
|
|
0e60c5802d | ||
|
|
7adf30e326 | ||
|
|
f9a3315d75 | ||
|
|
c0ca68e2db | ||
|
|
fdc9fbe876 | ||
|
|
18f1ac6c62 | ||
|
|
81ef40fbb7 | ||
|
|
41abe17286 | ||
|
|
a01b4d0566 | ||
|
|
11f00a2e6e | ||
|
|
07f0a107d3 | ||
|
|
30ab6f79ff | ||
|
|
125072a30e | ||
|
|
aec31c43c0 | ||
|
|
83e5832bc1 | ||
|
|
244ca93aa4 | ||
|
|
ff68c047f9 | ||
|
|
b662cb77a4 | ||
|
|
3e2863dca5 | ||
|
|
6e95b0d052 | ||
|
|
da4aa69c89 | ||
|
|
84970e9e9b | ||
|
|
37ac1aa62c | ||
|
|
69b8a4faf1 | ||
|
|
8a6988d381 | ||
|
|
79779b51da | ||
|
|
8b60585004 | ||
|
|
df6a397e52 | ||
|
|
274c6306a8 | ||
|
|
a398c8af2f | ||
|
|
fc82cf1cf2 | ||
|
|
48b1de0b59 | ||
|
|
3edc30d067 | ||
|
|
ff6dc727f5 | ||
|
|
a0d4e4ed3f | ||
|
|
71759e3752 | ||
|
|
79345119c6 | ||
|
|
9af8ceb063 | ||
|
|
f5a0429f0d | ||
|
|
cc22c9d61c | ||
|
|
45f5afd2b7 | ||
|
|
c9acc2912e | ||
|
|
f0604d1e97 | ||
|
|
531c657b64 | ||
|
|
c50ccd4e06 | ||
|
|
184f79ad3f | ||
|
|
e78e810cfe | ||
|
|
c804ef1888 | ||
|
|
037abd7037 | ||
|
|
75f462f0e1 | ||
|
|
9f92449e15 | ||
|
|
a917590862 | ||
|
|
41b92740ea | ||
|
|
d2964576c7 | ||
|
|
9a28ad590c | ||
|
|
15fe6ce23f | ||
|
|
17f90de677 | ||
|
|
631fd755c8 | ||
|
|
9bceb65ad8 | ||
|
|
56ffa7af79 | ||
|
|
f210708f3b | ||
|
|
916cf0ae0d | ||
|
|
e6540229cb | ||
|
|
360f0e8ffd | ||
|
|
038bb1f6bc | ||
|
|
d73bee81ab | ||
|
|
f93187b024 | ||
|
|
49b45ddd18 | ||
|
|
8b7a737ceb | ||
|
|
5b88213f61 | ||
|
|
785df62183 | ||
|
|
1b025f681c | ||
|
|
114a9b041d | ||
|
|
fbd100ef10 | ||
|
|
e458c56139 | ||
|
|
b68b2a907b | ||
|
|
905f9190ae | ||
|
|
aa4f8b6fa7 | ||
|
|
9100e3fb65 | ||
|
|
47527d48ee | ||
|
|
989c217b3f | ||
|
|
1961dcf824 | ||
|
|
4b00eb4a9f | ||
|
|
6cc152e26f | ||
|
|
d403dcf95c | ||
|
|
c0e849b394 | ||
|
|
2e4c2d3ca8 | ||
|
|
1391a2d858 | ||
|
|
ee441b6b9a | ||
|
|
c384df9651 | ||
|
|
6479d6bb6f | ||
|
|
fd029201b0 | ||
|
|
a7c0ba6d28 | ||
|
|
66e9f5a8bf | ||
|
|
10df3ec227 | ||
|
|
9c0fe73102 | ||
|
|
1af1ba6b5f |
176
CHANGELOG.md
176
CHANGELOG.md
@@ -1,3 +1,179 @@
|
|||||||
|
# v2.14.4
|
||||||
|
- [#992](https://github.com/xmrig/xmrig/pull/992) Fixed compilation with Clang 3.5.
|
||||||
|
- [#1012](https://github.com/xmrig/xmrig/pull/1012) Fixed compilation with Clang 9.0.
|
||||||
|
- In HTTP API for unknown hashrate now used `null` instead of `0.0`.
|
||||||
|
- Fixed MSVC 2019 version detection.
|
||||||
|
- Removed obsolete automatic variants.
|
||||||
|
|
||||||
|
# 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
|
||||||
|
- Restored compatibility with https://stellite.hashvault.pro.
|
||||||
|
|
||||||
|
# v2.9.0
|
||||||
|
- [#899](https://github.com/xmrig/xmrig/issues/899) Added support for new algorithm `cn/half` for Masari and Stellite forks.
|
||||||
|
- [#834](https://github.com/xmrig/xmrig/pull/834) Added ASM optimized code for AMD Bulldozer.
|
||||||
|
- [#839](https://github.com/xmrig/xmrig/issues/839) Fixed FreeBSD compile.
|
||||||
|
- [#857](https://github.com/xmrig/xmrig/pull/857) Fixed impossible to build for macOS without clang.
|
||||||
|
|
||||||
|
# v2.8.3
|
||||||
|
- [#813](https://github.com/xmrig/xmrig/issues/813) Fixed critical bug with Minergate pool and variant 2.
|
||||||
|
|
||||||
|
# v2.8.1
|
||||||
|
- [#768](https://github.com/xmrig/xmrig/issues/768) Fixed build with Visual Studio 2015.
|
||||||
|
- [#769](https://github.com/xmrig/xmrig/issues/769) Fixed regression, some ANSI escape sequences was in log with disabled colors.
|
||||||
|
- [#777](https://github.com/xmrig/xmrig/issues/777) Better report about pool connection issues.
|
||||||
|
- Simplified checks for ASM auto detection, only AES support necessary.
|
||||||
|
- Added missing options to `--help` output.
|
||||||
|
|
||||||
|
# v2.8.0
|
||||||
|
- **[#753](https://github.com/xmrig/xmrig/issues/753) Added new algorithm [CryptoNight variant 2](https://github.com/xmrig/xmrig/issues/753) for Monero fork, thanks [@SChernykh](https://github.com/SChernykh).**
|
||||||
|
- Added global and per thread option `"asm"` and and command line equivalent.
|
||||||
|
- **[#758](https://github.com/xmrig/xmrig/issues/758) Added SSL/TLS support for secure connections to pools.**
|
||||||
|
- Added per pool options `"tls"` and `"tls-fingerprint"` and command line equivalents.
|
||||||
|
- [#767](https://github.com/xmrig/xmrig/issues/767) Added config autosave feature, same with GPU miners.
|
||||||
|
- [#245](https://github.com/xmrig/xmrig-proxy/issues/245) Fixed API ID collision when run multiple miners on same machine.
|
||||||
|
- [#757](https://github.com/xmrig/xmrig/issues/757) Fixed send buffer overflow.
|
||||||
|
|
||||||
|
# v2.6.4
|
||||||
|
- [#700](https://github.com/xmrig/xmrig/issues/700) `cryptonight-lite/ipbc` replaced to `cryptonight-heavy/tube` for **Bittube (TUBE)**.
|
||||||
|
- Added `cryptonight/rto` (cryptonight variant 1 with IPBC/TUBE mod) variant for **Arto (RTO)** coin.
|
||||||
|
- Added `cryptonight/xao` (original cryptonight with bigger iteration count) variant for **Alloy (XAO)** coin.
|
||||||
|
- Better variant detection for **nicehash.com** and **minergate.com**.
|
||||||
|
- [#692](https://github.com/xmrig/xmrig/issues/692) Added support for specify both algorithm and variant via single `algo` option.
|
||||||
|
|
||||||
|
# v2.6.3
|
||||||
|
- **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork.
|
||||||
|
- **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork.
|
||||||
|
- Added new detailed hashrate report.
|
||||||
|
- [#446](https://github.com/xmrig/xmrig/issues/446) Likely fixed SIGBUS error on 32 bit ARM CPUs.
|
||||||
|
- [#551](https://github.com/xmrig/xmrig/issues/551) Fixed `cn-heavy` algorithm on ARMv8.
|
||||||
|
- [#614](https://github.com/xmrig/xmrig/issues/614) Fixed display issue with huge pages percentage when colors disabled.
|
||||||
|
- [#615](https://github.com/xmrig/xmrig/issues/615) Fixed build without libcpuid.
|
||||||
|
- [#629](https://github.com/xmrig/xmrig/pull/629) Fixed file logging with non-seekable files.
|
||||||
|
- [#672](https://github.com/xmrig/xmrig/pull/672) Reverted back `cryptonight-light` and exit if no valid algorithm specified.
|
||||||
|
|
||||||
|
# v2.6.2
|
||||||
|
- [#607](https://github.com/xmrig/xmrig/issues/607) Fixed donation bug.
|
||||||
|
- [#610](https://github.com/xmrig/xmrig/issues/610) Fixed ARM build.
|
||||||
|
|
||||||
|
# v2.6.1
|
||||||
|
- [#168](https://github.com/xmrig/xmrig-proxy/issues/168) Added support for [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/blob/dev/doc/STRATUM_EXT.md#1-mining-algorithm-negotiation).
|
||||||
|
- Added IPBC coin support, base algorithm `cn-lite` variant `ipbc`.
|
||||||
|
- [#581](https://github.com/xmrig/xmrig/issues/581) Added support for upcoming Stellite (XTL) fork, base algorithm `cn` variant `xtl`, variant can set now, no need do it after fork.
|
||||||
|
- Added support for **rig-id** stratum protocol extensions, compatible with xmr-stak.
|
||||||
|
- Changed behavior for option `variant=-1` for `cryptonight`, now variant is `1` by default, if you mine old coins need change `variant` to `0`.
|
||||||
|
- A lot of small fixes and better unification with proxy code.
|
||||||
|
|
||||||
|
# v2.6.0-beta3
|
||||||
|
- [#563](https://github.com/xmrig/xmrig/issues/563) **Added [advanced threads mode](https://github.com/xmrig/xmrig/issues/563), now possible configure each thread individually.**
|
||||||
|
- [#255](https://github.com/xmrig/xmrig/issues/563) Low power mode extended to **triple**, **quard** and **penta** modes.
|
||||||
|
- [#519](https://github.com/xmrig/xmrig/issues/519) Fixed high donation levels, improved donation start time randomization.
|
||||||
|
- [#554](https://github.com/xmrig/xmrig/issues/554) Fixed regression with `print-time` option.
|
||||||
|
|
||||||
|
# v2.6.0-beta2
|
||||||
|
- Improved performance for `cryptonight v7` especially in double hash mode.
|
||||||
|
- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 disabled for internal HTTP API by default, was causing issues on some systems.
|
||||||
|
- Added short aliases for algorithm names: `cn`, `cn-lite` and `cn-heavy`.
|
||||||
|
- Fixed regressions (v2.6.0-beta1 affected)
|
||||||
|
- [#494](https://github.com/xmrig/xmrig/issues/494) Command line option `--donate-level` was broken.
|
||||||
|
- [#502](https://github.com/xmrig/xmrig/issues/502) Build without libmicrohttpd was broken.
|
||||||
|
- Fixed nonce calculation for `--av 4` (software AES, double hash) was causing reduction of effective hashrate and rejected shares on nicehash.
|
||||||
|
|
||||||
|
# v2.6.0-beta1
|
||||||
|
- [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.**
|
||||||
|
- HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization.
|
||||||
|
- Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested.
|
||||||
|
- Added API endpoint `PUT /1/config` to update current config.
|
||||||
|
- Added API endpoint `GET /1/config` to get current active config.
|
||||||
|
- Added API endpoint `GET /1/threads` to get current active threads configuration.
|
||||||
|
- API endpoint `GET /` now deprecated, use `GET /1/summary` instead.
|
||||||
|
- Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API.
|
||||||
|
- Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified.
|
||||||
|
|
||||||
|
# v2.5.3
|
||||||
|
- Fixed critical bug, in some cases miner was can't recovery connection and switch to failover pool, version 2.5.2 affected. If you use v2.6.0-beta3 this issue doesn't concern you.
|
||||||
|
- [#499](https://github.com/xmrig/xmrig/issues/499) IPv6 support disabled for internal HTTP API.
|
||||||
|
- Added workaround for nicehash.com if you use `cryptonightv7.<region>.nicehash.com` option `variant=1` will be set automatically.
|
||||||
|
|
||||||
|
# v2.5.2
|
||||||
|
- [#448](https://github.com/xmrig/xmrig/issues/478) Fixed broken reconnect.
|
||||||
|
|
||||||
|
# v2.5.1
|
||||||
|
- [#454](https://github.com/xmrig/xmrig/issues/454) Fixed build with libmicrohttpd version below v0.9.35.
|
||||||
|
- [#456](https://github.com/xmrig/xmrig/issues/459) Verbose errors related to donation pool was not fully silenced.
|
||||||
|
- [#459](https://github.com/xmrig/xmrig/issues/459) Fixed regression (version 2.5.0 affected) with connection to **xmr.f2pool.com**.
|
||||||
|
|
||||||
|
# v2.5.0
|
||||||
|
- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on April 6.**
|
||||||
|
- Added full IPv6 support.
|
||||||
|
- Added protocol extension, when use the miner with xmrig-proxy 2.5+ no more need manually specify `nicehash` option.
|
||||||
|
- [#123](https://github.com/xmrig/xmrig-proxy/issues/123) Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy was parsed incorrectly.
|
||||||
|
- [#428](https://github.com/xmrig/xmrig/issues/428) Fixed regression (version 2.4.5 affected) with CPU cache size detection.
|
||||||
|
|
||||||
|
# v2.4.5
|
||||||
|
- [#324](https://github.com/xmrig/xmrig/pull/324) Fixed build without libmicrohttpd (CMake cache issue).
|
||||||
|
- [#341](https://github.com/xmrig/xmrig/issues/341) Fixed wrong exit code and added command line option `--dry-run`.
|
||||||
|
- [#385](https://github.com/xmrig/xmrig/pull/385) Up to 20% performance increase for non-AES CPU and fixed Intel Core 2 cache detection.
|
||||||
|
|
||||||
|
# v2.4.4
|
||||||
|
- Added libmicrohttpd version to --version output.
|
||||||
|
- Fixed bug in singal handler, in some cases miner wasn't shutdown properly.
|
||||||
|
- Fixed recent MSVC 2017 version detection.
|
||||||
|
- [#279](https://github.com/xmrig/xmrig/pull/279) Fixed build on some macOS versions.
|
||||||
|
|
||||||
|
# v2.4.3
|
||||||
|
- [#94](https://github.com/xmrig/xmrig/issues/94#issuecomment-342019257) [#216](https://github.com/xmrig/xmrig/issues/216) Added **ARMv8** and **ARMv7** support. Hardware AES supported, thanks [Imran Yusuff](https://github.com/imranyusuff).
|
||||||
|
- [#157](https://github.com/xmrig/xmrig/issues/157) [#196](https://github.com/xmrig/xmrig/issues/196) Fixed Linux compile issues.
|
||||||
|
- [#184](https://github.com/xmrig/xmrig/issues/184) Fixed cache size detection for CPUs with disabled Hyper-Threading.
|
||||||
|
- [#200](https://github.com/xmrig/xmrig/issues/200) In some cases miner was doesn't write log to stdout.
|
||||||
|
|
||||||
|
# v2.4.2
|
||||||
|
- [#60](https://github.com/xmrig/xmrig/issues/60) Added FreeBSD support, thanks [vcambur](https://github.com/vcambur).
|
||||||
|
- [#153](https://github.com/xmrig/xmrig/issues/153) Fixed issues with dwarfpool.com.
|
||||||
|
|
||||||
# v2.4.1
|
# v2.4.1
|
||||||
- [#147](https://github.com/xmrig/xmrig/issues/147) Fixed comparability with monero-stratum.
|
- [#147](https://github.com/xmrig/xmrig/issues/147) Fixed comparability with monero-stratum.
|
||||||
|
|
||||||
|
|||||||
291
CMakeLists.txt
291
CMakeLists.txt
@@ -1,50 +1,86 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
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_HTTPD "HTTP REST API" ON)
|
option(WITH_SUMO "CryptoNight-Heavy support" ON)
|
||||||
|
option(WITH_CN_PICO "CryptoNight-Pico support" ON)
|
||||||
|
option(WITH_CN_GPU "CryptoNight-GPU support" ON)
|
||||||
|
option(WITH_HTTPD "HTTP REST API" ON)
|
||||||
|
option(WITH_DEBUG_LOG "Enable debug log output" 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)
|
||||||
|
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
src/3rdparty/align.h
|
|
||||||
src/api/Api.h
|
|
||||||
src/api/ApiState.h
|
|
||||||
src/api/NetworkState.h
|
src/api/NetworkState.h
|
||||||
src/App.h
|
src/App.h
|
||||||
src/Console.h
|
src/base/io/Json.h
|
||||||
src/Cpu.h
|
src/base/io/Watcher.h
|
||||||
src/interfaces/IClientListener.h
|
src/base/kernel/interfaces/IConfigListener.h
|
||||||
src/interfaces/IConsoleListener.h
|
src/base/kernel/interfaces/ISignalListener.h
|
||||||
|
src/base/kernel/interfaces/IWatcherListener.h
|
||||||
|
src/base/kernel/Entry.h
|
||||||
|
src/base/kernel/Process.h
|
||||||
|
src/base/kernel/Signals.h
|
||||||
|
src/base/net/Pool.h
|
||||||
|
src/base/net/Pools.h
|
||||||
|
src/base/tools/Arguments.h
|
||||||
|
src/base/tools/Handle.h
|
||||||
|
src/base/tools/String.h
|
||||||
|
src/common/config/CommonConfig.h
|
||||||
|
src/common/config/ConfigLoader.h
|
||||||
|
src/common/config/ConfigWatcher.h
|
||||||
|
src/common/Console.h
|
||||||
|
src/common/cpu/Cpu.h
|
||||||
|
src/common/crypto/Algorithm.h
|
||||||
|
src/common/crypto/keccak.h
|
||||||
|
src/common/interfaces/IClientListener.h
|
||||||
|
src/common/interfaces/IConfig.h
|
||||||
|
src/common/interfaces/IConfigCreator.h
|
||||||
|
src/common/interfaces/IConsoleListener.h
|
||||||
|
src/common/interfaces/IControllerListener.h
|
||||||
|
src/common/interfaces/ICpuInfo.h
|
||||||
|
src/common/interfaces/ILogBackend.h
|
||||||
|
src/common/interfaces/IStrategy.h
|
||||||
|
src/common/interfaces/IStrategyListener.h
|
||||||
|
src/common/log/BasicLog.h
|
||||||
|
src/common/log/ConsoleLog.h
|
||||||
|
src/common/log/FileLog.h
|
||||||
|
src/common/log/Log.h
|
||||||
|
src/common/net/Client.h
|
||||||
|
src/common/net/Id.h
|
||||||
|
src/common/net/Job.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/utils/c_str.h
|
||||||
|
src/common/utils/mm_malloc.h
|
||||||
|
src/common/xmrig.h
|
||||||
|
src/core/ConfigLoader_platform.h
|
||||||
|
src/core/ConfigLoader_default.h
|
||||||
|
src/core/Controller.h
|
||||||
src/interfaces/IJobResultListener.h
|
src/interfaces/IJobResultListener.h
|
||||||
src/interfaces/ILogBackend.h
|
src/interfaces/IThread.h
|
||||||
src/interfaces/IStrategy.h
|
|
||||||
src/interfaces/IStrategyListener.h
|
|
||||||
src/interfaces/IWorker.h
|
src/interfaces/IWorker.h
|
||||||
src/log/ConsoleLog.h
|
|
||||||
src/log/FileLog.h
|
|
||||||
src/log/Log.h
|
|
||||||
src/Mem.h
|
src/Mem.h
|
||||||
src/net/Client.h
|
|
||||||
src/net/Job.h
|
|
||||||
src/net/JobId.h
|
|
||||||
src/net/JobResult.h
|
src/net/JobResult.h
|
||||||
src/net/Network.h
|
src/net/Network.h
|
||||||
src/net/strategies/DonateStrategy.h
|
src/net/strategies/DonateStrategy.h
|
||||||
src/net/strategies/FailoverStrategy.h
|
|
||||||
src/net/strategies/SinglePoolStrategy.h
|
|
||||||
src/net/SubmitResult.h
|
|
||||||
src/net/Url.h
|
|
||||||
src/Options.h
|
|
||||||
src/Platform.h
|
|
||||||
src/Summary.h
|
src/Summary.h
|
||||||
src/version.h
|
src/version.h
|
||||||
src/workers/DoubleWorker.h
|
src/workers/CpuThread.h
|
||||||
src/workers/Handle.h
|
src/workers/Handle.h
|
||||||
src/workers/Hashrate.h
|
src/workers/Hashrate.h
|
||||||
src/workers/SingleWorker.h
|
src/workers/MultiWorker.h
|
||||||
src/workers/Worker.h
|
src/workers/Worker.h
|
||||||
src/workers/Workers.h
|
src/workers/Workers.h
|
||||||
)
|
)
|
||||||
@@ -53,64 +89,82 @@ set(HEADERS_CRYPTO
|
|||||||
src/crypto/c_blake256.h
|
src/crypto/c_blake256.h
|
||||||
src/crypto/c_groestl.h
|
src/crypto/c_groestl.h
|
||||||
src/crypto/c_jh.h
|
src/crypto/c_jh.h
|
||||||
src/crypto/c_keccak.h
|
|
||||||
src/crypto/c_skein.h
|
src/crypto/c_skein.h
|
||||||
src/crypto/CryptoNight.h
|
src/crypto/CryptoNight.h
|
||||||
src/crypto/CryptoNight_p.h
|
src/crypto/CryptoNight_constants.h
|
||||||
|
src/crypto/CryptoNight_monero.h
|
||||||
src/crypto/CryptoNight_test.h
|
src/crypto/CryptoNight_test.h
|
||||||
src/crypto/groestl_tables.h
|
src/crypto/groestl_tables.h
|
||||||
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/asm/CryptonightR_template.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (XMRIG_ARM)
|
||||||
|
set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_arm.h)
|
||||||
|
else()
|
||||||
|
set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_x86.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/api/Api.cpp
|
|
||||||
src/api/ApiState.cpp
|
|
||||||
src/api/NetworkState.cpp
|
src/api/NetworkState.cpp
|
||||||
src/App.cpp
|
src/App.cpp
|
||||||
src/Console.cpp
|
src/base/io/Json.cpp
|
||||||
src/log/ConsoleLog.cpp
|
src/base/io/Watcher.cpp
|
||||||
src/log/FileLog.cpp
|
src/base/kernel/Entry.cpp
|
||||||
src/log/Log.cpp
|
src/base/kernel/Process.cpp
|
||||||
|
src/base/kernel/Signals.cpp
|
||||||
|
src/base/net/Pool.cpp
|
||||||
|
src/base/net/Pools.cpp
|
||||||
|
src/base/tools/Arguments.cpp
|
||||||
|
src/base/tools/Handle.cpp
|
||||||
|
src/base/tools/String.cpp
|
||||||
|
src/common/config/CommonConfig.cpp
|
||||||
|
src/common/config/ConfigLoader.cpp
|
||||||
|
src/common/config/ConfigWatcher.cpp
|
||||||
|
src/common/Console.cpp
|
||||||
|
src/common/crypto/Algorithm.cpp
|
||||||
|
src/common/crypto/keccak.cpp
|
||||||
|
src/common/log/BasicLog.cpp
|
||||||
|
src/common/log/ConsoleLog.cpp
|
||||||
|
src/common/log/FileLog.cpp
|
||||||
|
src/common/log/Log.cpp
|
||||||
|
src/common/net/Client.cpp
|
||||||
|
src/common/net/Job.cpp
|
||||||
|
src/common/net/strategies/FailoverStrategy.cpp
|
||||||
|
src/common/net/strategies/SinglePoolStrategy.cpp
|
||||||
|
src/common/net/SubmitResult.cpp
|
||||||
|
src/common/Platform.cpp
|
||||||
|
src/core/Config.cpp
|
||||||
|
src/core/Controller.cpp
|
||||||
src/Mem.cpp
|
src/Mem.cpp
|
||||||
src/net/Client.cpp
|
|
||||||
src/net/Job.cpp
|
|
||||||
src/net/Network.cpp
|
src/net/Network.cpp
|
||||||
src/net/strategies/DonateStrategy.cpp
|
src/net/strategies/DonateStrategy.cpp
|
||||||
src/net/strategies/FailoverStrategy.cpp
|
|
||||||
src/net/strategies/SinglePoolStrategy.cpp
|
|
||||||
src/net/SubmitResult.cpp
|
|
||||||
src/net/Url.cpp
|
|
||||||
src/Options.cpp
|
|
||||||
src/Platform.cpp
|
|
||||||
src/Summary.cpp
|
src/Summary.cpp
|
||||||
src/workers/DoubleWorker.cpp
|
src/workers/CpuThread.cpp
|
||||||
src/workers/Handle.cpp
|
src/workers/Handle.cpp
|
||||||
src/workers/Hashrate.cpp
|
src/workers/Hashrate.cpp
|
||||||
src/workers/SingleWorker.cpp
|
src/workers/MultiWorker.cpp
|
||||||
src/workers/Worker.cpp
|
src/workers/Worker.cpp
|
||||||
src/workers/Workers.cpp
|
src/workers/Workers.cpp
|
||||||
src/xmrig.cpp
|
src/xmrig.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES_CRYPTO
|
set(SOURCES_CRYPTO
|
||||||
src/crypto/c_keccak.c
|
|
||||||
src/crypto/c_groestl.c
|
src/crypto/c_groestl.c
|
||||||
src/crypto/c_blake256.c
|
src/crypto/c_blake256.c
|
||||||
src/crypto/c_jh.c
|
src/crypto/c_jh.c
|
||||||
src/crypto/c_skein.c
|
src/crypto/c_skein.c
|
||||||
src/crypto/soft_aes.c
|
|
||||||
src/crypto/soft_aes.c
|
|
||||||
src/crypto/CryptoNight.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
set(SOURCES_OS
|
set(SOURCES_OS
|
||||||
res/app.rc
|
res/app.rc
|
||||||
src/App_win.cpp
|
src/App_win.cpp
|
||||||
src/Cpu_win.cpp
|
src/base/io/Json_win.cpp
|
||||||
|
src/common/Platform_win.cpp
|
||||||
src/Mem_win.cpp
|
src/Mem_win.cpp
|
||||||
src/Platform_win.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions(/DWIN32)
|
add_definitions(/DWIN32)
|
||||||
@@ -118,112 +172,111 @@ if (WIN32)
|
|||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
set(SOURCES_OS
|
set(SOURCES_OS
|
||||||
src/App_unix.cpp
|
src/App_unix.cpp
|
||||||
src/Cpu_mac.cpp
|
src/base/io/Json_unix.cpp
|
||||||
|
src/common/Platform_mac.cpp
|
||||||
src/Mem_unix.cpp
|
src/Mem_unix.cpp
|
||||||
src/Platform_mac.cpp
|
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set(SOURCES_OS
|
set(SOURCES_OS
|
||||||
src/App_unix.cpp
|
src/App_unix.cpp
|
||||||
src/Cpu_unix.cpp
|
src/base/io/Json_unix.cpp
|
||||||
|
src/common/Platform_unix.cpp
|
||||||
src/Mem_unix.cpp
|
src/Mem_unix.cpp
|
||||||
src/Platform_unix.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(EXTRA_LIBS pthread)
|
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
|
||||||
|
set(EXTRA_LIBS kvm pthread)
|
||||||
|
else()
|
||||||
|
set(EXTRA_LIBS pthread rt dl)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||||
|
EXECUTE_PROCESS(COMMAND uname -o COMMAND tr -d '\n' OUTPUT_VARIABLE OPERATING_SYSTEM)
|
||||||
|
if (OPERATING_SYSTEM MATCHES "Android")
|
||||||
|
set(EXTRA_LIBS ${EXTRA_LIBS} log)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(/D__STDC_FORMAT_MACROS)
|
add_definitions(/D__STDC_FORMAT_MACROS)
|
||||||
add_definitions(/DUNICODE)
|
add_definitions(/DUNICODE)
|
||||||
add_definitions(/DRAPIDJSON_SSE2)
|
|
||||||
#add_definitions(/DAPP_DEBUG)
|
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
find_package(UV REQUIRED)
|
find_package(UV REQUIRED)
|
||||||
|
|
||||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
include(cmake/flags.cmake)
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
|
|
||||||
|
|
||||||
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wall -Wno-strict-aliasing")
|
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall -fno-exceptions -fno-rtti")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
|
|
||||||
|
|
||||||
if (WIN32)
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
|
||||||
else()
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_definitions(/D_GNU_SOURCE)
|
|
||||||
|
|
||||||
if (${CMAKE_VERSION} VERSION_LESS "3.1.0")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-2")
|
|
||||||
|
|
||||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL")
|
|
||||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
|
||||||
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)
|
|
||||||
add_definitions(/DNOMINMAX)
|
|
||||||
|
|
||||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wall")
|
|
||||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall -fno-exceptions -fno-rtti -Wno-missing-braces")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (WITH_LIBCPUID)
|
if (WITH_LIBCPUID)
|
||||||
add_subdirectory(src/3rdparty/libcpuid)
|
add_subdirectory(src/3rdparty/libcpuid)
|
||||||
|
|
||||||
include_directories(src/3rdparty/libcpuid)
|
include_directories(src/3rdparty/libcpuid)
|
||||||
set(CPUID_LIB cpuid)
|
set(CPUID_LIB cpuid)
|
||||||
set(SOURCES_CPUID src/Cpu.cpp)
|
set(SOURCES_CPUID src/core/cpu/AdvancedCpuInfo.h src/core/cpu/AdvancedCpuInfo.cpp src/core/cpu/Cpu.cpp)
|
||||||
else()
|
else()
|
||||||
add_definitions(/DXMRIG_NO_LIBCPUID)
|
add_definitions(/DXMRIG_NO_LIBCPUID)
|
||||||
set(SOURCES_CPUID src/Cpu_stub.cpp)
|
set(SOURCES_CPUID src/common/cpu/BasicCpuInfo.h src/common/cpu/Cpu.cpp)
|
||||||
|
|
||||||
|
if (XMRIG_ARM)
|
||||||
|
set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo_arm.cpp)
|
||||||
|
else()
|
||||||
|
set(SOURCES_CPUID ${SOURCES_CPUID} src/common/cpu/BasicCpuInfo.cpp)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include(cmake/OpenSSL.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)
|
||||||
add_definitions(/DHAVE_SYSLOG_H)
|
add_definitions(/DHAVE_SYSLOG_H)
|
||||||
set(SOURCES_SYSLOG src/log/SysLog.h src/log/SysLog.cpp)
|
set(SOURCES_SYSLOG src/common/log/SysLog.h src/common/log/SysLog.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT WITH_AEON)
|
if (NOT WITH_AEON)
|
||||||
add_definitions(/DXMRIG_NO_AEON)
|
add_definitions(/DXMRIG_NO_AEON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT WITH_SUMO)
|
||||||
|
add_definitions(/DXMRIG_NO_SUMO)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT WITH_IPBC)
|
||||||
|
add_definitions(/DXMRIG_NO_IPBC)
|
||||||
|
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)
|
||||||
|
|
||||||
if (MHD_FOUND)
|
if (MHD_FOUND)
|
||||||
include_directories(${MHD_INCLUDE_DIRS})
|
include_directories(${MHD_INCLUDE_DIRS})
|
||||||
set(HTTPD_SOURCES src/api/Httpd.h src/api/Httpd.cpp)
|
set(HTTPD_SOURCES
|
||||||
|
src/api/Api.h
|
||||||
|
src/api/ApiRouter.h
|
||||||
|
src/common/api/HttpBody.h
|
||||||
|
src/common/api/Httpd.h
|
||||||
|
src/common/api/HttpReply.h
|
||||||
|
src/common/api/HttpRequest.h
|
||||||
|
src/api/Api.cpp
|
||||||
|
src/api/ApiRouter.cpp
|
||||||
|
src/common/api/Httpd.cpp
|
||||||
|
src/common/api/HttpRequest.cpp
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_HTTPD=OFF` to build without http deamon support")
|
message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_HTTPD=OFF` to build without http deamon support")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
set(HTTPD_SOURCES "")
|
||||||
|
set(MHD_LIBRARY "")
|
||||||
add_definitions(/DXMRIG_NO_HTTPD)
|
add_definitions(/DXMRIG_NO_HTTPD)
|
||||||
add_definitions(/DXMRIG_NO_API)
|
add_definitions(/DXMRIG_NO_API)
|
||||||
endif()
|
endif()
|
||||||
@@ -232,5 +285,13 @@ include_directories(src)
|
|||||||
include_directories(src/3rdparty)
|
include_directories(src/3rdparty)
|
||||||
include_directories(${UV_INCLUDE_DIR})
|
include_directories(${UV_INCLUDE_DIR})
|
||||||
|
|
||||||
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES})
|
if (BUILD_STATIC)
|
||||||
target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
set(CMAKE_EXE_LINKER_FLAGS " -static")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (WITH_DEBUG_LOG)
|
||||||
|
add_definitions(/DAPP_DEBUG)
|
||||||
|
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} ${CN_GPU_SOURCES})
|
||||||
|
target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||||
|
|||||||
125
README.md
125
README.md
@@ -1,11 +1,19 @@
|
|||||||
# XMRig
|
# XMRig
|
||||||
XMRig is high performance Monero (XMR) CPU miner, with the official full Windows support.
|
|
||||||
Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 complete rewritten from scratch on C++.
|
|
||||||
|
|
||||||
* This is the CPU-mining version, there is also a [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia).
|
[](https://github.com/xmrig/xmrig/releases)
|
||||||
|
[](https://github.com/xmrig/xmrig/releases)
|
||||||
|
[](https://github.com/xmrig/xmrig/releases)
|
||||||
|
[](https://github.com/xmrig/xmrig/blob/master/LICENSE)
|
||||||
|
[](https://github.com/xmrig/xmrig/stargazers)
|
||||||
|
[](https://github.com/xmrig/xmrig/network)
|
||||||
|
|
||||||
|
XMRig is a high performance Monero (XMR) CPU miner, with official support for Windows.
|
||||||
|
Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 completely rewritten from scratch on C++.
|
||||||
|
|
||||||
|
* This is the **CPU-mining** version, there is also a [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia) and [AMD GPU version]( https://github.com/xmrig/xmrig-amd).
|
||||||
* [Roadmap](https://github.com/xmrig/xmrig/issues/106) for next releases.
|
* [Roadmap](https://github.com/xmrig/xmrig/issues/106) for next releases.
|
||||||
|
|
||||||
<img src="http://i.imgur.com/OKZRVDh.png" width="619" >
|
<img src="http://i.imgur.com/Ymumes5.png" width="670" >
|
||||||
|
|
||||||
#### Table of contents
|
#### Table of contents
|
||||||
* [Features](#features)
|
* [Features](#features)
|
||||||
@@ -16,6 +24,7 @@ Originally based on cpuminer-multi with heavy optimizations/rewrites and removin
|
|||||||
* [Common Issues](#common-issues)
|
* [Common Issues](#common-issues)
|
||||||
* [Other information](#other-information)
|
* [Other information](#other-information)
|
||||||
* [Donations](#donations)
|
* [Donations](#donations)
|
||||||
|
* [Release checksums](#release-checksums)
|
||||||
* [Contacts](#contacts)
|
* [Contacts](#contacts)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -37,64 +46,81 @@ Originally based on cpuminer-multi with heavy optimizations/rewrites and removin
|
|||||||
* Clone with `git clone https://github.com/xmrig/xmrig.git` :hammer: [Build instructions](https://github.com/xmrig/xmrig/wiki/Build).
|
* Clone with `git clone https://github.com/xmrig/xmrig.git` :hammer: [Build instructions](https://github.com/xmrig/xmrig/wiki/Build).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
### Basic example
|
Use [config.xmrig.com](https://config.xmrig.com/xmrig) to generate, edit or share configurations.
|
||||||
```
|
|
||||||
xmrig.exe -o pool.minemonero.pro:5555 -u YOUR_WALLET -p x -k
|
|
||||||
```
|
|
||||||
|
|
||||||
### Failover
|
|
||||||
```
|
|
||||||
xmrig.exe -o pool.minemonero.pro:5555 -u YOUR_WALLET1 -p x -k -o pool.supportxmr.com:5555 -u YOUR_WALLET2 -p x -k
|
|
||||||
```
|
|
||||||
For failover you can add multiple pools, maximum count not limited.
|
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
```
|
```
|
||||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite
|
-a, --algo=ALGO specify the algorithm to use
|
||||||
-o, --url=URL URL of mining server
|
cryptonight
|
||||||
-O, --userpass=U:P username:password pair for mining server
|
cryptonight-lite
|
||||||
-u, --user=USERNAME username for mining server
|
cryptonight-heavy
|
||||||
-p, --pass=PASSWORD password for mining server
|
-o, --url=URL URL of mining server
|
||||||
-t, --threads=N number of miner threads
|
-O, --userpass=U:P username:password pair for mining server
|
||||||
-v, --av=N algorithm variation, 0 auto select
|
-u, --user=USERNAME username for mining server
|
||||||
-k, --keepalive send keepalived for prevent timeout (need pool support)
|
-p, --pass=PASSWORD password for mining server
|
||||||
-r, --retries=N number of times to retry before switch to backup server (default: 5)
|
--rig-id=ID rig identifier for pool-side statistics (needs pool support)
|
||||||
-R, --retry-pause=N time to pause between retries (default: 5)
|
-t, --threads=N number of miner threads
|
||||||
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1
|
-v, --av=N algorithm variation, 0 auto select
|
||||||
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)
|
-k, --keepalive send keepalived packet for prevent timeout (needs pool support)
|
||||||
--no-huge-pages disable huge pages support
|
--nicehash enable nicehash.com support
|
||||||
--no-color disable colored output
|
--tls enable SSL/TLS support (needs pool support)
|
||||||
--donate-level=N donate level, default 5% (5 minutes in 100 minutes)
|
--tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning
|
||||||
--user-agent set custom user-agent string for pool
|
-r, --retries=N number of times to retry before switch to backup server (default: 5)
|
||||||
-B, --background run the miner in the background
|
-R, --retry-pause=N time to pause between retries (default: 5)
|
||||||
-c, --config=FILE load a JSON-format configuration file
|
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1
|
||||||
-l, --log-file=FILE log all output to a file
|
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)
|
||||||
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)
|
--no-huge-pages disable huge pages support
|
||||||
--safe safe adjust threads and av settings for current CPU
|
--no-color disable colored output
|
||||||
--nicehash enable nicehash support
|
--variant algorithm PoW variant
|
||||||
--print-time=N print hashrate report every N seconds
|
--donate-level=N donate level, default 5% (5 minutes in 100 minutes)
|
||||||
-h, --help display this help and exit
|
--user-agent set custom user-agent string for pool
|
||||||
-V, --version output version information and exit
|
-B, --background run the miner in the background
|
||||||
|
-c, --config=FILE load a JSON-format configuration file
|
||||||
|
-l, --log-file=FILE log all output to a file
|
||||||
|
-S, --syslog use system log for output messages
|
||||||
|
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)
|
||||||
|
--safe safe adjust threads and av settings for current CPU
|
||||||
|
--asm=ASM ASM code for cn/2, possible values: auto, none, intel, ryzen.
|
||||||
|
--print-time=N print hashrate report every N seconds
|
||||||
|
--api-port=N port for the miner API
|
||||||
|
--api-access-token=T access token for API
|
||||||
|
--api-worker-id=ID custom worker-id for API
|
||||||
|
--api-id=ID custom instance ID for API
|
||||||
|
--api-ipv6 enable IPv6 support for API
|
||||||
|
--api-no-restricted enable full remote access (only if API token set)
|
||||||
|
--dry-run test configuration and exit
|
||||||
|
-h, --help display this help and exit
|
||||||
|
-V, --version output version information and exit
|
||||||
```
|
```
|
||||||
|
|
||||||
Also you can use configuration via config file, default **config.json**. You can load multiple config files and combine it with command line options.
|
Also you can use configuration via config file, default name **config.json**. Some options available only via config file: [`autosave`](https://github.com/xmrig/xmrig/issues/767), [`hw-aes`](https://github.com/xmrig/xmrig/issues/563). `watch` option currently not implemented in miners only in proxy.
|
||||||
|
|
||||||
## Algorithm variations
|
## Algorithm variations
|
||||||
Since version 0.8.0.
|
|
||||||
* `--av=1` For CPUs with hardware AES.
|
- `av` option used for automatic and simple threads mode (when you specify only threads count).
|
||||||
* `--av=2` Lower power mode (double hash) of `1`.
|
- For [advanced threads mode](https://github.com/xmrig/xmrig/issues/563) each thread configured individually and `av` option not used.
|
||||||
* `--av=3` Software AES implementation.
|
|
||||||
* `--av=4` Lower power mode (double hash) of `3`.
|
| av | Hashes per round | Hardware AES |
|
||||||
|
|----|------------------|--------------|
|
||||||
|
| 1 | 1 (Single) | yes |
|
||||||
|
| 2 | 2 (Double) | yes |
|
||||||
|
| 3 | 1 (Single) | no |
|
||||||
|
| 4 | 2 (Double) | no |
|
||||||
|
| 5 | 3 (Triple) | yes |
|
||||||
|
| 6 | 4 (Quard) | yes |
|
||||||
|
| 7 | 5 (Penta) | yes |
|
||||||
|
| 8 | 3 (Triple) | no |
|
||||||
|
| 9 | 4 (Quard) | no |
|
||||||
|
| 10 | 5 (Penta) | no |
|
||||||
|
|
||||||
## Common Issues
|
## Common Issues
|
||||||
### HUGE PAGES unavailable
|
### HUGE PAGES unavailable
|
||||||
* Run XMRig as Administrator.
|
* Run XMRig as Administrator.
|
||||||
* Since version 0.8.0 XMRig automatically enable SeLockMemoryPrivilege for current user, but reboot or sign out still required. [Manual instruction](https://msdn.microsoft.com/en-gb/library/ms190730.aspx).
|
* Since version 0.8.0 XMRig automatically enables SeLockMemoryPrivilege for current user, but reboot or sign out still required. [Manual instruction](https://msdn.microsoft.com/en-gb/library/ms190730.aspx).
|
||||||
|
|
||||||
## Other information
|
## Other information
|
||||||
* No HTTP support, only stratum protocol support.
|
* No HTTP support, only stratum protocol support.
|
||||||
* No TLS support.
|
* Default donation 5% (5 minutes in 100 minutes) can be reduced to 1% via option `donate-level`.
|
||||||
* Default donation 5% (5 minutes in 100 minutes) can be reduced to 1% via command line option `--donate-level`.
|
|
||||||
|
|
||||||
|
|
||||||
### CPU mining performance
|
### CPU mining performance
|
||||||
@@ -106,7 +132,7 @@ Please note performance is highly dependent on system load. The numbers above ar
|
|||||||
### Maximum performance checklist
|
### Maximum performance checklist
|
||||||
* Idle operating system.
|
* Idle operating system.
|
||||||
* Do not exceed optimal thread count.
|
* Do not exceed optimal thread count.
|
||||||
* Use modern CPUs with AES-NI instructuon set.
|
* Use modern CPUs with AES-NI instruction set.
|
||||||
* Try setup optimal cpu affinity.
|
* Try setup optimal cpu affinity.
|
||||||
* Enable fast memory (Large/Huge pages).
|
* Enable fast memory (Large/Huge pages).
|
||||||
|
|
||||||
@@ -117,3 +143,4 @@ Please note performance is highly dependent on system load. The numbers above ar
|
|||||||
## Contacts
|
## Contacts
|
||||||
* support@xmrig.com
|
* support@xmrig.com
|
||||||
* [reddit](https://www.reddit.com/user/XMRig/)
|
* [reddit](https://www.reddit.com/user/XMRig/)
|
||||||
|
* [twitter](https://twitter.com/xmrig_dev)
|
||||||
|
|||||||
@@ -8,15 +8,25 @@
|
|||||||
find_path(
|
find_path(
|
||||||
MHD_INCLUDE_DIR
|
MHD_INCLUDE_DIR
|
||||||
NAMES microhttpd.h
|
NAMES microhttpd.h
|
||||||
|
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
|
||||||
|
PATH_SUFFIXES "include"
|
||||||
DOC "microhttpd include dir"
|
DOC "microhttpd include dir"
|
||||||
|
NO_DEFAULT_PATH
|
||||||
)
|
)
|
||||||
|
|
||||||
|
find_path(MHD_INCLUDE_DIR NAMES microhttpd.h)
|
||||||
|
|
||||||
find_library(
|
find_library(
|
||||||
MHD_LIBRARY
|
MHD_LIBRARY
|
||||||
NAMES microhttpd microhttpd-10 libmicrohttpd libmicrohttpd-dll
|
NAMES libmicrohttpd.a microhttpd libmicrohttpd
|
||||||
|
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
|
||||||
|
PATH_SUFFIXES "lib"
|
||||||
DOC "microhttpd library"
|
DOC "microhttpd library"
|
||||||
|
NO_DEFAULT_PATH
|
||||||
)
|
)
|
||||||
|
|
||||||
|
find_library(MHD_LIBRARY NAMES microhttpd libmicrohttpd)
|
||||||
|
|
||||||
set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR})
|
set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR})
|
||||||
set(MHD_LIBRARIES ${MHD_LIBRARY})
|
set(MHD_LIBRARIES ${MHD_LIBRARY})
|
||||||
|
|
||||||
@@ -34,6 +44,6 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(mhd DEFAULT_MSG MHD_INCLUDE_DIR MHD_LIBRARY)
|
find_package_handle_standard_args(MHD DEFAULT_MSG MHD_LIBRARY MHD_INCLUDE_DIR)
|
||||||
mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY)
|
mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
|
find_path(
|
||||||
|
UV_INCLUDE_DIR
|
||||||
|
NAMES uv.h
|
||||||
|
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
|
||||||
|
PATH_SUFFIXES "include"
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
find_path(UV_INCLUDE_DIR NAMES uv.h)
|
find_path(UV_INCLUDE_DIR NAMES uv.h)
|
||||||
find_library(UV_LIBRARY NAMES uv libuv)
|
|
||||||
|
find_library(
|
||||||
|
UV_LIBRARY
|
||||||
|
NAMES libuv.a uv libuv
|
||||||
|
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
|
||||||
|
PATH_SUFFIXES "lib"
|
||||||
|
NO_DEFAULT_PATH
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(UV_LIBRARY NAMES libuv.a uv libuv)
|
||||||
|
|
||||||
set(UV_LIBRARIES ${UV_LIBRARY})
|
set(UV_LIBRARIES ${UV_LIBRARY})
|
||||||
set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR})
|
set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR})
|
||||||
|
|||||||
25
cmake/OpenSSL.cmake
Normal file
25
cmake/OpenSSL.cmake
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
if (WITH_TLS)
|
||||||
|
set(OPENSSL_ROOT_DIR ${XMRIG_DEPS})
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
set(OPENSSL_USE_STATIC_LIBS TRUE)
|
||||||
|
set(OPENSSL_MSVC_STATIC_RT TRUE)
|
||||||
|
|
||||||
|
set(EXTRA_LIBS ${EXTRA_LIBS} Crypt32)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(OpenSSL)
|
||||||
|
|
||||||
|
if (OPENSSL_FOUND)
|
||||||
|
set(TLS_SOURCES src/common/net/Tls.h src/common/net/Tls.cpp)
|
||||||
|
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "OpenSSL NOT found: use `-DWITH_TLS=OFF` to build without TLS support")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(TLS_SOURCES "")
|
||||||
|
set(OPENSSL_LIBRARIES "")
|
||||||
|
add_definitions(/DXMRIG_NO_TLS)
|
||||||
|
|
||||||
|
set(CMAKE_PROJECT_NAME "${CMAKE_PROJECT_NAME}-notls")
|
||||||
|
endif()
|
||||||
45
cmake/asm.cmake
Normal file
45
cmake/asm.cmake
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
|
set(XMRIG_ASM_LIBRARY "xmrig-asm")
|
||||||
|
|
||||||
|
if (CMAKE_C_COMPILER_ID MATCHES MSVC)
|
||||||
|
enable_language(ASM_MASM)
|
||||||
|
|
||||||
|
if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141)
|
||||||
|
set(XMRIG_ASM_FILES
|
||||||
|
"src/crypto/asm/cn_main_loop.asm"
|
||||||
|
"src/crypto/asm/CryptonightR_template.asm"
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(XMRIG_ASM_FILES
|
||||||
|
"src/crypto/asm/win64/cn_main_loop.asm"
|
||||||
|
"src/crypto/asm/win64/CryptonightR_template.asm"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY ASM_MASM)
|
||||||
|
else()
|
||||||
|
enable_language(ASM)
|
||||||
|
|
||||||
|
if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU)
|
||||||
|
set(XMRIG_ASM_FILES
|
||||||
|
"src/crypto/asm/win64/cn_main_loop.S"
|
||||||
|
"src/crypto/asm/CryptonightR_template.S"
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(XMRIG_ASM_FILES
|
||||||
|
"src/crypto/asm/cn_main_loop.S"
|
||||||
|
"src/crypto/asm/CryptonightR_template.S"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY C)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES})
|
||||||
|
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)
|
||||||
|
else()
|
||||||
|
set(XMRIG_ASM_SOURCES "")
|
||||||
|
set(XMRIG_ASM_LIBRARY "")
|
||||||
|
add_definitions(/DXMRIG_NO_ASM)
|
||||||
|
endif()
|
||||||
23
cmake/cn-gpu.cmake
Normal file
23
cmake/cn-gpu.cmake
Normal 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()
|
||||||
43
cmake/cpu.cmake
Normal file
43
cmake/cpu.cmake
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
if (NOT CMAKE_SYSTEM_PROCESSOR)
|
||||||
|
message(WARNING "CMAKE_SYSTEM_PROCESSOR not defined")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
|
||||||
|
add_definitions(/DRAPIDJSON_SSE2)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT ARM_TARGET)
|
||||||
|
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv8-a)$")
|
||||||
|
set(ARM_TARGET 8)
|
||||||
|
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$")
|
||||||
|
set(ARM_TARGET 7)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (ARM_TARGET AND ARM_TARGET GREATER 6)
|
||||||
|
set(XMRIG_ARM ON)
|
||||||
|
set(WITH_LIBCPUID OFF)
|
||||||
|
add_definitions(/DXMRIG_ARM)
|
||||||
|
|
||||||
|
message(STATUS "Use ARM_TARGET=${ARM_TARGET} (${CMAKE_SYSTEM_PROCESSOR})")
|
||||||
|
|
||||||
|
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()
|
||||||
83
cmake/flags.cmake
Normal file
83
cmake/flags.cmake
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||||
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
|
add_definitions(/DNDEBUG)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti -Wno-class-memaccess")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s")
|
||||||
|
|
||||||
|
if (XMRIG_ARMv8)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions")
|
||||||
|
elseif (XMRIG_ARMv7)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions")
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
|
||||||
|
|
||||||
|
add_definitions(/DHAVE_ROTR)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||||
|
else()
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions(/D_GNU_SOURCE)
|
||||||
|
|
||||||
|
if (${CMAKE_VERSION} VERSION_LESS "3.1.0")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-2")
|
||||||
|
|
||||||
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL")
|
||||||
|
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)
|
||||||
|
add_definitions(/DNOMINMAX)
|
||||||
|
add_definitions(/DHAVE_ROTR)
|
||||||
|
|
||||||
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti -Wno-missing-braces")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
||||||
|
|
||||||
|
if (XMRIG_ARMv8)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS}")
|
||||||
|
elseif (XMRIG_ARMv7)
|
||||||
|
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}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
|
||||||
|
|
||||||
|
check_symbol_exists("_rotr" "x86intrin.h" HAVE_ROTR)
|
||||||
|
if (HAVE_ROTR)
|
||||||
|
add_definitions(/DHAVE_ROTR)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
31
doc/ALGORITHMS.md
Normal file
31
doc/ALGORITHMS.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Algorithms
|
||||||
|
|
||||||
|
XMRig uses a different way to specify algorithms, compared to other miners.
|
||||||
|
|
||||||
|
Algorithm selection splitted to 2 parts:
|
||||||
|
|
||||||
|
* Global base algorithm per miner or proxy instance, `algo` option. Possible values: `cryptonight`, `cryptonight-lite`, `cryptonight-heavy`.
|
||||||
|
* Algorithm variant specified separately for each pool, `variant` option.
|
||||||
|
* [Full table for supported algorithm and variants.](https://github.com/xmrig/xmrig-proxy/blob/master/doc/STRATUM_EXT.md#14-algorithm-names-and-variants)
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"algo": "cryptonight",
|
||||||
|
...
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"url": "...",
|
||||||
|
"variant": 1,
|
||||||
|
...
|
||||||
|
}
|
||||||
|
],
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mining algorithm negotiation
|
||||||
|
If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) miner will choice proper variant automaticaly and if you choice wrong base algorithm you will see error message.
|
||||||
|
|
||||||
|
Pools with mining algorithm negotiation support.
|
||||||
|
* [www.hashvault.pro](https://www.hashvault.pro/)
|
||||||
53
doc/API.md
Normal file
53
doc/API.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# HTTP API
|
||||||
|
|
||||||
|
If you want use API you need choice a port where is internal HTTP server will listen for incoming connections. API will not available if miner built without `libmicrohttpd`.
|
||||||
|
|
||||||
|
Example configuration:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"api": {
|
||||||
|
"port": 44444,
|
||||||
|
"access-token": "TOKEN",
|
||||||
|
"worker-id": null,
|
||||||
|
"ipv6": false,
|
||||||
|
"restricted": false
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
* **port** Port for incoming connections `http://<miner ip>:<port>`.
|
||||||
|
* **access-token** [Bearer](https://gist.github.com/xmrig/c75fdd1f8e0f3bac05500be2ab718f8e#file-api-html-L54) access token to secure access to API.
|
||||||
|
* **worker-id** Optional worker name, if not set will be detected automatically.
|
||||||
|
* **ipv6** Enable (`true`) or disable (`false`) IPv6 for API.
|
||||||
|
* **restricted** Use `false` to allow remote configuration.
|
||||||
|
|
||||||
|
If you prefer use command line options instead of config file, you can use options: `--api-port`, `--api-access-token`, `--api-worker-id`, `--api-ipv6` and `api-no-restricted`.
|
||||||
|
|
||||||
|
## Endpoints
|
||||||
|
|
||||||
|
### GET /1/summary
|
||||||
|
|
||||||
|
Get miner summary information. [Example](api/1/summary.json).
|
||||||
|
|
||||||
|
### GET /1/threads
|
||||||
|
|
||||||
|
Get detailed information about miner threads. [Example](api/1/threads.json).
|
||||||
|
|
||||||
|
|
||||||
|
## Restricted endpoints
|
||||||
|
|
||||||
|
All API endpoints below allow access to sensitive information and remote configure miner. You should set `access-token` and allow unrestricted access (`"restricted": false`).
|
||||||
|
|
||||||
|
### GET /1/config
|
||||||
|
|
||||||
|
Get current miner configuration. [Example](api/1/config.json).
|
||||||
|
|
||||||
|
|
||||||
|
### PUT /1/config
|
||||||
|
|
||||||
|
Update current miner configuration. Common use case, get current configuration, make changes, and upload it to miner.
|
||||||
|
|
||||||
|
Curl example:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -v --data-binary @config.json -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer SECRET" http://127.0.0.1:44444/1/config
|
||||||
|
```
|
||||||
63
doc/api/1/config.json
Normal file
63
doc/api/1/config.json
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
{
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"api": {
|
||||||
|
"port": 44444,
|
||||||
|
"access-token": "TOKEN",
|
||||||
|
"worker-id": null,
|
||||||
|
"ipv6": false,
|
||||||
|
"restricted": false
|
||||||
|
},
|
||||||
|
"av": 1,
|
||||||
|
"background": false,
|
||||||
|
"colors": true,
|
||||||
|
"cpu-affinity": null,
|
||||||
|
"cpu-priority": null,
|
||||||
|
"donate-level": 5,
|
||||||
|
"huge-pages": true,
|
||||||
|
"hw-aes": null,
|
||||||
|
"log-file": null,
|
||||||
|
"max-cpu-usage": 75,
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"url": "pool.monero.hashvault.pro:3333",
|
||||||
|
"user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD",
|
||||||
|
"pass": "x",
|
||||||
|
"keepalive": false,
|
||||||
|
"nicehash": false,
|
||||||
|
"variant": -1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "pool.supportxmr.com:3333",
|
||||||
|
"user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD",
|
||||||
|
"pass": "x",
|
||||||
|
"keepalive": false,
|
||||||
|
"nicehash": false,
|
||||||
|
"variant": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"print-time": 60,
|
||||||
|
"retries": 5,
|
||||||
|
"retry-pause": 5,
|
||||||
|
"safe": false,
|
||||||
|
"threads": [
|
||||||
|
{
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user-agent": null,
|
||||||
|
"syslog": false,
|
||||||
|
"watch": false
|
||||||
|
}
|
||||||
73
doc/api/1/summary.json
Normal file
73
doc/api/1/summary.json
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"id": "92f3104f9a2ee78c",
|
||||||
|
"worker_id": "Ubuntu-1604-xenial-64-minimal",
|
||||||
|
"version": "2.6.0-beta3",
|
||||||
|
"kind": "cpu",
|
||||||
|
"ua": "XMRig/2.6.0-beta3 (Linux x86_64) libuv/1.8.0 gcc/5.4.0",
|
||||||
|
"cpu": {
|
||||||
|
"brand": "Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz",
|
||||||
|
"aes": true,
|
||||||
|
"x64": true,
|
||||||
|
"sockets": 1
|
||||||
|
},
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"hugepages": true,
|
||||||
|
"donate_level": 5,
|
||||||
|
"hashrate": {
|
||||||
|
"total": [
|
||||||
|
296.24,
|
||||||
|
296.23,
|
||||||
|
295.97
|
||||||
|
],
|
||||||
|
"highest": 296.5,
|
||||||
|
"threads": [
|
||||||
|
[
|
||||||
|
73.39,
|
||||||
|
73.39,
|
||||||
|
73.28
|
||||||
|
],
|
||||||
|
[
|
||||||
|
74.72,
|
||||||
|
74.72,
|
||||||
|
74.71
|
||||||
|
],
|
||||||
|
[
|
||||||
|
74.72,
|
||||||
|
74.72,
|
||||||
|
74.71
|
||||||
|
],
|
||||||
|
[
|
||||||
|
73.39,
|
||||||
|
73.39,
|
||||||
|
73.27
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"results": {
|
||||||
|
"diff_current": 9990,
|
||||||
|
"shares_good": 30,
|
||||||
|
"shares_total": 30,
|
||||||
|
"avg_time": 31,
|
||||||
|
"hashes_total": 311833,
|
||||||
|
"best": [
|
||||||
|
278199,
|
||||||
|
181923,
|
||||||
|
103717,
|
||||||
|
96632,
|
||||||
|
56154,
|
||||||
|
51580,
|
||||||
|
45667,
|
||||||
|
33159,
|
||||||
|
29581,
|
||||||
|
29514
|
||||||
|
],
|
||||||
|
"error_log": []
|
||||||
|
},
|
||||||
|
"connection": {
|
||||||
|
"pool": "pool.monero.hashvault.pro:3333",
|
||||||
|
"uptime": 953,
|
||||||
|
"ping": 35,
|
||||||
|
"failures": 0,
|
||||||
|
"error_log": []
|
||||||
|
}
|
||||||
|
}
|
||||||
65
doc/api/1/threads.json
Normal file
65
doc/api/1/threads.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"hugepages": [
|
||||||
|
4,
|
||||||
|
4
|
||||||
|
],
|
||||||
|
"memory": 8388608,
|
||||||
|
"threads": [
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"av": 1,
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 0,
|
||||||
|
"priority": -1,
|
||||||
|
"soft_aes": false,
|
||||||
|
"hashrate": [
|
||||||
|
73.39,
|
||||||
|
73.4,
|
||||||
|
73.28
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"av": 1,
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 1,
|
||||||
|
"priority": -1,
|
||||||
|
"soft_aes": false,
|
||||||
|
"hashrate": [
|
||||||
|
74.72,
|
||||||
|
74.72,
|
||||||
|
74.7
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"av": 1,
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 2,
|
||||||
|
"priority": -1,
|
||||||
|
"soft_aes": false,
|
||||||
|
"hashrate": [
|
||||||
|
74.71,
|
||||||
|
74.72,
|
||||||
|
74.7
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"algo": "cryptonight",
|
||||||
|
"av": 1,
|
||||||
|
"low_power_mode": 1,
|
||||||
|
"affine_to_cpu": 3,
|
||||||
|
"priority": -1,
|
||||||
|
"soft_aes": false,
|
||||||
|
"hashrate": [
|
||||||
|
73.39,
|
||||||
|
73.4,
|
||||||
|
73.28
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
res/app.ico
BIN
res/app.ico
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 21 KiB |
@@ -4,8 +4,8 @@
|
|||||||
IDI_ICON1 ICON DISCARDABLE "app.ico"
|
IDI_ICON1 ICON DISCARDABLE "app.ico"
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_BUILD,APP_VER_REV
|
FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0
|
||||||
PRODUCTVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_BUILD,APP_VER_REV
|
PRODUCTVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS VS_FF_DEBUG
|
FILEFLAGS VS_FF_DEBUG
|
||||||
|
|||||||
65
src/3rdparty/aligned_malloc.h
vendored
Normal file
65
src/3rdparty/aligned_malloc.h
vendored
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* 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 __ALIGNED_MALLOC_H__
|
||||||
|
#define __ALIGNED_MALLOC_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
||||||
|
#else
|
||||||
|
// Some systems (e.g. those with GNU libc) declare posix_memalign with an
|
||||||
|
// exception specifier. Via an "egregious workaround" in
|
||||||
|
// Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid
|
||||||
|
// redeclaration of glibc's declaration.
|
||||||
|
extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_malloc(size_t __size, size_t __align)
|
||||||
|
{
|
||||||
|
if (__align == 1) {
|
||||||
|
return malloc(__size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(__align & (__align - 1)) && __align < sizeof(void *))
|
||||||
|
__align = sizeof(void *);
|
||||||
|
|
||||||
|
void *__mallocedMemory;
|
||||||
|
if (posix_memalign(&__mallocedMemory, __align, __size)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return __mallocedMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static __inline__ void __attribute__((__always_inline__)) _mm_free(void *__p)
|
||||||
|
{
|
||||||
|
free(__p);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ALIGNED_MALLOC_H__ */
|
||||||
1661
src/3rdparty/libcpuid/asm-bits.c
vendored
1661
src/3rdparty/libcpuid/asm-bits.c
vendored
File diff suppressed because it is too large
Load Diff
124
src/3rdparty/libcpuid/asm-bits.h
vendored
124
src/3rdparty/libcpuid/asm-bits.h
vendored
@@ -1,53 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008 Veselin Georgiev,
|
* Copyright 2008 Veselin Georgiev,
|
||||||
* anrieffNOSPAM @ mgail_DOT.com (convert to gmail)
|
* anrieffNOSPAM @ mgail_DOT.com (convert to gmail)
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#ifndef __ASM_BITS_H__
|
#ifndef __ASM_BITS_H__
|
||||||
#define __ASM_BITS_H__
|
#define __ASM_BITS_H__
|
||||||
#include "libcpuid.h"
|
#include "libcpuid.h"
|
||||||
|
|
||||||
/* Determine Compiler: */
|
/* Determine Compiler: */
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# define COMPILER_MICROSOFT
|
#if !defined(COMPILER_MICROSOFT)
|
||||||
#elif defined(__GNUC__)
|
# define COMPILER_MICROSOFT
|
||||||
# define COMPILER_GCC
|
#endif
|
||||||
#endif
|
#elif defined(__GNUC__)
|
||||||
|
#if !defined(COMPILER_GCC)
|
||||||
/* Determine Platform */
|
# define COMPILER_GCC
|
||||||
#if defined(__x86_64__) || defined(_M_AMD64)
|
#endif
|
||||||
# define PLATFORM_X64
|
#elif defined(__clang__)
|
||||||
#elif defined(__i386__) || defined(_M_IX86)
|
#if !defined(COMPILER_CLANG)
|
||||||
# define PLATFORM_X86
|
# define COMPILER_CLANG
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */
|
|
||||||
#if (defined(COMPILER_GCC) && defined(PLATFORM_X64)) || defined(PLATFORM_X86)
|
/* Determine Platform */
|
||||||
# define INLINE_ASM_SUPPORTED
|
#if defined(__x86_64__) || defined(_M_AMD64)
|
||||||
#endif
|
#if !defined(PLATFORM_X64)
|
||||||
|
# define PLATFORM_X64
|
||||||
int cpuid_exists_by_eflags(void);
|
#endif
|
||||||
void exec_cpuid(uint32_t *regs);
|
#elif defined(__i386__) || defined(_M_IX86)
|
||||||
void busy_sse_loop(int cycles);
|
#if !defined(PLATFORM_X86)
|
||||||
|
# define PLATFORM_X86
|
||||||
#endif /* __ASM_BITS_H__ */
|
#endif
|
||||||
|
#elif defined(__ARMEL__)
|
||||||
|
#if !defined(PLATFORM_ARM)
|
||||||
|
# define PLATFORM_ARM
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Under Windows/AMD64 with MSVC, inline assembly isn't supported */
|
||||||
|
#if (((defined(COMPILER_GCC) || defined(COMPILER_CLANG))) && \
|
||||||
|
(defined(PLATFORM_X64) || defined(PLATFORM_X86) || defined(PLATFORM_ARM))) || \
|
||||||
|
(defined(COMPILER_MICROSOFT) && defined(PLATFORM_X86))
|
||||||
|
# define INLINE_ASM_SUPPORTED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int cpuid_exists_by_eflags(void);
|
||||||
|
void exec_cpuid(uint32_t *regs);
|
||||||
|
void busy_sse_loop(int cycles);
|
||||||
|
|
||||||
|
#endif /* __ASM_BITS_H__ */
|
||||||
|
|||||||
56
src/3rdparty/libcpuid/cpuid_main.c
vendored
56
src/3rdparty/libcpuid/cpuid_main.c
vendored
@@ -221,42 +221,42 @@ static void load_features_common(struct cpu_raw_data_t* raw, struct cpu_id_t* da
|
|||||||
|
|
||||||
static cpu_vendor_t cpuid_vendor_identify(const uint32_t *raw_vendor, char *vendor_str)
|
static cpu_vendor_t cpuid_vendor_identify(const uint32_t *raw_vendor, char *vendor_str)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
cpu_vendor_t vendor = VENDOR_UNKNOWN;
|
cpu_vendor_t vendor = VENDOR_UNKNOWN;
|
||||||
const struct { cpu_vendor_t vendor; char match[16]; }
|
const struct { cpu_vendor_t vendor; char match[16]; }
|
||||||
matchtable[NUM_CPU_VENDORS] = {
|
matchtable[NUM_CPU_VENDORS] = {
|
||||||
/* source: http://www.sandpile.org/ia32/cpuid.htm */
|
/* source: http://www.sandpile.org/ia32/cpuid.htm */
|
||||||
{ VENDOR_INTEL , "GenuineIntel" },
|
{ VENDOR_INTEL , "GenuineIntel" },
|
||||||
{ VENDOR_AMD , "AuthenticAMD" },
|
{ VENDOR_AMD , "AuthenticAMD" },
|
||||||
{ VENDOR_CYRIX , "CyrixInstead" },
|
{ VENDOR_CYRIX , "CyrixInstead" },
|
||||||
{ VENDOR_NEXGEN , "NexGenDriven" },
|
{ VENDOR_NEXGEN , "NexGenDriven" },
|
||||||
{ VENDOR_TRANSMETA , "GenuineTMx86" },
|
{ VENDOR_TRANSMETA , "GenuineTMx86" },
|
||||||
{ VENDOR_UMC , "UMC UMC UMC " },
|
{ VENDOR_UMC , "UMC UMC UMC " },
|
||||||
{ VENDOR_CENTAUR , "CentaurHauls" },
|
{ VENDOR_CENTAUR , "CentaurHauls" },
|
||||||
{ VENDOR_RISE , "RiseRiseRise" },
|
{ VENDOR_RISE , "RiseRiseRise" },
|
||||||
{ VENDOR_SIS , "SiS SiS SiS " },
|
{ VENDOR_SIS , "SiS SiS SiS " },
|
||||||
{ VENDOR_NSC , "Geode by NSC" },
|
{ VENDOR_NSC , "Geode by NSC" },
|
||||||
};
|
};
|
||||||
|
|
||||||
memcpy(vendor_str + 0, &raw_vendor[1], 4);
|
memcpy(vendor_str + 0, &raw_vendor[1], 4);
|
||||||
memcpy(vendor_str + 4, &raw_vendor[3], 4);
|
memcpy(vendor_str + 4, &raw_vendor[3], 4);
|
||||||
memcpy(vendor_str + 8, &raw_vendor[2], 4);
|
memcpy(vendor_str + 8, &raw_vendor[2], 4);
|
||||||
vendor_str[12] = 0;
|
vendor_str[12] = 0;
|
||||||
|
|
||||||
/* Determine vendor: */
|
/* Determine vendor: */
|
||||||
for (i = 0; i < NUM_CPU_VENDORS; i++)
|
for (i = 0; i < NUM_CPU_VENDORS; i++)
|
||||||
if (!strcmp(vendor_str, matchtable[i].match)) {
|
if (!strcmp(vendor_str, matchtable[i].match)) {
|
||||||
vendor = matchtable[i].vendor;
|
vendor = matchtable[i].vendor;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return vendor;
|
return vendor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
|
static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
|
||||||
{
|
{
|
||||||
int i, j, basic, xmodel, xfamily, ext;
|
int i, j, basic, xmodel, xfamily, ext;
|
||||||
char brandstr[64] = {0};
|
char brandstr[64] = {0};
|
||||||
data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str);
|
data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str);
|
||||||
|
|
||||||
if (data->vendor == VENDOR_UNKNOWN)
|
if (data->vendor == VENDOR_UNKNOWN)
|
||||||
return set_error(ERR_CPU_UNKN);
|
return set_error(ERR_CPU_UNKN);
|
||||||
|
|||||||
39
src/3rdparty/libcpuid/libcpuid.h
vendored
39
src/3rdparty/libcpuid/libcpuid.h
vendored
@@ -60,7 +60,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** @mainpage A simple libcpuid introduction
|
/** @mainpage A simple libcpuid introduction
|
||||||
*
|
*
|
||||||
* LibCPUID provides CPU identification and access to the CPUID and RDTSC
|
* LibCPUID provides CPU identification and access to the CPUID and RDTSC
|
||||||
* instructions on the x86.
|
* instructions on the x86.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -82,6 +82,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** @defgroup libcpuid LibCPUID
|
/** @defgroup libcpuid LibCPUID
|
||||||
|
* @brief LibCPUID provides CPU identification
|
||||||
@{ */
|
@{ */
|
||||||
|
|
||||||
/* Include some integer type specifications: */
|
/* Include some integer type specifications: */
|
||||||
@@ -535,23 +536,23 @@ typedef enum {
|
|||||||
* @brief Describes common library error codes
|
* @brief Describes common library error codes
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ERR_OK = 0, /*!< "No error" */
|
ERR_OK = 0, /*!< No error */
|
||||||
ERR_NO_CPUID = -1, /*!< "CPUID instruction is not supported" */
|
ERR_NO_CPUID = -1, /*!< CPUID instruction is not supported */
|
||||||
ERR_NO_RDTSC = -2, /*!< "RDTSC instruction is not supported" */
|
ERR_NO_RDTSC = -2, /*!< RDTSC instruction is not supported */
|
||||||
ERR_NO_MEM = -3, /*!< "Memory allocation failed" */
|
ERR_NO_MEM = -3, /*!< Memory allocation failed */
|
||||||
ERR_OPEN = -4, /*!< "File open operation failed" */
|
ERR_OPEN = -4, /*!< File open operation failed */
|
||||||
ERR_BADFMT = -5, /*!< "Bad file format" */
|
ERR_BADFMT = -5, /*!< Bad file format */
|
||||||
ERR_NOT_IMP = -6, /*!< "Not implemented" */
|
ERR_NOT_IMP = -6, /*!< Not implemented */
|
||||||
ERR_CPU_UNKN = -7, /*!< "Unsupported processor" */
|
ERR_CPU_UNKN = -7, /*!< Unsupported processor */
|
||||||
ERR_NO_RDMSR = -8, /*!< "RDMSR instruction is not supported" */
|
ERR_NO_RDMSR = -8, /*!< RDMSR instruction is not supported */
|
||||||
ERR_NO_DRIVER= -9, /*!< "RDMSR driver error (generic)" */
|
ERR_NO_DRIVER= -9, /*!< RDMSR driver error (generic) */
|
||||||
ERR_NO_PERMS = -10, /*!< "No permissions to install RDMSR driver" */
|
ERR_NO_PERMS = -10, /*!< No permissions to install RDMSR driver */
|
||||||
ERR_EXTRACT = -11, /*!< "Cannot extract RDMSR driver (read only media?)" */
|
ERR_EXTRACT = -11, /*!< Cannot extract RDMSR driver (read only media?) */
|
||||||
ERR_HANDLE = -12, /*!< "Bad handle" */
|
ERR_HANDLE = -12, /*!< Bad handle */
|
||||||
ERR_INVMSR = -13, /*!< "Invalid MSR" */
|
ERR_INVMSR = -13, /*!< Invalid MSR */
|
||||||
ERR_INVCNB = -14, /*!< "Invalid core number" */
|
ERR_INVCNB = -14, /*!< Invalid core number */
|
||||||
ERR_HANDLE_R = -15, /*!< "Error on handle read" */
|
ERR_HANDLE_R = -15, /*!< Error on handle read */
|
||||||
ERR_INVRANGE = -16, /*!< "Invalid given range" */
|
ERR_INVRANGE = -16, /*!< Invalid given range */
|
||||||
} cpu_error_t;
|
} cpu_error_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -668,7 +669,7 @@ struct cpu_epc_t cpuid_get_epc(int index, const struct cpu_raw_data_t* raw);
|
|||||||
const char* cpuid_lib_version(void);
|
const char* cpuid_lib_version(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}; /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
5
src/3rdparty/libcpuid/libcpuid_internal.h
vendored
5
src/3rdparty/libcpuid/libcpuid_internal.h
vendored
@@ -75,8 +75,9 @@ enum _intel_bits_t {
|
|||||||
_3 = LBIT( 14 ),
|
_3 = LBIT( 14 ),
|
||||||
_5 = LBIT( 15 ),
|
_5 = LBIT( 15 ),
|
||||||
_7 = LBIT( 16 ),
|
_7 = LBIT( 16 ),
|
||||||
XEON_ = LBIT( 17 ),
|
_9 = LBIT( 17 ),
|
||||||
ATOM_ = LBIT( 18 ),
|
XEON_ = LBIT( 18 ),
|
||||||
|
ATOM_ = LBIT( 19 ),
|
||||||
};
|
};
|
||||||
typedef enum _intel_bits_t intel_bits_t;
|
typedef enum _intel_bits_t intel_bits_t;
|
||||||
|
|
||||||
|
|||||||
28
src/3rdparty/libcpuid/libcpuid_types.h
vendored
28
src/3rdparty/libcpuid/libcpuid_types.h
vendored
@@ -32,6 +32,32 @@
|
|||||||
#ifndef __LIBCPUID_TYPES_H__
|
#ifndef __LIBCPUID_TYPES_H__
|
||||||
#define __LIBCPUID_TYPES_H__
|
#define __LIBCPUID_TYPES_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#if !defined(_MSC_VER) || _MSC_VER >= 1600
|
||||||
|
# include <stdint.h>
|
||||||
|
#else
|
||||||
|
/* we have to provide our own: */
|
||||||
|
# if !defined(__int32_t_defined)
|
||||||
|
typedef int int32_t;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !defined(__uint32_t_defined)
|
||||||
|
typedef unsigned uint32_t;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
typedef signed char int8_t;
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef signed short int16_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
#if (defined _MSC_VER) && (_MSC_VER <= 1300)
|
||||||
|
/* MSVC 6.0: no long longs ... */
|
||||||
|
typedef signed __int64 int64_t;
|
||||||
|
typedef unsigned __int64 uint64_t;
|
||||||
|
#else
|
||||||
|
/* all other sane compilers: */
|
||||||
|
typedef signed long long int64_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __LIBCPUID_TYPES_H__ */
|
#endif /* __LIBCPUID_TYPES_H__ */
|
||||||
|
|||||||
4
src/3rdparty/libcpuid/recog_amd.c
vendored
4
src/3rdparty/libcpuid/recog_amd.c
vendored
@@ -49,6 +49,10 @@ enum _amd_model_codes_t {
|
|||||||
_1400,
|
_1400,
|
||||||
_1500,
|
_1500,
|
||||||
_1600,
|
_1600,
|
||||||
|
_1900,
|
||||||
|
_2400,
|
||||||
|
_2500,
|
||||||
|
_2700,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void load_amd_features(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
|
static void load_amd_features(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
|
||||||
|
|||||||
3
src/3rdparty/libcpuid/recog_intel.c
vendored
3
src/3rdparty/libcpuid/recog_intel.c
vendored
@@ -376,7 +376,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
|
|||||||
bits |= bit_matchtable[i].bit;
|
bits |= bit_matchtable[i].bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((i = match_pattern(bs, "Core(TM) [im][357]")) != 0) {
|
if ((i = match_pattern(bs, "Core(TM) [im][3579]")) != 0) {
|
||||||
bits |= CORE_;
|
bits |= CORE_;
|
||||||
i--;
|
i--;
|
||||||
switch (bs[i + 9]) {
|
switch (bs[i + 9]) {
|
||||||
@@ -387,6 +387,7 @@ static intel_code_and_bits_t get_brand_code_and_bits(struct cpu_id_t* data)
|
|||||||
case '3': bits |= _3; break;
|
case '3': bits |= _3; break;
|
||||||
case '5': bits |= _5; break;
|
case '5': bits |= _5; break;
|
||||||
case '7': bits |= _7; break;
|
case '7': bits |= _7; break;
|
||||||
|
case '9': bits |= _9; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < COUNT_OF(matchtable); i++)
|
for (i = 0; i < COUNT_OF(matchtable); i++)
|
||||||
|
|||||||
151
src/App.cpp
151
src/App.cpp
@@ -4,8 +4,10 @@
|
|||||||
* 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 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,133 +30,103 @@
|
|||||||
|
|
||||||
#include "api/Api.h"
|
#include "api/Api.h"
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "Console.h"
|
#include "base/kernel/Signals.h"
|
||||||
#include "Cpu.h"
|
#include "common/Console.h"
|
||||||
|
#include "common/cpu/Cpu.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "common/Platform.h"
|
||||||
|
#include "core/Config.h"
|
||||||
|
#include "core/Controller.h"
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
#include "log/ConsoleLog.h"
|
|
||||||
#include "log/FileLog.h"
|
|
||||||
#include "log/Log.h"
|
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "net/Network.h"
|
#include "net/Network.h"
|
||||||
#include "Options.h"
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "Summary.h"
|
#include "Summary.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "workers/Workers.h"
|
#include "workers/Workers.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
# include "log/SysLog.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef XMRIG_NO_HTTPD
|
#ifndef XMRIG_NO_HTTPD
|
||||||
# include "api/Httpd.h"
|
# include "common/api/Httpd.h"
|
||||||
#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_network(nullptr),
|
m_signals(nullptr)
|
||||||
m_options(nullptr)
|
|
||||||
{
|
{
|
||||||
m_self = this;
|
m_controller = new Controller(process);
|
||||||
|
if (m_controller->init() != 0) {
|
||||||
Cpu::init();
|
|
||||||
m_options = Options::parse(argc, argv);
|
|
||||||
if (!m_options) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::init();
|
if (!m_controller->config()->isBackground()) {
|
||||||
|
|
||||||
if (!m_options->background()) {
|
|
||||||
Log::add(new ConsoleLog(m_options->colors()));
|
|
||||||
m_console = new Console(this);
|
m_console = new Console(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_options->logFile()) {
|
|
||||||
Log::add(new FileLog(m_options->logFile()));
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef HAVE_SYSLOG_H
|
|
||||||
if (m_options->syslog()) {
|
|
||||||
Log::add(new SysLog());
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
Platform::init(m_options->userAgent());
|
|
||||||
Platform::setProcessPriority(m_options->priority());
|
|
||||||
|
|
||||||
m_network = new Network(m_options);
|
|
||||||
|
|
||||||
uv_signal_init(uv_default_loop(), &m_signal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
App::~App()
|
xmrig::App::~App()
|
||||||
{
|
{
|
||||||
uv_tty_reset_mode();
|
uv_tty_reset_mode();
|
||||||
|
|
||||||
|
delete m_signals;
|
||||||
|
delete m_console;
|
||||||
|
delete m_controller;
|
||||||
|
|
||||||
# ifndef XMRIG_NO_HTTPD
|
# ifndef XMRIG_NO_HTTPD
|
||||||
delete m_httpd;
|
delete m_httpd;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
delete m_console;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int App::exec()
|
int xmrig::App::exec()
|
||||||
{
|
{
|
||||||
if (!m_options) {
|
if (!m_controller->isReady()) {
|
||||||
return 0;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_signal_start(&m_signal, App::onSignal, SIGHUP);
|
m_signals = new Signals(this);
|
||||||
uv_signal_start(&m_signal, App::onSignal, SIGTERM);
|
|
||||||
uv_signal_start(&m_signal, App::onSignal, SIGINT);
|
|
||||||
|
|
||||||
background();
|
background();
|
||||||
|
|
||||||
if (!CryptoNight::init(m_options->algo(), m_options->algoVariant())) {
|
Mem::init(m_controller->config()->isHugePages());
|
||||||
LOG_ERR("\"%s\" hash self-test failed.", m_options->algoName());
|
|
||||||
return 1;
|
Summary::print(m_controller);
|
||||||
|
|
||||||
|
if (m_controller->config()->isDryRun()) {
|
||||||
|
LOG_NOTICE("OK");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages());
|
|
||||||
Summary::print();
|
|
||||||
|
|
||||||
# ifndef XMRIG_NO_API
|
# ifndef XMRIG_NO_API
|
||||||
Api::start();
|
Api::start(m_controller);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifndef XMRIG_NO_HTTPD
|
# ifndef XMRIG_NO_HTTPD
|
||||||
m_httpd = new Httpd(m_options->apiPort(), m_options->apiToken());
|
m_httpd = new Httpd(
|
||||||
|
m_controller->config()->apiPort(),
|
||||||
|
m_controller->config()->apiToken(),
|
||||||
|
m_controller->config()->isApiIPv6(),
|
||||||
|
m_controller->config()->isApiRestricted()
|
||||||
|
);
|
||||||
|
|
||||||
m_httpd->start();
|
m_httpd->start();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
Workers::start(m_options->affinity(), m_options->priority());
|
Workers::start(m_controller);
|
||||||
|
|
||||||
m_network->connect();
|
m_controller->network()->connect();
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
delete m_network;
|
|
||||||
|
|
||||||
Options::release();
|
|
||||||
Mem::release();
|
|
||||||
Platform::release();
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void App::onConsoleCommand(char command)
|
void xmrig::App::onConsoleCommand(char command)
|
||||||
{
|
{
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -164,14 +136,16 @@ void App::onConsoleCommand(char command)
|
|||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'P':
|
case 'P':
|
||||||
LOG_INFO(m_options->colors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
if (Workers::isEnabled()) {
|
||||||
Workers::setEnabled(false);
|
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
||||||
|
Workers::setEnabled(false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'R':
|
case 'R':
|
||||||
if (!Workers::isEnabled()) {
|
if (!Workers::isEnabled()) {
|
||||||
LOG_INFO(m_options->colors() ? "\x1B[01;32mresumed" : "resumed");
|
LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;32mresumed" : "resumed");
|
||||||
Workers::setEnabled(true);
|
Workers::setEnabled(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -187,16 +161,7 @@ void App::onConsoleCommand(char command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void App::close()
|
void xmrig::App::onSignal(int signum)
|
||||||
{
|
|
||||||
m_network->stop();
|
|
||||||
Workers::stop();
|
|
||||||
|
|
||||||
uv_stop(uv_default_loop());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void App::onSignal(uv_signal_t *handle, int signum)
|
|
||||||
{
|
{
|
||||||
switch (signum)
|
switch (signum)
|
||||||
{
|
{
|
||||||
@@ -213,9 +178,17 @@ 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()
|
||||||
|
{
|
||||||
|
m_controller->network()->stop();
|
||||||
|
Workers::stop();
|
||||||
|
|
||||||
|
uv_stop(uv_default_loop());
|
||||||
}
|
}
|
||||||
|
|||||||
58
src/App.h
58
src/App.h
@@ -4,8 +4,10 @@
|
|||||||
* 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 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,47 +23,51 @@
|
|||||||
* 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/ISignalListener.h"
|
||||||
|
#include "common/interfaces/IConsoleListener.h"
|
||||||
|
|
||||||
#include "interfaces/IConsoleListener.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Console;
|
class Console;
|
||||||
class Httpd;
|
class Httpd;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Controller;
|
||||||
class Network;
|
class Network;
|
||||||
class Options;
|
class Process;
|
||||||
|
class Signals;
|
||||||
|
|
||||||
|
|
||||||
class App : public IConsoleListener
|
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();
|
||||||
|
|
||||||
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;
|
|
||||||
Network *m_network;
|
|
||||||
Options *m_options;
|
|
||||||
uv_signal_t m_signal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __APP_H__ */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_APP_H */
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -29,18 +30,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "Cpu.h"
|
#include "common/log/Log.h"
|
||||||
#include "log/Log.h"
|
#include "core/Config.h"
|
||||||
#include "Options.h"
|
#include "core/Controller.h"
|
||||||
|
|
||||||
|
|
||||||
void App::background()
|
void xmrig::App::background()
|
||||||
{
|
{
|
||||||
if (m_options->affinity() != -1L) {
|
signal(SIGPIPE, SIG_IGN);
|
||||||
Cpu::setAffinity(-1, m_options->affinity());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_options->background()) {
|
if (!m_controller->config()->isBackground()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -27,17 +28,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "Options.h"
|
#include "core/Controller.h"
|
||||||
#include "Cpu.h"
|
#include "core/Config.h"
|
||||||
|
|
||||||
|
|
||||||
void App::background()
|
void xmrig::App::background()
|
||||||
{
|
{
|
||||||
if (m_options->affinity() != -1L) {
|
if (!m_controller->config()->isBackground()) {
|
||||||
Cpu::setAffinity(-1, m_options->affinity());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_options->background()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
114
src/Cpu.cpp
114
src/Cpu.cpp
@@ -1,114 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <libcpuid.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
|
||||||
|
|
||||||
|
|
||||||
bool Cpu::m_l2_exclusive = false;
|
|
||||||
char Cpu::m_brand[64] = { 0 };
|
|
||||||
int Cpu::m_flags = 0;
|
|
||||||
int Cpu::m_l2_cache = 0;
|
|
||||||
int Cpu::m_l3_cache = 0;
|
|
||||||
int Cpu::m_sockets = 1;
|
|
||||||
int Cpu::m_totalCores = 0;
|
|
||||||
int Cpu::m_totalThreads = 0;
|
|
||||||
|
|
||||||
|
|
||||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
|
||||||
{
|
|
||||||
if (m_totalThreads == 1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cache = 0;
|
|
||||||
if (m_l3_cache) {
|
|
||||||
cache = m_l2_exclusive ? (m_l2_cache + m_l3_cache) : m_l3_cache;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cache = m_l2_cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
|
||||||
|
|
||||||
if (cache) {
|
|
||||||
count = cache / size;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
count = m_totalThreads / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > m_totalThreads) {
|
|
||||||
count = m_totalThreads;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((float) count / m_totalThreads * 100) > maxCpuUsage) {
|
|
||||||
count = (int) ceil((float) m_totalThreads * (maxCpuUsage / 100.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
return count < 1 ? 1 : count;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Cpu::initCommon()
|
|
||||||
{
|
|
||||||
struct cpu_raw_data_t raw = { 0 };
|
|
||||||
struct cpu_id_t data = { 0 };
|
|
||||||
|
|
||||||
cpuid_get_raw_data(&raw);
|
|
||||||
cpu_identify(&raw, &data);
|
|
||||||
|
|
||||||
strncpy(m_brand, data.brand_str, sizeof(m_brand) - 1);
|
|
||||||
|
|
||||||
m_totalThreads = data.total_logical_cpus;
|
|
||||||
m_sockets = m_totalThreads / data.num_logical_cpus;
|
|
||||||
m_totalCores = data.num_cores *m_sockets;
|
|
||||||
|
|
||||||
m_l3_cache = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0;
|
|
||||||
|
|
||||||
// Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97
|
|
||||||
if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) {
|
|
||||||
m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets;
|
|
||||||
m_l2_exclusive = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
|
||||||
m_flags |= X86_64;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
if (data.flags[CPU_FEATURE_AES]) {
|
|
||||||
m_flags |= AES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.flags[CPU_FEATURE_BMI2]) {
|
|
||||||
m_flags |= BMI2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
67
src/Cpu.h
67
src/Cpu.h
@@ -1,67 +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 __CPU_H__
|
|
||||||
#define __CPU_H__
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
|
|
||||||
class Cpu
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Flags {
|
|
||||||
X86_64 = 1,
|
|
||||||
AES = 2,
|
|
||||||
BMI2 = 4
|
|
||||||
};
|
|
||||||
|
|
||||||
static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
|
|
||||||
static void init();
|
|
||||||
static void setAffinity(int id, uint64_t mask);
|
|
||||||
|
|
||||||
static inline bool hasAES() { return (m_flags & AES) != 0; }
|
|
||||||
static inline bool isX64() { return (m_flags & X86_64) != 0; }
|
|
||||||
static inline const char *brand() { return m_brand; }
|
|
||||||
static inline int cores() { return m_totalCores; }
|
|
||||||
static inline int l2() { return m_l2_cache; }
|
|
||||||
static inline int l3() { return m_l3_cache; }
|
|
||||||
static inline int sockets() { return m_sockets; }
|
|
||||||
static inline int threads() { return m_totalThreads; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void initCommon();
|
|
||||||
|
|
||||||
static bool m_l2_exclusive;
|
|
||||||
static char m_brand[64];
|
|
||||||
static int m_flags;
|
|
||||||
static int m_l2_cache;
|
|
||||||
static int m_l3_cache;
|
|
||||||
static int m_sockets;
|
|
||||||
static int m_totalCores;
|
|
||||||
static int m_totalThreads;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CPU_H__ */
|
|
||||||
86
src/Mem.cpp
86
src/Mem.cpp
@@ -4,8 +4,10 @@
|
|||||||
* 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 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
|
||||||
@@ -22,66 +24,54 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <memory.h>
|
#include "common/utils/mm_malloc.h"
|
||||||
|
|
||||||
|
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
|
#include "crypto/CryptoNight_constants.h"
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "Options.h"
|
|
||||||
|
|
||||||
|
|
||||||
bool Mem::m_doubleHash = false;
|
bool Mem::m_enabled = true;
|
||||||
int Mem::m_algo = 0;
|
int Mem::m_flags = 0;
|
||||||
int Mem::m_flags = 0;
|
|
||||||
int Mem::m_threads = 0;
|
|
||||||
size_t Mem::m_offset = 0;
|
|
||||||
uint8_t *Mem::m_memory = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
cryptonight_ctx *Mem::create(int threadId)
|
MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
|
||||||
{
|
{
|
||||||
# ifndef XMRIG_NO_AEON
|
using namespace xmrig;
|
||||||
if (m_algo == Options::ALGO_CRYPTONIGHT_LITE) {
|
|
||||||
return createLite(threadId);
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
MemInfo info;
|
||||||
|
info.size = cn_select_memory(algorithm) * count;
|
||||||
|
|
||||||
const int ratio = m_doubleHash ? 2 : 1;
|
constexpr const size_t align_size = 2 * 1024 * 1024;
|
||||||
ctx->memory = &m_memory[MEMORY * (threadId * ratio + 1)];
|
info.size = ((info.size + align_size - 1) / align_size) * align_size;
|
||||||
|
info.pages = info.size / align_size;
|
||||||
|
|
||||||
return ctx;
|
allocate(info, m_enabled);
|
||||||
}
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096));
|
||||||
|
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);
|
||||||
|
|
||||||
void *Mem::calloc(size_t num, size_t size)
|
c->generated_code_data.variant = xmrig::VARIANT_MAX;
|
||||||
{
|
c->generated_code_data.height = (uint64_t)(-1);
|
||||||
void *mem = &m_memory[m_offset];
|
c->generated_code_double_data = c->generated_code_data;
|
||||||
m_offset += (num * size);
|
|
||||||
|
|
||||||
memset(mem, 0, num * size);
|
ctx[i] = c;
|
||||||
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_NO_AEON
|
|
||||||
cryptonight_ctx *Mem::createLite(int threadId) {
|
|
||||||
cryptonight_ctx *ctx;
|
|
||||||
|
|
||||||
if (!m_doubleHash) {
|
|
||||||
const size_t offset = MEMORY * (threadId + 1);
|
|
||||||
|
|
||||||
ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[offset + MEMORY_LITE]);
|
|
||||||
ctx->memory = &m_memory[offset];
|
|
||||||
return ctx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
return info;
|
||||||
ctx->memory = &m_memory[MEMORY * (threadId + 1)];
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
void Mem::release(cryptonight_ctx **ctx, size_t count, MemInfo &info)
|
||||||
|
{
|
||||||
|
release(info);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
_mm_free(ctx[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
52
src/Mem.h
52
src/Mem.h
@@ -4,8 +4,10 @@
|
|||||||
* 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 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,20 +23,30 @@
|
|||||||
* 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 __MEM_H__
|
#ifndef XMRIG_MEM_H
|
||||||
#define __MEM_H__
|
#define XMRIG_MEM_H
|
||||||
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#include "align.h"
|
#include "common/xmrig.h"
|
||||||
|
|
||||||
|
|
||||||
struct cryptonight_ctx;
|
struct cryptonight_ctx;
|
||||||
|
|
||||||
|
|
||||||
|
struct MemInfo
|
||||||
|
{
|
||||||
|
alignas(16) uint8_t *memory;
|
||||||
|
|
||||||
|
size_t hugePages;
|
||||||
|
size_t pages;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Mem
|
class Mem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -44,29 +56,23 @@ public:
|
|||||||
Lock = 4
|
Lock = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
|
static MemInfo create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count);
|
||||||
static cryptonight_ctx *create(int threadId);
|
static void init(bool enabled);
|
||||||
static void *calloc(size_t num, size_t size);
|
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
|
||||||
static void release();
|
|
||||||
|
static void *allocateExecutableMemory(size_t size);
|
||||||
|
static void protectExecutableMemory(void *p, size_t size);
|
||||||
|
static void flushInstructionCache(void *p, size_t size);
|
||||||
|
|
||||||
static inline bool isDoubleHash() { return m_doubleHash; }
|
|
||||||
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }
|
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }
|
||||||
static inline bool isHugepagesEnabled() { return (m_flags & HugepagesEnabled) != 0; }
|
|
||||||
static inline int flags() { return m_flags; }
|
|
||||||
static inline int threads() { return m_threads; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool m_doubleHash;
|
static void allocate(MemInfo &info, bool enabled);
|
||||||
static int m_algo;
|
static void release(MemInfo &info);
|
||||||
static int m_flags;
|
|
||||||
static int m_threads;
|
|
||||||
static size_t m_offset;
|
|
||||||
VAR_ALIGN(16, static uint8_t *m_memory);
|
|
||||||
|
|
||||||
# ifndef XMRIG_NO_AEON
|
static int m_flags;
|
||||||
static cryptonight_ctx *createLite(int threadId);
|
static bool m_enabled;
|
||||||
# endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __MEM_H__ */
|
#endif /* XMRIG_MEM_H */
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
* 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 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
|
||||||
@@ -23,69 +25,90 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <mm_malloc.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "common/utils/mm_malloc.h"
|
||||||
|
#include "common/xmrig.h"
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
#include "log/Log.h"
|
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "Options.h"
|
|
||||||
|
|
||||||
|
|
||||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
void Mem::init(bool enabled)
|
||||||
{
|
{
|
||||||
m_algo = algo;
|
m_enabled = enabled;
|
||||||
m_threads = threads;
|
}
|
||||||
m_doubleHash = doubleHash;
|
|
||||||
|
|
||||||
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
|
||||||
const size_t size = MEMORY * (threads * ratio + 1);
|
void Mem::allocate(MemInfo &info, bool enabled)
|
||||||
|
{
|
||||||
|
info.hugePages = 0;
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
|
info.memory = static_cast<uint8_t*>(_mm_malloc(info.size, 4096));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_flags |= HugepagesAvailable;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# if defined(__APPLE__)
|
# if defined(__APPLE__)
|
||||||
m_memory = static_cast<uint8_t*>(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0));
|
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0));
|
||||||
|
# elif defined(__FreeBSD__)
|
||||||
|
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0));
|
||||||
# else
|
# else
|
||||||
m_memory = static_cast<uint8_t*>(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0));
|
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0));
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (m_memory == MAP_FAILED) {
|
if (info.memory == MAP_FAILED) {
|
||||||
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
|
return allocate(info, false);;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_flags |= HugepagesEnabled;
|
info.hugePages = info.pages;
|
||||||
|
|
||||||
if (madvise(m_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) {
|
if (madvise(info.memory, info.size, MADV_RANDOM | MADV_WILLNEED) != 0) {
|
||||||
LOG_ERR("madvise failed");
|
LOG_ERR("madvise failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mlock(m_memory, size) == 0) {
|
if (mlock(info.memory, info.size) == 0) {
|
||||||
m_flags |= Lock;
|
m_flags |= Lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Mem::release()
|
void Mem::release(MemInfo &info)
|
||||||
{
|
{
|
||||||
const int size = MEMORY * (m_threads + 1);
|
if (info.hugePages) {
|
||||||
|
|
||||||
if (m_flags & HugepagesEnabled) {
|
|
||||||
if (m_flags & Lock) {
|
if (m_flags & Lock) {
|
||||||
munlock(m_memory, size);
|
munlock(info.memory, info.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
munmap(m_memory, size);
|
munmap(info.memory, info.size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_mm_free(m_memory);
|
_mm_free(info.memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *Mem::allocateExecutableMemory(size_t size)
|
||||||
|
{
|
||||||
|
# if defined(__APPLE__)
|
||||||
|
return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
|
# else
|
||||||
|
return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mem::protectExecutableMemory(void *p, size_t size)
|
||||||
|
{
|
||||||
|
mprotect(p, size, PROT_READ | PROT_EXEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mem::flushInstructionCache(void *p, size_t size)
|
||||||
|
{
|
||||||
|
# ifndef __FreeBSD__
|
||||||
|
__builtin___clear_cache(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + size);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@
|
|||||||
* 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 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
|
||||||
@@ -27,16 +29,13 @@
|
|||||||
#include <ntsecapi.h>
|
#include <ntsecapi.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
# include <mm_malloc.h>
|
|
||||||
#else
|
|
||||||
# include <malloc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "log/Log.h"
|
#include "common/log/Log.h"
|
||||||
|
#include "common/utils/mm_malloc.h"
|
||||||
|
#include "common/xmrig.h"
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
|
#include "crypto/CryptoNight_constants.h"
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "Options.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
@@ -144,42 +143,62 @@ static BOOL TrySetLockPagesPrivilege() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
void Mem::init(bool enabled)
|
||||||
{
|
{
|
||||||
m_algo = algo;
|
m_enabled = enabled;
|
||||||
m_threads = threads;
|
|
||||||
m_doubleHash = doubleHash;
|
|
||||||
|
|
||||||
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
if (enabled && TrySetLockPagesPrivilege()) {
|
||||||
const size_t size = MEMORY * (threads * ratio + 1);
|
|
||||||
|
|
||||||
if (!enabled) {
|
|
||||||
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TrySetLockPagesPrivilege()) {
|
|
||||||
m_flags |= HugepagesAvailable;
|
m_flags |= HugepagesAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_memory = static_cast<uint8_t*>(VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE));
|
|
||||||
if (!m_memory) {
|
|
||||||
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_flags |= HugepagesEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Mem::release()
|
void Mem::allocate(MemInfo &info, bool enabled)
|
||||||
{
|
{
|
||||||
if (m_flags & HugepagesEnabled) {
|
info.hugePages = 0;
|
||||||
VirtualFree(m_memory, 0, MEM_RELEASE);
|
|
||||||
|
if (!enabled) {
|
||||||
|
info.memory = static_cast<uint8_t*>(_mm_malloc(info.size, 4096));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.memory = static_cast<uint8_t*>(VirtualAlloc(nullptr, info.size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE));
|
||||||
|
if (info.memory) {
|
||||||
|
info.hugePages = info.pages;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
allocate(info, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mem::release(MemInfo &info)
|
||||||
|
{
|
||||||
|
if (info.hugePages) {
|
||||||
|
VirtualFree(info.memory, 0, MEM_RELEASE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_mm_free(m_memory);
|
_mm_free(info.memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *Mem::allocateExecutableMemory(size_t size)
|
||||||
|
{
|
||||||
|
return VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
::FlushInstructionCache(GetCurrentProcess(), p, size);
|
||||||
|
}
|
||||||
|
|||||||
729
src/Options.cpp
729
src/Options.cpp
@@ -1,729 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# include "getopt/getopt.h"
|
|
||||||
#else
|
|
||||||
# include <getopt.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
|
||||||
#include "donate.h"
|
|
||||||
#include "net/Url.h"
|
|
||||||
#include "Options.h"
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "rapidjson/document.h"
|
|
||||||
#include "rapidjson/error/en.h"
|
|
||||||
#include "rapidjson/filereadstream.h"
|
|
||||||
#include "version.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ARRAY_SIZE
|
|
||||||
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
Options *Options::m_self = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
static char const usage[] = "\
|
|
||||||
Usage: " APP_ID " [OPTIONS]\n\
|
|
||||||
Options:\n\
|
|
||||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
|
|
||||||
-o, --url=URL URL of mining server\n\
|
|
||||||
-O, --userpass=U:P username:password pair for mining server\n\
|
|
||||||
-u, --user=USERNAME username for mining server\n\
|
|
||||||
-p, --pass=PASSWORD password for mining server\n\
|
|
||||||
-t, --threads=N number of miner threads\n\
|
|
||||||
-v, --av=N algorithm variation, 0 auto select\n\
|
|
||||||
-k, --keepalive send keepalived for prevent timeout (need pool support)\n\
|
|
||||||
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
|
|
||||||
-R, --retry-pause=N time to pause between retries (default: 5)\n\
|
|
||||||
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
|
|
||||||
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
|
|
||||||
--no-huge-pages disable huge pages support\n\
|
|
||||||
--no-color disable colored output\n\
|
|
||||||
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
|
|
||||||
--user-agent set custom user-agent string for pool\n\
|
|
||||||
-B, --background run the miner in the background\n\
|
|
||||||
-c, --config=FILE load a JSON-format configuration file\n\
|
|
||||||
-l, --log-file=FILE log all output to a file\n"
|
|
||||||
# ifdef HAVE_SYSLOG_H
|
|
||||||
"\
|
|
||||||
-S, --syslog use system log for output messages\n"
|
|
||||||
# endif
|
|
||||||
"\
|
|
||||||
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\
|
|
||||||
--safe safe adjust threads and av settings for current CPU\n\
|
|
||||||
--nicehash enable nicehash/xmrig-proxy support\n\
|
|
||||||
--print-time=N print hashrate report every N seconds\n\
|
|
||||||
--api-port=N port for the miner API\n\
|
|
||||||
--api-access-token=T access token for API\n\
|
|
||||||
--api-worker-id=ID custom worker-id for API\n\
|
|
||||||
-h, --help display this help and exit\n\
|
|
||||||
-V, --version output version information and exit\n\
|
|
||||||
";
|
|
||||||
|
|
||||||
|
|
||||||
static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
|
|
||||||
|
|
||||||
|
|
||||||
static struct option const options[] = {
|
|
||||||
{ "algo", 1, nullptr, 'a' },
|
|
||||||
{ "av", 1, nullptr, 'v' },
|
|
||||||
{ "background", 0, nullptr, 'B' },
|
|
||||||
{ "config", 1, nullptr, 'c' },
|
|
||||||
{ "cpu-affinity", 1, nullptr, 1020 },
|
|
||||||
{ "cpu-priority", 1, nullptr, 1021 },
|
|
||||||
{ "donate-level", 1, nullptr, 1003 },
|
|
||||||
{ "help", 0, nullptr, 'h' },
|
|
||||||
{ "keepalive", 0, nullptr ,'k' },
|
|
||||||
{ "log-file", 1, nullptr, 'l' },
|
|
||||||
{ "max-cpu-usage", 1, nullptr, 1004 },
|
|
||||||
{ "nicehash", 0, nullptr, 1006 },
|
|
||||||
{ "no-color", 0, nullptr, 1002 },
|
|
||||||
{ "no-huge-pages", 0, nullptr, 1009 },
|
|
||||||
{ "pass", 1, nullptr, 'p' },
|
|
||||||
{ "print-time", 1, nullptr, 1007 },
|
|
||||||
{ "retries", 1, nullptr, 'r' },
|
|
||||||
{ "retry-pause", 1, nullptr, 'R' },
|
|
||||||
{ "safe", 0, nullptr, 1005 },
|
|
||||||
{ "syslog", 0, nullptr, 'S' },
|
|
||||||
{ "threads", 1, nullptr, 't' },
|
|
||||||
{ "url", 1, nullptr, 'o' },
|
|
||||||
{ "user", 1, nullptr, 'u' },
|
|
||||||
{ "user-agent", 1, nullptr, 1008 },
|
|
||||||
{ "userpass", 1, nullptr, 'O' },
|
|
||||||
{ "version", 0, nullptr, 'V' },
|
|
||||||
{ "api-port", 1, nullptr, 4000 },
|
|
||||||
{ "api-access-token", 1, nullptr, 4001 },
|
|
||||||
{ "api-worker-id", 1, nullptr, 4002 },
|
|
||||||
{ 0, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static struct option const config_options[] = {
|
|
||||||
{ "algo", 1, nullptr, 'a' },
|
|
||||||
{ "av", 1, nullptr, 'v' },
|
|
||||||
{ "background", 0, nullptr, 'B' },
|
|
||||||
{ "colors", 0, nullptr, 2000 },
|
|
||||||
{ "cpu-affinity", 1, nullptr, 1020 },
|
|
||||||
{ "cpu-priority", 1, nullptr, 1021 },
|
|
||||||
{ "donate-level", 1, nullptr, 1003 },
|
|
||||||
{ "huge-pages", 0, nullptr, 1009 },
|
|
||||||
{ "log-file", 1, nullptr, 'l' },
|
|
||||||
{ "max-cpu-usage", 1, nullptr, 1004 },
|
|
||||||
{ "print-time", 1, nullptr, 1007 },
|
|
||||||
{ "retries", 1, nullptr, 'r' },
|
|
||||||
{ "retry-pause", 1, nullptr, 'R' },
|
|
||||||
{ "safe", 0, nullptr, 1005 },
|
|
||||||
{ "syslog", 0, nullptr, 'S' },
|
|
||||||
{ "threads", 1, nullptr, 't' },
|
|
||||||
{ "user-agent", 1, nullptr, 1008 },
|
|
||||||
{ 0, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static struct option const pool_options[] = {
|
|
||||||
{ "url", 1, nullptr, 'o' },
|
|
||||||
{ "pass", 1, nullptr, 'p' },
|
|
||||||
{ "user", 1, nullptr, 'u' },
|
|
||||||
{ "userpass", 1, nullptr, 'O' },
|
|
||||||
{ "keepalive", 0, nullptr ,'k' },
|
|
||||||
{ "nicehash", 0, nullptr, 1006 },
|
|
||||||
{ 0, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static struct option const api_options[] = {
|
|
||||||
{ "port", 1, nullptr, 4000 },
|
|
||||||
{ "access-token", 1, nullptr, 4001 },
|
|
||||||
{ "worker-id", 1, nullptr, 4002 },
|
|
||||||
{ 0, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const char *algo_names[] = {
|
|
||||||
"cryptonight",
|
|
||||||
# ifndef XMRIG_NO_AEON
|
|
||||||
"cryptonight-lite"
|
|
||||||
# endif
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Options *Options::parse(int argc, char **argv)
|
|
||||||
{
|
|
||||||
Options *options = new Options(argc, argv);
|
|
||||||
if (options->isReady()) {
|
|
||||||
m_self = options;
|
|
||||||
return m_self;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete options;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *Options::algoName() const
|
|
||||||
{
|
|
||||||
return algo_names[m_algo];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Options::Options(int argc, char **argv) :
|
|
||||||
m_background(false),
|
|
||||||
m_colors(true),
|
|
||||||
m_doubleHash(false),
|
|
||||||
m_hugePages(true),
|
|
||||||
m_ready(false),
|
|
||||||
m_safe(false),
|
|
||||||
m_syslog(false),
|
|
||||||
m_apiToken(nullptr),
|
|
||||||
m_apiWorkerId(nullptr),
|
|
||||||
m_logFile(nullptr),
|
|
||||||
m_userAgent(nullptr),
|
|
||||||
m_algo(0),
|
|
||||||
m_algoVariant(0),
|
|
||||||
m_apiPort(0),
|
|
||||||
m_donateLevel(kDonateLevel),
|
|
||||||
m_maxCpuUsage(75),
|
|
||||||
m_printTime(60),
|
|
||||||
m_priority(-1),
|
|
||||||
m_retries(5),
|
|
||||||
m_retryPause(5),
|
|
||||||
m_threads(0),
|
|
||||||
m_affinity(-1L)
|
|
||||||
{
|
|
||||||
m_pools.push_back(new Url());
|
|
||||||
|
|
||||||
int key;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
key = getopt_long(argc, argv, short_options, options, NULL);
|
|
||||||
if (key < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parseArg(key, optarg)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind < argc) {
|
|
||||||
fprintf(stderr, "%s: unsupported non-option argument '%s'\n", argv[0], argv[optind]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_pools[0]->isValid()) {
|
|
||||||
parseConfig(Platform::defaultConfigName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_pools[0]->isValid()) {
|
|
||||||
fprintf(stderr, "No pool URL supplied. Exiting.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_algoVariant = getAlgoVariant();
|
|
||||||
if (m_algoVariant == AV2_AESNI_DOUBLE || m_algoVariant == AV4_SOFT_AES_DOUBLE) {
|
|
||||||
m_doubleHash = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_threads) {
|
|
||||||
m_threads = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage);
|
|
||||||
}
|
|
||||||
else if (m_safe) {
|
|
||||||
const int count = Cpu::optimalThreadsCount(m_algo, m_doubleHash, m_maxCpuUsage);
|
|
||||||
if (m_threads > count) {
|
|
||||||
m_threads = count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Url *url : m_pools) {
|
|
||||||
url->applyExceptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ready = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Options::~Options()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Options::getJSON(const char *fileName, rapidjson::Document &doc)
|
|
||||||
{
|
|
||||||
uv_fs_t req;
|
|
||||||
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
|
|
||||||
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()) {
|
|
||||||
printf("%s:%d: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return doc.IsObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Options::parseArg(int key, const char *arg)
|
|
||||||
{
|
|
||||||
switch (key) {
|
|
||||||
case 'a': /* --algo */
|
|
||||||
if (!setAlgo(arg)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'o': /* --url */
|
|
||||||
if (m_pools.size() > 1 || m_pools[0]->isValid()) {
|
|
||||||
Url *url = new Url(arg);
|
|
||||||
if (url->isValid()) {
|
|
||||||
m_pools.push_back(url);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
delete url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_pools[0]->parse(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_pools.back()->isValid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'O': /* --userpass */
|
|
||||||
if (!m_pools.back()->setUserpass(arg)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'u': /* --user */
|
|
||||||
m_pools.back()->setUser(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'p': /* --pass */
|
|
||||||
m_pools.back()->setPassword(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'l': /* --log-file */
|
|
||||||
free(m_logFile);
|
|
||||||
m_logFile = strdup(arg);
|
|
||||||
m_colors = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4001: /* --access-token */
|
|
||||||
free(m_apiToken);
|
|
||||||
m_apiToken = strdup(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4002: /* --worker-id */
|
|
||||||
free(m_apiWorkerId);
|
|
||||||
m_apiWorkerId = strdup(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'r': /* --retries */
|
|
||||||
case 'R': /* --retry-pause */
|
|
||||||
case 'v': /* --av */
|
|
||||||
case 1003: /* --donate-level */
|
|
||||||
case 1004: /* --max-cpu-usage */
|
|
||||||
case 1007: /* --print-time */
|
|
||||||
case 1021: /* --cpu-priority */
|
|
||||||
case 4000: /* --api-port */
|
|
||||||
return parseArg(key, strtol(arg, nullptr, 10));
|
|
||||||
|
|
||||||
case 'B': /* --background */
|
|
||||||
case 'k': /* --keepalive */
|
|
||||||
case 'S': /* --syslog */
|
|
||||||
case 1005: /* --safe */
|
|
||||||
case 1006: /* --nicehash */
|
|
||||||
return parseBoolean(key, true);
|
|
||||||
|
|
||||||
case 1002: /* --no-color */
|
|
||||||
case 1009: /* --no-huge-pages */
|
|
||||||
return parseBoolean(key, false);
|
|
||||||
|
|
||||||
case 't': /* --threads */
|
|
||||||
if (strncmp(arg, "all", 3) == 0) {
|
|
||||||
m_threads = Cpu::threads();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parseArg(key, strtol(arg, nullptr, 10));
|
|
||||||
|
|
||||||
case 'V': /* --version */
|
|
||||||
showVersion();
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case 'h': /* --help */
|
|
||||||
showUsage(0);
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case 'c': /* --config */
|
|
||||||
parseConfig(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1020: { /* --cpu-affinity */
|
|
||||||
const char *p = strstr(arg, "0x");
|
|
||||||
return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
case 1008: /* --user-agent */
|
|
||||||
free(m_userAgent);
|
|
||||||
m_userAgent = strdup(arg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Options::parseArg(int key, uint64_t arg)
|
|
||||||
{
|
|
||||||
switch (key) {
|
|
||||||
case 'r': /* --retries */
|
|
||||||
if (arg < 1 || arg > 1000) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_retries = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'R': /* --retry-pause */
|
|
||||||
if (arg < 1 || arg > 3600) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_retryPause = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 't': /* --threads */
|
|
||||||
if (arg < 1 || arg > 1024) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_threads = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'v': /* --av */
|
|
||||||
if (arg > 1000) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_algoVariant = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1003: /* --donate-level */
|
|
||||||
if (arg < 1 || arg > 99) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_donateLevel = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1004: /* --max-cpu-usage */
|
|
||||||
if (arg < 1 || arg > 100) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_maxCpuUsage = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1007: /* --print-time */
|
|
||||||
if (arg > 1000) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_printTime = (int) arg;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1020: /* --cpu-affinity */
|
|
||||||
if (arg) {
|
|
||||||
m_affinity = arg;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1021: /* --cpu-priority */
|
|
||||||
if (arg <= 5) {
|
|
||||||
m_priority = (int) arg;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4000: /* --api-port */
|
|
||||||
if (arg <= 65536) {
|
|
||||||
m_apiPort = (int) arg;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Options::parseBoolean(int key, bool enable)
|
|
||||||
{
|
|
||||||
switch (key) {
|
|
||||||
case 'k': /* --keepalive */
|
|
||||||
m_pools.back()->setKeepAlive(enable);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'B': /* --background */
|
|
||||||
m_background = enable;
|
|
||||||
m_colors = enable ? false : m_colors;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'S': /* --syslog */
|
|
||||||
m_syslog = enable;
|
|
||||||
m_colors = enable ? false : m_colors;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1002: /* --no-color */
|
|
||||||
m_colors = enable;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1005: /* --safe */
|
|
||||||
m_safe = enable;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1006: /* --nicehash */
|
|
||||||
m_pools.back()->setNicehash(enable);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1009: /* --no-huge-pages */
|
|
||||||
m_hugePages = enable;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2000: /* colors */
|
|
||||||
m_colors = enable;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Url *Options::parseUrl(const char *arg) const
|
|
||||||
{
|
|
||||||
auto url = new Url(arg);
|
|
||||||
if (!url->isValid()) {
|
|
||||||
delete url;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Options::parseConfig(const char *fileName)
|
|
||||||
{
|
|
||||||
rapidjson::Document doc;
|
|
||||||
if (!getJSON(fileName, doc)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
|
|
||||||
parseJSON(&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(&pool_options[i], value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const rapidjson::Value &api = doc["api"];
|
|
||||||
if (api.IsObject()) {
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) {
|
|
||||||
parseJSON(&api_options[i], api);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Options::parseJSON(const struct option *option, const rapidjson::Value &object)
|
|
||||||
{
|
|
||||||
if (!option->name || !object.HasMember(option->name)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rapidjson::Value &value = object[option->name];
|
|
||||||
|
|
||||||
if (option->has_arg && value.IsString()) {
|
|
||||||
parseArg(option->val, value.GetString());
|
|
||||||
}
|
|
||||||
else if (option->has_arg && value.IsUint64()) {
|
|
||||||
parseArg(option->val, value.GetUint64());
|
|
||||||
}
|
|
||||||
else if (!option->has_arg && value.IsBool()) {
|
|
||||||
parseBoolean(option->val, value.IsTrue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Options::showUsage(int status) const
|
|
||||||
{
|
|
||||||
if (status) {
|
|
||||||
fprintf(stderr, "Try \"" APP_ID "\" --help' for more information.\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf(usage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Options::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)
|
|
||||||
" i386"
|
|
||||||
# elif defined(__x86_64__) || defined(_M_AMD64)
|
|
||||||
" x86_64"
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(__AES__) || defined(_MSC_VER)
|
|
||||||
" AES-NI"
|
|
||||||
# endif
|
|
||||||
"\n");
|
|
||||||
|
|
||||||
printf("\nlibuv/%s\n", uv_version_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Options::setAlgo(const char *algo)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(algo_names); i++) {
|
|
||||||
if (algo_names[i] && !strcmp(algo, algo_names[i])) {
|
|
||||||
m_algo = (int) i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifndef XMRIG_NO_AEON
|
|
||||||
if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) {
|
|
||||||
m_algo = ALGO_CRYPTONIGHT_LITE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
if (i == ARRAY_SIZE(algo_names) - 1) {
|
|
||||||
showUsage(1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Options::getAlgoVariant() const
|
|
||||||
{
|
|
||||||
# ifndef XMRIG_NO_AEON
|
|
||||||
if (m_algo == ALGO_CRYPTONIGHT_LITE) {
|
|
||||||
return getAlgoVariantLite();
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
|
||||||
return Cpu::hasAES() ? AV1_AESNI : AV3_SOFT_AES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
|
||||||
return m_algoVariant + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_algoVariant;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_NO_AEON
|
|
||||||
int Options::getAlgoVariantLite() const
|
|
||||||
{
|
|
||||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
|
||||||
return Cpu::hasAES() ? AV2_AESNI_DOUBLE : AV4_SOFT_AES_DOUBLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
|
||||||
return m_algoVariant + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_algoVariant;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
134
src/Options.h
134
src/Options.h
@@ -1,134 +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 __OPTIONS_H__
|
|
||||||
#define __OPTIONS_H__
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
#include "rapidjson/fwd.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Url;
|
|
||||||
struct option;
|
|
||||||
|
|
||||||
|
|
||||||
class Options
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Algo {
|
|
||||||
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
|
|
||||||
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
|
||||||
};
|
|
||||||
|
|
||||||
enum AlgoVariant {
|
|
||||||
AV0_AUTO,
|
|
||||||
AV1_AESNI,
|
|
||||||
AV2_AESNI_DOUBLE,
|
|
||||||
AV3_SOFT_AES,
|
|
||||||
AV4_SOFT_AES_DOUBLE,
|
|
||||||
AV_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline Options* i() { return m_self; }
|
|
||||||
static Options *parse(int argc, char **argv);
|
|
||||||
|
|
||||||
inline bool background() const { return m_background; }
|
|
||||||
inline bool colors() const { return m_colors; }
|
|
||||||
inline bool doubleHash() const { return m_doubleHash; }
|
|
||||||
inline bool hugePages() const { return m_hugePages; }
|
|
||||||
inline bool syslog() const { return m_syslog; }
|
|
||||||
inline const char *apiToken() const { return m_apiToken; }
|
|
||||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
|
||||||
inline const char *logFile() const { return m_logFile; }
|
|
||||||
inline const char *userAgent() const { return m_userAgent; }
|
|
||||||
inline const std::vector<Url*> &pools() const { return m_pools; }
|
|
||||||
inline int algo() const { return m_algo; }
|
|
||||||
inline int algoVariant() const { return m_algoVariant; }
|
|
||||||
inline int apiPort() const { return m_apiPort; }
|
|
||||||
inline int donateLevel() const { return m_donateLevel; }
|
|
||||||
inline int printTime() const { return m_printTime; }
|
|
||||||
inline int priority() const { return m_priority; }
|
|
||||||
inline int retries() const { return m_retries; }
|
|
||||||
inline int retryPause() const { return m_retryPause; }
|
|
||||||
inline int threads() const { return m_threads; }
|
|
||||||
inline int64_t affinity() const { return m_affinity; }
|
|
||||||
|
|
||||||
inline static void release() { delete m_self; }
|
|
||||||
|
|
||||||
const char *algoName() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Options(int argc, char **argv);
|
|
||||||
~Options();
|
|
||||||
|
|
||||||
inline bool isReady() const { return m_ready; }
|
|
||||||
|
|
||||||
static Options *m_self;
|
|
||||||
|
|
||||||
bool getJSON(const char *fileName, rapidjson::Document &doc);
|
|
||||||
bool parseArg(int key, const char *arg);
|
|
||||||
bool parseArg(int key, uint64_t arg);
|
|
||||||
bool parseBoolean(int key, bool enable);
|
|
||||||
Url *parseUrl(const char *arg) const;
|
|
||||||
void parseConfig(const char *fileName);
|
|
||||||
void parseJSON(const struct option *option, const rapidjson::Value &object);
|
|
||||||
void showUsage(int status) const;
|
|
||||||
void showVersion(void);
|
|
||||||
|
|
||||||
bool setAlgo(const char *algo);
|
|
||||||
|
|
||||||
int getAlgoVariant() const;
|
|
||||||
# ifndef XMRIG_NO_AEON
|
|
||||||
int getAlgoVariantLite() const;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
bool m_background;
|
|
||||||
bool m_colors;
|
|
||||||
bool m_doubleHash;
|
|
||||||
bool m_hugePages;
|
|
||||||
bool m_ready;
|
|
||||||
bool m_safe;
|
|
||||||
bool m_syslog;
|
|
||||||
char *m_apiToken;
|
|
||||||
char *m_apiWorkerId;
|
|
||||||
char *m_logFile;
|
|
||||||
char *m_userAgent;
|
|
||||||
int m_algo;
|
|
||||||
int m_algoVariant;
|
|
||||||
int m_apiPort;
|
|
||||||
int m_donateLevel;
|
|
||||||
int m_maxCpuUsage;
|
|
||||||
int m_printTime;
|
|
||||||
int m_priority;
|
|
||||||
int m_retries;
|
|
||||||
int m_retryPause;
|
|
||||||
int m_threads;
|
|
||||||
int64_t m_affinity;
|
|
||||||
std::vector<Url*> m_pools;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __OPTIONS_H__ */
|
|
||||||
@@ -1,108 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "version.h"
|
|
||||||
|
|
||||||
#ifdef XMRIG_NVIDIA_PROJECT
|
|
||||||
# include "nvidia/cryptonight.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static inline char *createUserAgent()
|
|
||||||
{
|
|
||||||
const size_t max = 160;
|
|
||||||
|
|
||||||
char *buf = new char[max];
|
|
||||||
|
|
||||||
# ifdef XMRIG_NVIDIA_PROJECT
|
|
||||||
const int cudaVersion = cuda_get_runtime_version();
|
|
||||||
snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__);
|
|
||||||
# else
|
|
||||||
snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::init(const char *userAgent)
|
|
||||||
{
|
|
||||||
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::release()
|
|
||||||
{
|
|
||||||
delete [] m_userAgent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::setProcessPriority(int priority)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::setThreadPriority(int priority)
|
|
||||||
{
|
|
||||||
if (priority == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int prio = 19;
|
|
||||||
switch (priority)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
prio = 5;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
prio = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
prio = -5;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
prio = -10;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
prio = -15;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
setpriority(PRIO_PROCESS, 0, prio);
|
|
||||||
}
|
|
||||||
|
|
||||||
240
src/Summary.cpp
240
src/Summary.cpp
@@ -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-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
|
||||||
@@ -23,146 +24,147 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
#include "base/net/Pool.h"
|
||||||
#include "log/Log.h"
|
#include "common/cpu/Cpu.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "core/Config.h"
|
||||||
|
#include "core/Controller.h"
|
||||||
|
#include "crypto/Asm.h"
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "net/Url.h"
|
|
||||||
#include "Options.h"
|
|
||||||
#include "Summary.h"
|
#include "Summary.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
|
||||||
static void print_versions()
|
#ifndef XMRIG_NO_ASM
|
||||||
|
static const char *coloredAsmNames[] = {
|
||||||
|
"\x1B[1;31mnone\x1B[0m",
|
||||||
|
"auto",
|
||||||
|
"\x1B[1;32mintel\x1B[0m",
|
||||||
|
"\x1B[1;32mryzen\x1B[0m",
|
||||||
|
"\x1B[1;32mbulldozer\x1B[0m"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline static const char *asmName(xmrig::Assembly assembly, bool colors)
|
||||||
{
|
{
|
||||||
char buf[16];
|
return colors ? coloredAsmNames[assembly] : xmrig::Asm::toString(assembly);
|
||||||
|
|
||||||
# if defined(__clang__)
|
|
||||||
snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
|
||||||
# elif defined(__GNUC__)
|
|
||||||
snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
|
||||||
# elif defined(_MSC_VER)
|
|
||||||
snprintf(buf, 16, " MSVC/%d", MSVC_VERSION);
|
|
||||||
# else
|
|
||||||
buf[0] = '\0';
|
|
||||||
# endif
|
|
||||||
|
|
||||||
|
|
||||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s",
|
|
||||||
APP_VERSION, uv_version_string(), buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_memory() {
|
|
||||||
if (Options::i()->colors()) {
|
|
||||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s, %s",
|
|
||||||
Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable",
|
|
||||||
Mem::isHugepagesEnabled() ? "\x1B[01;32menabled" : "\x1B[01;31mdisabled");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log::i()->text(" * HUGE PAGES: %s, %s", Mem::isHugepagesAvailable() ? "available" : "unavailable", Mem::isHugepagesEnabled() ? "enabled" : "disabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_cpu()
|
|
||||||
{
|
|
||||||
if (Options::i()->colors()) {
|
|
||||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI",
|
|
||||||
Cpu::brand(),
|
|
||||||
Cpu::sockets(),
|
|
||||||
Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-",
|
|
||||||
Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-");
|
|
||||||
# ifndef XMRIG_NO_LIBCPUID
|
|
||||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-");
|
|
||||||
# ifndef XMRIG_NO_LIBCPUID
|
|
||||||
Log::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_threads()
|
|
||||||
{
|
|
||||||
char buf[32];
|
|
||||||
if (Options::i()->affinity() != -1L) {
|
|
||||||
snprintf(buf, 32, ", affinity=0x%" PRIX64, Options::i()->affinity());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf[0] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s",
|
|
||||||
Options::i()->threads(),
|
|
||||||
Options::i()->algoName(),
|
|
||||||
Options::i()->algoVariant(),
|
|
||||||
Options::i()->colors() && Options::i()->donateLevel() == 0 ? "\x1B[01;31m" : "",
|
|
||||||
Options::i()->donateLevel(),
|
|
||||||
buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_pools()
|
|
||||||
{
|
|
||||||
const std::vector<Url*> &pools = Options::i()->pools();
|
|
||||||
|
|
||||||
for (size_t i = 0; i < pools.size(); ++i) {
|
|
||||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d",
|
|
||||||
i + 1,
|
|
||||||
pools[i]->host(),
|
|
||||||
pools[i]->port());
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef APP_DEBUG
|
|
||||||
for (size_t i = 0; i < pools.size(); ++i) {
|
|
||||||
Log::i()->text("%s:%d, user: %s, pass: %s, ka: %d, nicehash: %d", pools[i]->host(), pools[i]->port(), pools[i]->user(), pools[i]->password(), pools[i]->isKeepAlive(), pools[i]->isNicehash());
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_NO_API
|
|
||||||
static void print_api()
|
|
||||||
{
|
|
||||||
if (Options::i()->apiPort() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", Options::i()->apiPort());
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void print_commands()
|
static void print_memory(xmrig::Config *config) {
|
||||||
{
|
# ifdef _WIN32
|
||||||
if (Options::i()->colors()) {
|
if (config->isColors()) {
|
||||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume");
|
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
|
||||||
|
"HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume");
|
Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable");
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void print_cpu(xmrig::Config *config)
|
||||||
|
{
|
||||||
|
using namespace xmrig;
|
||||||
|
|
||||||
|
if (config->isColors()) {
|
||||||
|
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%d)") " %sx64 %sAES %sAVX2",
|
||||||
|
"CPU",
|
||||||
|
Cpu::info()->brand(),
|
||||||
|
Cpu::info()->sockets(),
|
||||||
|
Cpu::info()->isX64() ? "\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
|
||||||
|
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
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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
|
||||||
|
Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::info()->L2() / 1024.0, Cpu::info()->L3() / 1024.0);
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Summary::print()
|
static void print_threads(xmrig::Config *config)
|
||||||
{
|
{
|
||||||
print_versions();
|
if (config->threadsMode() != xmrig::Config::Advanced) {
|
||||||
print_memory();
|
char buf[32] = { 0 };
|
||||||
print_cpu();
|
if (config->affinity() != -1L) {
|
||||||
print_threads();
|
snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity());
|
||||||
print_pools();
|
}
|
||||||
|
|
||||||
# ifndef XMRIG_NO_API
|
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s")
|
||||||
print_api();
|
: " * %-13s%d, %s, av=%d, %sdonate=%d%%%s",
|
||||||
|
"THREADS",
|
||||||
|
config->threadsCount(),
|
||||||
|
config->algorithm().name(),
|
||||||
|
config->algoVariant(),
|
||||||
|
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
|
||||||
|
config->donateLevel(),
|
||||||
|
buf);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%")
|
||||||
|
: " * %-13s%d, %s, %sdonate=%d%%",
|
||||||
|
"THREADS",
|
||||||
|
config->threadsCount(),
|
||||||
|
config->algorithm().name(),
|
||||||
|
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
|
||||||
|
config->donateLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifndef XMRIG_NO_ASM
|
||||||
|
if (config->assembly() == xmrig::ASM_AUTO) {
|
||||||
|
const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly();
|
||||||
|
|
||||||
|
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s")
|
||||||
|
: " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors()));
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
print_commands();
|
|
||||||
|
static void print_commands(xmrig::Config *config)
|
||||||
|
{
|
||||||
|
if (config->isColors()) {
|
||||||
|
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
|
||||||
|
MAGENTA_BOLD("p") WHITE_BOLD("ause, ")
|
||||||
|
MAGENTA_BOLD("r") WHITE_BOLD("esume"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Summary::print(xmrig::Controller *controller)
|
||||||
|
{
|
||||||
|
controller->config()->printVersions();
|
||||||
|
print_memory(controller->config());
|
||||||
|
print_cpu(controller->config());
|
||||||
|
print_threads(controller->config());
|
||||||
|
controller->config()->printPools();
|
||||||
|
controller->config()->printAPI();
|
||||||
|
|
||||||
|
print_commands(controller->config());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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,10 +25,15 @@
|
|||||||
#define __SUMMARY_H__
|
#define __SUMMARY_H__
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
class Controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Summary
|
class Summary
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void print();
|
static void print(xmrig::Controller *controller);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -25,17 +26,17 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "api/Api.h"
|
#include "api/Api.h"
|
||||||
#include "api/ApiState.h"
|
#include "api/ApiRouter.h"
|
||||||
|
#include "common/api/HttpReply.h"
|
||||||
|
#include "common/api/HttpRequest.h"
|
||||||
|
|
||||||
|
|
||||||
ApiState *Api::m_state = nullptr;
|
ApiRouter *Api::m_router = nullptr;
|
||||||
uv_mutex_t Api::m_mutex;
|
|
||||||
|
|
||||||
|
|
||||||
bool Api::start()
|
bool Api::start(xmrig::Controller *controller)
|
||||||
{
|
{
|
||||||
uv_mutex_init(&m_mutex);
|
m_router = new ApiRouter(controller);
|
||||||
m_state = new ApiState();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -43,43 +44,30 @@ bool Api::start()
|
|||||||
|
|
||||||
void Api::release()
|
void Api::release()
|
||||||
{
|
{
|
||||||
delete m_state;
|
delete m_router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *Api::get(const char *url, int *status)
|
void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
|
||||||
{
|
{
|
||||||
if (!m_state) {
|
if (!m_router) {
|
||||||
return nullptr;
|
reply.status = 500;
|
||||||
}
|
|
||||||
|
|
||||||
uv_mutex_lock(&m_mutex);
|
|
||||||
char *buf = m_state->get(url, status);
|
|
||||||
uv_mutex_unlock(&m_mutex);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Api::tick(const Hashrate *hashrate)
|
|
||||||
{
|
|
||||||
if (!m_state) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_mutex_lock(&m_mutex);
|
if (req.method() == xmrig::HttpRequest::Get) {
|
||||||
m_state->tick(hashrate);
|
return m_router->get(req, reply);
|
||||||
uv_mutex_unlock(&m_mutex);
|
}
|
||||||
|
|
||||||
|
m_router->exec(req, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Api::tick(const NetworkState &network)
|
void Api::tick(const xmrig::NetworkState &network)
|
||||||
{
|
{
|
||||||
if (!m_state) {
|
if (!m_router) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_mutex_lock(&m_mutex);
|
m_router->tick(network);
|
||||||
m_state->tick(network);
|
|
||||||
uv_mutex_unlock(&m_mutex);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,31 +22,36 @@
|
|||||||
* 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>
|
||||||
|
|
||||||
|
|
||||||
class ApiState;
|
class ApiRouter;
|
||||||
class Hashrate;
|
class Hashrate;
|
||||||
class NetworkState;
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
class Controller;
|
||||||
|
class HttpReply;
|
||||||
|
class HttpRequest;
|
||||||
|
class NetworkState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Api
|
class Api
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool start();
|
static bool start(xmrig::Controller *controller);
|
||||||
static void release();
|
static void release();
|
||||||
|
|
||||||
static char *get(const char *url, int *status);
|
static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
|
||||||
static void tick(const Hashrate *hashrate);
|
static void tick(const xmrig::NetworkState &results);
|
||||||
static void tick(const NetworkState &results);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ApiState *m_state;
|
static ApiRouter *m_router;
|
||||||
static uv_mutex_t m_mutex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __API_H__ */
|
#endif /* XMRIG_API_H */
|
||||||
|
|||||||
341
src/api/ApiRouter.cpp
Normal file
341
src/api/ApiRouter.cpp
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
/* 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 <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
# include "winsock2.h"
|
||||||
|
#else
|
||||||
|
# include "unistd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "api/ApiRouter.h"
|
||||||
|
#include "common/api/HttpReply.h"
|
||||||
|
#include "common/api/HttpRequest.h"
|
||||||
|
#include "common/cpu/Cpu.h"
|
||||||
|
#include "common/crypto/keccak.h"
|
||||||
|
#include "common/net/Job.h"
|
||||||
|
#include "common/Platform.h"
|
||||||
|
#include "core/Config.h"
|
||||||
|
#include "core/Controller.h"
|
||||||
|
#include "interfaces/IThread.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
#include "rapidjson/prettywriter.h"
|
||||||
|
#include "rapidjson/stringbuffer.h"
|
||||||
|
#include "version.h"
|
||||||
|
#include "workers/Hashrate.h"
|
||||||
|
#include "workers/Workers.h"
|
||||||
|
|
||||||
|
|
||||||
|
static inline rapidjson::Value normalize(double d)
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
if (!isnormal(d)) {
|
||||||
|
return Value(kNullType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Value(floor(d * 100.0) / 100.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ApiRouter::ApiRouter(xmrig::Controller *controller) :
|
||||||
|
m_controller(controller)
|
||||||
|
{
|
||||||
|
memset(m_workerId, 0, sizeof(m_workerId));
|
||||||
|
|
||||||
|
setWorkerId(controller->config()->apiWorkerId());
|
||||||
|
genId(controller->config()->apiId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ApiRouter::~ApiRouter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const
|
||||||
|
{
|
||||||
|
rapidjson::Document doc;
|
||||||
|
|
||||||
|
if (req.match("/1/config")) {
|
||||||
|
if (req.isRestricted()) {
|
||||||
|
reply.status = 403;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_controller->config()->getJSON(doc);
|
||||||
|
|
||||||
|
return finalize(reply, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.match("/1/threads")) {
|
||||||
|
getThreads(doc);
|
||||||
|
|
||||||
|
return finalize(reply, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.SetObject();
|
||||||
|
|
||||||
|
getIdentify(doc);
|
||||||
|
getMiner(doc);
|
||||||
|
getHashrate(doc);
|
||||||
|
getResults(doc);
|
||||||
|
getConnection(doc);
|
||||||
|
|
||||||
|
return finalize(reply, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
|
||||||
|
{
|
||||||
|
if (req.method() == xmrig::HttpRequest::Put && req.match("/1/config")) {
|
||||||
|
m_controller->config()->reload(req.body());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.status = 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::tick(const xmrig::NetworkState &network)
|
||||||
|
{
|
||||||
|
m_network = network;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig)
|
||||||
|
{
|
||||||
|
updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
rapidjson::StringBuffer buffer(nullptr, 4096);
|
||||||
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
||||||
|
writer.SetMaxDecimalPlaces(10);
|
||||||
|
doc.Accept(writer);
|
||||||
|
|
||||||
|
reply.status = 200;
|
||||||
|
reply.buf = strdup(buffer.GetString());
|
||||||
|
reply.size = buffer.GetSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::genId(const char *id)
|
||||||
|
{
|
||||||
|
memset(m_id, 0, sizeof(m_id));
|
||||||
|
|
||||||
|
if (id && strlen(id) > 0) {
|
||||||
|
strncpy(m_id, id, sizeof(m_id) - 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uv_interface_address_t *interfaces;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (uv_interface_addresses(&interfaces, &count) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) {
|
||||||
|
uint8_t hash[200];
|
||||||
|
const size_t addrSize = sizeof(interfaces[i].phys_addr);
|
||||||
|
const size_t inSize = strlen(APP_KIND) + addrSize + sizeof(uint16_t);
|
||||||
|
const uint16_t port = static_cast<uint16_t>(m_controller->config()->apiPort());
|
||||||
|
|
||||||
|
uint8_t *input = new uint8_t[inSize]();
|
||||||
|
memcpy(input, &port, sizeof(uint16_t));
|
||||||
|
memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize);
|
||||||
|
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND));
|
||||||
|
|
||||||
|
xmrig::keccak(input, inSize, hash);
|
||||||
|
xmrig::Job::toHex(hash, 8, m_id);
|
||||||
|
|
||||||
|
delete [] input;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uv_free_interface_addresses(interfaces, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getConnection(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
rapidjson::Value connection(rapidjson::kObjectType);
|
||||||
|
connection.AddMember("pool", rapidjson::StringRef(m_network.pool), allocator);
|
||||||
|
connection.AddMember("uptime", m_network.connectionTime(), allocator);
|
||||||
|
connection.AddMember("ping", m_network.latency(), allocator);
|
||||||
|
connection.AddMember("failures", m_network.failures, allocator);
|
||||||
|
connection.AddMember("error_log", rapidjson::Value(rapidjson::kArrayType), allocator);
|
||||||
|
|
||||||
|
doc.AddMember("connection", connection, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getHashrate(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
rapidjson::Value hashrate(rapidjson::kObjectType);
|
||||||
|
rapidjson::Value total(rapidjson::kArrayType);
|
||||||
|
rapidjson::Value threads(rapidjson::kArrayType);
|
||||||
|
|
||||||
|
const Hashrate *hr = Workers::hashrate();
|
||||||
|
|
||||||
|
total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator);
|
||||||
|
total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
|
||||||
|
total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < Workers::threads(); i++) {
|
||||||
|
rapidjson::Value thread(rapidjson::kArrayType);
|
||||||
|
thread.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||||
|
thread.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||||
|
thread.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
||||||
|
|
||||||
|
threads.PushBack(thread, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
hashrate.AddMember("total", total, allocator);
|
||||||
|
hashrate.AddMember("highest", normalize(hr->highest()), allocator);
|
||||||
|
hashrate.AddMember("threads", threads, allocator);
|
||||||
|
doc.AddMember("hashrate", hashrate, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getIdentify(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
doc.AddMember("id", rapidjson::StringRef(m_id), doc.GetAllocator());
|
||||||
|
doc.AddMember("worker_id", rapidjson::StringRef(m_workerId), doc.GetAllocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getMiner(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace xmrig;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
rapidjson::Value cpu(rapidjson::kObjectType);
|
||||||
|
cpu.AddMember("brand", rapidjson::StringRef(Cpu::info()->brand()), allocator);
|
||||||
|
cpu.AddMember("aes", Cpu::info()->hasAES(), allocator);
|
||||||
|
cpu.AddMember("x64", Cpu::info()->isX64(), allocator);
|
||||||
|
cpu.AddMember("sockets", Cpu::info()->sockets(), allocator);
|
||||||
|
|
||||||
|
doc.AddMember("version", APP_VERSION, allocator);
|
||||||
|
doc.AddMember("kind", APP_KIND, allocator);
|
||||||
|
doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator);
|
||||||
|
doc.AddMember("cpu", cpu, allocator);
|
||||||
|
doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator);
|
||||||
|
doc.AddMember("hugepages", Workers::hugePages() > 0, allocator);
|
||||||
|
doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getResults(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
rapidjson::Value results(rapidjson::kObjectType);
|
||||||
|
|
||||||
|
results.AddMember("diff_current", m_network.diff, allocator);
|
||||||
|
results.AddMember("shares_good", m_network.accepted, allocator);
|
||||||
|
results.AddMember("shares_total", m_network.accepted + m_network.rejected, allocator);
|
||||||
|
results.AddMember("avg_time", m_network.avgTime(), allocator);
|
||||||
|
results.AddMember("hashes_total", m_network.total, allocator);
|
||||||
|
|
||||||
|
rapidjson::Value best(rapidjson::kArrayType);
|
||||||
|
for (size_t i = 0; i < m_network.topDiff.size(); ++i) {
|
||||||
|
best.PushBack(m_network.topDiff[i], allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.AddMember("best", best, allocator);
|
||||||
|
results.AddMember("error_log", rapidjson::Value(rapidjson::kArrayType), allocator);
|
||||||
|
|
||||||
|
doc.AddMember("results", results, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::getThreads(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
doc.SetObject();
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
const Hashrate *hr = Workers::hashrate();
|
||||||
|
|
||||||
|
Workers::threadsSummary(doc);
|
||||||
|
|
||||||
|
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
|
||||||
|
rapidjson::Value list(rapidjson::kArrayType);
|
||||||
|
|
||||||
|
size_t i = 0;
|
||||||
|
for (const xmrig::IThread *thread : threads) {
|
||||||
|
rapidjson::Value value = thread->toAPI(doc);
|
||||||
|
|
||||||
|
rapidjson::Value hashrate(rapidjson::kArrayType);
|
||||||
|
hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||||
|
hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||||
|
hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
value.AddMember("hashrate", hashrate, allocator);
|
||||||
|
list.PushBack(value, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.AddMember("threads", list, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::setWorkerId(const char *id)
|
||||||
|
{
|
||||||
|
memset(m_workerId, 0, sizeof(m_workerId));
|
||||||
|
|
||||||
|
if (id && strlen(id) > 0) {
|
||||||
|
strncpy(m_workerId, id, sizeof(m_workerId) - 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gethostname(m_workerId, sizeof(m_workerId) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ApiRouter::updateWorkerId(const char *id, const char *previousId)
|
||||||
|
{
|
||||||
|
if (id == previousId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != nullptr && previousId != nullptr && strcmp(id, previousId) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setWorkerId(id);
|
||||||
|
}
|
||||||
76
src/api/ApiRouter.h
Normal file
76
src/api/ApiRouter.h
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_APIROUTER_H
|
||||||
|
#define XMRIG_APIROUTER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "api/NetworkState.h"
|
||||||
|
#include "common/interfaces/IControllerListener.h"
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Hashrate;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
class Controller;
|
||||||
|
class HttpReply;
|
||||||
|
class HttpRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ApiRouter : public xmrig::IControllerListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ApiRouter(xmrig::Controller *controller);
|
||||||
|
~ApiRouter() override;
|
||||||
|
|
||||||
|
void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const;
|
||||||
|
void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
|
||||||
|
|
||||||
|
void tick(const xmrig::NetworkState &results);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const;
|
||||||
|
void genId(const char *id);
|
||||||
|
void getConnection(rapidjson::Document &doc) const;
|
||||||
|
void getHashrate(rapidjson::Document &doc) const;
|
||||||
|
void getIdentify(rapidjson::Document &doc) const;
|
||||||
|
void getMiner(rapidjson::Document &doc) const;
|
||||||
|
void getResults(rapidjson::Document &doc) const;
|
||||||
|
void getThreads(rapidjson::Document &doc) const;
|
||||||
|
void setWorkerId(const char *id);
|
||||||
|
void updateWorkerId(const char *id, const char *previousId);
|
||||||
|
|
||||||
|
char m_id[32];
|
||||||
|
char m_workerId[128];
|
||||||
|
xmrig::NetworkState m_network;
|
||||||
|
xmrig::Controller *m_controller;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* XMRIG_APIROUTER_H */
|
||||||
@@ -1,260 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <string.h>
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
#if _WIN32
|
|
||||||
# include "winsock2.h"
|
|
||||||
#else
|
|
||||||
# include "unistd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#include "api/ApiState.h"
|
|
||||||
#include "Cpu.h"
|
|
||||||
#include "Mem.h"
|
|
||||||
#include "net/Job.h"
|
|
||||||
#include "Options.h"
|
|
||||||
#include "Platform.h"
|
|
||||||
#include "rapidjson/document.h"
|
|
||||||
#include "rapidjson/stringbuffer.h"
|
|
||||||
#include "rapidjson/prettywriter.h"
|
|
||||||
#include "version.h"
|
|
||||||
#include "workers/Hashrate.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include "crypto/c_keccak.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline double normalize(double d)
|
|
||||||
{
|
|
||||||
if (!std::isnormal(d)) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::floor(d * 100.0) / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ApiState::ApiState()
|
|
||||||
{
|
|
||||||
m_threads = Options::i()->threads();
|
|
||||||
m_hashrate = new double[m_threads * 3]();
|
|
||||||
|
|
||||||
memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
|
|
||||||
memset(m_workerId, 0, sizeof(m_workerId));
|
|
||||||
|
|
||||||
if (Options::i()->apiWorkerId()) {
|
|
||||||
strncpy(m_workerId, Options::i()->apiWorkerId(), sizeof(m_workerId) - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gethostname(m_workerId, sizeof(m_workerId) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
genId();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ApiState::~ApiState()
|
|
||||||
{
|
|
||||||
delete [] m_hashrate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *ApiState::get(const char *url, int *status) const
|
|
||||||
{
|
|
||||||
rapidjson::Document doc;
|
|
||||||
doc.SetObject();
|
|
||||||
|
|
||||||
getIdentify(doc);
|
|
||||||
getMiner(doc);
|
|
||||||
getHashrate(doc);
|
|
||||||
getResults(doc);
|
|
||||||
getConnection(doc);
|
|
||||||
|
|
||||||
return finalize(doc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::tick(const Hashrate *hashrate)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < m_threads; ++i) {
|
|
||||||
m_hashrate[i * 3] = hashrate->calc((size_t) i, Hashrate::ShortInterval);
|
|
||||||
m_hashrate[i * 3 + 1] = hashrate->calc((size_t) i, Hashrate::MediumInterval);
|
|
||||||
m_hashrate[i * 3 + 2] = hashrate->calc((size_t) i, Hashrate::LargeInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_totalHashrate[0] = hashrate->calc(Hashrate::ShortInterval);
|
|
||||||
m_totalHashrate[1] = hashrate->calc(Hashrate::MediumInterval);
|
|
||||||
m_totalHashrate[2] = hashrate->calc(Hashrate::LargeInterval);
|
|
||||||
m_highestHashrate = hashrate->highest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::tick(const NetworkState &network)
|
|
||||||
{
|
|
||||||
m_network = network;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char *ApiState::finalize(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
rapidjson::StringBuffer buffer(0, 4096);
|
|
||||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
|
||||||
writer.SetMaxDecimalPlaces(10);
|
|
||||||
doc.Accept(writer);
|
|
||||||
|
|
||||||
return strdup(buffer.GetString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::genId()
|
|
||||||
{
|
|
||||||
memset(m_id, 0, sizeof(m_id));
|
|
||||||
|
|
||||||
uv_interface_address_t *interfaces;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
if (uv_interface_addresses(&interfaces, &count) < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) {
|
|
||||||
uint8_t hash[200];
|
|
||||||
const size_t addrSize = sizeof(interfaces[i].phys_addr);
|
|
||||||
const size_t inSize = strlen(APP_KIND) + addrSize;
|
|
||||||
|
|
||||||
uint8_t *input = new uint8_t[inSize]();
|
|
||||||
memcpy(input, interfaces[i].phys_addr, addrSize);
|
|
||||||
memcpy(input + addrSize, APP_KIND, strlen(APP_KIND));
|
|
||||||
|
|
||||||
keccak(input, static_cast<int>(inSize), hash, sizeof(hash));
|
|
||||||
Job::toHex(hash, 8, m_id);
|
|
||||||
|
|
||||||
delete [] input;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uv_free_interface_addresses(interfaces, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::getConnection(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
auto &allocator = doc.GetAllocator();
|
|
||||||
|
|
||||||
rapidjson::Value connection(rapidjson::kObjectType);
|
|
||||||
connection.AddMember("pool", rapidjson::StringRef(m_network.pool), allocator);
|
|
||||||
connection.AddMember("uptime", m_network.connectionTime(), allocator);
|
|
||||||
connection.AddMember("ping", m_network.latency(), allocator);
|
|
||||||
connection.AddMember("failures", m_network.failures, allocator);
|
|
||||||
connection.AddMember("error_log", rapidjson::Value(rapidjson::kArrayType), allocator);
|
|
||||||
|
|
||||||
doc.AddMember("connection", connection, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::getHashrate(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
auto &allocator = doc.GetAllocator();
|
|
||||||
|
|
||||||
rapidjson::Value hashrate(rapidjson::kObjectType);
|
|
||||||
rapidjson::Value total(rapidjson::kArrayType);
|
|
||||||
rapidjson::Value threads(rapidjson::kArrayType);
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
|
||||||
total.PushBack(normalize(m_totalHashrate[i]), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < m_threads * 3; i += 3) {
|
|
||||||
rapidjson::Value thread(rapidjson::kArrayType);
|
|
||||||
thread.PushBack(normalize(m_hashrate[i]), allocator);
|
|
||||||
thread.PushBack(normalize(m_hashrate[i + 1]), allocator);
|
|
||||||
thread.PushBack(normalize(m_hashrate[i + 2]), allocator);
|
|
||||||
|
|
||||||
threads.PushBack(thread, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
hashrate.AddMember("total", total, allocator);
|
|
||||||
hashrate.AddMember("highest", normalize(m_highestHashrate), allocator);
|
|
||||||
hashrate.AddMember("threads", threads, allocator);
|
|
||||||
doc.AddMember("hashrate", hashrate, allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::getIdentify(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
doc.AddMember("id", rapidjson::StringRef(m_id), doc.GetAllocator());
|
|
||||||
doc.AddMember("worker_id", rapidjson::StringRef(m_workerId), doc.GetAllocator());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::getMiner(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
auto &allocator = doc.GetAllocator();
|
|
||||||
|
|
||||||
rapidjson::Value cpu(rapidjson::kObjectType);
|
|
||||||
cpu.AddMember("brand", rapidjson::StringRef(Cpu::brand()), allocator);
|
|
||||||
cpu.AddMember("aes", Cpu::hasAES(), allocator);
|
|
||||||
cpu.AddMember("x64", Cpu::isX64(), allocator);
|
|
||||||
cpu.AddMember("sockets", Cpu::sockets(), allocator);
|
|
||||||
|
|
||||||
doc.AddMember("version", APP_VERSION, allocator);
|
|
||||||
doc.AddMember("kind", APP_KIND, allocator);
|
|
||||||
doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator);
|
|
||||||
doc.AddMember("cpu", cpu, allocator);
|
|
||||||
doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator);
|
|
||||||
doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator);
|
|
||||||
doc.AddMember("donate_level", Options::i()->donateLevel(), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ApiState::getResults(rapidjson::Document &doc) const
|
|
||||||
{
|
|
||||||
auto &allocator = doc.GetAllocator();
|
|
||||||
|
|
||||||
rapidjson::Value results(rapidjson::kObjectType);
|
|
||||||
|
|
||||||
results.AddMember("diff_current", m_network.diff, allocator);
|
|
||||||
results.AddMember("shares_good", m_network.accepted, allocator);
|
|
||||||
results.AddMember("shares_total", m_network.accepted + m_network.rejected, allocator);
|
|
||||||
results.AddMember("avg_time", m_network.avgTime(), allocator);
|
|
||||||
results.AddMember("hashes_total", m_network.total, allocator);
|
|
||||||
|
|
||||||
rapidjson::Value best(rapidjson::kArrayType);
|
|
||||||
for (size_t i = 0; i < m_network.topDiff.size(); ++i) {
|
|
||||||
best.PushBack(m_network.topDiff[i], allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
results.AddMember("best", best, allocator);
|
|
||||||
results.AddMember("error_log", rapidjson::Value(rapidjson::kArrayType), allocator);
|
|
||||||
|
|
||||||
doc.AddMember("results", results, allocator);
|
|
||||||
}
|
|
||||||
@@ -1,116 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <microhttpd.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "api/Api.h"
|
|
||||||
#include "api/Httpd.h"
|
|
||||||
#include "log/Log.h"
|
|
||||||
|
|
||||||
|
|
||||||
Httpd::Httpd(int port, const char *accessToken) :
|
|
||||||
m_accessToken(accessToken),
|
|
||||||
m_port(port),
|
|
||||||
m_daemon(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Httpd::start()
|
|
||||||
{
|
|
||||||
if (!m_port) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
|
|
||||||
if (!m_daemon) {
|
|
||||||
LOG_ERR("HTTP Daemon failed to start.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Httpd::auth(const char *header)
|
|
||||||
{
|
|
||||||
if (!m_accessToken) {
|
|
||||||
return MHD_HTTP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_accessToken && !header) {
|
|
||||||
return MHD_HTTP_UNAUTHORIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t size = strlen(header);
|
|
||||||
if (size < 8 || strlen(m_accessToken) != size - 7 || memcmp("Bearer ", header, 7) != 0) {
|
|
||||||
return MHD_HTTP_FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strncmp(m_accessToken, header + 7, strlen(m_accessToken)) == 0 ? MHD_HTTP_OK : MHD_HTTP_FORBIDDEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Httpd::done(MHD_Connection *connection, int status, MHD_Response *rsp)
|
|
||||||
{
|
|
||||||
if (!rsp) {
|
|
||||||
rsp = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
MHD_add_response_header(rsp, "Content-Type", "application/json");
|
|
||||||
MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*");
|
|
||||||
MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET");
|
|
||||||
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization");
|
|
||||||
|
|
||||||
const int ret = MHD_queue_response(connection, status, rsp);
|
|
||||||
MHD_destroy_response(rsp);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
|
|
||||||
{
|
|
||||||
if (strcmp(method, "OPTIONS") == 0) {
|
|
||||||
return done(connection, MHD_HTTP_OK, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(method, "GET") != 0) {
|
|
||||||
return MHD_NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = static_cast<Httpd*>(cls)->auth(MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Authorization"));
|
|
||||||
if (status != MHD_HTTP_OK) {
|
|
||||||
return done(connection, status, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *buf = Api::get(url, &status);
|
|
||||||
if (buf == nullptr) {
|
|
||||||
return MHD_NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*) buf, MHD_RESPMEM_MUST_FREE);
|
|
||||||
return done(connection, status, rsp);
|
|
||||||
}
|
|
||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -23,15 +23,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
#include "api/NetworkState.h"
|
#include "api/NetworkState.h"
|
||||||
#include "net/SubmitResult.h"
|
#include "common/net/SubmitResult.h"
|
||||||
|
|
||||||
|
|
||||||
NetworkState::NetworkState() :
|
xmrig::NetworkState::NetworkState() :
|
||||||
diff(0),
|
diff(0),
|
||||||
accepted(0),
|
accepted(0),
|
||||||
failures(0),
|
failures(0),
|
||||||
@@ -43,23 +44,23 @@ NetworkState::NetworkState() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int NetworkState::connectionTime() const
|
int xmrig::NetworkState::connectionTime() const
|
||||||
{
|
{
|
||||||
return m_active ? ((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0;
|
return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t NetworkState::avgTime() const
|
uint32_t xmrig::NetworkState::avgTime() const
|
||||||
{
|
{
|
||||||
if (m_latency.empty()) {
|
if (m_latency.empty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint32_t) connectionTime() / m_latency.size();
|
return connectionTime() / (uint32_t)m_latency.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
@@ -73,7 +74,7 @@ uint32_t NetworkState::latency() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetworkState::add(const SubmitResult &result, const char *error)
|
void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
||||||
{
|
{
|
||||||
if (error) {
|
if (error) {
|
||||||
rejected++;
|
rejected++;
|
||||||
@@ -93,7 +94,7 @@ 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);
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ void NetworkState::setPool(const char *host, int port, const char *ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetworkState::stop()
|
void xmrig::NetworkState::stop()
|
||||||
{
|
{
|
||||||
m_active = false;
|
m_active = false;
|
||||||
diff = 0;
|
diff = 0;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
@@ -58,4 +62,8 @@ private:
|
|||||||
uint64_t m_connectionTime;
|
uint64_t m_connectionTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __NETWORKSTATE_H__ */
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_NETWORKSTATE_H */
|
||||||
|
|||||||
93
src/base/io/Json.cpp
Normal file
93
src/base/io/Json.cpp
Normal 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
53
src/base/io/Json.h
Normal 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
62
src/base/io/Json_unix.cpp
Normal 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
124
src/base/io/Json_win.cpp
Normal 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;
|
||||||
|
}
|
||||||
94
src/base/io/Watcher.cpp
Normal file
94
src/base/io/Watcher.cpp
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) :
|
||||||
|
m_listener(listener),
|
||||||
|
m_path(path)
|
||||||
|
{
|
||||||
|
m_fsEvent = new uv_fs_event_t;
|
||||||
|
uv_fs_event_init(uv_default_loop(), m_fsEvent);
|
||||||
|
|
||||||
|
m_timer = new uv_timer_t;
|
||||||
|
uv_timer_init(uv_default_loop(), m_timer);
|
||||||
|
|
||||||
|
m_fsEvent->data = m_timer->data = this;
|
||||||
|
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::Watcher::~Watcher()
|
||||||
|
{
|
||||||
|
Handle::close(m_timer);
|
||||||
|
Handle::close(m_fsEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Watcher::onTimer(uv_timer_t *handle)
|
||||||
|
{
|
||||||
|
static_cast<Watcher *>(handle->data)->reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
uv_timer_stop(m_timer);
|
||||||
|
uv_timer_start(m_timer, xmrig::Watcher::onTimer, 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);
|
||||||
|
}
|
||||||
67
src/base/io/Watcher.h
Normal file
67
src/base/io/Watcher.h
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* 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/tools/String.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct uv_fs_event_s uv_fs_event_t;
|
||||||
|
typedef struct uv_timer_s uv_timer_t;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IWatcherListener;
|
||||||
|
|
||||||
|
|
||||||
|
class Watcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Watcher(const String &path, IWatcherListener *listener);
|
||||||
|
~Watcher();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
IWatcherListener *m_listener;
|
||||||
|
String m_path;
|
||||||
|
uv_fs_event_t *m_fsEvent;
|
||||||
|
uv_timer_t *m_timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
#endif /* XMRIG_WATCHER_H */
|
||||||
121
src/base/kernel/Entry.cpp
Normal file
121
src/base/kernel/Entry.cpp
Normal 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;
|
||||||
|
}
|
||||||
@@ -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,38 +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 __DOUBLEWORKER_H__
|
#ifndef XMRIG_ENTRY_H
|
||||||
#define __DOUBLEWORKER_H__
|
#define XMRIG_ENTRY_H
|
||||||
|
|
||||||
|
|
||||||
#include "align.h"
|
namespace xmrig {
|
||||||
#include "net/Job.h"
|
|
||||||
#include "net/JobResult.h"
|
|
||||||
#include "workers/Worker.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Handle;
|
class Process;
|
||||||
|
|
||||||
|
|
||||||
class DoubleWorker : public Worker
|
class Entry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DoubleWorker(Handle *handle);
|
enum Id {
|
||||||
~DoubleWorker();
|
Default,
|
||||||
|
Usage,
|
||||||
|
Version
|
||||||
|
};
|
||||||
|
|
||||||
void start() override;
|
static Id get(const Process &process);
|
||||||
|
static int exec(const Process &process, Id id);
|
||||||
private:
|
|
||||||
bool resume(const Job &job);
|
|
||||||
void consumeJob();
|
|
||||||
void save(const Job &job);
|
|
||||||
|
|
||||||
class State;
|
|
||||||
|
|
||||||
uint8_t m_hash[64];
|
|
||||||
State *m_state;
|
|
||||||
State *m_pausedState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __SINGLEWORKER_H__ */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_ENTRY_H */
|
||||||
101
src/base/kernel/Process.cpp
Normal file
101
src/base/kernel/Process.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
|
||||||
|
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>(static_cast<uintptr_t>(time(nullptr)) ^ 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
64
src/base/kernel/Process.h
Normal 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 */
|
||||||
63
src/base/kernel/Signals.cpp
Normal file
63
src/base/kernel/Signals.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/* 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 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2018 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, xmrig::Signals::onSignal, signums[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::Signals::~Signals()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < kSignalsCount; ++i) {
|
||||||
|
Handle::close(m_signals[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
|
||||||
|
{
|
||||||
|
static_cast<xmrig::Signals *>(handle->data)->m_listener->onSignal(signum);
|
||||||
|
}
|
||||||
62
src/base/kernel/Signals.h
Normal file
62
src/base/kernel/Signals.h
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_SIGNALS_H
|
||||||
|
#define XMRIG_SIGNALS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct uv_signal_s uv_signal_t;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class ISignalListener;
|
||||||
|
|
||||||
|
|
||||||
|
class Signals
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
constexpr static const size_t kSignalsCount = 3;
|
||||||
|
|
||||||
|
Signals(ISignalListener *listener);
|
||||||
|
~Signals();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void close(int signum);
|
||||||
|
|
||||||
|
static void onSignal(uv_signal_t *handle, int signum);
|
||||||
|
|
||||||
|
ISignalListener *m_listener;
|
||||||
|
uv_signal_t *m_signals[kSignalsCount];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_SIGNALS_H */
|
||||||
47
src/base/kernel/interfaces/IConfigListener.h
Normal file
47
src/base/kernel/interfaces/IConfigListener.h
Normal 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
|
||||||
47
src/base/kernel/interfaces/ISignalListener.h
Normal file
47
src/base/kernel/interfaces/ISignalListener.h
Normal 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
|
||||||
47
src/base/kernel/interfaces/IWatcherListener.h
Normal file
47
src/base/kernel/interfaces/IWatcherListener.h
Normal 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_IWATCHERLISTENER_H
|
||||||
|
#define XMRIG_IWATCHERLISTENER_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class String;
|
||||||
|
|
||||||
|
|
||||||
|
class IWatcherListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IWatcherListener() = default;
|
||||||
|
|
||||||
|
virtual void onFileChanged(const String &fileName) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif // XMRIG_IWATCHERLISTENER_H
|
||||||
505
src/base/net/Pool.cpp
Normal file
505
src/base/net/Pool.cpp
Normal file
@@ -0,0 +1,505 @@
|
|||||||
|
/* 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-2019 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 <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/io/Json.h"
|
||||||
|
#include "base/net/Pool.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef APP_DEBUG
|
||||||
|
# include "common/log/Log.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define strncasecmp _strnicmp
|
||||||
|
# define strcasecmp _stricmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::Pool::Pool() :
|
||||||
|
m_enabled(true),
|
||||||
|
m_nicehash(false),
|
||||||
|
m_tls(false),
|
||||||
|
m_keepAlive(0),
|
||||||
|
m_port(kDefaultPort)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Parse url.
|
||||||
|
*
|
||||||
|
* Valid urls:
|
||||||
|
* example.com
|
||||||
|
* example.com:3333
|
||||||
|
* stratum+tcp://example.com
|
||||||
|
* stratum+tcp://example.com:3333
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
xmrig::Pool::Pool(const char *url) :
|
||||||
|
m_enabled(true),
|
||||||
|
m_nicehash(false),
|
||||||
|
m_tls(false),
|
||||||
|
m_keepAlive(0),
|
||||||
|
m_port(kDefaultPort)
|
||||||
|
{
|
||||||
|
parse(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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_tls(tls),
|
||||||
|
m_keepAlive(keepAlive),
|
||||||
|
m_host(host),
|
||||||
|
m_password(password),
|
||||||
|
m_user(user),
|
||||||
|
m_port(port)
|
||||||
|
{
|
||||||
|
const size_t size = m_host.size() + 8;
|
||||||
|
assert(size > 8);
|
||||||
|
|
||||||
|
char *url = new char[size]();
|
||||||
|
snprintf(url, size - 1, "%s:%d", m_host.data(), m_port);
|
||||||
|
|
||||||
|
m_url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const
|
||||||
|
{
|
||||||
|
if (m_algorithms.empty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &a : m_algorithms) {
|
||||||
|
if (algorithm == a) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
|
if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT) {
|
||||||
|
return m_algorithm.variant() == xmrig::VARIANT_XTL || m_algorithm.variant() == xmrig::VARIANT_MSR;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
&& m_enabled == other.m_enabled
|
||||||
|
&& m_tls == other.m_tls
|
||||||
|
&& m_keepAlive == other.m_keepAlive
|
||||||
|
&& m_port == other.m_port
|
||||||
|
&& m_algorithm == other.m_algorithm
|
||||||
|
&& m_fingerprint == other.m_fingerprint
|
||||||
|
&& m_host == other.m_host
|
||||||
|
&& m_password == other.m_password
|
||||||
|
&& m_rigId == other.m_rigId
|
||||||
|
&& m_url == other.m_url
|
||||||
|
&& m_user == other.m_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Pool::parse(const char *url)
|
||||||
|
{
|
||||||
|
assert(url != nullptr);
|
||||||
|
|
||||||
|
const char *p = strstr(url, "://");
|
||||||
|
const char *base = url;
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
if (strncasecmp(url, "stratum+tcp://", 14) == 0) {
|
||||||
|
m_tls = false;
|
||||||
|
}
|
||||||
|
else if (strncasecmp(url, "stratum+ssl://", 14) == 0) {
|
||||||
|
m_tls = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
base = url + 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strlen(base) || *base == '/') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_url = url;
|
||||||
|
if (base[0] == '[') {
|
||||||
|
return parseIPv6(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *port = strchr(base, ':');
|
||||||
|
if (!port) {
|
||||||
|
m_host = base;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t size = static_cast<size_t>(port++ - base + 1);
|
||||||
|
char *host = new char[size]();
|
||||||
|
memcpy(host, base, size - 1);
|
||||||
|
|
||||||
|
m_host = host;
|
||||||
|
m_port = static_cast<uint16_t>(strtol(port, nullptr, 10));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Pool::setUserpass(const char *userpass)
|
||||||
|
{
|
||||||
|
const char *p = strchr(userpass, ':');
|
||||||
|
if (!p) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *user = new char[p - userpass + 1]();
|
||||||
|
strncpy(user, userpass, static_cast<size_t>(p - userpass));
|
||||||
|
|
||||||
|
m_user = user;
|
||||||
|
m_password = p + 1;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value obj(kObjectType);
|
||||||
|
|
||||||
|
obj.AddMember(StringRef(kUrl), m_url.toJSON(), allocator);
|
||||||
|
obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator);
|
||||||
|
obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator);
|
||||||
|
obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator);
|
||||||
|
|
||||||
|
# ifndef XMRIG_PROXY_PROJECT
|
||||||
|
obj.AddMember(StringRef(kNicehash), isNicehash(), allocator);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) {
|
||||||
|
obj.AddMember(StringRef(kKeepalive), m_keepAlive > 0, allocator);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj.AddMember(StringRef(kKeepalive), m_keepAlive, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (m_algorithm.variant()) {
|
||||||
|
case VARIANT_AUTO:
|
||||||
|
case VARIANT_0:
|
||||||
|
case VARIANT_1:
|
||||||
|
obj.AddMember(StringRef(kVariant), m_algorithm.variant(), allocator);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VARIANT_2:
|
||||||
|
obj.AddMember(StringRef(kVariant), 2, allocator);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
obj.AddMember(StringRef(kVariant), StringRef(m_algorithm.variantName()), allocator);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.AddMember(StringRef(kEnabled), m_enabled, allocator);
|
||||||
|
obj.AddMember(StringRef(kTls), isTLS(), allocator);
|
||||||
|
obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pool::adjust(const Algorithm &algorithm)
|
||||||
|
{
|
||||||
|
if (!isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_algorithm.isValid()) {
|
||||||
|
m_algorithm.setAlgo(algorithm.algo());
|
||||||
|
adjustVariant(algorithm.variant());
|
||||||
|
}
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pool::setAlgo(const xmrig::Algorithm &algorithm)
|
||||||
|
{
|
||||||
|
m_algorithm = algorithm;
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef APP_DEBUG
|
||||||
|
void xmrig::Pool::print() const
|
||||||
|
{
|
||||||
|
LOG_NOTICE("url: %s", m_url.data());
|
||||||
|
LOG_DEBUG ("host: %s", m_host.data());
|
||||||
|
LOG_DEBUG ("port: %d", static_cast<int>(m_port));
|
||||||
|
LOG_DEBUG ("user: %s", m_user.data());
|
||||||
|
LOG_DEBUG ("pass: %s", m_password.data());
|
||||||
|
LOG_DEBUG ("rig-id %s", m_rigId.data());
|
||||||
|
LOG_DEBUG ("algo: %s", m_algorithm.name());
|
||||||
|
LOG_DEBUG ("nicehash: %d", static_cast<int>(m_nicehash));
|
||||||
|
LOG_DEBUG ("keepAlive: %d", m_keepAlive);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Pool::parseIPv6(const char *addr)
|
||||||
|
{
|
||||||
|
const char *end = strchr(addr, ']');
|
||||||
|
if (!end) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *port = strchr(end, ':');
|
||||||
|
if (!port) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t size = static_cast<size_t>(end - addr);
|
||||||
|
char *host = new char[size]();
|
||||||
|
memcpy(host, addr + 1, size - 1);
|
||||||
|
|
||||||
|
m_host = host;
|
||||||
|
m_port = static_cast<uint16_t>(strtol(port + 1, nullptr, 10));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pool::addVariant(xmrig::Variant variant)
|
||||||
|
{
|
||||||
|
const xmrig::Algorithm algorithm(m_algorithm.algo(), variant);
|
||||||
|
if (!algorithm.isValid() || m_algorithm == algorithm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_algorithms.push_back(algorithm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pool::adjustVariant(const xmrig::Variant variantHint)
|
||||||
|
{
|
||||||
|
# ifndef XMRIG_PROXY_PROJECT
|
||||||
|
using namespace xmrig;
|
||||||
|
|
||||||
|
if (m_host.contains(".nicehash.com")) {
|
||||||
|
m_keepAlive = false;
|
||||||
|
m_nicehash = true;
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
switch (m_port) {
|
||||||
|
case 3355:
|
||||||
|
case 33355:
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT && m_host.contains("cryptonight.");
|
||||||
|
m_algorithm.setVariant(VARIANT_0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3363:
|
||||||
|
case 33363:
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT && m_host.contains("cryptonightv7.");
|
||||||
|
m_algorithm.setVariant(VARIANT_1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3364:
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT_HEAVY && m_host.contains("cryptonightheavy.");
|
||||||
|
m_algorithm.setVariant(VARIANT_0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3367:
|
||||||
|
case 33367:
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT && m_host.contains("cryptonightv8.");
|
||||||
|
m_algorithm.setVariant(VARIANT_2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
m_algorithm.setAlgo(INVALID_ALGO);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tls = m_port > 33000;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_host.contains(".minergate.com")) {
|
||||||
|
m_keepAlive = false;
|
||||||
|
bool valid = true;
|
||||||
|
m_algorithm.setVariant(VARIANT_1);
|
||||||
|
|
||||||
|
if (m_host.contains("xmr.pool.")) {
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT;
|
||||||
|
m_algorithm.setVariant(m_port == 45700 ? VARIANT_AUTO : VARIANT_0);
|
||||||
|
}
|
||||||
|
else if (m_host.contains("aeon.pool.") && m_port == 45690) {
|
||||||
|
valid = m_algorithm.algo() == CRYPTONIGHT_LITE;
|
||||||
|
m_algorithm.setVariant(VARIANT_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
m_algorithm.setAlgo(INVALID_ALGO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variantHint != VARIANT_AUTO) {
|
||||||
|
m_algorithm.setVariant(variantHint);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_algorithm.variant() != VARIANT_AUTO) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) {
|
||||||
|
m_algorithm.setVariant(VARIANT_0);
|
||||||
|
}
|
||||||
|
else if (m_algorithm.algo() == CRYPTONIGHT_LITE) {
|
||||||
|
m_algorithm.setVariant(VARIANT_1);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pool::rebuild()
|
||||||
|
{
|
||||||
|
m_algorithms.clear();
|
||||||
|
|
||||||
|
if (!m_algorithm.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_algorithms.push_back(m_algorithm);
|
||||||
|
|
||||||
|
# ifndef XMRIG_PROXY_PROJECT
|
||||||
|
addVariant(VARIANT_4);
|
||||||
|
addVariant(VARIANT_WOW);
|
||||||
|
addVariant(VARIANT_2);
|
||||||
|
addVariant(VARIANT_1);
|
||||||
|
addVariant(VARIANT_0);
|
||||||
|
addVariant(VARIANT_HALF);
|
||||||
|
addVariant(VARIANT_XTL);
|
||||||
|
addVariant(VARIANT_TUBE);
|
||||||
|
addVariant(VARIANT_MSR);
|
||||||
|
addVariant(VARIANT_XHV);
|
||||||
|
addVariant(VARIANT_XAO);
|
||||||
|
addVariant(VARIANT_RTO);
|
||||||
|
addVariant(VARIANT_GPU);
|
||||||
|
addVariant(VARIANT_RWZ);
|
||||||
|
addVariant(VARIANT_ZLS);
|
||||||
|
addVariant(VARIANT_DOUBLE);
|
||||||
|
addVariant(VARIANT_AUTO);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
124
src/base/net/Pool.h
Normal file
124
src/base/net/Pool.h
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_POOL_H
|
||||||
|
#define XMRIG_POOL_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/tools/String.h"
|
||||||
|
#include "common/crypto/Algorithm.h"
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Pool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
constexpr static const char *kDefaultPassword = "x";
|
||||||
|
constexpr static const char *kDefaultUser = "x";
|
||||||
|
constexpr static uint16_t kDefaultPort = 3333;
|
||||||
|
constexpr static int kKeepAliveTimeout = 60;
|
||||||
|
|
||||||
|
Pool();
|
||||||
|
Pool(const char *url);
|
||||||
|
Pool(const rapidjson::Value &object);
|
||||||
|
Pool(const char *host,
|
||||||
|
uint16_t port,
|
||||||
|
const char *user = nullptr,
|
||||||
|
const char *password = nullptr,
|
||||||
|
int keepAlive = 0,
|
||||||
|
bool nicehash = false,
|
||||||
|
bool tls = false
|
||||||
|
);
|
||||||
|
|
||||||
|
inline bool isNicehash() const { return m_nicehash; }
|
||||||
|
inline bool isTLS() const { return m_tls; }
|
||||||
|
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||||
|
inline const char *fingerprint() const { return m_fingerprint.data(); }
|
||||||
|
inline const char *host() const { return m_host.data(); }
|
||||||
|
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; }
|
||||||
|
inline const char *rigId() const { return m_rigId.data(); }
|
||||||
|
inline const char *url() const { return m_url.data(); }
|
||||||
|
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||||
|
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||||
|
inline const Algorithms &algorithms() const { return m_algorithms; }
|
||||||
|
inline int keepAlive() const { return m_keepAlive; }
|
||||||
|
inline uint16_t port() const { return m_port; }
|
||||||
|
inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; }
|
||||||
|
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||||
|
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); }
|
||||||
|
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
|
inline void setPassword(const char *password) { m_password = password; }
|
||||||
|
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||||
|
inline void setTLS(bool tls) { m_tls = tls; }
|
||||||
|
inline void setUser(const char *user) { m_user = user; }
|
||||||
|
inline 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); }
|
||||||
|
|
||||||
|
bool isCompatible(const Algorithm &algorithm) const;
|
||||||
|
bool isEnabled() const;
|
||||||
|
bool isEqual(const Pool &other) const;
|
||||||
|
bool parse(const char *url);
|
||||||
|
bool setUserpass(const char *userpass);
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
void adjust(const Algorithm &algorithm);
|
||||||
|
void setAlgo(const Algorithm &algorithm);
|
||||||
|
|
||||||
|
# ifdef APP_DEBUG
|
||||||
|
void print() const;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool parseIPv6(const char *addr);
|
||||||
|
void addVariant(Variant variant);
|
||||||
|
void adjustVariant(const Variant variantHint);
|
||||||
|
void rebuild();
|
||||||
|
|
||||||
|
Algorithm m_algorithm;
|
||||||
|
Algorithms m_algorithms;
|
||||||
|
bool m_enabled;
|
||||||
|
bool m_nicehash;
|
||||||
|
bool m_tls;
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_POOL_H */
|
||||||
207
src/base/net/Pools.cpp
Normal file
207
src/base/net/Pools.cpp
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
/* 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/Pools.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "common/net/strategies/FailoverStrategy.h"
|
||||||
|
#include "common/net/strategies/SinglePoolStrategy.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::Pools::Pools() :
|
||||||
|
m_retries(5),
|
||||||
|
m_retryPause(5)
|
||||||
|
{
|
||||||
|
# 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(),
|
||||||
|
pool.algorithm().variantName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s",
|
||||||
|
i,
|
||||||
|
pool.isEnabled() ? "" : "-",
|
||||||
|
pool.url(),
|
||||||
|
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::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
88
src/base/net/Pools.h
Normal file
88
src/base/net/Pools.h
Normal 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_POOLS_H
|
||||||
|
#define XMRIG_POOLS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/net/Pool.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IStrategy;
|
||||||
|
class IStrategyListener;
|
||||||
|
|
||||||
|
|
||||||
|
class Pools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Pools();
|
||||||
|
|
||||||
|
inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); }
|
||||||
|
inline const std::vector<Pool> &data() const { return m_data; }
|
||||||
|
inline int retries() const { return m_retries; }
|
||||||
|
inline int retryPause() const { return m_retryPause; }
|
||||||
|
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 setRetries(int retries);
|
||||||
|
void setRetryPause(int retryPause);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Pool ¤t();
|
||||||
|
|
||||||
|
int m_retries;
|
||||||
|
int m_retryPause;
|
||||||
|
std::vector<Pool> m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_POOLS_H */
|
||||||
76
src/base/tools/Arguments.cpp
Normal file
76
src/base/tools/Arguments.cpp
Normal 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);
|
||||||
|
}
|
||||||
61
src/base/tools/Arguments.h
Normal file
61
src/base/tools/Arguments.h
Normal 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 */
|
||||||
79
src/base/tools/Handle.cpp
Normal file
79
src/base/tools/Handle.cpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/* 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/tools/Handle.h"
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_fs_event_t *handle)
|
||||||
|
{
|
||||||
|
if (handle) {
|
||||||
|
uv_fs_event_stop(handle);
|
||||||
|
close(reinterpret_cast<uv_handle_t *>(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_getaddrinfo_t *handle)
|
||||||
|
{
|
||||||
|
if (handle) {
|
||||||
|
uv_cancel(reinterpret_cast<uv_req_t *>(handle));
|
||||||
|
close(reinterpret_cast<uv_handle_t *>(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_handle_t *handle)
|
||||||
|
{
|
||||||
|
uv_close(handle, [](uv_handle_t *handle) { delete handle; });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_signal_t *handle)
|
||||||
|
{
|
||||||
|
if (handle) {
|
||||||
|
uv_signal_stop(handle);
|
||||||
|
close(reinterpret_cast<uv_handle_t *>(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_tcp_t *handle)
|
||||||
|
{
|
||||||
|
if (handle) {
|
||||||
|
close(reinterpret_cast<uv_handle_t *>(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Handle::close(uv_timer_s *handle)
|
||||||
|
{
|
||||||
|
if (handle) {
|
||||||
|
uv_timer_stop(handle);
|
||||||
|
close(reinterpret_cast<uv_handle_t *>(handle));
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/base/tools/Handle.h
Normal file
55
src/base/tools/Handle.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* 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_HANDLE_H
|
||||||
|
#define XMRIG_HANDLE_H
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct uv_fs_event_s uv_fs_event_t;
|
||||||
|
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
|
||||||
|
typedef struct uv_handle_s uv_handle_t;
|
||||||
|
typedef struct uv_signal_s uv_signal_t;
|
||||||
|
typedef struct uv_tcp_s uv_tcp_t;
|
||||||
|
typedef struct uv_timer_s uv_timer_t;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Handle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void close(uv_fs_event_t *handle);
|
||||||
|
static void close(uv_getaddrinfo_t *handle);
|
||||||
|
static void close(uv_handle_t *handle);
|
||||||
|
static void close(uv_signal_t *handle);
|
||||||
|
static void close(uv_tcp_t *handle);
|
||||||
|
static void close(uv_timer_t *handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_HANDLE_H */
|
||||||
225
src/base/tools/String.cpp
Normal file
225
src/base/tools/String.cpp
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
/* 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 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/String.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::String::String(const char *str) :
|
||||||
|
m_data(nullptr),
|
||||||
|
m_size(str == nullptr ? 0 : strlen(str))
|
||||||
|
{
|
||||||
|
if (m_size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_data = new char[m_size + 1];
|
||||||
|
memcpy(m_data, str, m_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::String::String(const char *str, size_t size) :
|
||||||
|
m_data(nullptr),
|
||||||
|
m_size(size)
|
||||||
|
{
|
||||||
|
if (str == nullptr) {
|
||||||
|
m_size = 0;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_data = new char[m_size + 1];
|
||||||
|
memcpy(m_data, str, m_size);
|
||||||
|
m_data[m_size] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::String::String(const String &other) :
|
||||||
|
m_data(nullptr),
|
||||||
|
m_size(other.m_size)
|
||||||
|
{
|
||||||
|
if (other.m_data == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_data = new char[m_size + 1];
|
||||||
|
memcpy(m_data, other.m_data, m_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::String::isEqual(const char *str) const
|
||||||
|
{
|
||||||
|
return (m_data != nullptr && str != nullptr && strcmp(m_data, str) == 0) || (m_data == nullptr && str == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::String::isEqual(const String &other) const
|
||||||
|
{
|
||||||
|
if (m_size != other.m_size) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (m_data != nullptr && other.m_data != nullptr && memcmp(m_data, other.m_data, m_size) == 0) || (m_data == nullptr && other.m_data == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::String::toJSON() const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
return isNull() ? Value(kNullType) : Value(StringRef(m_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::String::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
return isNull() ? Value(kNullType) : Value(m_data, doc.GetAllocator());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<xmrig::String> xmrig::String::split(char sep) const
|
||||||
|
{
|
||||||
|
std::vector<xmrig::String> out;
|
||||||
|
if (m_size == 0) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t start = 0;
|
||||||
|
size_t pos = 0;
|
||||||
|
|
||||||
|
for (pos = 0; pos < m_size; ++pos) {
|
||||||
|
if (m_data[pos] == sep) {
|
||||||
|
if ((pos - start) > 0) {
|
||||||
|
out.push_back(String(m_data + start, pos - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
start = pos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pos - start) > 0) {
|
||||||
|
out.push_back(String(m_data + start, pos - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::String xmrig::String::join(const std::vector<xmrig::String> &vec, char sep)
|
||||||
|
{
|
||||||
|
if (vec.empty()) {
|
||||||
|
return String();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = vec.size();
|
||||||
|
for (const String &str : vec) {
|
||||||
|
size += str.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t offset = 0;
|
||||||
|
char *buf = new char[size];
|
||||||
|
|
||||||
|
for (const String &str : vec) {
|
||||||
|
memcpy(buf + offset, str.data(), str.size());
|
||||||
|
|
||||||
|
offset += str.size() + 1;
|
||||||
|
|
||||||
|
if (offset < size) {
|
||||||
|
buf[offset - 1] = sep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[size - 1] = '\0';
|
||||||
|
|
||||||
|
return String(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::String::copy(const char *str)
|
||||||
|
{
|
||||||
|
delete [] m_data;
|
||||||
|
|
||||||
|
if (str == nullptr) {
|
||||||
|
m_size = 0;
|
||||||
|
m_data = nullptr;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_size = strlen(str);
|
||||||
|
m_data = new char[m_size + 1];
|
||||||
|
|
||||||
|
memcpy(m_data, str, m_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::String::copy(const String &other)
|
||||||
|
{
|
||||||
|
if (m_size > 0) {
|
||||||
|
if (m_size == other.m_size) {
|
||||||
|
memcpy(m_data, other.m_data, m_size + 1);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] m_data;
|
||||||
|
|
||||||
|
if (other.m_data == nullptr) {
|
||||||
|
m_size = 0;
|
||||||
|
m_data = nullptr;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_size = other.m_size;
|
||||||
|
m_data = new char[m_size + 1];
|
||||||
|
|
||||||
|
memcpy(m_data, other.m_data, m_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::String::move(char *str)
|
||||||
|
{
|
||||||
|
delete [] m_data;
|
||||||
|
|
||||||
|
m_size = str == nullptr ? 0 : strlen(str);
|
||||||
|
m_data = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::String::move(String &&other)
|
||||||
|
{
|
||||||
|
delete [] m_data;
|
||||||
|
|
||||||
|
m_data = other.m_data;
|
||||||
|
m_size = other.m_size;
|
||||||
|
|
||||||
|
other.m_data = nullptr;
|
||||||
|
other.m_size = 0;
|
||||||
|
}
|
||||||
104
src/base/tools/String.h
Normal file
104
src/base/tools/String.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/* 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 2016-2018 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_STRING_H
|
||||||
|
#define XMRIG_STRING_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Simple C string wrapper.
|
||||||
|
*
|
||||||
|
* 1. I know about std:string.
|
||||||
|
* 2. For some reason I prefer don't use std:string in miner, eg because of file size of MSYS2 builds.
|
||||||
|
* 3. nullptr and JSON conversion supported.
|
||||||
|
*/
|
||||||
|
class String
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline String() : m_data(nullptr), m_size(0) {}
|
||||||
|
inline String(char *str) : m_data(str), m_size(str == nullptr ? 0 : strlen(str)) {}
|
||||||
|
inline String(String &&other) : m_data(other.m_data), m_size(other.m_size) { other.m_data = nullptr; other.m_size = 0; }
|
||||||
|
|
||||||
|
String(const char *str);
|
||||||
|
String(const char *str, size_t size);
|
||||||
|
String(const String &other);
|
||||||
|
|
||||||
|
inline ~String() { delete [] m_data; }
|
||||||
|
|
||||||
|
|
||||||
|
bool isEqual(const char *str) const;
|
||||||
|
bool isEqual(const String &other) const;
|
||||||
|
|
||||||
|
|
||||||
|
inline bool contains(const char *str) const { return isNull() ? false : strstr(m_data, str) != nullptr; }
|
||||||
|
|
||||||
|
|
||||||
|
inline bool isEmpty() const { return size() == 0; }
|
||||||
|
inline bool isNull() const { return m_data == nullptr; }
|
||||||
|
inline char *data() { return m_data; }
|
||||||
|
inline const char *data() const { return m_data; }
|
||||||
|
inline size_t size() const { return m_size; }
|
||||||
|
|
||||||
|
|
||||||
|
inline bool operator!=(const char *str) const { return !isEqual(str); }
|
||||||
|
inline bool operator!=(const String &other) const { return !isEqual(other); }
|
||||||
|
inline bool operator<(const String &str) const { return strcmp(data(), str.data()) < 0; }
|
||||||
|
inline bool operator==(const char *str) const { return isEqual(str); }
|
||||||
|
inline bool operator==(const String &other) const { return isEqual(other); }
|
||||||
|
inline operator const char*() const { return m_data; }
|
||||||
|
inline String &operator=(char *str) { move(str); return *this; }
|
||||||
|
inline String &operator=(const char *str) { copy(str); return *this; }
|
||||||
|
inline String &operator=(const String &str) { copy(str); return *this; }
|
||||||
|
inline String &operator=(String &&other) { move(std::move(other)); return *this; }
|
||||||
|
|
||||||
|
rapidjson::Value toJSON() const;
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
|
std::vector<xmrig::String> split(char sep) const;
|
||||||
|
|
||||||
|
static String join(const std::vector<xmrig::String> &vec, char sep);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void copy(const char *str);
|
||||||
|
void copy(const String &other);
|
||||||
|
void move(char *str);
|
||||||
|
void move(String &&other);
|
||||||
|
|
||||||
|
char *m_data;
|
||||||
|
size_t m_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_STRING_H */
|
||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Console.h"
|
#include "common/Console.h"
|
||||||
#include "interfaces/IConsoleListener.h"
|
#include "interfaces/IConsoleListener.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@@ -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
|
||||||
@@ -26,37 +27,33 @@
|
|||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef XMRIG_NO_TLS
|
||||||
|
# include <openssl/ssl.h>
|
||||||
|
# include <openssl/err.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
|
|
||||||
char *Platform::m_defaultConfigName = nullptr;
|
xmrig::String Platform::m_userAgent;
|
||||||
char *Platform::m_userAgent = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
const char *Platform::defaultConfigName()
|
void Platform::init(const char *userAgent)
|
||||||
{
|
{
|
||||||
size_t size = 520;
|
# ifndef XMRIG_NO_TLS
|
||||||
|
SSL_library_init();
|
||||||
|
SSL_load_error_strings();
|
||||||
|
ERR_load_BIO_strings();
|
||||||
|
ERR_load_crypto_strings();
|
||||||
|
SSL_load_error_strings();
|
||||||
|
OpenSSL_add_all_digests();
|
||||||
|
# endif
|
||||||
|
|
||||||
if (m_defaultConfigName == nullptr) {
|
if (userAgent) {
|
||||||
m_defaultConfigName = new char[size];
|
m_userAgent = userAgent;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (uv_exepath(m_defaultConfigName, &size) < 0) {
|
m_userAgent = createUserAgent();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
@@ -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,25 +22,33 @@
|
|||||||
* 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 __PLATFORM_H__
|
#ifndef XMRIG_PLATFORM_H
|
||||||
#define __PLATFORM_H__
|
#define XMRIG_PLATFORM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/tools/String.h"
|
||||||
|
|
||||||
|
|
||||||
class Platform
|
class Platform
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const char *defaultConfigName();
|
static bool setThreadAffinity(uint64_t cpu_id);
|
||||||
|
static uint32_t setTimerResolution(uint32_t resolution);
|
||||||
static void init(const char *userAgent);
|
static void init(const char *userAgent);
|
||||||
static void release();
|
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; }
|
static inline const char *userAgent() { return m_userAgent; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static char *m_defaultConfigName;
|
static char *createUserAgent();
|
||||||
static char *m_userAgent;
|
|
||||||
|
static xmrig::String m_userAgent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __PLATFORM_H__ */
|
#endif /* XMRIG_PLATFORM_H */
|
||||||
@@ -22,9 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <sched.h>
|
#include <mach/thread_act.h>
|
||||||
|
#include <mach/thread_policy.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
@@ -37,25 +38,21 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static inline char *createUserAgent()
|
char *Platform::createUserAgent()
|
||||||
{
|
{
|
||||||
const size_t max = 160;
|
constexpr const size_t max = 256;
|
||||||
|
|
||||||
char *buf = new char[max];
|
char *buf = new char[max]();
|
||||||
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string());
|
||||||
|
|
||||||
# if defined(__x86_64__)
|
|
||||||
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
|
|
||||||
# else
|
|
||||||
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifdef XMRIG_NVIDIA_PROJECT
|
# ifdef XMRIG_NVIDIA_PROJECT
|
||||||
const int cudaVersion = cuda_get_runtime_version();
|
const int cudaVersion = cuda_get_runtime_version();
|
||||||
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
|
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifdef __GNUC__
|
# ifdef __clang__
|
||||||
|
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
# elif defined(__GNUC__)
|
||||||
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@@ -63,15 +60,24 @@ static inline char *createUserAgent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::init(const char *userAgent)
|
bool Platform::setThreadAffinity(uint64_t cpu_id)
|
||||||
{
|
{
|
||||||
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
|
thread_port_t mach_thread;
|
||||||
|
thread_affinity_policy_data_t policy = { static_cast<integer_t>(cpu_id) };
|
||||||
|
mach_thread = pthread_mach_thread_np(pthread_self());
|
||||||
|
|
||||||
|
return thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1) == KERN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::release()
|
uint32_t Platform::setTimerResolution(uint32_t resolution)
|
||||||
|
{
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Platform::restoreTimerResolution()
|
||||||
{
|
{
|
||||||
delete [] m_userAgent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -80,7 +86,6 @@ void Platform::setProcessPriority(int priority)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::setThreadPriority(int priority)
|
void Platform::setThreadPriority(int priority)
|
||||||
{
|
{
|
||||||
if (priority == -1) {
|
if (priority == -1) {
|
||||||
@@ -115,13 +120,5 @@ void Platform::setThreadPriority(int priority)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setpriority(PRIO_PROCESS, 0, prio);
|
setpriority(PRIO_PROCESS, 0, prio);
|
||||||
|
|
||||||
if (priority == 0) {
|
|
||||||
sched_param param;
|
|
||||||
param.sched_priority = 0;
|
|
||||||
|
|
||||||
if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) {
|
|
||||||
sched_setscheduler(0, SCHED_BATCH, ¶m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
162
src/common/Platform_unix.cpp
Normal file
162
src/common/Platform_unix.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/* 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 2016-2018 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/param.h>
|
||||||
|
# include <sys/cpuset.h>
|
||||||
|
# include <pthread_np.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
#ifdef XMRIG_NVIDIA_PROJECT
|
||||||
|
# include "nvidia/cryptonight.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
typedef cpuset_t cpu_set_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
char *Platform::createUserAgent()
|
||||||
|
{
|
||||||
|
constexpr const size_t max = 256;
|
||||||
|
|
||||||
|
char *buf = new char[max]();
|
||||||
|
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
||||||
|
|
||||||
|
# if defined(__x86_64__)
|
||||||
|
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
|
||||||
|
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_NVIDIA_PROJECT
|
||||||
|
const int cudaVersion = cuda_get_runtime_version();
|
||||||
|
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef __clang__
|
||||||
|
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
# elif defined(__GNUC__)
|
||||||
|
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Platform::setThreadAffinity(uint64_t cpu_id)
|
||||||
|
{
|
||||||
|
cpu_set_t mn;
|
||||||
|
CPU_ZERO(&mn);
|
||||||
|
CPU_SET(cpu_id, &mn);
|
||||||
|
|
||||||
|
# ifndef __ANDROID__
|
||||||
|
return pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mn) == 0;
|
||||||
|
# else
|
||||||
|
return sched_setaffinity(gettid(), sizeof(cpu_set_t), &mn) == 0;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t Platform::setTimerResolution(uint32_t resolution)
|
||||||
|
{
|
||||||
|
return resolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Platform::restoreTimerResolution()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Platform::setProcessPriority(int priority)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Platform::setThreadPriority(int priority)
|
||||||
|
{
|
||||||
|
if (priority == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int prio = 19;
|
||||||
|
switch (priority)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
prio = 5;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
prio = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
prio = -5;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
prio = -10;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
prio = -15;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setpriority(PRIO_PROCESS, 0, prio);
|
||||||
|
|
||||||
|
# ifdef SCHED_IDLE
|
||||||
|
if (priority == 0) {
|
||||||
|
sched_param param;
|
||||||
|
param.sched_priority = 0;
|
||||||
|
|
||||||
|
if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) {
|
||||||
|
sched_setscheduler(0, SCHED_BATCH, ¶m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
@@ -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 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,19 +23,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "log/Log.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef XMRIG_NVIDIA_PROJECT
|
#ifdef XMRIG_NVIDIA_PROJECT
|
||||||
# include "nvidia/cryptonight.h"
|
# include "nvidia/cryptonight.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_AMD_PROJECT
|
||||||
|
static uint32_t timerResolution = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static inline OSVERSIONINFOEX winOsVersion()
|
static inline OSVERSIONINFOEX winOsVersion()
|
||||||
{
|
{
|
||||||
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
|
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
|
||||||
@@ -53,12 +62,12 @@ static inline OSVERSIONINFOEX winOsVersion()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline char *createUserAgent()
|
char *Platform::createUserAgent()
|
||||||
{
|
{
|
||||||
const auto osver = winOsVersion();
|
const auto osver = winOsVersion();
|
||||||
const size_t max = 160;
|
constexpr const size_t max = 256;
|
||||||
|
|
||||||
char *buf = new char[max];
|
char *buf = new char[max]();
|
||||||
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
|
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
|
||||||
|
|
||||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
# if defined(__x86_64__) || defined(_M_AMD64)
|
||||||
@@ -82,16 +91,41 @@ static inline char *createUserAgent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::init(const char *userAgent)
|
bool Platform::setThreadAffinity(uint64_t cpu_id)
|
||||||
{
|
{
|
||||||
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
|
if (cpu_id >= 64) {
|
||||||
|
LOG_ERR("Unable to set affinity. Windows supports only affinity up to 63.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Platform::release()
|
uint32_t Platform::setTimerResolution(uint32_t resolution)
|
||||||
{
|
{
|
||||||
delete [] m_defaultConfigName;
|
# ifdef XMRIG_AMD_PROJECT
|
||||||
delete [] m_userAgent;
|
TIMECAPS tc;
|
||||||
|
|
||||||
|
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
timerResolution = std::min<uint32_t>(std::max<uint32_t>(tc.wPeriodMin, resolution), tc.wPeriodMax);
|
||||||
|
|
||||||
|
return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0;
|
||||||
|
# else
|
||||||
|
return resolution;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Platform::restoreTimerResolution()
|
||||||
|
{
|
||||||
|
# ifdef XMRIG_AMD_PROJECT
|
||||||
|
if (timerResolution) {
|
||||||
|
timeEndPeriod(timerResolution);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -122,6 +156,7 @@ void Platform::setProcessPriority(int priority)
|
|||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
prio = REALTIME_PRIORITY_CLASS;
|
prio = REALTIME_PRIORITY_CLASS;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -131,7 +166,6 @@ void Platform::setProcessPriority(int priority)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Platform::setThreadPriority(int priority)
|
void Platform::setThreadPriority(int priority)
|
||||||
{
|
{
|
||||||
if (priority == -1) {
|
if (priority == -1) {
|
||||||
@@ -4,7 +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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* 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,40 +22,48 @@
|
|||||||
* 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 __HTTPBODY_H__
|
||||||
|
#define __HTTPBODY_H__
|
||||||
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
void Cpu::init()
|
class HttpBody
|
||||||
{
|
{
|
||||||
# ifdef XMRIG_NO_LIBCPUID
|
public:
|
||||||
m_totalThreads = sysconf(_SC_NPROCESSORS_CONF);
|
inline HttpBody() :
|
||||||
# endif
|
m_pos(0)
|
||||||
|
{}
|
||||||
initCommon();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Cpu::setAffinity(int id, uint64_t mask)
|
inline bool write(const char *data, size_t size)
|
||||||
{
|
{
|
||||||
cpu_set_t set;
|
if (size > (sizeof(m_data) - m_pos - 1)) {
|
||||||
CPU_ZERO(&set);
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < m_totalThreads; i++) {
|
|
||||||
if (mask & (1UL << i)) {
|
|
||||||
CPU_SET(i, &set);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(m_data + m_pos, data, size);
|
||||||
|
|
||||||
|
m_pos += size;
|
||||||
|
m_data[m_pos] = '\0';
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == -1) {
|
|
||||||
sched_setaffinity(0, sizeof(&set), &set);
|
inline const char *data() const { return m_data; }
|
||||||
} else {
|
|
||||||
pthread_setaffinity_np(pthread_self(), sizeof(&set), &set);
|
private:
|
||||||
}
|
char m_data[32768];
|
||||||
}
|
size_t m_pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __HTTPBODY_H__ */
|
||||||
@@ -4,7 +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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* 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,34 +22,32 @@
|
|||||||
* 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 __SINGLEWORKER_H__
|
#ifndef __HTTPREPLY_H__
|
||||||
#define __SINGLEWORKER_H__
|
#define __HTTPREPLY_H__
|
||||||
|
|
||||||
|
|
||||||
#include "net/Job.h"
|
#include <stdint.h>
|
||||||
#include "net/JobResult.h"
|
|
||||||
#include "workers/Worker.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Handle;
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class SingleWorker : public Worker
|
class HttpReply
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SingleWorker(Handle *handle);
|
HttpReply() :
|
||||||
|
buf(nullptr),
|
||||||
|
status(200),
|
||||||
|
size(0)
|
||||||
|
{}
|
||||||
|
|
||||||
void start() override;
|
char *buf;
|
||||||
|
int status;
|
||||||
private:
|
size_t size;
|
||||||
bool resume(const Job &job);
|
|
||||||
void consumeJob();
|
|
||||||
void save(const Job &job);
|
|
||||||
|
|
||||||
Job m_job;
|
|
||||||
Job m_paused;
|
|
||||||
JobResult m_result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __SINGLEWORKER_H__ */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __HTTPREPLY_H__ */
|
||||||
175
src/common/api/HttpRequest.cpp
Normal file
175
src/common/api/HttpRequest.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
/* 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 2016-2018 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 <microhttpd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common/api/HttpBody.h"
|
||||||
|
#include "common/api/HttpRequest.h"
|
||||||
|
#include "common/api/HttpReply.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MHD_HTTP_PAYLOAD_TOO_LARGE
|
||||||
|
# define MHD_HTTP_PAYLOAD_TOO_LARGE 413
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::HttpRequest::HttpRequest(MHD_Connection *connection, const char *url, const char *method, const char *uploadData, size_t *uploadSize, void **cls) :
|
||||||
|
m_fulfilled(true),
|
||||||
|
m_restricted(true),
|
||||||
|
m_uploadData(uploadData),
|
||||||
|
m_url(url),
|
||||||
|
m_body(static_cast<HttpBody*>(*cls)),
|
||||||
|
m_method(Unsupported),
|
||||||
|
m_connection(connection),
|
||||||
|
m_uploadSize(uploadSize),
|
||||||
|
m_cls(cls)
|
||||||
|
{
|
||||||
|
if (strcmp(method, MHD_HTTP_METHOD_OPTIONS) == 0) {
|
||||||
|
m_method = Options;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, MHD_HTTP_METHOD_GET) == 0) {
|
||||||
|
m_method = Get;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, MHD_HTTP_METHOD_PUT) == 0) {
|
||||||
|
m_method = Put;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::HttpRequest::~HttpRequest()
|
||||||
|
{
|
||||||
|
if (m_fulfilled) {
|
||||||
|
delete m_body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::HttpRequest::match(const char *path) const
|
||||||
|
{
|
||||||
|
return strcmp(m_url, path) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::HttpRequest::process(const char *accessToken, bool restricted, xmrig::HttpReply &reply)
|
||||||
|
{
|
||||||
|
m_restricted = restricted || !accessToken;
|
||||||
|
|
||||||
|
if (m_body) {
|
||||||
|
if (*m_uploadSize != 0) {
|
||||||
|
if (!m_body->write(m_uploadData, *m_uploadSize)) {
|
||||||
|
*m_cls = nullptr;
|
||||||
|
m_fulfilled = true;
|
||||||
|
reply.status = MHD_HTTP_PAYLOAD_TOO_LARGE;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*m_uploadSize = 0;
|
||||||
|
m_fulfilled = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fulfilled = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
reply.status = auth(accessToken);
|
||||||
|
if (reply.status != MHD_HTTP_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_restricted && m_method != Get) {
|
||||||
|
reply.status = MHD_HTTP_FORBIDDEN;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_method == Get) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *contentType = MHD_lookup_connection_value(m_connection, MHD_HEADER_KIND, "Content-Type");
|
||||||
|
if (!contentType || strcmp(contentType, "application/json") != 0) {
|
||||||
|
reply.status = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_body = new xmrig::HttpBody();
|
||||||
|
m_fulfilled = false;
|
||||||
|
*m_cls = m_body;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::HttpRequest::body() const
|
||||||
|
{
|
||||||
|
return m_body ? m_body->data() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int xmrig::HttpRequest::end(const HttpReply &reply)
|
||||||
|
{
|
||||||
|
if (reply.buf) {
|
||||||
|
return end(reply.status, MHD_create_response_from_buffer(reply.size ? reply.size : strlen(reply.buf), (void*) reply.buf, MHD_RESPMEM_MUST_FREE));
|
||||||
|
}
|
||||||
|
|
||||||
|
return end(reply.status, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int xmrig::HttpRequest::end(int status, MHD_Response *rsp)
|
||||||
|
{
|
||||||
|
if (!rsp) {
|
||||||
|
rsp = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
MHD_add_response_header(rsp, "Content-Type", "application/json");
|
||||||
|
MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*");
|
||||||
|
MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET, PUT");
|
||||||
|
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization, Content-Type");
|
||||||
|
|
||||||
|
const int ret = MHD_queue_response(m_connection, status, rsp);
|
||||||
|
MHD_destroy_response(rsp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int xmrig::HttpRequest::auth(const char *accessToken)
|
||||||
|
{
|
||||||
|
if (!accessToken) {
|
||||||
|
return MHD_HTTP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *header = MHD_lookup_connection_value(m_connection, MHD_HEADER_KIND, "Authorization");
|
||||||
|
if (accessToken && !header) {
|
||||||
|
return MHD_HTTP_UNAUTHORIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t size = strlen(header);
|
||||||
|
if (size < 8 || strlen(accessToken) != size - 7 || memcmp("Bearer ", header, 7) != 0) {
|
||||||
|
return MHD_HTTP_FORBIDDEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strncmp(accessToken, header + 7, strlen(accessToken)) == 0 ? MHD_HTTP_OK : MHD_HTTP_FORBIDDEN;
|
||||||
|
}
|
||||||
84
src/common/api/HttpRequest.h
Normal file
84
src/common/api/HttpRequest.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/* 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 2016-2018 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 __HTTPREQUEST_H__
|
||||||
|
#define __HTTPREQUEST_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct MHD_Connection;
|
||||||
|
struct MHD_Response;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class HttpBody;
|
||||||
|
class HttpReply;
|
||||||
|
|
||||||
|
|
||||||
|
class HttpRequest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Method {
|
||||||
|
Unsupported,
|
||||||
|
Options,
|
||||||
|
Get,
|
||||||
|
Put
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpRequest(MHD_Connection *connection, const char *url, const char *method, const char *uploadData, size_t *uploadSize, void **cls);
|
||||||
|
~HttpRequest();
|
||||||
|
|
||||||
|
inline bool isFulfilled() const { return m_fulfilled; }
|
||||||
|
inline bool isRestricted() const { return m_restricted; }
|
||||||
|
inline Method method() const { return m_method; }
|
||||||
|
|
||||||
|
bool match(const char *path) const;
|
||||||
|
bool process(const char *accessToken, bool restricted, xmrig::HttpReply &reply);
|
||||||
|
const char *body() const;
|
||||||
|
int end(const HttpReply &reply);
|
||||||
|
int end(int status, MHD_Response *rsp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int auth(const char *accessToken);
|
||||||
|
|
||||||
|
bool m_fulfilled;
|
||||||
|
bool m_restricted;
|
||||||
|
const char *m_uploadData;
|
||||||
|
const char *m_url;
|
||||||
|
HttpBody *m_body;
|
||||||
|
Method m_method;
|
||||||
|
MHD_Connection *m_connection;
|
||||||
|
size_t *m_uploadSize;
|
||||||
|
void **m_cls;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __HTTPREQUEST_H__ */
|
||||||
148
src/common/api/Httpd.cpp
Normal file
148
src/common/api/Httpd.cpp
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
/* 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 2016-2018 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 <microhttpd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "api/Api.h"
|
||||||
|
#include "common/api/Httpd.h"
|
||||||
|
#include "common/api/HttpReply.h"
|
||||||
|
#include "common/api/HttpRequest.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
|
||||||
|
|
||||||
|
Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
|
||||||
|
m_idle(true),
|
||||||
|
m_IPv6(IPv6),
|
||||||
|
m_restricted(restricted),
|
||||||
|
m_accessToken(accessToken ? strdup(accessToken) : nullptr),
|
||||||
|
m_port(port),
|
||||||
|
m_daemon(nullptr)
|
||||||
|
{
|
||||||
|
uv_timer_init(uv_default_loop(), &m_timer);
|
||||||
|
m_timer.data = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Httpd::~Httpd()
|
||||||
|
{
|
||||||
|
uv_timer_stop(&m_timer);
|
||||||
|
|
||||||
|
if (m_daemon) {
|
||||||
|
MHD_stop_daemon(m_daemon);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete m_accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Httpd::start()
|
||||||
|
{
|
||||||
|
if (!m_port) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int flags = 0;
|
||||||
|
# if MHD_VERSION >= 0x00093500
|
||||||
|
if (m_IPv6 && MHD_is_feature_supported(MHD_FEATURE_IPv6)) {
|
||||||
|
flags |= MHD_USE_DUAL_STACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
|
||||||
|
flags |= MHD_USE_EPOLL_LINUX_ONLY;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
|
||||||
|
if (!m_daemon) {
|
||||||
|
LOG_ERR("HTTP Daemon failed to start.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
# if MHD_VERSION >= 0x00093900
|
||||||
|
uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval);
|
||||||
|
# else
|
||||||
|
uv_timer_start(&m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Httpd::process(xmrig::HttpRequest &req)
|
||||||
|
{
|
||||||
|
xmrig::HttpReply reply;
|
||||||
|
if (!req.process(m_accessToken, m_restricted, reply)) {
|
||||||
|
return req.end(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.isFulfilled()) {
|
||||||
|
return MHD_YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
Api::exec(req, reply);
|
||||||
|
|
||||||
|
return req.end(reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Httpd::run()
|
||||||
|
{
|
||||||
|
MHD_run(m_daemon);
|
||||||
|
|
||||||
|
# if MHD_VERSION >= 0x00093900
|
||||||
|
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
|
||||||
|
if (m_idle && info->num_connections) {
|
||||||
|
uv_timer_set_repeat(&m_timer, kActiveInterval);
|
||||||
|
m_idle = false;
|
||||||
|
}
|
||||||
|
else if (!m_idle && !info->num_connections) {
|
||||||
|
uv_timer_set_repeat(&m_timer, kIdleInterval);
|
||||||
|
m_idle = true;
|
||||||
|
}
|
||||||
|
# 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)
|
||||||
|
{
|
||||||
|
xmrig::HttpRequest req(connection, url, method, uploadData, uploadSize, con_cls);
|
||||||
|
|
||||||
|
if (req.method() == xmrig::HttpRequest::Options) {
|
||||||
|
return req.end(MHD_HTTP_OK, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.method() == xmrig::HttpRequest::Unsupported) {
|
||||||
|
return req.end(MHD_HTTP_METHOD_NOT_ALLOWED, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<Httpd*>(cls)->process(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Httpd::onTimer(uv_timer_t *handle)
|
||||||
|
{
|
||||||
|
static_cast<Httpd*>(handle->data)->run();
|
||||||
|
}
|
||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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,21 +33,38 @@ struct MHD_Daemon;
|
|||||||
struct MHD_Response;
|
struct MHD_Response;
|
||||||
|
|
||||||
|
|
||||||
|
class UploadCtx;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
class HttpRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Httpd
|
class Httpd
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Httpd(int port, const char *accessToken);
|
Httpd(int port, const char *accessToken, bool IPv6, bool restricted);
|
||||||
|
~Httpd();
|
||||||
bool start();
|
bool start();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int auth(const char *header);
|
constexpr static const int kIdleInterval = 200;
|
||||||
|
constexpr static const int kActiveInterval = 25;
|
||||||
|
|
||||||
static int done(MHD_Connection *connection, int status, MHD_Response *rsp);
|
int process(xmrig::HttpRequest &req);
|
||||||
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
|
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 void onTimer(uv_timer_t *handle);
|
||||||
|
|
||||||
|
bool m_idle;
|
||||||
|
bool m_IPv6;
|
||||||
|
bool m_restricted;
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __HTTPD_H__ */
|
#endif /* __HTTPD_H__ */
|
||||||
422
src/common/config/CommonConfig.cpp
Normal file
422
src/common/config/CommonConfig.cpp
Normal file
@@ -0,0 +1,422 @@
|
|||||||
|
/* 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 <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef XMRIG_NO_HTTPD
|
||||||
|
# include <microhttpd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef XMRIG_NO_TLS
|
||||||
|
# include <openssl/opensslv.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_AMD_PROJECT
|
||||||
|
# if defined(__APPLE__)
|
||||||
|
# include <OpenCL/cl.h>
|
||||||
|
# else
|
||||||
|
# include "3rdparty/CL/cl.h"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_NVIDIA_PROJECT
|
||||||
|
# include "nvidia/cryptonight.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/io/Json.h"
|
||||||
|
#include "common/config/CommonConfig.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "donate.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
#include "rapidjson/filewritestream.h"
|
||||||
|
#include "rapidjson/prettywriter.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::CommonConfig::CommonConfig() :
|
||||||
|
m_algorithm(CRYPTONIGHT, VARIANT_AUTO),
|
||||||
|
m_adjusted(false),
|
||||||
|
m_apiIPv6(false),
|
||||||
|
m_apiRestricted(true),
|
||||||
|
m_autoSave(true),
|
||||||
|
m_background(false),
|
||||||
|
m_dryRun(false),
|
||||||
|
m_syslog(false),
|
||||||
|
m_watch(true),
|
||||||
|
m_apiPort(0),
|
||||||
|
m_donateLevel(kDefaultDonateLevel),
|
||||||
|
m_printTime(60),
|
||||||
|
m_state(NoneState)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::isColors() const
|
||||||
|
{
|
||||||
|
return Log::colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::CommonConfig::printAPI()
|
||||||
|
{
|
||||||
|
# ifndef XMRIG_NO_API
|
||||||
|
if (apiPort() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d")
|
||||||
|
: " * %-13s%s:%d",
|
||||||
|
"API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort());
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::CommonConfig::printPools()
|
||||||
|
{
|
||||||
|
m_pools.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::CommonConfig::printVersions()
|
||||||
|
{
|
||||||
|
char buf[256] = { 0 };
|
||||||
|
|
||||||
|
# if defined(__clang__)
|
||||||
|
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
# elif defined(__GNUC__)
|
||||||
|
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||||
|
# elif defined(_MSC_VER)
|
||||||
|
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s")
|
||||||
|
: " * %-13s%s/%s %s",
|
||||||
|
"ABOUT", APP_NAME, APP_VERSION, buf);
|
||||||
|
|
||||||
|
# if defined(XMRIG_AMD_PROJECT)
|
||||||
|
# if CL_VERSION_2_0
|
||||||
|
const char *ocl = "2.0";
|
||||||
|
# elif CL_VERSION_1_2
|
||||||
|
const char *ocl = "1.2";
|
||||||
|
# elif CL_VERSION_1_1
|
||||||
|
const char *ocl = "1.1";
|
||||||
|
# elif CL_VERSION_1_0
|
||||||
|
const char *ocl = "1.0";
|
||||||
|
# else
|
||||||
|
const char *ocl = "0.0";
|
||||||
|
# endif
|
||||||
|
int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl);
|
||||||
|
# elif defined(XMRIG_NVIDIA_PROJECT)
|
||||||
|
const int cudaVersion = cuda_get_runtime_version();
|
||||||
|
int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100);
|
||||||
|
# else
|
||||||
|
memset(buf, 0, 16);
|
||||||
|
|
||||||
|
# if !defined(XMRIG_NO_HTTPD) || !defined(XMRIG_NO_TLS)
|
||||||
|
int length = 0;
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT)
|
||||||
|
{
|
||||||
|
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
|
||||||
|
length += snprintf(buf + length, (sizeof buf) - length, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef XMRIG_NO_HTTPD
|
||||||
|
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
||||||
|
# endif
|
||||||
|
|
||||||
|
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
||||||
|
: " * %-13slibuv/%s %s",
|
||||||
|
"LIBS", uv_version_string(), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::save()
|
||||||
|
{
|
||||||
|
if (m_fileName.isNull()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
rapidjson::Document doc;
|
||||||
|
getJSON(doc);
|
||||||
|
|
||||||
|
if (Json::save(m_fileName, doc)) {
|
||||||
|
LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::finalize()
|
||||||
|
{
|
||||||
|
if (m_state == ReadyState) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_state == ErrorState) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_algorithm.isValid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pools.adjust(m_algorithm);
|
||||||
|
|
||||||
|
if (!m_pools.active()) {
|
||||||
|
m_state = ErrorState;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_state = ReadyState;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case BackgroundKey: /* --background */
|
||||||
|
m_background = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SyslogKey: /* --syslog */
|
||||||
|
m_syslog = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeepAliveKey: /* --keepalive */
|
||||||
|
m_pools.setKeepAlive(enable);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TlsKey: /* --tls */
|
||||||
|
m_pools.setTLS(enable);
|
||||||
|
break;
|
||||||
|
|
||||||
|
# ifndef XMRIG_PROXY_PROJECT
|
||||||
|
case NicehashKey: /* --nicehash */
|
||||||
|
m_pools.setNicehash(enable);
|
||||||
|
break;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
case ColorKey: /* --no-color */
|
||||||
|
Log::colors = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WatchKey: /* watch */
|
||||||
|
m_watch = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiIPv6Key: /* ipv6 */
|
||||||
|
m_apiIPv6 = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiRestrictedKey: /* restricted */
|
||||||
|
m_apiRestricted = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DryRunKey: /* --dry-run */
|
||||||
|
m_dryRun = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AutoSaveKey:
|
||||||
|
m_autoSave = enable;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::parseString(int key, const char *arg)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case AlgorithmKey: /* --algo */
|
||||||
|
m_algorithm.parseAlgorithm(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UserpassKey: /* --userpass */
|
||||||
|
return m_pools.setUserpass(arg);
|
||||||
|
|
||||||
|
case UrlKey: /* --url */
|
||||||
|
return m_pools.setUrl(arg);
|
||||||
|
|
||||||
|
case UserKey: /* --user */
|
||||||
|
m_pools.setUser(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PasswordKey: /* --pass */
|
||||||
|
m_pools.setPassword(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RigIdKey: /* --rig-id */
|
||||||
|
m_pools.setRigId(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FingerprintKey: /* --tls-fingerprint */
|
||||||
|
m_pools.setFingerprint(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VariantKey: /* --variant */
|
||||||
|
m_pools.setVariant(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LogFileKey: /* --log-file */
|
||||||
|
m_logFile = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiAccessTokenKey: /* --api-access-token */
|
||||||
|
m_apiToken = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiWorkerIdKey: /* --api-worker-id */
|
||||||
|
m_apiWorkerId = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiIdKey: /* --api-id */
|
||||||
|
m_apiId = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UserAgentKey: /* --user-agent */
|
||||||
|
m_userAgent = arg;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RetriesKey: /* --retries */
|
||||||
|
case RetryPauseKey: /* --retry-pause */
|
||||||
|
case ApiPort: /* --api-port */
|
||||||
|
case PrintTimeKey: /* --print-time */
|
||||||
|
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||||
|
|
||||||
|
case BackgroundKey: /* --background */
|
||||||
|
case SyslogKey: /* --syslog */
|
||||||
|
case KeepAliveKey: /* --keepalive */
|
||||||
|
case NicehashKey: /* --nicehash */
|
||||||
|
case TlsKey: /* --tls */
|
||||||
|
case ApiIPv6Key: /* --api-ipv6 */
|
||||||
|
case DryRunKey: /* --dry-run */
|
||||||
|
return parseBoolean(key, true);
|
||||||
|
|
||||||
|
case ColorKey: /* --no-color */
|
||||||
|
case WatchKey: /* --no-watch */
|
||||||
|
case ApiRestrictedKey: /* --api-no-restricted */
|
||||||
|
return parseBoolean(key, false);
|
||||||
|
|
||||||
|
case DonateLevelKey: /* --donate-level */
|
||||||
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
|
if (strncmp(arg, "minemonero.pro", 14) == 0) {
|
||||||
|
m_donateLevel = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
return parseUint64(key, strtol(arg, nullptr, 10));
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg)
|
||||||
|
{
|
||||||
|
return parseInt(key, static_cast<int>(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)
|
||||||
|
{
|
||||||
|
m_fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::CommonConfig::parseInt(int key, int arg)
|
||||||
|
{
|
||||||
|
switch (key) {
|
||||||
|
case RetriesKey: /* --retries */
|
||||||
|
m_pools.setRetries(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RetryPauseKey: /* --retry-pause */
|
||||||
|
m_pools.setRetryPause(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KeepAliveKey: /* --keepalive */
|
||||||
|
m_pools.setKeepAlive(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VariantKey: /* --variant */
|
||||||
|
m_pools.setVariant(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DonateLevelKey: /* --donate-level */
|
||||||
|
if (arg >= kMinimumDonateLevel && arg <= 99) {
|
||||||
|
m_donateLevel = arg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ApiPort: /* --api-port */
|
||||||
|
if (arg > 0 && arg <= 65536) {
|
||||||
|
m_apiPort = arg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PrintTimeKey: /* --print-time */
|
||||||
|
if (arg >= 0 && arg <= 3600) {
|
||||||
|
m_printTime = arg;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
112
src/common/config/CommonConfig.h
Normal file
112
src/common/config/CommonConfig.h
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/* 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_COMMONCONFIG_H
|
||||||
|
#define XMRIG_COMMONCONFIG_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/net/Pools.h"
|
||||||
|
#include "base/tools/String.h"
|
||||||
|
#include "common/interfaces/IConfig.h"
|
||||||
|
#include "common/xmrig.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class CommonConfig : public IConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CommonConfig();
|
||||||
|
|
||||||
|
inline bool isApiIPv6() const { return m_apiIPv6; }
|
||||||
|
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||||
|
inline bool isAutoSave() const { return m_autoSave; }
|
||||||
|
inline bool isBackground() const { return m_background; }
|
||||||
|
inline bool isDryRun() const { return m_dryRun; }
|
||||||
|
inline bool isSyslog() const { return m_syslog; }
|
||||||
|
inline const char *apiId() const { return m_apiId.data(); }
|
||||||
|
inline const char *apiToken() const { return m_apiToken.data(); }
|
||||||
|
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
|
||||||
|
inline const char *logFile() const { return m_logFile.data(); }
|
||||||
|
inline const char *userAgent() const { return m_userAgent.data(); }
|
||||||
|
inline const Pools &pools() const { return m_pools; }
|
||||||
|
inline int apiPort() const { return m_apiPort; }
|
||||||
|
inline int donateLevel() const { return m_donateLevel; }
|
||||||
|
inline int printTime() const { return m_printTime; }
|
||||||
|
|
||||||
|
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
||||||
|
inline const Algorithm &algorithm() const override { return m_algorithm; }
|
||||||
|
inline const String &fileName() const override { return m_fileName; }
|
||||||
|
|
||||||
|
bool save() override;
|
||||||
|
|
||||||
|
bool isColors() const;
|
||||||
|
void printAPI();
|
||||||
|
void printPools();
|
||||||
|
void printVersions();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
enum State {
|
||||||
|
NoneState,
|
||||||
|
ReadyState,
|
||||||
|
ErrorState
|
||||||
|
};
|
||||||
|
|
||||||
|
bool finalize() override;
|
||||||
|
bool parseBoolean(int key, bool enable) override;
|
||||||
|
bool parseString(int key, const char *arg) override;
|
||||||
|
bool parseUint64(int key, uint64_t arg) override;
|
||||||
|
void parseJSON(const rapidjson::Document &doc) override;
|
||||||
|
void setFileName(const char *fileName) override;
|
||||||
|
|
||||||
|
Algorithm m_algorithm;
|
||||||
|
bool m_adjusted;
|
||||||
|
bool m_apiIPv6;
|
||||||
|
bool m_apiRestricted;
|
||||||
|
bool m_autoSave;
|
||||||
|
bool m_background;
|
||||||
|
bool m_dryRun;
|
||||||
|
bool m_syslog;
|
||||||
|
bool m_watch;
|
||||||
|
int m_apiPort;
|
||||||
|
int m_donateLevel;
|
||||||
|
int m_printTime;
|
||||||
|
Pools m_pools;
|
||||||
|
State m_state;
|
||||||
|
String m_apiId;
|
||||||
|
String m_apiToken;
|
||||||
|
String m_apiWorkerId;
|
||||||
|
String m_fileName;
|
||||||
|
String m_logFile;
|
||||||
|
String m_userAgent;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool parseInt(int key, int arg);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
#endif /* XMRIG_COMMONCONFIG_H */
|
||||||
272
src/common/config/ConfigLoader.cpp
Normal file
272
src/common/config/ConfigLoader.cpp
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
/* 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 <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#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/io/Json.h"
|
||||||
|
#include "base/kernel/interfaces/IConfigListener.h"
|
||||||
|
#include "base/kernel/Process.h"
|
||||||
|
#include "common/config/ConfigLoader.h"
|
||||||
|
#include "common/config/ConfigWatcher.h"
|
||||||
|
#include "common/interfaces/IConfig.h"
|
||||||
|
#include "common/Platform.h"
|
||||||
|
#include "core/ConfigCreator.h"
|
||||||
|
#include "core/ConfigLoader_platform.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
#include "rapidjson/error/en.h"
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG
|
||||||
|
# include "core/ConfigLoader_default.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr;
|
||||||
|
xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr;
|
||||||
|
xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ARRAY_SIZE
|
||||||
|
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::loadFromFile(xmrig::IConfig *config, const char *fileName)
|
||||||
|
{
|
||||||
|
rapidjson::Document doc;
|
||||||
|
if (!getJSON(fileName, doc)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->setFileName(fileName);
|
||||||
|
|
||||||
|
return loadFromJSON(config, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const char *json)
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
Document doc;
|
||||||
|
doc.Parse<kParseCommentsFlag | kParseTrailingCommasFlag>(json);
|
||||||
|
|
||||||
|
if (doc.HasParseError() || !doc.IsObject()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadFromJSON(config, doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson::Document &doc)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
|
||||||
|
parseJSON(config, &config_options[i], doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rapidjson::Value &api = doc["api"];
|
||||||
|
if (api.IsObject()) {
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) {
|
||||||
|
parseJSON(config, &api_options[i], api);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config->parseJSON(doc);
|
||||||
|
|
||||||
|
return config->finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json)
|
||||||
|
{
|
||||||
|
xmrig::IConfig *config = m_creator->create();
|
||||||
|
if (!loadFromJSON(config, json)) {
|
||||||
|
delete config;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
config->setFileName(oldConfig->fileName());
|
||||||
|
const bool saved = config->save();
|
||||||
|
|
||||||
|
if (config->isWatch() && m_watcher && saved) {
|
||||||
|
delete config;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_listener->onNewConfig(config);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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_listener = listener;
|
||||||
|
|
||||||
|
xmrig::IConfig *config = m_creator->create();
|
||||||
|
int key;
|
||||||
|
int argc = process->arguments().argc();
|
||||||
|
char **argv = process->arguments().argv();
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
key = getopt_long(argc, argv, short_options, options, nullptr);
|
||||||
|
if (key < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parseArg(config, key, optarg)) {
|
||||||
|
delete config;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind < argc) {
|
||||||
|
fprintf(stderr, "%s: unsupported non-option argument '%s'\n", argv[0], argv[optind]);
|
||||||
|
delete config;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config->finalize()) {
|
||||||
|
delete config;
|
||||||
|
|
||||||
|
config = m_creator->create();
|
||||||
|
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->algorithm().isValid()) {
|
||||||
|
fprintf(stderr, "No valid algorithm specified. Exiting.\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "No valid configuration found. Exiting.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
delete config;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::ConfigLoader::release()
|
||||||
|
{
|
||||||
|
delete m_watcher;
|
||||||
|
delete m_creator;
|
||||||
|
|
||||||
|
m_watcher = nullptr;
|
||||||
|
m_creator = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc)
|
||||||
|
{
|
||||||
|
if (Json::get(fileName, doc)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doc.HasParseError()) {
|
||||||
|
printf("%s<offset:%zu>: \"%s\"\n", fileName, doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "unable to open \"%s\".\n", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::ConfigLoader::parseArg(xmrig::IConfig *config, int key, const char *arg)
|
||||||
|
{
|
||||||
|
if (key == xmrig::IConfig::ConfigKey) {
|
||||||
|
return loadFromFile(config, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config->parseString(key, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::ConfigLoader::parseJSON(xmrig::IConfig *config, const struct option *option, const rapidjson::Value &object)
|
||||||
|
{
|
||||||
|
if (!option->name || !object.HasMember(option->name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rapidjson::Value &value = object[option->name];
|
||||||
|
|
||||||
|
if (option->has_arg) {
|
||||||
|
if (value.IsString()) {
|
||||||
|
config->parseString(option->val, value.GetString());
|
||||||
|
}
|
||||||
|
else if (value.IsInt64()) {
|
||||||
|
config->parseUint64(option->val, value.GetUint64());
|
||||||
|
}
|
||||||
|
else if (value.IsBool()) {
|
||||||
|
config->parseBoolean(option->val, value.IsTrue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (value.IsBool()) {
|
||||||
|
config->parseBoolean(option->val, value.IsTrue());
|
||||||
|
}
|
||||||
|
}
|
||||||
72
src/common/config/ConfigLoader.h
Normal file
72
src/common/config/ConfigLoader.h
Normal 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_CONFIGLOADER_H
|
||||||
|
#define XMRIG_CONFIGLOADER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct option;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigWatcher;
|
||||||
|
class IConfigCreator;
|
||||||
|
class IConfigListener;
|
||||||
|
class IConfig;
|
||||||
|
class Process;
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool loadFromFile(IConfig *config, const char *fileName);
|
||||||
|
static bool loadFromJSON(IConfig *config, const char *json);
|
||||||
|
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
|
||||||
|
static bool reload(IConfig *oldConfig, const char *json);
|
||||||
|
static bool watch(IConfig *config);
|
||||||
|
static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener);
|
||||||
|
static void release();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool getJSON(const char *fileName, rapidjson::Document &doc);
|
||||||
|
static bool parseArg(IConfig *config, int key, const char *arg);
|
||||||
|
static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object);
|
||||||
|
|
||||||
|
static ConfigWatcher *m_watcher;
|
||||||
|
static IConfigCreator *m_creator;
|
||||||
|
static IConfigListener *m_listener;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
#endif /* XMRIG_CONFIGLOADER_H */
|
||||||
64
src/common/config/ConfigWatcher.cpp
Normal file
64
src/common/config/ConfigWatcher.cpp
Normal 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/io/Watcher.h"
|
||||||
|
#include "base/kernel/interfaces/IConfigListener.h"
|
||||||
|
#include "common/config/ConfigLoader.h"
|
||||||
|
#include "common/config/ConfigWatcher.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "core/ConfigCreator.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::ConfigWatcher::ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener) :
|
||||||
|
m_creator(creator),
|
||||||
|
m_listener(listener)
|
||||||
|
{
|
||||||
|
m_watcher = new Watcher(path, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::ConfigWatcher::~ConfigWatcher()
|
||||||
|
{
|
||||||
|
delete m_watcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::ConfigWatcher::onFileChanged(const String &fileName)
|
||||||
|
{
|
||||||
|
LOG_WARN("\"%s\" was changed, reloading configuration", fileName.data());
|
||||||
|
|
||||||
|
IConfig *config = m_creator->create();
|
||||||
|
ConfigLoader::loadFromFile(config, fileName);
|
||||||
|
|
||||||
|
if (!config->finalize()) {
|
||||||
|
LOG_ERR("reloading failed");
|
||||||
|
|
||||||
|
delete config;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_listener->onNewConfig(config);
|
||||||
|
}
|
||||||
@@ -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,43 +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 __APISTATE_H__
|
#ifndef XMRIG_CONFIGWATCHER_H
|
||||||
#define __APISTATE_H__
|
#define XMRIG_CONFIGWATCHER_H
|
||||||
|
|
||||||
|
|
||||||
#include "api/NetworkState.h"
|
#include "base/kernel/interfaces/IWatcherListener.h"
|
||||||
|
#include "base/tools/String.h"
|
||||||
#include "rapidjson/fwd.h"
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
class Hashrate;
|
struct option;
|
||||||
|
|
||||||
|
|
||||||
class ApiState
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IConfigCreator;
|
||||||
|
class IConfigListener;
|
||||||
|
class Watcher;
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigWatcher : public IWatcherListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApiState();
|
ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener);
|
||||||
~ApiState();
|
~ConfigWatcher() override;
|
||||||
|
|
||||||
char *get(const char *url, int *status) const;
|
protected:
|
||||||
void tick(const Hashrate *hashrate);
|
void onFileChanged(const String &fileName) override;
|
||||||
void tick(const NetworkState &results);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *finalize(rapidjson::Document &doc) const;
|
IConfigCreator *m_creator;
|
||||||
void genId();
|
IConfigListener *m_listener;
|
||||||
void getConnection(rapidjson::Document &doc) const;
|
Watcher *m_watcher;
|
||||||
void getHashrate(rapidjson::Document &doc) const;
|
|
||||||
void getIdentify(rapidjson::Document &doc) const;
|
|
||||||
void getMiner(rapidjson::Document &doc) const;
|
|
||||||
void getResults(rapidjson::Document &doc) const;
|
|
||||||
|
|
||||||
char m_id[17];
|
|
||||||
char m_workerId[128];
|
|
||||||
double *m_hashrate;
|
|
||||||
double m_highestHashrate;
|
|
||||||
double m_totalHashrate[3];
|
|
||||||
int m_threads;
|
|
||||||
NetworkState m_network;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __APISTATE_H__ */
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
#endif /* __CONFIGWATCHER_H__ */
|
||||||
@@ -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-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
|
||||||
@@ -21,20 +22,30 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# include <intrin.h>
|
# include <intrin.h>
|
||||||
|
|
||||||
# define bit_AES (1 << 25)
|
|
||||||
# define bit_BMI2 (1 << 8)
|
|
||||||
#else
|
#else
|
||||||
# include <cpuid.h>
|
# include <cpuid.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#ifndef bit_AES
|
||||||
|
# define bit_AES (1 << 25)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef bit_OSXSAVE
|
||||||
|
# define bit_OSXSAVE (1 << 27)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef bit_AVX2
|
||||||
|
# define bit_AVX2 (1 << 5)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
#include "common/cpu/BasicCpuInfo.h"
|
||||||
|
|
||||||
|
|
||||||
#define VENDOR_ID (0)
|
#define VENDOR_ID (0)
|
||||||
@@ -69,7 +80,7 @@ static inline void cpuid(int level, int output[4]) {
|
|||||||
|
|
||||||
|
|
||||||
static inline void cpu_brand_string(char* s) {
|
static inline void cpu_brand_string(char* s) {
|
||||||
int cpu_info[4] = { 0 };
|
int32_t cpu_info[4] = { 0 };
|
||||||
cpuid(VENDOR_ID, cpu_info);
|
cpuid(VENDOR_ID, cpu_info);
|
||||||
|
|
||||||
if (cpu_info[EAX_Reg] >= 4) {
|
if (cpu_info[EAX_Reg] >= 4) {
|
||||||
@@ -84,50 +95,65 @@ static inline void cpu_brand_string(char* s) {
|
|||||||
|
|
||||||
static inline bool has_aes_ni()
|
static inline bool has_aes_ni()
|
||||||
{
|
{
|
||||||
int cpu_info[4] = { 0 };
|
int32_t cpu_info[4] = { 0 };
|
||||||
cpuid(PROCESSOR_INFO, cpu_info);
|
cpuid(PROCESSOR_INFO, cpu_info);
|
||||||
|
|
||||||
return cpu_info[ECX_Reg] & bit_AES;
|
return (cpu_info[ECX_Reg] & bit_AES) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool has_bmi2() {
|
static inline bool has_avx2()
|
||||||
int cpu_info[4] = { 0 };
|
{
|
||||||
|
int32_t cpu_info[4] = { 0 };
|
||||||
cpuid(EXTENDED_FEATURES, cpu_info);
|
cpuid(EXTENDED_FEATURES, cpu_info);
|
||||||
|
|
||||||
return cpu_info[EBX_Reg] & bit_BMI2;
|
return (cpu_info[EBX_Reg] & bit_AVX2) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char Cpu::m_brand[64] = { 0 };
|
static inline bool has_ossave()
|
||||||
int Cpu::m_flags = 0;
|
|
||||||
int Cpu::m_l2_cache = 0;
|
|
||||||
int Cpu::m_l3_cache = 0;
|
|
||||||
int Cpu::m_sockets = 1;
|
|
||||||
int Cpu::m_totalCores = 0;
|
|
||||||
int Cpu::m_totalThreads = 0;
|
|
||||||
|
|
||||||
|
|
||||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
|
||||||
{
|
{
|
||||||
int count = m_totalThreads / 2;
|
int32_t cpu_info[4] = { 0 };
|
||||||
return count < 1 ? 1 : count;
|
cpuid(PROCESSOR_INFO, cpu_info);
|
||||||
|
|
||||||
|
return (cpu_info[ECX_Reg] & bit_OSXSAVE) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Cpu::initCommon()
|
xmrig::BasicCpuInfo::BasicCpuInfo() :
|
||||||
|
m_assembly(ASM_NONE),
|
||||||
|
m_aes(has_aes_ni()),
|
||||||
|
m_avx2(has_avx2() && has_ossave()),
|
||||||
|
m_brand(),
|
||||||
|
m_threads(std::thread::hardware_concurrency())
|
||||||
{
|
{
|
||||||
cpu_brand_string(m_brand);
|
cpu_brand_string(m_brand);
|
||||||
|
|
||||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
# ifndef XMRIG_NO_ASM
|
||||||
m_flags |= X86_64;
|
if (hasAES()) {
|
||||||
|
char vendor[13] = { 0 };
|
||||||
|
int32_t data[4] = { 0 };
|
||||||
|
|
||||||
|
cpuid(0, data);
|
||||||
|
|
||||||
|
memcpy(vendor + 0, &data[1], 4);
|
||||||
|
memcpy(vendor + 4, &data[3], 4);
|
||||||
|
memcpy(vendor + 8, &data[2], 4);
|
||||||
|
|
||||||
|
if (memcmp(vendor, "GenuineIntel", 12) == 0) {
|
||||||
|
m_assembly = ASM_INTEL;
|
||||||
|
}
|
||||||
|
else if (memcmp(vendor, "AuthenticAMD", 12) == 0) {
|
||||||
|
m_assembly = ASM_RYZEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
if (has_aes_ni()) {
|
|
||||||
m_flags |= AES;
|
|
||||||
}
|
size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
|
||||||
|
{
|
||||||
if (has_bmi2()) {
|
const size_t count = threads() / 2;
|
||||||
m_flags |= BMI2;
|
|
||||||
}
|
return count < 1 ? 1 : count;
|
||||||
}
|
}
|
||||||
73
src/common/cpu/BasicCpuInfo.h
Normal file
73
src/common/cpu/BasicCpuInfo.h
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/* 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-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
|
||||||
|
* 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_BASICCPUINFO_H
|
||||||
|
#define XMRIG_BASICCPUINFO_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/interfaces/ICpuInfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class BasicCpuInfo : public ICpuInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BasicCpuInfo();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override;
|
||||||
|
|
||||||
|
inline Assembly assembly() const override { return m_assembly; }
|
||||||
|
inline bool hasAES() const override { return m_aes; }
|
||||||
|
inline bool hasAVX2() const override { return m_avx2; }
|
||||||
|
inline bool isSupported() const override { return true; }
|
||||||
|
inline const char *brand() const override { return m_brand; }
|
||||||
|
inline int32_t cores() const override { return -1; }
|
||||||
|
inline int32_t L2() const override { return -1; }
|
||||||
|
inline int32_t L3() const override { return -1; }
|
||||||
|
inline int32_t nodes() const override { return -1; }
|
||||||
|
inline int32_t sockets() const override { return 1; }
|
||||||
|
inline int32_t threads() const override { return m_threads; }
|
||||||
|
|
||||||
|
# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__)
|
||||||
|
inline bool isX64() const override { return true; }
|
||||||
|
# else
|
||||||
|
inline bool isX64() const override { return false; }
|
||||||
|
# endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
Assembly m_assembly;
|
||||||
|
bool m_aes;
|
||||||
|
bool m_avx2;
|
||||||
|
char m_brand[64];
|
||||||
|
int32_t m_threads;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_BASICCPUINFO_H */
|
||||||
58
src/common/cpu/BasicCpuInfo_arm.cpp
Normal file
58
src/common/cpu/BasicCpuInfo_arm.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* 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-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
|
||||||
|
* 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 <string.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#if __ARM_FEATURE_CRYPTO
|
||||||
|
# include <sys/auxv.h>
|
||||||
|
# include <asm/hwcap.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/cpu/BasicCpuInfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::BasicCpuInfo::BasicCpuInfo() :
|
||||||
|
m_aes(false),
|
||||||
|
m_avx2(false),
|
||||||
|
m_brand(),
|
||||||
|
m_threads(std::thread::hardware_concurrency())
|
||||||
|
{
|
||||||
|
# ifdef XMRIG_ARMv8
|
||||||
|
memcpy(m_brand, "ARMv8", 5);
|
||||||
|
# else
|
||||||
|
memcpy(m_brand, "ARMv7", 5);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if __ARM_FEATURE_CRYPTO
|
||||||
|
m_aes = getauxval(AT_HWCAP) & HWCAP_AES;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
|
||||||
|
{
|
||||||
|
return threads();
|
||||||
|
}
|
||||||
@@ -22,31 +22,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Cpu.h"
|
#include "common/cpu/BasicCpuInfo.h"
|
||||||
|
#include "common/cpu/Cpu.h"
|
||||||
|
|
||||||
|
|
||||||
void Cpu::init()
|
static xmrig::ICpuInfo *cpuInfo = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::ICpuInfo *xmrig::Cpu::info()
|
||||||
{
|
{
|
||||||
# ifdef XMRIG_NO_LIBCPUID
|
assert(cpuInfo != nullptr);
|
||||||
SYSTEM_INFO sysinfo;
|
|
||||||
GetSystemInfo(&sysinfo);
|
|
||||||
|
|
||||||
m_totalThreads = sysinfo.dwNumberOfProcessors;
|
return cpuInfo;
|
||||||
# endif
|
|
||||||
|
|
||||||
initCommon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Cpu::setAffinity(int id, uint64_t mask)
|
void xmrig::Cpu::init()
|
||||||
{
|
{
|
||||||
if (id == -1) {
|
assert(cpuInfo == nullptr);
|
||||||
SetProcessAffinityMask(GetCurrentProcess(), mask);
|
|
||||||
}
|
cpuInfo = new BasicCpuInfo();
|
||||||
else {
|
}
|
||||||
SetThreadAffinityMask(GetCurrentThread(), mask);
|
|
||||||
}
|
|
||||||
|
void xmrig::Cpu::release()
|
||||||
|
{
|
||||||
|
assert(cpuInfo != nullptr);
|
||||||
|
|
||||||
|
delete cpuInfo;
|
||||||
|
cpuInfo = nullptr;
|
||||||
}
|
}
|
||||||
@@ -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 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* 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 +21,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 __ALIGN_H__
|
#ifndef XMRIG_CPU_H
|
||||||
#define __ALIGN_H__
|
#define XMRIG_CPU_H
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# define VAR_ALIGN(x, decl) __declspec(align(x)) decl
|
|
||||||
#else
|
|
||||||
# define VAR_ALIGN(x, decl) decl __attribute__ ((aligned(x)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALIGN_H__ */
|
#include "common/interfaces/ICpuInfo.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Cpu
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ICpuInfo *info();
|
||||||
|
static void init();
|
||||||
|
static void release();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_CPU_H */
|
||||||
297
src/common/crypto/Algorithm.cpp
Normal file
297
src/common/crypto/Algorithm.cpp
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
/* 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 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
|
||||||
|
* 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 <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/crypto/Algorithm.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define strncasecmp _strnicmp
|
||||||
|
# define strcasecmp _stricmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ARRAY_SIZE
|
||||||
|
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
struct AlgoData
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
const char *shortName;
|
||||||
|
xmrig::Algo algo;
|
||||||
|
xmrig::Variant variant;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static AlgoData const algorithms[] = {
|
||||||
|
{ "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO },
|
||||||
|
{ "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 },
|
||||||
|
{ "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
|
||||||
|
{ "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
|
||||||
|
{ "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR },
|
||||||
|
{ "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO },
|
||||||
|
{ "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO },
|
||||||
|
{ "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||||
|
{ "cryptonight/half", "cn/half", 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
|
||||||
|
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
|
||||||
|
{ "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
|
||||||
|
{ "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
|
||||||
|
{ "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef XMRIG_NO_SUMO
|
||||||
|
{ "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO },
|
||||||
|
{ "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
|
||||||
|
{ "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV },
|
||||||
|
{ "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE },
|
||||||
|
# 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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_PROXY_PROJECT
|
||||||
|
static AlgoData const xmrStakAlgorithms[] = {
|
||||||
|
{ "cryptonight-monerov7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
|
||||||
|
{ "cryptonight_v7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
|
||||||
|
{ "cryptonight-monerov8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||||
|
{ "cryptonight_v8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||||
|
{ "cryptonight_v7_stellite", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
|
||||||
|
{ "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
|
||||||
|
{ "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
|
||||||
|
{ "cryptonight_lite_v7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
|
||||||
|
{ "cryptonight_heavy", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
|
||||||
|
{ "cryptonight_haven", nullptr, xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV },
|
||||||
|
{ "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_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
|
||||||
|
|
||||||
|
|
||||||
|
static const char *variants[] = {
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"tube",
|
||||||
|
"xtl",
|
||||||
|
"msr",
|
||||||
|
"xhv",
|
||||||
|
"xao",
|
||||||
|
"rto",
|
||||||
|
"2",
|
||||||
|
"half",
|
||||||
|
"trtl",
|
||||||
|
"gpu",
|
||||||
|
"wow",
|
||||||
|
"r",
|
||||||
|
"rwz",
|
||||||
|
"zls",
|
||||||
|
"double"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static_assert(xmrig::VARIANT_MAX == ARRAY_SIZE(variants), "variants size mismatch");
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Algorithm::isValid() const
|
||||||
|
{
|
||||||
|
if (m_algo == INVALID_ALGO) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
|
||||||
|
if (algorithms[i].algo == m_algo && algorithms[i].variant == m_variant) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::Algorithm::variantName() const
|
||||||
|
{
|
||||||
|
if (m_variant == VARIANT_AUTO) {
|
||||||
|
return "auto";
|
||||||
|
}
|
||||||
|
|
||||||
|
return variants[m_variant];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Algorithm::parseAlgorithm(const char *algo)
|
||||||
|
{
|
||||||
|
m_algo = INVALID_ALGO;
|
||||||
|
m_variant = VARIANT_AUTO;
|
||||||
|
|
||||||
|
assert(algo != nullptr);
|
||||||
|
if (algo == nullptr || strlen(algo) < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*algo == '!') {
|
||||||
|
m_flags |= Forced;
|
||||||
|
|
||||||
|
return parseAlgorithm(algo + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
|
||||||
|
if ((strcasecmp(algo, algorithms[i].name) == 0) || (strcasecmp(algo, algorithms[i].shortName) == 0)) {
|
||||||
|
m_algo = algorithms[i].algo;
|
||||||
|
m_variant = algorithms[i].variant;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_algo == INVALID_ALGO) {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Algorithm::parseVariant(const char *variant)
|
||||||
|
{
|
||||||
|
m_variant = VARIANT_AUTO;
|
||||||
|
|
||||||
|
if (variant == nullptr || strlen(variant) < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*variant == '!') {
|
||||||
|
m_flags |= Forced;
|
||||||
|
|
||||||
|
return parseVariant(variant + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(variants); i++) {
|
||||||
|
if (strcasecmp(variant, variants[i]) == 0) {
|
||||||
|
m_variant = static_cast<Variant>(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcasecmp(variant, "xtlv9") == 0) {
|
||||||
|
m_variant = VARIANT_HALF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Algorithm::parseVariant(int variant)
|
||||||
|
{
|
||||||
|
assert(variant >= -1 && variant <= 2);
|
||||||
|
|
||||||
|
switch (variant) {
|
||||||
|
case -1:
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
m_variant = static_cast<Variant>(variant);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
m_variant = VARIANT_2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Algorithm::setAlgo(Algo algo)
|
||||||
|
{
|
||||||
|
m_algo = algo;
|
||||||
|
|
||||||
|
if (m_algo == CRYPTONIGHT_PICO && m_variant == VARIANT_AUTO) {
|
||||||
|
m_variant = xmrig::VARIANT_TRTL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_PROXY_PROJECT
|
||||||
|
void xmrig::Algorithm::parseXmrStakAlgorithm(const char *algo)
|
||||||
|
{
|
||||||
|
m_algo = INVALID_ALGO;
|
||||||
|
m_variant = VARIANT_AUTO;
|
||||||
|
|
||||||
|
assert(algo != nullptr);
|
||||||
|
if (algo == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(xmrStakAlgorithms); i++) {
|
||||||
|
if (strcasecmp(algo, xmrStakAlgorithms[i].name) == 0) {
|
||||||
|
m_algo = xmrStakAlgorithms[i].algo;
|
||||||
|
m_variant = xmrStakAlgorithms[i].variant;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_algo == INVALID_ALGO) {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::Algorithm::name(bool shortName) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
|
||||||
|
if (algorithms[i].algo == m_algo && algorithms[i].variant == m_variant) {
|
||||||
|
return shortName ? algorithms[i].shortName : algorithms[i].name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "invalid";
|
||||||
|
}
|
||||||
103
src/common/crypto/Algorithm.h
Normal file
103
src/common/crypto/Algorithm.h
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* 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 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
|
||||||
|
* 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_ALGORITHM_H
|
||||||
|
#define XMRIG_ALGORITHM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/xmrig.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Algorithm
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Flags {
|
||||||
|
None = 0,
|
||||||
|
Forced = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
inline Algorithm() :
|
||||||
|
m_algo(INVALID_ALGO),
|
||||||
|
m_flags(0),
|
||||||
|
m_variant(VARIANT_AUTO)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline Algorithm(Algo algo, Variant variant) :
|
||||||
|
m_flags(0),
|
||||||
|
m_variant(variant)
|
||||||
|
{
|
||||||
|
setAlgo(algo);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Algorithm(const char *algo) :
|
||||||
|
m_flags(0)
|
||||||
|
{
|
||||||
|
parseAlgorithm(algo);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Algo algo() const { return m_algo; }
|
||||||
|
inline bool isEqual(const Algorithm &other) const { return m_algo == other.m_algo && m_variant == other.m_variant; }
|
||||||
|
inline bool isForced() const { return m_flags & Forced; }
|
||||||
|
inline const char *name() const { return name(false); }
|
||||||
|
inline const char *shortName() const { return name(true); }
|
||||||
|
inline int flags() const { return m_flags; }
|
||||||
|
inline Variant variant() const { return m_variant; }
|
||||||
|
inline void setVariant(Variant variant) { m_variant = variant; }
|
||||||
|
|
||||||
|
inline bool operator!=(const Algorithm &other) const { return !isEqual(other); }
|
||||||
|
inline bool operator==(const Algorithm &other) const { return isEqual(other); }
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
|
const char *variantName() const;
|
||||||
|
void parseAlgorithm(const char *algo);
|
||||||
|
void parseVariant(const char *variant);
|
||||||
|
void parseVariant(int variant);
|
||||||
|
void setAlgo(Algo algo);
|
||||||
|
|
||||||
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
|
void parseXmrStakAlgorithm(const char *algo);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char *name(bool shortName) const;
|
||||||
|
|
||||||
|
Algo m_algo;
|
||||||
|
int m_flags;
|
||||||
|
Variant m_variant;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::vector<xmrig::Algorithm> Algorithms;
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
#endif /* __ALGORITHM_H__ */
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user