1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-10 09:02:45 -05:00

Compare commits

..

79 Commits

Author SHA1 Message Date
xmrig
8d9025f2ca Update README.md 2018-04-22 22:47:05 +07:00
XMRig
38874fbb0a Added workaround for nicehash.com if you use cryptonightv7.<region>.nicehash.com option variant=1 will be set automatically. 2018-04-22 12:57:37 +07:00
xmrig
90a09f20b3 Update CHANGELOG.md 2018-04-21 22:52:06 +07:00
XMRig
7365e0486b Disable IPv6 for API. 2018-04-21 22:35:26 +07:00
XMRig
593056113c #541 Revert all changes in Client::close(). 2018-04-21 22:23:12 +07:00
xmrig
888d80240d Merge pull request #559 from chinarulezzz/master
log/Log.cpp: va_list 'args' was opened but not closed by va_end()
2018-04-21 21:35:41 +07:00
chinarulezzz
0814c28998 log/Log.cpp: va_list 'args' was opened but not closed by va_end() 2018-04-17 23:24:31 +03:00
xmrig
1c2b5acb2c Update README.md 2018-04-08 02:31:04 +07:00
xmrig
d24babb96e Update README.md 2018-03-29 17:15:41 +07:00
xmrig
1bd05d136b Update README.md 2018-03-26 13:59:20 +07:00
XMRig
ec08550fd9 v2.5.2 2018-03-26 13:34:04 +07:00
XMRig
6f4ed5f66d #478 Fixed totally broken reconnect. 2018-03-26 11:47:01 +07:00
xmrig
f852996f97 Update README.md 2018-03-25 15:14:19 +07:00
xmrig
38da8ef86c Update README.md 2018-03-25 15:04:00 +07:00
XMRig
dd7f70d6e8 Fix error in config.json 2018-03-24 13:55:45 +07:00
XMRig
89608ade3b Removed unused private field in FailoverStrategy class. 2018-03-24 13:45:54 +07:00
XMRig
f8f89a0946 v2.5.1 release candidate. 2018-03-24 13:04:04 +07:00
xmrig
e99928aa44 Update CHANGELOG.md 2018-03-24 11:02:04 +07:00
XMRig
1011fd4891 Partial fix for ARMv7 2018-03-24 10:14:21 +07:00
XMRig
673a1291e1 Randomized donation start time. 2018-03-24 09:41:32 +07:00
XMRig
8aa73318c8 Backport changes from proxy. 2018-03-24 00:10:39 +07:00
XMRig
ff68840220 Merge branch 'master' of github.com:xmrig/xmrig 2018-03-20 06:21:14 +07:00
XMRig
f2625b7ff5 New app icon. 2018-03-20 06:20:43 +07:00
xmrig
4440d3edd5 Update README.md 2018-03-19 07:03:50 +07:00
XMRig
efa21b2531 #454 Fixed build with libmicrohttpd version below v0.9.35. 2018-03-18 08:30:56 +07:00
XMRig
2de5d92d3a Removed unnecessary pointers cast. 2018-03-18 05:48:19 +07:00
xmrig
2e320d28d9 Update CHANGELOG.md 2018-03-17 18:08:17 +07:00
XMRig
e58429a044 Merge branch 'feature-donate-failover' 2018-03-17 17:57:02 +07:00
XMRig
ed5bf3420c Add donate pool IP address to avoid DNS issues. 2018-03-17 17:55:11 +07:00
xmrig
a7cf34d2eb Update CHANGELOG.md 2018-03-17 16:38:32 +07:00
XMRig
de5016dda8 #459 Fix issue with xmr.f2pool.com 2018-03-17 16:30:41 +07:00
XMRig
1cf1d616c6 DonateStrategy now use FailoverStrategy internally and possible to use any other IStrategy. 2018-03-17 14:33:30 +07:00
XMRig
c46c019c83 Unify network strategies with upcoming proxy. 2018-03-17 05:03:14 +07:00
XMRig
a2f747fb0c Pass all options to network strategies in constructor. 2018-03-17 04:16:08 +07:00
XMRig
38c39321d0 Merge branch 'master' of github.com:xmrig/xmrig 2018-03-17 01:08:41 +07:00
XMRig
7ab81ef19a #456 Don't show error "JSON decode failed" in quiet mode. 2018-03-17 01:07:53 +07:00
XMRig
2e503f7f8c Merge branch 'master' into dev 2018-03-16 15:02:02 +07:00
xmrig
3d41629170 Update README.md 2018-03-15 01:32:09 +07:00
xmrig
7959cf39fa Update README.md 2018-03-14 23:43:57 +07:00
XMRig
d48921bfc8 v2.5.0 2018-03-14 20:33:17 +07:00
XMRig
04c02d4add Fix macOS compile. 2018-03-14 20:22:30 +07:00
XMRig
2c2b3d2f36 Fix FindMHD.cmake 2018-03-14 19:58:38 +07:00
XMRig
0e60c5802d Fix. 2018-03-14 17:17:36 +07:00
XMRig
7adf30e326 Remove align.h. 2018-03-14 17:11:51 +07:00
XMRig
f9a3315d75 Fixes for 32 bit gcc builds. 2018-03-14 16:58:39 +07:00
XMRig
c0ca68e2db Fix FindUV.cmake and FindMHD.cmake. 2018-03-14 06:32:43 +07:00
xmrig
fdc9fbe876 Merge pull request #442 from kpcyrd/static
Add -DBUILD_STATIC=ON for static builds
2018-03-13 22:35:06 +07:00
XMRig
18f1ac6c62 Merge branch 'dev' 2018-03-13 22:33:37 +07:00
XMRig
81ef40fbb7 Fix for previous commit. 2018-03-13 21:01:00 +07:00
XMRig
41abe17286 #438 Fixed memory release. 2018-03-13 20:59:35 +07:00
XMRig
a01b4d0566 Simplify variant selection. 2018-03-13 17:50:09 +07:00
kpcyrd
11f00a2e6e Add -DBUILD_STATIC=ON for static builds
See #238
2018-03-12 21:03:04 +01:00
XMRig
07f0a107d3 Change port for AEON donate. 2018-03-13 02:17:19 +07:00
XMRig
30ab6f79ff Merge branch 'v1-pow' into dev 2018-03-13 01:49:54 +07:00
XMRig
125072a30e Added test hashes for AEON. 2018-03-13 01:29:31 +07:00
XMRig
aec31c43c0 Better v1 PoW implementation, added variant option. 2018-03-12 22:29:44 +07:00
XMRig
83e5832bc1 Some small fixes. 2018-03-12 14:44:23 +07:00
XMRig
244ca93aa4 Change donation address to separate old and new versions. 2018-03-09 13:15:55 +07:00
XMRig
ff68c047f9 v2.5.0-dev 2018-03-09 01:49:24 +07:00
XMRig
b662cb77a4 Revert changes in Api class, single threaded http server will not be included in 2.5 release. 2018-03-09 01:47:44 +07:00
XMRig
3e2863dca5 Merge branch 'vtnerd-monero-v1-pow' into dev
# Conflicts:
#	src/api/Httpd.cpp
#	src/api/Httpd.h
2018-03-09 01:41:47 +07:00
xmrig
6e95b0d052 Update CHANGELOG.md 2018-03-09 01:30:32 +07:00
xmrig
da4aa69c89 Update CHANGELOG.md 2018-03-09 00:56:29 +07:00
XMRig
84970e9e9b Added coin field support added in xmrig-proxy 2.5. 2018-03-09 00:50:06 +07:00
XMRig
37ac1aa62c Automatically enable nicehash when use with upcoming xmrig-proxy 2.5. 2018-03-07 21:56:43 +07:00
XMRig
69b8a4faf1 Added option to disable Monero v7 PoW, may useful in future if other coins update their network to v7 without PoW change. 2018-03-07 19:12:18 +07:00
XMRig
8a6988d381 Added full IPv6 support. 2018-03-07 16:38:58 +07:00
XMRig
79779b51da Added reference hashes. 2018-03-07 15:32:44 +07:00
XMRig
8b60585004 PoW changes WIP 2018-03-06 21:34:20 +07:00
XMRig
df6a397e52 Update copyright and move version into Job class. 2018-03-06 17:06:07 +07:00
XMRig
274c6306a8 Merge branch 'monero-v1-pow' of https://github.com/vtnerd/xmrig into vtnerd-monero-v1-pow 2018-03-06 16:37:33 +07:00
XMRig
a398c8af2f Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy parsed incorrectly. 2018-03-05 13:54:21 +07:00
XMRig
fc82cf1cf2 #428 Fixed regression with CPU cache size detection. 2018-03-05 02:15:05 +07:00
Lee Clagett
48b1de0b59 Changes for the Monero v1 PoW 2018-03-02 22:17:29 +00:00
XMRig
3edc30d067 Use adaptive timer instead of idle handler for HTTP server. 2018-03-01 09:53:27 +07:00
XMRig
ff6dc727f5 Added XMRIG_DEPS cmake variable for unified dependencies. 2018-02-21 00:52:52 +07:00
XMRig
a0d4e4ed3f Run internal http server in main loop to avoid requirement to thread synchronization. 2018-02-20 23:22:34 +07:00
XMRig
71759e3752 Merge branch 'master' into dev 2018-02-20 22:48:39 +07:00
xmrig
79345119c6 Update CHANGELOG.md 2018-02-19 15:58:44 +07:00
55 changed files with 1078 additions and 459 deletions

View File

@@ -1,7 +1,27 @@
# 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 # v2.4.5
- [#324](https://github.com/xmrig/xmrig/pull/324) Fixed build without libmicrohttpd (CMake cache issue). - [#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`. - [#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 with for non-AES CPU and fixed Intel Core 2 cache detection. - [#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 # v2.4.4
- Added libmicrohttpd version to --version output. - Added libmicrohttpd version to --version output.

View File

@@ -4,13 +4,13 @@ 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_HTTPD "HTTP REST API" ON)
option(BUILD_STATIC "Build static binary" OFF)
include (CheckIncludeFile) include (CheckIncludeFile)
include (cmake/cpu.cmake) include (cmake/cpu.cmake)
set(HEADERS set(HEADERS
src/3rdparty/align.h
src/api/Api.h src/api/Api.h
src/api/ApiState.h src/api/ApiState.h
src/api/NetworkState.h src/api/NetworkState.h
@@ -29,8 +29,8 @@ set(HEADERS
src/log/Log.h src/log/Log.h
src/Mem.h src/Mem.h
src/net/Client.h src/net/Client.h
src/net/Id.h
src/net/Job.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
@@ -48,6 +48,7 @@ set(HEADERS
src/workers/SingleWorker.h src/workers/SingleWorker.h
src/workers/Worker.h src/workers/Worker.h
src/workers/Workers.h src/workers/Workers.h
src/xmrig.h
) )
set(HEADERS_CRYPTO set(HEADERS_CRYPTO
@@ -57,6 +58,7 @@ set(HEADERS_CRYPTO
src/crypto/c_keccak.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_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
@@ -204,5 +206,9 @@ include_directories(src)
include_directories(src/3rdparty) include_directories(src/3rdparty)
include_directories(${UV_INCLUDE_DIR}) include_directories(${UV_INCLUDE_DIR})
if (BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS " -static")
endif()
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES})
target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})

View File

@@ -1,4 +1,7 @@
# XMRig # XMRig
:warning: **If you mine Monero, Aeon, Sumokoin, Turtlecoin, Stellite, GRAFT, Haven Protocol, IPBC, [PLEASE READ](https://github.com/xmrig/xmrig/issues/482)!** :warning:
[![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases) [![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases)
[![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases)
[![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/releases) [![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/releases)
@@ -23,6 +26,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
@@ -62,11 +66,13 @@ Use [config.xmrig.com](https://config.xmrig.com/xmrig) to generate, edit or shar
--cpu-priority set process priority (0 idle, 2 normal to 5 highest) --cpu-priority set process priority (0 idle, 2 normal to 5 highest)
--no-huge-pages disable huge pages support --no-huge-pages disable huge pages support
--no-color disable colored output --no-color disable colored output
--variant algorithm PoW variant
--donate-level=N donate level, default 5% (5 minutes in 100 minutes) --donate-level=N donate level, default 5% (5 minutes in 100 minutes)
--user-agent set custom user-agent string for pool --user-agent set custom user-agent string for pool
-B, --background run the miner in the background -B, --background run the miner in the background
-c, --config=FILE load a JSON-format configuration file -c, --config=FILE load a JSON-format configuration file
-l, --log-file=FILE log all output to a 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) --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)
--safe safe adjust threads and av settings for current CPU --safe safe adjust threads and av settings for current CPU
--nicehash enable nicehash/xmrig-proxy support --nicehash enable nicehash/xmrig-proxy support
@@ -115,6 +121,15 @@ Please note performance is highly dependent on system load. The numbers above ar
* XMR: `48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD` * XMR: `48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD`
* BTC: `1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT` * BTC: `1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT`
## Release checksums
### SHA-256
```
5ae25d05b7735dd6e2482e8dba0cf0f5d10f9738855c4ad4eaf449b8ccd2e5be xmrig-2.5.3-xenial-amd64.tar.gz/xmrig-2.5.3/xmrig
f11f3b381425ca4181c425d5b693407431f964759bb903f66b7cd2345fcdd786 xmrig-2.5.3-gcc-win32.zip/xmrig.exe
67df8b89714e2921931092861361dbae4716c4ab872c767c92adae24dca01514 xmrig-2.5.3-gcc-win64.zip/xmrig.exe
52bf6e0ef72c84282f4df411125384444c521ed9143e5d8c7e7e445d7d55e143 xmrig-2.5.3-msvc-win64.zip/xmrig.exe
```
## Contacts ## Contacts
* support@xmrig.com * support@xmrig.com
* [reddit](https://www.reddit.com/user/XMRig/) * [reddit](https://www.reddit.com/user/XMRig/)

View File

@@ -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)

View File

@@ -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})

View File

@@ -6,6 +6,10 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
endif() endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(/DNDEBUG)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES GNU) if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -36,6 +36,8 @@
void App::background() void App::background()
{ {
signal(SIGPIPE, SIG_IGN);
if (m_options->affinity() != -1L) { if (m_options->affinity() != -1L) {
Cpu::setAffinity(-1, m_options->affinity()); Cpu::setAffinity(-1, m_options->affinity());
} }

View File

@@ -100,9 +100,9 @@ void Cpu::initCommon()
m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets; m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets;
m_l2_exclusive = true; m_l2_exclusive = true;
} }
// Workaround for Intel Core Solo, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue // Workaround for Intel Pentium Dual-Core, Core Duo, Core 2 Duo, Core 2 Quad and their Xeon homologue
// These processors have L2 cache shared by 2 cores. // These processors have L2 cache shared by 2 cores.
else if (data.vendor == VENDOR_INTEL && data.family == 0x06 && (data.model == 0x0E || data.model == 0x0F || data.model == 0x07)) { else if (data.vendor == VENDOR_INTEL && data.ext_family == 0x06 && (data.ext_model == 0x0E || data.ext_model == 0x0F || data.ext_model == 0x17)) {
int l2_count_per_socket = m_totalCores > 1 ? m_totalCores / 2 : 1; int l2_count_per_socket = m_totalCores > 1 ? m_totalCores / 2 : 1;
m_l2_cache = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0; m_l2_cache = data.l2_cache > 0 ? data.l2_cache * l2_count_per_socket * m_sockets : 0;
} }

View File

@@ -24,13 +24,18 @@
#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
#ifndef bit_AES
# define bit_AES (1 << 25)
#endif
#ifndef bit_BMI2
# define bit_BMI2 (1 << 8)
#endif
#include <string.h> #include <string.h>
@@ -87,7 +92,7 @@ static inline bool has_aes_ni()
int cpu_info[4] = { 0 }; int 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;
} }
@@ -95,7 +100,7 @@ static inline bool has_bmi2() {
int cpu_info[4] = { 0 }; int 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_BMI2) != 0;
} }

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -28,28 +29,30 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h" #include "Options.h"
#include "xmrig.h"
bool Mem::m_doubleHash = false; bool Mem::m_doubleHash = false;
int Mem::m_algo = 0; int Mem::m_algo = 0;
int Mem::m_flags = 0; int Mem::m_flags = 0;
int Mem::m_threads = 0; int Mem::m_threads = 0;
size_t Mem::m_offset = 0; size_t Mem::m_offset = 0;
uint8_t *Mem::m_memory = nullptr; size_t Mem::m_size = 0;
alignas(16) uint8_t *Mem::m_memory = nullptr;
cryptonight_ctx *Mem::create(int threadId) cryptonight_ctx *Mem::create(int threadId)
{ {
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
if (m_algo == Options::ALGO_CRYPTONIGHT_LITE) { if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
return createLite(threadId); return createLite(threadId);
} }
# endif # endif
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
const int ratio = m_doubleHash ? 2 : 1; const int ratio = m_doubleHash ? 2 : 1;
ctx->memory = &m_memory[MEMORY * (threadId * ratio + 1)]; ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
return ctx; return ctx;
} }
@@ -72,15 +75,15 @@ cryptonight_ctx *Mem::createLite(int threadId) {
cryptonight_ctx *ctx; cryptonight_ctx *ctx;
if (!m_doubleHash) { if (!m_doubleHash) {
const size_t offset = MEMORY * (threadId + 1); const size_t offset = MONERO_MEMORY * (threadId + 1);
ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[offset + MEMORY_LITE]); ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[offset + AEON_MEMORY]);
ctx->memory = &m_memory[offset]; ctx->memory = &m_memory[offset];
return ctx; return ctx;
} }
ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
ctx->memory = &m_memory[MEMORY * (threadId + 1)]; ctx->memory = &m_memory[MONERO_MEMORY * (threadId + 1)];
return ctx; return ctx;
} }

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -29,9 +30,6 @@
#include <stdint.h> #include <stdint.h>
#include "align.h"
struct cryptonight_ctx; struct cryptonight_ctx;
@@ -61,7 +59,8 @@ private:
static int m_flags; static int m_flags;
static int m_threads; static int m_threads;
static size_t m_offset; static size_t m_offset;
VAR_ALIGN(16, static uint8_t *m_memory); static size_t m_size;
alignas(16) static uint8_t *m_memory;
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
static cryptonight_ctx *createLite(int threadId); static cryptonight_ctx *createLite(int threadId);

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -37,6 +38,7 @@
#include "log/Log.h" #include "log/Log.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h" #include "Options.h"
#include "xmrig.h"
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
@@ -45,35 +47,35 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
m_threads = threads; m_threads = threads;
m_doubleHash = doubleHash; m_doubleHash = doubleHash;
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const size_t size = MEMORY * (threads * ratio + 1); m_size = MONERO_MEMORY * (threads * ratio + 1);
if (!enabled) { if (!enabled) {
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16)); m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
return true; return true;
} }
m_flags |= HugepagesAvailable; m_flags |= HugepagesAvailable;
# 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)); m_memory = static_cast<uint8_t*>(mmap(0, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0));
# elif defined(__FreeBSD__) # elif defined(__FreeBSD__)
m_memory = static_cast<uint8_t*>(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); m_memory = static_cast<uint8_t*>(mmap(0, m_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)); m_memory = static_cast<uint8_t*>(mmap(0, m_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0));
# endif # endif
if (m_memory == MAP_FAILED) { if (m_memory == MAP_FAILED) {
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16)); m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
return true; return true;
} }
m_flags |= HugepagesEnabled; m_flags |= HugepagesEnabled;
if (madvise(m_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) { if (madvise(m_memory, m_size, MADV_RANDOM | MADV_WILLNEED) != 0) {
LOG_ERR("madvise failed"); LOG_ERR("madvise failed");
} }
if (mlock(m_memory, size) == 0) { if (mlock(m_memory, m_size) == 0) {
m_flags |= Lock; m_flags |= Lock;
} }
@@ -83,14 +85,12 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
void Mem::release() void Mem::release()
{ {
const int size = MEMORY * (m_threads + 1);
if (m_flags & HugepagesEnabled) { if (m_flags & HugepagesEnabled) {
if (m_flags & Lock) { if (m_flags & Lock) {
munlock(m_memory, size); munlock(m_memory, m_size);
} }
munmap(m_memory, size); munmap(m_memory, m_size);
} }
else { else {
_mm_free(m_memory); _mm_free(m_memory);

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -37,6 +38,7 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
#include "Options.h" #include "Options.h"
#include "xmrig.h"
/***************************************************************** /*****************************************************************
@@ -150,11 +152,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
m_threads = threads; m_threads = threads;
m_doubleHash = doubleHash; m_doubleHash = doubleHash;
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const size_t size = MEMORY * (threads * ratio + 1); m_size = MONERO_MEMORY * (threads * ratio + 1);
if (!enabled) { if (!enabled) {
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16)); m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
return true; return true;
} }
@@ -162,9 +164,9 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
m_flags |= HugepagesAvailable; m_flags |= HugepagesAvailable;
} }
m_memory = static_cast<uint8_t*>(VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); m_memory = static_cast<uint8_t*>(VirtualAlloc(NULL, m_size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE));
if (!m_memory) { if (!m_memory) {
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16)); m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
} }
else { else {
m_flags |= HugepagesEnabled; m_flags |= HugepagesEnabled;

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -47,6 +47,7 @@
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
#include "rapidjson/filereadstream.h" #include "rapidjson/filereadstream.h"
#include "version.h" #include "version.h"
#include "xmrig.h"
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
@@ -74,6 +75,7 @@ Options:\n\
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
--no-huge-pages disable huge pages support\n\ --no-huge-pages disable huge pages support\n\
--no-color disable colored output\n\ --no-color disable colored output\n\
--variant algorithm PoW variant\n\
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
--user-agent set custom user-agent string for pool\n\ --user-agent set custom user-agent string for pool\n\
-B, --background run the miner in the background\n\ -B, --background run the miner in the background\n\
@@ -118,6 +120,7 @@ static struct option const options[] = {
{ "nicehash", 0, nullptr, 1006 }, { "nicehash", 0, nullptr, 1006 },
{ "no-color", 0, nullptr, 1002 }, { "no-color", 0, nullptr, 1002 },
{ "no-huge-pages", 0, nullptr, 1009 }, { "no-huge-pages", 0, nullptr, 1009 },
{ "variant", 1, nullptr, 1010 },
{ "pass", 1, nullptr, 'p' }, { "pass", 1, nullptr, 'p' },
{ "print-time", 1, nullptr, 1007 }, { "print-time", 1, nullptr, 1007 },
{ "retries", 1, nullptr, 'r' }, { "retries", 1, nullptr, 'r' },
@@ -163,6 +166,7 @@ static struct option const pool_options[] = {
{ "user", 1, nullptr, 'u' }, { "user", 1, nullptr, 'u' },
{ "userpass", 1, nullptr, 'O' }, { "userpass", 1, nullptr, 'O' },
{ "keepalive", 0, nullptr ,'k' }, { "keepalive", 0, nullptr ,'k' },
{ "variant", 1, nullptr, 1010 },
{ "nicehash", 0, nullptr, 1006 }, { "nicehash", 0, nullptr, 1006 },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@@ -272,9 +276,7 @@ Options::Options(int argc, char **argv) :
} }
} }
for (Url *url : m_pools) { adjust();
url->applyExceptions();
}
m_ready = true; m_ready = true;
} }
@@ -380,6 +382,7 @@ bool Options::parseArg(int key, const char *arg)
case 1007: /* --print-time */ case 1007: /* --print-time */
case 1021: /* --cpu-priority */ case 1021: /* --cpu-priority */
case 4000: /* --api-port */ case 4000: /* --api-port */
case 1010: /* --variant */
return parseArg(key, strtol(arg, nullptr, 10)); return parseArg(key, strtol(arg, nullptr, 10));
case 'B': /* --background */ case 'B': /* --background */
@@ -498,6 +501,10 @@ bool Options::parseArg(int key, uint64_t arg)
m_printTime = (int) arg; m_printTime = (int) arg;
break; break;
case 1010: /* --variant */
m_pools.back()->setVariant((int) arg);
break;
case 1020: /* --cpu-affinity */ case 1020: /* --cpu-affinity */
if (arg) { if (arg) {
m_affinity = arg; m_affinity = arg;
@@ -585,6 +592,14 @@ Url *Options::parseUrl(const char *arg) const
} }
void Options::adjust()
{
for (Url *url : m_pools) {
url->adjust(m_algo);
}
}
void Options::parseConfig(const char *fileName) void Options::parseConfig(const char *fileName)
{ {
rapidjson::Document doc; rapidjson::Document doc;
@@ -629,7 +644,7 @@ void Options::parseJSON(const struct option *option, const rapidjson::Value &obj
if (option->has_arg && value.IsString()) { if (option->has_arg && value.IsString()) {
parseArg(option->val, value.GetString()); parseArg(option->val, value.GetString());
} }
else if (option->has_arg && value.IsUint64()) { else if (option->has_arg && value.IsInt64()) {
parseArg(option->val, value.GetUint64()); parseArg(option->val, value.GetUint64());
} }
else if (!option->has_arg && value.IsBool()) { else if (!option->has_arg && value.IsBool()) {
@@ -695,7 +710,7 @@ bool Options::setAlgo(const char *algo)
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) { if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) {
m_algo = ALGO_CRYPTONIGHT_LITE; m_algo = xmrig::ALGO_CRYPTONIGHT_LITE;
break; break;
} }
# endif # endif
@@ -713,7 +728,7 @@ bool Options::setAlgo(const char *algo)
int Options::getAlgoVariant() const int Options::getAlgoVariant() const
{ {
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
if (m_algo == ALGO_CRYPTONIGHT_LITE) { if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
return getAlgoVariantLite(); return getAlgoVariantLite();
} }
# endif # endif

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -39,11 +39,6 @@ struct option;
class Options class Options
{ {
public: public:
enum Algo {
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
};
enum AlgoVariant { enum AlgoVariant {
AV0_AUTO, AV0_AUTO,
AV1_AESNI, AV1_AESNI,
@@ -96,6 +91,7 @@ private:
bool parseArg(int key, uint64_t arg); bool parseArg(int key, uint64_t arg);
bool parseBoolean(int key, bool enable); bool parseBoolean(int key, bool enable);
Url *parseUrl(const char *arg) const; Url *parseUrl(const char *arg) const;
void adjust();
void parseConfig(const char *fileName); void parseConfig(const char *fileName);
void parseJSON(const struct option *option, const rapidjson::Value &object); void parseJSON(const struct option *option, const rapidjson::Value &object);
void showUsage(int status) const; void showUsage(int status) const;

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -45,7 +45,15 @@ bool Httpd::start()
return false; return false;
} }
m_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END); unsigned int flags = MHD_USE_SELECT_INTERNALLY;
# if MHD_VERSION >= 0x00093500
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
flags = MHD_USE_EPOLL_LINUX_ONLY | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY;
}
# endif
m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
if (!m_daemon) { if (!m_daemon) {
LOG_ERR("HTTP Daemon failed to start."); LOG_ERR("HTTP Daemon failed to start.");
return false; return false;

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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

View File

@@ -16,11 +16,12 @@
"threads": null, // number of miner threads "threads": null, // number of miner threads
"pools": [ "pools": [
{ {
"url": "pool.minemonero.pro:5555", // URL of mining server "url": "failover.xmrig.com:443", // URL of mining server
"user": "", // username for mining server "user": "YOUR_WALLET", // username for mining server
"pass": "x", // password for mining server "pass": "x", // password for mining server
"keepalive": true, // send keepalived for prevent timeout (need pool support) "keepalive": true, // send keepalived for prevent timeout (need pool support)
"nicehash": false // enable nicehash/xmrig-proxy support "nicehash": false, // enable nicehash/xmrig-proxy support
"variant": -1 // algorithm PoW variant
} }
], ],
"api": { "api": {

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -24,6 +25,7 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#if defined(XMRIG_ARM) #if defined(XMRIG_ARM)
# include "crypto/CryptoNight_arm.h" # include "crypto/CryptoNight_arm.h"
#else #else
@@ -34,60 +36,74 @@
#include "net/Job.h" #include "net/Job.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "Options.h" #include "Options.h"
#include "xmrig.h"
void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr; void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr;
static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx) { #define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \
switch (variant) { \
case xmrig::VARIANT_V1: \
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
\
case xmrig::VARIANT_NONE: \
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
\
default: \
break; \
}
static void cryptonight_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, struct cryptonight_ctx *ctx, int variant) {
# if !defined(XMRIG_ARMv7) # if !defined(XMRIG_ARMv7)
cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx); CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
# endif # endif
} }
static void cryptonight_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
# if !defined(XMRIG_ARMv7) # if !defined(XMRIG_ARMv7)
cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx); CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
# endif # endif
} }
static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx); CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
} }
static void cryptonight_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx); CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
} }
#ifndef XMRIG_NO_AEON #ifndef XMRIG_NO_AEON
static void cryptonight_lite_av1_aesni(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_lite_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
# if !defined(XMRIG_ARMv7)
cryptonight_hash<0x40000, MEMORY_LITE, 0xFFFF0, false>(input, size, output, ctx);
#endif
}
static void cryptonight_lite_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) {
# if !defined(XMRIG_ARMv7) # if !defined(XMRIG_ARMv7)
cryptonight_double_hash<0x40000, MEMORY_LITE, 0xFFFF0, false>(input, size, output, ctx); CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
# endif # endif
} }
static void cryptonight_lite_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_lite_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
cryptonight_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx); # if !defined(XMRIG_ARMv7)
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
# endif
} }
static void cryptonight_lite_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) { static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
cryptonight_double_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx); CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
} }
void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = {
static void cryptonight_lite_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
}
void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
cryptonight_av1_aesni, cryptonight_av1_aesni,
cryptonight_av2_aesni_double, cryptonight_av2_aesni_double,
cryptonight_av3_softaes, cryptonight_av3_softaes,
@@ -98,7 +114,7 @@ void (*cryptonight_variations[8])(const void *input, size_t size, void *output,
cryptonight_lite_av4_softaes_double cryptonight_lite_av4_softaes_double
}; };
#else #else
void (*cryptonight_variations[4])(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = { void (*cryptonight_variations[4])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
cryptonight_av1_aesni, cryptonight_av1_aesni,
cryptonight_av2_aesni_double, cryptonight_av2_aesni_double,
cryptonight_av3_softaes, cryptonight_av3_softaes,
@@ -109,7 +125,7 @@ void (*cryptonight_variations[4])(const void *input, size_t size, void *output,
bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx) bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx)
{ {
cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx); cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx, job.variant());
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target(); return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
} }
@@ -122,7 +138,7 @@ bool CryptoNight::init(int algo, int variant)
} }
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
const int index = algo == Options::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1); const int index = algo == xmrig::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
# else # else
const int index = variant - 1; const int index = variant - 1;
# endif # endif
@@ -133,9 +149,9 @@ bool CryptoNight::init(int algo, int variant)
} }
void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx) void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant)
{ {
cryptonight_hash_ctx(input, size, output, ctx); cryptonight_hash_ctx(input, size, output, ctx, variant);
} }
@@ -144,19 +160,33 @@ bool CryptoNight::selfTest(int algo) {
return false; return false;
} }
char output[64]; uint8_t output[64];
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16); struct cryptonight_ctx *ctx = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 16));
ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16); ctx->memory = static_cast<uint8_t *>(_mm_malloc(MONERO_MEMORY * 2, 16));
cryptonight_hash_ctx(test_input, 76, output, ctx); cryptonight_hash_ctx(test_input, 76, output, ctx, 0);
const bool doubleHash = Options::i()->doubleHash();
# ifndef XMRIG_NO_AEON
bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0;
# else
bool rc = memcmp(output, test_output_v0, (doubleHash ? 64 : 32)) == 0;
# endif
if (rc) {
cryptonight_hash_ctx(test_input, 76, output, ctx, 1);
# ifndef XMRIG_NO_AEON
rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, (doubleHash ? 64 : 32)) == 0;
# else
rc = memcmp(output, test_output_v1, (doubleHash ? 64 : 32)) == 0;
# endif
}
_mm_free(ctx->memory); _mm_free(ctx->memory);
_mm_free(ctx); _mm_free(ctx);
# ifndef XMRIG_NO_AEON return rc;
return memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
# else
return memcmp(output, test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
# endif
} }

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -29,17 +30,19 @@
#include <stdint.h> #include <stdint.h>
#include "align.h" #define AEON_MEMORY 1048576
#define AEON_MASK 0xFFFF0
#define AEON_ITER 0x40000
#define MONERO_MEMORY 2097152
#define MEMORY 2097152 /* 2 MiB */ #define MONERO_MASK 0x1FFFF0
#define MEMORY_LITE 1048576 /* 1 MiB */ #define MONERO_ITER 0x80000
struct cryptonight_ctx { struct cryptonight_ctx {
VAR_ALIGN(16, uint8_t state0[200]); alignas(16) uint8_t state0[200];
VAR_ALIGN(16, uint8_t state1[200]); alignas(16) uint8_t state1[200];
VAR_ALIGN(16, uint8_t* memory); alignas(16) uint8_t* memory;
}; };
@@ -52,7 +55,7 @@ class CryptoNight
public: public:
static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx); static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx);
static bool init(int algo, int variant); static bool init(int algo, int variant);
static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx); static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant);
private: private:
static bool selfTest(int algo); static bool selfTest(int algo);

View File

@@ -5,8 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016 Imran Yusuff <https://github.com/imranyusuff> * Copyright 2016 Imran Yusuff <https://github.com/imranyusuff>
* 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 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
@@ -34,6 +35,7 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_monero.h"
#include "crypto/soft_aes.h" #include "crypto/soft_aes.h"
@@ -47,27 +49,27 @@ extern "C"
} }
static inline void do_blake_hash(const void* input, size_t len, char* output) { static inline void do_blake_hash(const uint8_t *input, size_t len, uint8_t *output) {
blake256_hash(reinterpret_cast<uint8_t*>(output), static_cast<const uint8_t*>(input), len); blake256_hash(output, input, len);
} }
static inline void do_groestl_hash(const void* input, size_t len, char* output) { static inline void do_groestl_hash(const uint8_t *input, size_t len, uint8_t *output) {
groestl(static_cast<const uint8_t*>(input), len * 8, reinterpret_cast<uint8_t*>(output)); groestl(input, len * 8, output);
} }
static inline void do_jh_hash(const void* input, size_t len, char* output) { static inline void do_jh_hash(const uint8_t *input, size_t len, uint8_t *output) {
jh_hash(32 * 8, static_cast<const uint8_t*>(input), 8 * len, reinterpret_cast<uint8_t*>(output)); jh_hash(32 * 8, input, 8 * len, output);
} }
static inline void do_skein_hash(const void* input, size_t len, char* output) { static inline void do_skein_hash(const uint8_t *input, size_t len, uint8_t *output) {
xmr_skein(static_cast<const uint8_t*>(input), reinterpret_cast<uint8_t*>(output)); xmr_skein(input, output);
} }
void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash}; void (* const extra_hashes[4])(const uint8_t *, size_t, uint8_t *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
static inline __attribute__((always_inline)) __m128i _mm_set_epi64x(const uint64_t a, const uint64_t b) static inline __attribute__((always_inline)) __m128i _mm_set_epi64x(const uint64_t a, const uint64_t b)
@@ -136,20 +138,6 @@ static inline __m128i sl_xor(__m128i tmp1)
} }
template<uint8_t rcon>
static inline void aes_genkey_sub(__m128i* xout0, __m128i* xout2)
{
// __m128i xout1 = _mm_aeskeygenassist_si128(*xout2, rcon);
// xout1 = _mm_shuffle_epi32(xout1, 0xFF); // see PSHUFD, set all elems to 4th elem
// *xout0 = sl_xor(*xout0);
// *xout0 = _mm_xor_si128(*xout0, xout1);
// xout1 = _mm_aeskeygenassist_si128(*xout0, 0x00);
// xout1 = _mm_shuffle_epi32(xout1, 0xAA); // see PSHUFD, set all elems to 3rd elem
// *xout2 = sl_xor(*xout2);
// *xout2 = _mm_xor_si128(*xout2, xout1);
}
template<uint8_t rcon> template<uint8_t rcon>
static inline void soft_aes_genkey_sub(__m128i* xout0, __m128i* xout2) static inline void soft_aes_genkey_sub(__m128i* xout0, __m128i* xout2)
{ {
@@ -344,10 +332,12 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
} }
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES> template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
{ {
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200); keccak(input, (int) size, ctx->state0, 200);
VARIANT1_INIT(0);
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory); cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
@@ -374,6 +364,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
} }
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
VARIANT1_1(&l0[idx0 & MASK]);
idx0 = EXTRACT64(cx); idx0 = EXTRACT64(cx);
bx0 = cx; bx0 = cx;
@@ -385,8 +376,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
al0 += hi; al0 += hi;
ah0 += lo; ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
((uint64_t*)&l0[idx0 & MASK])[1] = ah0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch; ah0 ^= ch;
al0 ^= cl; al0 ^= cl;
@@ -396,15 +389,18 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0); cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
keccakf(h0, 24); keccakf(h0, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output)); extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
} }
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES> template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
{ {
keccak((const uint8_t *) input, (int) size, ctx->state0, 200); keccak(input, (int) size, ctx->state0, 200);
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); keccak(input + size, (int) size, ctx->state1, 200);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory; const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM; const uint8_t* l1 = ctx->memory + MEM;
@@ -443,6 +439,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK]);
VARIANT1_1(&l1[idx1 & MASK]);
idx0 = EXTRACT64(cx0); idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1); idx1 = EXTRACT64(cx1);
@@ -458,8 +456,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al0 += hi; al0 += hi;
ah0 += lo; ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0; ((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0; ((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch; ah0 ^= ch;
al0 ^= cl; al0 ^= cl;
@@ -472,8 +472,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al1 += hi; al1 += hi;
ah1 += lo; ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1; ((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1; ((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch; ah1 ^= ch;
al1 ^= cl; al1 ^= cl;
@@ -486,8 +488,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
keccakf(h0, 24); keccakf(h0, 24);
keccakf(h1, 24); keccakf(h1, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output)); extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32); extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
} }
#endif /* __CRYPTONIGHT_ARM_H__ */ #endif /* __CRYPTONIGHT_ARM_H__ */

View File

@@ -0,0 +1,61 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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 __CRYPTONIGHT_MONERO_H__
#define __CRYPTONIGHT_MONERO_H__
// VARIANT ALTERATIONS
#ifndef XMRIG_ARM
# define VARIANT1_INIT(part) \
uint64_t tweak1_2_##part = 0; \
if (VARIANT > 0) { \
tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(input + 35 + part * size) ^ \
*(reinterpret_cast<const uint64_t*>(ctx->state##part) + 24)); \
}
#else
# define VARIANT1_INIT(part) \
uint64_t tweak1_2_##part = 0; \
if (VARIANT > 0) { \
volatile const uint64_t a = *reinterpret_cast<const uint64_t*>(input + 35 + part * size); \
volatile const uint64_t b = *(reinterpret_cast<const uint64_t*>(ctx->state##part) + 24); \
tweak1_2_##part = a ^ b; \
}
#endif
#define VARIANT1_1(p) \
if (VARIANT > 0) { \
const uint8_t tmp = reinterpret_cast<const uint8_t*>(p)[11]; \
static const uint32_t table = 0x75310; \
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \
}
#define VARIANT1_2(p, part) \
if (VARIANT > 0) { \
(p) ^= tweak1_2_##part; \
}
#endif /* __CRYPTONIGHT_MONERO_H__ */

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -39,7 +40,7 @@ const static uint8_t test_input[152] = {
}; };
const static uint8_t test_output0[64] = { const static uint8_t test_output_v0[64] = {
0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66, 0x1B, 0x60, 0x6A, 0x3F, 0x4A, 0x07, 0xD6, 0x48, 0x9A, 0x1B, 0xCD, 0x07, 0x69, 0x7B, 0xD1, 0x66,
0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F, 0x96, 0xB6, 0x1C, 0x8A, 0xE9, 0x82, 0xF6, 0x1A, 0x90, 0x16, 0x0F, 0x4E, 0x52, 0x82, 0x8A, 0x7F,
0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7, 0x1A, 0x3F, 0xFB, 0xEE, 0x90, 0x9B, 0x42, 0x0D, 0x91, 0xF7, 0xBE, 0x6E, 0x5F, 0xB5, 0x6D, 0xB7,
@@ -47,12 +48,30 @@ const static uint8_t test_output0[64] = {
}; };
// Monero v7
const static uint8_t test_output_v1[64] = {
0xC9, 0xFA, 0xE8, 0x42, 0x5D, 0x86, 0x88, 0xDC, 0x23, 0x6B, 0xCD, 0xBC, 0x42, 0xFD, 0xB4, 0x2D,
0x37, 0x6C, 0x6E, 0xC1, 0x90, 0x50, 0x1A, 0xA8, 0x4B, 0x04, 0xA4, 0xB4, 0xCF, 0x1E, 0xE1, 0x22,
0xF2, 0x2D, 0x3D, 0x62, 0x03, 0xD2, 0xA0, 0x8B, 0x41, 0xD9, 0x02, 0x72, 0x78, 0xD8, 0xBC, 0xC9,
0x83, 0xAC, 0xAD, 0xA9, 0xB6, 0x8E, 0x52, 0xE3, 0xC6, 0x89, 0x69, 0x2A, 0x50, 0xE9, 0x21, 0xD9
};
#ifndef XMRIG_NO_AEON #ifndef XMRIG_NO_AEON
const static uint8_t test_output1[64] = { const static uint8_t test_output_v0_lite[64] = {
0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE, 0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE,
0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD, 0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD,
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E,
0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88, 0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88
};
// AEON v2
const static uint8_t test_output_v1_lite[64] = {
0x87, 0xC4, 0xE5, 0x70, 0x65, 0x3E, 0xB4, 0xC2, 0xB4, 0x2B, 0x7A, 0x0D, 0x54, 0x65, 0x59, 0x45,
0x2D, 0xFA, 0xB5, 0x73, 0xB8, 0x2E, 0xC5, 0x2F, 0x15, 0x2B, 0x7F, 0xF9, 0x8E, 0x79, 0x44, 0x6F,
0x6D, 0x8C, 0xDC, 0x44, 0x4E, 0x9B, 0xBB, 0xFD, 0x68, 0xFC, 0x43, 0xFC, 0xD4, 0x85, 0x5B, 0x22,
0x8C, 0x8A, 0x1B, 0xD9, 0x1D, 0x9D, 0x00, 0x28, 0x5B, 0xEC, 0x02, 0xB7, 0xCA, 0x2D, 0x67, 0x41
}; };
#endif #endif

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -34,6 +35,7 @@
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_monero.h"
#include "crypto/soft_aes.h" #include "crypto/soft_aes.h"
@@ -47,27 +49,27 @@ extern "C"
} }
static inline void do_blake_hash(const void* input, size_t len, char* output) { static inline void do_blake_hash(const uint8_t *input, size_t len, uint8_t *output) {
blake256_hash(reinterpret_cast<uint8_t*>(output), static_cast<const uint8_t*>(input), len); blake256_hash(output, input, len);
} }
static inline void do_groestl_hash(const void* input, size_t len, char* output) { static inline void do_groestl_hash(const uint8_t *input, size_t len, uint8_t *output) {
groestl(static_cast<const uint8_t*>(input), len * 8, reinterpret_cast<uint8_t*>(output)); groestl(input, len * 8, output);
} }
static inline void do_jh_hash(const void* input, size_t len, char* output) { static inline void do_jh_hash(const uint8_t *input, size_t len, uint8_t *output) {
jh_hash(32 * 8, static_cast<const uint8_t*>(input), 8 * len, reinterpret_cast<uint8_t*>(output)); jh_hash(32 * 8, input, 8 * len, output);
} }
static inline void do_skein_hash(const void* input, size_t len, char* output) { static inline void do_skein_hash(const uint8_t *input, size_t len, uint8_t *output) {
xmr_skein(static_cast<const uint8_t*>(input), reinterpret_cast<uint8_t*>(output)); xmr_skein(input, output);
} }
void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash}; void (* const extra_hashes[4])(const uint8_t *, size_t, uint8_t *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
@@ -307,10 +309,12 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
} }
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES> template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
{ {
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200); keccak(input, (int) size, ctx->state0, 200);
VARIANT1_INIT(0);
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory); cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
@@ -334,6 +338,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
} }
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
VARIANT1_1(&l0[idx0 & MASK]);
idx0 = EXTRACT64(cx); idx0 = EXTRACT64(cx);
bx0 = cx; bx0 = cx;
@@ -345,8 +350,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
al0 += hi; al0 += hi;
ah0 += lo; ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
((uint64_t*)&l0[idx0 & MASK])[1] = ah0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch; ah0 ^= ch;
al0 ^= cl; al0 ^= cl;
@@ -356,15 +363,18 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0); cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
keccakf(h0, 24); keccakf(h0, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output)); extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
} }
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES> template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
{ {
keccak((const uint8_t *) input, (int) size, ctx->state0, 200); keccak(input, (int) size, ctx->state0, 200);
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); keccak(input + size, (int) size, ctx->state1, 200);
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory; const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM; const uint8_t* l1 = ctx->memory + MEM;
@@ -401,6 +411,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); _mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); _mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK]);
VARIANT1_1(&l1[idx1 & MASK]);
idx0 = EXTRACT64(cx0); idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1); idx1 = EXTRACT64(cx1);
@@ -416,8 +428,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al0 += hi; al0 += hi;
ah0 += lo; ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0; ((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0; ((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch; ah0 ^= ch;
al0 ^= cl; al0 ^= cl;
@@ -430,8 +444,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al1 += hi; al1 += hi;
ah1 += lo; ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1; ((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1; ((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch; ah1 ^= ch;
al1 ^= cl; al1 ^= cl;
@@ -444,8 +460,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
keccakf(h0, 24); keccakf(h0, 24);
keccakf(h1, 24); keccakf(h1, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output)); extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32); extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
} }
#endif /* __CRYPTONIGHT_X86_H__ */ #endif /* __CRYPTONIGHT_X86_H__ */

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -31,6 +31,7 @@
* Percentage of your hashing power that you want to donate to the developer, can be 0 if you don't want to do that. * Percentage of your hashing power that you want to donate to the developer, can be 0 if you don't want to do that.
* Example of how it works for the default setting of 1: * Example of how it works for the default setting of 1:
* You miner will mine into your usual pool for 99 minutes, then switch to the developer's pool for 1 minute. * You miner will mine into your usual pool for 99 minutes, then switch to the developer's pool for 1 minute.
* Since v2.5.1 start time randomized in range from 50 to 150 minutes minus donation time.
* Switching is instant, and only happens after a successful connection, so you never loose any hashes. * Switching is instant, and only happens after a successful connection, so you never loose any hashes.
* *
* If you plan on changing this setting to 0 please consider making a one off donation to my wallet: * If you plan on changing this setting to 0 please consider making a one off donation to my wallet:

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -39,10 +39,10 @@ class IStrategyListener
public: public:
virtual ~IStrategyListener() {} virtual ~IStrategyListener() {}
virtual void onActive(Client *client) = 0; virtual void onActive(IStrategy *strategy, Client *client) = 0;
virtual void onJob(Client *client, const Job &job) = 0; virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0;
virtual void onPause(IStrategy *strategy) = 0; virtual void onPause(IStrategy *strategy) = 0;
virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; virtual void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) = 0;
}; };

View File

@@ -47,6 +47,8 @@ void Log::message(Log::Level level, const char* fmt, ...)
backend->message(level, fmt, copy); backend->message(level, fmt, copy);
va_end(copy); va_end(copy);
} }
va_end(args);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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,6 +21,7 @@
* 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 <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <iterator> #include <iterator>
#include <stdio.h> #include <stdio.h>
@@ -54,6 +55,8 @@ int64_t Client::m_sequence = 1;
Client::Client(int id, const char *agent, IClientListener *listener) : Client::Client(int id, const char *agent, IClientListener *listener) :
m_ipv6(false),
m_nicehash(false),
m_quiet(false), m_quiet(false),
m_agent(agent), m_agent(agent),
m_listener(listener), m_listener(listener),
@@ -63,6 +66,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
m_recvBufPos(0), m_recvBufPos(0),
m_state(UnconnectedState), m_state(UnconnectedState),
m_expire(0), m_expire(0),
m_jobs(0),
m_stream(nullptr), m_stream(nullptr),
m_socket(nullptr) m_socket(nullptr)
{ {
@@ -71,7 +75,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
m_resolver.data = this; m_resolver.data = this;
m_hints.ai_family = PF_INET; m_hints.ai_family = AF_UNSPEC;
m_hints.ai_socktype = SOCK_STREAM; m_hints.ai_socktype = SOCK_STREAM;
m_hints.ai_protocol = IPPROTO_TCP; m_hints.ai_protocol = IPPROTO_TCP;
@@ -109,16 +113,17 @@ void Client::connect(const Url *url)
} }
void Client::disconnect() void Client::deleteLater()
{ {
# ifndef XMRIG_PROXY_PROJECT if (!m_listener) {
uv_timer_stop(&m_keepAliveTimer); return;
# endif }
m_expire = 0; m_listener = nullptr;
m_failures = -1;
close(); if (!disconnect()) {
delete this;
}
} }
@@ -150,6 +155,19 @@ void Client::tick(uint64_t now)
} }
bool Client::disconnect()
{
# ifndef XMRIG_PROXY_PROJECT
uv_timer_stop(&m_keepAliveTimer);
# endif
m_expire = 0;
m_failures = -1;
return close();
}
int64_t Client::submit(const JobResult &result) int64_t Client::submit(const JobResult &result)
{ {
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
@@ -167,13 +185,34 @@ int64_t Client::submit(const JobResult &result)
# endif # endif
const size_t size = snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRIu64 ",\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n", const size_t size = snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRIu64 ",\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n",
m_sequence, m_rpcId, result.jobId.data(), nonce, data); m_sequence, m_rpcId.data(), result.jobId.data(), nonce, data);
# ifdef XMRIG_PROXY_PROJECT
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
# else
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff()); m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
# endif
return send(size); return send(size);
} }
bool Client::close()
{
if (m_state == UnconnectedState || m_state == ClosingState || !m_socket) {
return false;
}
setState(ClosingState);
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_socket)) == 0) {
uv_close(reinterpret_cast<uv_handle_t*>(m_socket), Client::onClose);
}
return true;
}
bool Client::isCriticalError(const char *message) bool Client::isCriticalError(const char *message)
{ {
if (!message) { if (!message) {
@@ -203,7 +242,14 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false; return false;
} }
Job job(m_id, m_url.isNicehash()); # ifdef XMRIG_PROXY_PROJECT
Job job(m_id, m_url.variant());
job.setClientId(m_rpcId);
job.setCoin(m_url.coin());
# else
Job job(m_id, m_nicehash, m_url.algo(), m_url.variant());
# endif
if (!job.setId(params["job_id"].GetString())) { if (!job.setId(params["job_id"].GetString())) {
*code = 3; *code = 3;
return false; return false;
@@ -219,32 +265,52 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false; return false;
} }
if (m_job == job) { if (params.HasMember("coin")) {
if (!m_quiet) { job.setCoin(params["coin"].GetString());
LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); }
}
close(); if (params.HasMember("variant")) {
job.setVariant(params["variant"].GetInt());
}
if (m_job != job) {
m_jobs++;
m_job = std::move(job);
return true;
}
if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459
return false; return false;
} }
m_job = std::move(job); if (!m_quiet) {
return true; LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
}
close();
return false;
} }
bool Client::parseLogin(const rapidjson::Value &result, int *code) bool Client::parseLogin(const rapidjson::Value &result, int *code)
{ {
const char *id = result["id"].GetString(); if (!m_rpcId.setId(result["id"].GetString())) {
if (!id || strlen(id) >= sizeof(m_rpcId)) {
*code = 1; *code = 1;
return false; return false;
} }
memset(m_rpcId, 0, sizeof(m_rpcId)); # ifndef XMRIG_PROXY_PROJECT
memcpy(m_rpcId, id, strlen(id)); m_nicehash = m_url.isNicehash();
# endif
return parseJob(result["job"], code); if (result.HasMember("extensions")) {
parseExtensions(result["extensions"]);
}
const bool rc = parseJob(result["job"], code);
m_jobs = 0;
return rc;
} }
@@ -259,7 +325,7 @@ int Client::resolve(const char *host)
m_failures = 0; m_failures = 0;
} }
const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, NULL, &m_hints); const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints);
if (r) { if (r) {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r)); LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r));
@@ -291,21 +357,25 @@ int64_t Client::send(size_t size)
} }
void Client::close() void Client::connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6)
{ {
if (m_state == UnconnectedState || m_state == ClosingState || !m_socket) { addrinfo *addr = nullptr;
return; m_ipv6 = ipv4.empty() && !ipv6.empty();
if (m_ipv6) {
addr = ipv6[ipv6.size() == 1 ? 0 : rand() % ipv6.size()];
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(addr->ai_addr), m_ip, 45);
}
else {
addr = ipv4[ipv4.size() == 1 ? 0 : rand() % ipv4.size()];
uv_ip4_name(reinterpret_cast<sockaddr_in*>(addr->ai_addr), m_ip, 16);
} }
setState(ClosingState); connect(addr->ai_addr);
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_socket)) == 0) {
uv_close(reinterpret_cast<uv_handle_t*>(m_socket), Client::onClose);
}
} }
void Client::connect(struct sockaddr *addr) void Client::connect(sockaddr *addr)
{ {
setState(ConnectingState); setState(ConnectingState);
@@ -366,6 +436,18 @@ void Client::login()
} }
void Client::onClose()
{
delete m_socket;
m_stream = nullptr;
m_socket = nullptr;
setState(UnconnectedState);
reconnect();
}
void Client::parse(char *line, size_t len) void Client::parse(char *line, size_t len)
{ {
startTimeout(); startTimeout();
@@ -374,6 +456,14 @@ void Client::parse(char *line, size_t len)
LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line); LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line);
if (len < 32 || line[0] != '{') {
if (!m_quiet) {
LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port());
}
return;
}
rapidjson::Document doc; rapidjson::Document doc;
if (doc.ParseInsitu(line).HasParseError()) { if (doc.ParseInsitu(line).HasParseError()) {
if (!m_quiet) { if (!m_quiet) {
@@ -397,6 +487,24 @@ void Client::parse(char *line, size_t len)
} }
void Client::parseExtensions(const rapidjson::Value &value)
{
if (!value.IsArray()) {
return;
}
for (const rapidjson::Value &ext : value.GetArray()) {
if (!ext.IsString()) {
continue;
}
if (strcmp(ext.GetString(), "nicehash") == 0) {
m_nicehash = true;
}
}
}
void Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error) void Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{ {
if (error.IsObject()) { if (error.IsObject()) {
@@ -456,7 +564,8 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code); LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code);
} }
return close(); close();
return;
} }
m_failures = 0; m_failures = 0;
@@ -476,12 +585,18 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
void Client::ping() void Client::ping()
{ {
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId)); send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
} }
void Client::reconnect() void Client::reconnect()
{ {
if (!m_listener) {
delete this;
return;
}
setState(ConnectingState); setState(ConnectingState);
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
@@ -530,29 +645,33 @@ void Client::startTimeout()
void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
{ {
auto client = getClient(handle->data); auto client = getClient(handle->data);
if (!client) {
return;
}
buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; buf->base = &client->m_recvBuf.base[client->m_recvBufPos];
buf->len = client->m_recvBuf.len - (unsigned long)client->m_recvBufPos; buf->len = client->m_recvBuf.len - client->m_recvBufPos;
} }
void Client::onClose(uv_handle_t *handle) void Client::onClose(uv_handle_t *handle)
{ {
auto client = getClient(handle->data); auto client = getClient(handle->data);
if (!client) {
return;
}
delete client->m_socket; client->onClose();
client->m_stream = nullptr;
client->m_socket = nullptr;
client->setState(UnconnectedState);
client->reconnect();
} }
void Client::onConnect(uv_connect_t *req, int status) void Client::onConnect(uv_connect_t *req, int status)
{ {
auto client = getClient(req->data); auto client = getClient(req->data);
if (!client) {
return;
}
if (status < 0) { if (status < 0) {
if (!client->m_quiet) { if (!client->m_quiet) {
LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
@@ -577,22 +696,28 @@ void Client::onConnect(uv_connect_t *req, int status)
void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
{ {
auto client = getClient(stream->data); auto client = getClient(stream->data);
if (!client) {
return;
}
if (nread < 0) { if (nread < 0) {
if (nread != UV_EOF && !client->m_quiet) { if (nread != UV_EOF && !client->m_quiet) {
LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread));
} }
return client->close(); client->close();
return;
} }
if ((size_t) nread > (sizeof(m_buf) - 8 - client->m_recvBufPos)) { if ((size_t) nread > (sizeof(m_buf) - 8 - client->m_recvBufPos)) {
return client->close(); client->close();
return;
} }
client->m_recvBufPos += nread; client->m_recvBufPos += nread;
char* end; char* end;
char* start = buf->base; char* start = client->m_recvBuf.base;
size_t remaining = client->m_recvBufPos; size_t remaining = client->m_recvBufPos;
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) { while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
@@ -609,11 +734,11 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
return; return;
} }
if (start == buf->base) { if (start == client->m_recvBuf.base) {
return; return;
} }
memcpy(buf->base, start, remaining); memcpy(client->m_recvBuf.base, start, remaining);
client->m_recvBufPos = remaining; client->m_recvBufPos = remaining;
} }
@@ -621,31 +746,43 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
{ {
auto client = getClient(req->data); auto client = getClient(req->data);
if (!client) {
return;
}
if (status < 0) { if (status < 0) {
LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); if (!client->m_quiet) {
LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
}
return client->reconnect(); return client->reconnect();
} }
addrinfo *ptr = res; addrinfo *ptr = res;
std::vector<addrinfo*> ipv4; std::vector<addrinfo*> ipv4;
std::vector<addrinfo*> ipv6;
while (ptr != nullptr) { while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) { if (ptr->ai_family == AF_INET) {
ipv4.push_back(ptr); ipv4.push_back(ptr);
} }
if (ptr->ai_family == AF_INET6) {
ipv6.push_back(ptr);
}
ptr = ptr->ai_next; ptr = ptr->ai_next;
} }
if (ipv4.empty()) { if (ipv4.empty() && ipv6.empty()) {
LOG_ERR("[%s:%u] DNS error: \"No IPv4 records found\"", client->m_url.host(), client->m_url.port()); if (!client->m_quiet) {
LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port());
}
uv_freeaddrinfo(res);
return client->reconnect(); return client->reconnect();
} }
ptr = ipv4[rand() % ipv4.size()]; client->connect(ipv4, ipv6);
uv_ip4_name(reinterpret_cast<sockaddr_in*>(ptr->ai_addr), client->m_ip, 16);
client->connect(ptr->ai_addr);
uv_freeaddrinfo(res); uv_freeaddrinfo(res);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -27,8 +27,10 @@
#include <map> #include <map>
#include <uv.h> #include <uv.h>
#include <vector>
#include "net/Id.h"
#include "net/Job.h" #include "net/Job.h"
#include "net/SubmitResult.h" #include "net/SubmitResult.h"
#include "net/Url.h" #include "net/Url.h"
@@ -54,12 +56,12 @@ public:
constexpr static int kKeepAliveTimeout = 60 * 1000; constexpr static int kKeepAliveTimeout = 60 * 1000;
Client(int id, const char *agent, IClientListener *listener); Client(int id, const char *agent, IClientListener *listener);
~Client();
bool disconnect();
int64_t submit(const JobResult &result); int64_t submit(const JobResult &result);
void connect(); void connect();
void connect(const Url *url); void connect(const Url *url);
void disconnect(); void deleteLater();
void setUrl(const Url *url); void setUrl(const Url *url);
void tick(uint64_t now); void tick(uint64_t now);
@@ -74,15 +76,20 @@ public:
inline void setRetryPause(int ms) { m_retryPause = ms; } inline void setRetryPause(int ms) { m_retryPause = ms; }
private: private:
~Client();
bool close();
bool isCriticalError(const char *message); bool isCriticalError(const char *message);
bool parseJob(const rapidjson::Value &params, int *code); bool parseJob(const rapidjson::Value &params, int *code);
bool parseLogin(const rapidjson::Value &result, int *code); bool parseLogin(const rapidjson::Value &result, int *code);
int resolve(const char *host); int resolve(const char *host);
int64_t send(size_t size); int64_t send(size_t size);
void close(); void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
void connect(struct sockaddr *addr); void connect(sockaddr *addr);
void login(); void login();
void onClose();
void parse(char *line, size_t len); void parse(char *line, size_t len);
void parseExtensions(const rapidjson::Value &value);
void parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error); void parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error);
void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); void parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error);
void ping(); void ping();
@@ -99,10 +106,11 @@ private:
static inline Client *getClient(void *data) { return static_cast<Client*>(data); } static inline Client *getClient(void *data) { return static_cast<Client*>(data); }
addrinfo m_hints; addrinfo m_hints;
bool m_ipv6;
bool m_nicehash;
bool m_quiet; bool m_quiet;
char m_buf[2048]; char m_buf[2048];
char m_ip[17]; char m_ip[46];
char m_rpcId[64];
char m_sendBuf[768]; char m_sendBuf[768];
const char *m_agent; const char *m_agent;
IClientListener *m_listener; IClientListener *m_listener;
@@ -115,11 +123,13 @@ private:
static int64_t m_sequence; static int64_t m_sequence;
std::map<int64_t, SubmitResult> m_results; std::map<int64_t, SubmitResult> m_results;
uint64_t m_expire; uint64_t m_expire;
uint64_t m_jobs;
Url m_url; Url m_url;
uv_buf_t m_recvBuf; uv_buf_t m_recvBuf;
uv_getaddrinfo_t m_resolver; uv_getaddrinfo_t m_resolver;
uv_stream_t *m_stream; uv_stream_t *m_stream;
uv_tcp_t *m_socket; uv_tcp_t *m_socket;
xmrig::Id m_rpcId;
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
uv_timer_t m_keepAliveTimer; uv_timer_t m_keepAliveTimer;

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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,40 +21,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 __JOBID_H__ #ifndef __ID_H__
#define __JOBID_H__ #define __ID_H__
#include <string.h> #include <string.h>
class JobId namespace xmrig {
class Id
{ {
public: public:
inline JobId() inline Id() :
m_data()
{ {
memset(m_data, 0, sizeof(m_data));
} }
inline JobId(const char *id, size_t sizeFix = 0) inline Id(const char *id, size_t sizeFix = 0)
{ {
setId(id, sizeFix); setId(id, sizeFix);
} }
inline bool operator==(const JobId &other) const inline bool operator==(const Id &other) const
{ {
return memcmp(m_data, other.m_data, sizeof(m_data)) == 0; return memcmp(m_data, other.m_data, sizeof(m_data)) == 0;
} }
inline bool operator!=(const JobId &other) const inline bool operator!=(const Id &other) const
{ {
return memcmp(m_data, other.m_data, sizeof(m_data)) != 0; return memcmp(m_data, other.m_data, sizeof(m_data)) != 0;
} }
Id &operator=(const Id &other)
{
memcpy(m_data, other.m_data, sizeof(m_data));
return *this;
}
inline bool setId(const char *id, size_t sizeFix = 0) inline bool setId(const char *id, size_t sizeFix = 0)
{ {
memset(m_data, 0, sizeof(m_data)); memset(m_data, 0, sizeof(m_data));
@@ -80,4 +91,8 @@ private:
char m_data[64]; char m_data[64];
}; };
#endif /* __JOBID_H__ */
} /* namespace xmrig */
#endif /* __ID_H__ */

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -55,13 +56,32 @@ static inline char hf_bin2hex(unsigned char c)
} }
Job::Job(int poolId, bool nicehash) : Job::Job() :
m_nicehash(nicehash), m_nicehash(false),
m_poolId(poolId), m_coin(),
m_algo(xmrig::ALGO_CRYPTONIGHT),
m_poolId(-2),
m_threadId(-1), m_threadId(-1),
m_variant(xmrig::VARIANT_AUTO),
m_size(0), m_size(0),
m_diff(0), m_diff(0),
m_target(0) m_target(0),
m_blob()
{
}
Job::Job(int poolId, bool nicehash, int algo, int variant) :
m_nicehash(nicehash),
m_coin(),
m_algo(algo),
m_poolId(poolId),
m_threadId(-1),
m_variant(variant),
m_size(0),
m_diff(0),
m_target(0),
m_blob()
{ {
} }
@@ -95,11 +115,6 @@ bool Job::setBlob(const char *blob)
m_nicehash = true; m_nicehash = true;
} }
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawBlob, 0, sizeof(m_rawBlob));
memcpy(m_rawBlob, blob, m_size * 2);
# endif
return true; return true;
} }
@@ -136,16 +151,38 @@ bool Job::setTarget(const char *target)
return false; return false;
} }
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawTarget, 0, sizeof(m_rawTarget));
memcpy(m_rawTarget, target, len);
# endif
m_diff = toDiff(m_target); m_diff = toDiff(m_target);
return true; return true;
} }
void Job::setCoin(const char *coin)
{
if (!coin || strlen(coin) > 4) {
memset(m_coin, 0, sizeof(m_coin));
return;
}
strncpy(m_coin, coin, sizeof(m_coin));
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::ALGO_CRYPTONIGHT_LITE : xmrig::ALGO_CRYPTONIGHT;
}
void Job::setVariant(int variant)
{
switch (variant) {
case xmrig::VARIANT_AUTO:
case xmrig::VARIANT_NONE:
case xmrig::VARIANT_V1:
m_variant = variant;
break;
default:
break;
}
}
bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) bool Job::fromHex(const char* in, unsigned int len, unsigned char* out)
{ {
bool error = false; bool error = false;
@@ -173,3 +210,9 @@ bool Job::operator==(const Job &other) const
{ {
return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
} }
bool Job::operator!=(const Job &other) const
{
return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
}

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -29,61 +30,60 @@
#include <stdint.h> #include <stdint.h>
#include "align.h" #include "net/Id.h"
#include "net/JobId.h" #include "xmrig.h"
class Job class Job
{ {
public: public:
Job(int poolId = -2, bool nicehash = false); Job();
Job(int poolId, bool nicehash, int algo, int variant);
~Job(); ~Job();
bool setBlob(const char *blob); bool setBlob(const char *blob);
bool setTarget(const char *target); bool setTarget(const char *target);
void setCoin(const char *coin);
void setVariant(int variant);
inline bool isNicehash() const { return m_nicehash; } inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool isValid() const { return m_size > 0 && m_diff > 0; }
inline bool setId(const char *id) { return m_id.setId(id); } inline bool setId(const char *id) { return m_id.setId(id); }
inline const JobId &id() const { return m_id; } inline const char *coin() const { return m_coin; }
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); } inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
inline const uint8_t *blob() const { return m_blob; } inline const uint8_t *blob() const { return m_blob; }
inline const xmrig::Id &id() const { return m_id; }
inline int poolId() const { return m_poolId; } inline int poolId() const { return m_poolId; }
inline int threadId() const { return m_threadId; } inline int threadId() const { return m_threadId; }
inline int variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); }
inline size_t size() const { return m_size; } inline size_t size() const { return m_size; }
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); } inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint32_t diff() const { return (uint32_t) m_diff; }
inline uint64_t target() const { return m_target; } inline uint64_t target() const { return m_target; }
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
inline void setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setThreadId(int threadId) { m_threadId = threadId; }
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; }
# endif
static bool fromHex(const char* in, unsigned int len, unsigned char* out); static bool fromHex(const char* in, unsigned int len, unsigned char* out);
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); } static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; } static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; }
static void toHex(const unsigned char* in, unsigned int len, char* out); static void toHex(const unsigned char* in, unsigned int len, char* out);
bool operator==(const Job &other) const; bool operator==(const Job &other) const;
bool operator!=(const Job &other) const;
private: private:
VAR_ALIGN(16, uint8_t m_blob[84]); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
bool m_nicehash; bool m_nicehash;
char m_coin[5];
int m_algo;
int m_poolId; int m_poolId;
int m_threadId; int m_threadId;
JobId m_id; int m_variant;
size_t m_size; size_t m_size;
uint64_t m_diff; uint64_t m_diff;
uint64_t m_target; uint64_t m_target;
uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
# ifdef XMRIG_PROXY_PROJECT xmrig::Id m_id;
VAR_ALIGN(16, char m_rawBlob[169]);
VAR_ALIGN(16, char m_rawTarget[17]);
# endif
}; };
#endif /* __JOB_H__ */ #endif /* __JOB_H__ */

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -36,11 +36,11 @@ class JobResult
{ {
public: public:
inline JobResult() : poolId(0), diff(0), nonce(0) {} inline JobResult() : poolId(0), diff(0), nonce(0) {}
inline JobResult(int poolId, const JobId &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) : inline JobResult(int poolId, const xmrig::Id &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) :
poolId(poolId), poolId(poolId),
jobId(jobId),
diff(diff), diff(diff),
nonce(nonce) nonce(nonce),
jobId(jobId)
{ {
memcpy(this->result, result, sizeof(this->result)); memcpy(this->result, result, sizeof(this->result));
} }
@@ -71,10 +71,10 @@ public:
int poolId; int poolId;
JobId jobId;
uint32_t diff; uint32_t diff;
uint32_t nonce; uint32_t nonce;
uint8_t result[32]; uint8_t result[32];
xmrig::Id jobId;
}; };
#endif /* __JOBRESULT_H__ */ #endif /* __JOBRESULT_H__ */

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -40,7 +40,6 @@
#include "net/SubmitResult.h" #include "net/SubmitResult.h"
#include "net/Url.h" #include "net/Url.h"
#include "Options.h" #include "Options.h"
#include "Platform.h"
#include "workers/Workers.h" #include "workers/Workers.h"
@@ -55,14 +54,14 @@ Network::Network(const Options *options) :
const std::vector<Url*> &pools = options->pools(); const std::vector<Url*> &pools = options->pools();
if (pools.size() > 1) { if (pools.size() > 1) {
m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this); m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this);
} }
else { else {
m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this); m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this);
} }
if (m_options->donateLevel() > 0) { if (m_options->donateLevel() > 0) {
m_donate = new DonateStrategy(Platform::userAgent(), this); m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), this);
} }
m_timer.data = this; m_timer.data = this;
@@ -93,9 +92,9 @@ void Network::stop()
} }
void Network::onActive(Client *client) void Network::onActive(IStrategy *strategy, Client *client)
{ {
if (client->id() == -1) { if (m_donate && m_donate == strategy) {
LOG_NOTICE("dev donate started"); LOG_NOTICE("dev donate started");
return; return;
} }
@@ -106,13 +105,13 @@ void Network::onActive(Client *client)
} }
void Network::onJob(Client *client, const Job &job) void Network::onJob(IStrategy *strategy, Client *client, const Job &job)
{ {
if (m_donate && m_donate->isActive() && client->id() != -1) { if (m_donate && m_donate->isActive() && m_donate != strategy) {
return; return;
} }
setJob(client, job); setJob(client, job, m_donate == strategy);
} }
@@ -142,7 +141,7 @@ void Network::onPause(IStrategy *strategy)
} }
void Network::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error)
{ {
m_state.add(result, error); m_state.add(result, error);
@@ -159,7 +158,7 @@ void Network::onResultAccepted(Client *client, const SubmitResult &result, const
} }
void Network::setJob(Client *client, const Job &job) void Network::setJob(Client *client, const Job &job, bool donate)
{ {
if (m_options->colors()) { if (m_options->colors()) {
LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff()); LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff());
@@ -169,7 +168,7 @@ void Network::setJob(Client *client, const Job &job)
} }
m_state.diff = job.diff(); m_state.diff = job.diff();
Workers::setJob(job); Workers::setJob(job, donate);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -49,16 +49,16 @@ public:
void stop(); void stop();
protected: protected:
void onActive(Client *client) override; void onActive(IStrategy *strategy, Client *client) override;
void onJob(Client *client, const Job &job) override; void onJob(IStrategy *strategy, Client *client, const Job &job) override;
void onJobResult(const JobResult &result) override; void onJobResult(const JobResult &result) override;
void onPause(IStrategy *strategy) override; void onPause(IStrategy *strategy) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
private: private:
constexpr static int kTickInterval = 1 * 1000; constexpr static int kTickInterval = 1 * 1000;
void setJob(Client *client, const Job &job); void setJob(Client *client, const Job &job, bool donate);
void tick(); void tick();
static void onTick(uv_timer_t *handle); static void onTick(uv_timer_t *handle);

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -28,6 +28,7 @@
#include "net/Url.h" #include "net/Url.h"
#include "xmrig.h"
#ifdef _MSC_VER #ifdef _MSC_VER
@@ -41,6 +42,9 @@ Url::Url() :
m_host(nullptr), m_host(nullptr),
m_password(nullptr), m_password(nullptr),
m_user(nullptr), m_user(nullptr),
m_algo(xmrig::ALGO_CRYPTONIGHT),
m_variant(xmrig::VARIANT_AUTO),
m_url(nullptr),
m_port(kDefaultPort) m_port(kDefaultPort)
{ {
} }
@@ -63,17 +67,23 @@ Url::Url(const char *url) :
m_host(nullptr), m_host(nullptr),
m_password(nullptr), m_password(nullptr),
m_user(nullptr), m_user(nullptr),
m_algo(xmrig::ALGO_CRYPTONIGHT),
m_variant(xmrig::VARIANT_AUTO),
m_url(nullptr),
m_port(kDefaultPort) m_port(kDefaultPort)
{ {
parse(url); parse(url);
} }
Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash) : Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash, int variant) :
m_keepAlive(keepAlive), m_keepAlive(keepAlive),
m_nicehash(nicehash), m_nicehash(nicehash),
m_password(password ? strdup(password) : nullptr), m_password(password ? strdup(password) : nullptr),
m_user(user ? strdup(user) : nullptr), m_user(user ? strdup(user) : nullptr),
m_algo(xmrig::ALGO_CRYPTONIGHT),
m_variant(variant),
m_url(nullptr),
m_port(port) m_port(port)
{ {
m_host = strdup(host); m_host = strdup(host);
@@ -85,6 +95,10 @@ Url::~Url()
free(m_host); free(m_host);
free(m_password); free(m_password);
free(m_user); free(m_user);
if (m_url) {
delete [] m_url;
}
} }
@@ -105,6 +119,10 @@ bool Url::parse(const char *url)
return false; return false;
} }
if (base[0] == '[') {
return parseIPv6(base);
}
const char *port = strchr(base, ':'); const char *port = strchr(base, ':');
if (!port) { if (!port) {
m_host = strdup(base); m_host = strdup(base);
@@ -112,9 +130,8 @@ bool Url::parse(const char *url)
} }
const size_t size = port++ - base + 1; const size_t size = port++ - base + 1;
m_host = static_cast<char*>(malloc(size)); m_host = new char[size]();
memcpy(m_host, base, size - 1); memcpy(m_host, base, size - 1);
m_host[size - 1] = '\0';
m_port = (uint16_t) strtol(port, nullptr, 10); m_port = (uint16_t) strtol(port, nullptr, 10);
return true; return true;
@@ -139,15 +156,34 @@ bool Url::setUserpass(const char *userpass)
} }
void Url::applyExceptions() const char *Url::url() const
{
if (!m_url) {
const size_t size = strlen(m_host) + 8;
m_url = new char[size];
snprintf(m_url, size - 1, "%s:%d", m_host, m_port);
}
return m_url;
}
void Url::adjust(int algo)
{ {
if (!isValid()) { if (!isValid()) {
return; return;
} }
m_algo = algo;
if (strstr(m_host, ".nicehash.com")) { if (strstr(m_host, ".nicehash.com")) {
m_keepAlive = false; m_keepAlive = false;
m_nicehash = true; m_nicehash = true;
if (strstr(m_host, "cryptonightv7.")) {
m_variant = xmrig::VARIANT_V1;
}
} }
if (strstr(m_host, ".minergate.com")) { if (strstr(m_host, ".minergate.com")) {
@@ -178,9 +214,40 @@ void Url::setUser(const char *user)
} }
void Url::setVariant(int variant)
{
switch (variant) {
case xmrig::VARIANT_AUTO:
case xmrig::VARIANT_NONE:
case xmrig::VARIANT_V1:
m_variant = variant;
break;
default:
break;
}
}
bool Url::operator==(const Url &other) const
{
if (m_port != other.m_port || m_keepAlive != other.m_keepAlive || m_nicehash != other.m_nicehash) {
return false;
}
if (strcmp(host(), other.host()) != 0 || strcmp(user(), other.user()) != 0 || strcmp(password(), other.password()) != 0) {
return false;
}
return true;
}
Url &Url::operator=(const Url *other) Url &Url::operator=(const Url *other)
{ {
m_keepAlive = other->m_keepAlive; m_keepAlive = other->m_keepAlive;
m_algo = other->m_algo;
m_variant = other->m_variant;
m_nicehash = other->m_nicehash; m_nicehash = other->m_nicehash;
m_port = other->m_port; m_port = other->m_port;
@@ -190,5 +257,32 @@ Url &Url::operator=(const Url *other)
setPassword(other->m_password); setPassword(other->m_password);
setUser(other->m_user); setUser(other->m_user);
if (m_url) {
delete [] m_url;
m_url = nullptr;
}
return *this; return *this;
} }
bool Url::parseIPv6(const char *addr)
{
const char *end = strchr(addr, ']');
if (!end) {
return false;
}
const char *port = strchr(end, ':');
if (!port) {
return false;
}
const size_t size = end - addr;
m_host = new char[size]();
memcpy(m_host, addr + 1, size - 1);
m_port = (uint16_t) strtol(port + 1, nullptr, 10);
return true;
}

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -37,7 +37,7 @@ public:
Url(); Url();
Url(const char *url); Url(const char *url);
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false ); Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = -1);
~Url(); ~Url();
inline bool isKeepAlive() const { return m_keepAlive; } inline bool isKeepAlive() const { return m_keepAlive; }
@@ -46,24 +46,35 @@ public:
inline const char *host() const { return m_host; } inline const char *host() const { return m_host; }
inline const char *password() const { return m_password ? m_password : kDefaultPassword; } inline const char *password() const { return m_password ? m_password : kDefaultPassword; }
inline const char *user() const { return m_user ? m_user : kDefaultUser; } inline const char *user() const { return m_user ? m_user : kDefaultUser; }
inline int algo() const { return m_algo; }
inline int variant() const { return m_variant; }
inline uint16_t port() const { return m_port; } inline uint16_t port() const { return m_port; }
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; } inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
inline void setVariant(bool monero) { m_variant = monero; }
bool parse(const char *url); bool parse(const char *url);
bool setUserpass(const char *userpass); bool setUserpass(const char *userpass);
void applyExceptions(); const char *url() const;
void adjust(int algo);
void setPassword(const char *password); void setPassword(const char *password);
void setUser(const char *user); void setUser(const char *user);
void setVariant(int variant);
bool operator==(const Url &other) const;
Url &operator=(const Url *other); Url &operator=(const Url *other);
private: private:
bool parseIPv6(const char *addr);
bool m_keepAlive; bool m_keepAlive;
bool m_nicehash; bool m_nicehash;
char *m_host; char *m_host;
char *m_password; char *m_password;
char *m_user; char *m_user;
int m_algo;
int m_variant;
mutable char *m_url;
uint16_t m_port; uint16_t m_port;
}; };

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -26,7 +26,9 @@
#include "net/Client.h" #include "net/Client.h"
#include "net/Job.h" #include "net/Job.h"
#include "net/strategies/DonateStrategy.h" #include "net/strategies/DonateStrategy.h"
#include "Options.h" #include "net/strategies/FailoverStrategy.h"
#include "Platform.h"
#include "xmrig.h"
extern "C" extern "C"
@@ -35,102 +37,120 @@ extern "C"
} }
DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : const static char *kDonatePool1 = "miner.fee.xmrig.com";
const static char *kDonatePool2 = "emergency.fee.xmrig.com";
static inline int random(int min, int max){
return min + rand() / (RAND_MAX / (max - min + 1) + 1);
}
DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener) :
m_active(false), m_active(false),
m_donateTime(Options::i()->donateLevel() * 60 * 1000), m_donateTime(level * 60 * 1000),
m_idleTime((100 - Options::i()->donateLevel()) * 60 * 1000), m_idleTime((100 - level) * 60 * 1000),
m_strategy(nullptr),
m_listener(listener) m_listener(listener)
{ {
uint8_t hash[200]; uint8_t hash[200];
char userId[65] = { 0 }; char userId[65] = { 0 };
const char *user = Options::i()->pools().front()->user();
keccak(reinterpret_cast<const uint8_t *>(user), static_cast<int>(strlen(user)), hash, sizeof(hash)); keccak(reinterpret_cast<const uint8_t *>(user), static_cast<int>(strlen(user)), hash, sizeof(hash));
Job::toHex(hash, 32, userId); Job::toHex(hash, 32, userId);
Url *url = new Url("fee.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, userId, nullptr, false, true); if (algo == xmrig::ALGO_CRYPTONIGHT) {
m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
}
else {
m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true));
}
m_client = new Client(-1, agent, this); m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true);
m_client->setUrl(url);
m_client->setRetryPause(Options::i()->retryPause() * 1000);
m_client->setQuiet(true);
delete url;
m_timer.data = this; m_timer.data = this;
uv_timer_init(uv_default_loop(), &m_timer); uv_timer_init(uv_default_loop(), &m_timer);
idle(); idle(random(3000, 9000) * 1000 - m_donateTime);
}
DonateStrategy::~DonateStrategy()
{
delete m_strategy;
} }
int64_t DonateStrategy::submit(const JobResult &result) int64_t DonateStrategy::submit(const JobResult &result)
{ {
return m_client->submit(result); return m_strategy->submit(result);
} }
void DonateStrategy::connect() void DonateStrategy::connect()
{ {
m_client->connect(); m_strategy->connect();
} }
void DonateStrategy::stop() void DonateStrategy::stop()
{ {
uv_timer_stop(&m_timer); uv_timer_stop(&m_timer);
m_client->disconnect(); m_strategy->stop();
} }
void DonateStrategy::tick(uint64_t now) void DonateStrategy::tick(uint64_t now)
{ {
m_client->tick(now); m_strategy->tick(now);
} }
void DonateStrategy::onClose(Client *client, int failures) void DonateStrategy::onActive(IStrategy *strategy, Client *client)
{
}
void DonateStrategy::onJobReceived(Client *client, const Job &job)
{
m_listener->onJob(client, job);
}
void DonateStrategy::onLoginSuccess(Client *client)
{ {
if (!isActive()) { if (!isActive()) {
uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0);
} }
m_active = true; m_active = true;
m_listener->onActive(client); m_listener->onActive(this, client);
} }
void DonateStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job)
{ {
m_listener->onResultAccepted(client, result, error); m_listener->onJob(this, client, job);
} }
void DonateStrategy::idle() void DonateStrategy::onPause(IStrategy *strategy)
{ {
uv_timer_start(&m_timer, DonateStrategy::onTimer, m_idleTime, 0); }
void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error)
{
m_listener->onResultAccepted(this, client, result, error);
}
void DonateStrategy::idle(uint64_t timeout)
{
uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0);
} }
void DonateStrategy::suspend() void DonateStrategy::suspend()
{ {
m_client->disconnect(); m_strategy->stop();
m_active = false; m_active = false;
m_listener->onPause(this); m_listener->onPause(this);
idle(); idle(m_idleTime);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -26,10 +26,12 @@
#include <uv.h> #include <uv.h>
#include <vector>
#include "interfaces/IClientListener.h" #include "interfaces/IClientListener.h"
#include "interfaces/IStrategy.h" #include "interfaces/IStrategy.h"
#include "interfaces/IStrategyListener.h"
class Client; class Client;
@@ -37,10 +39,11 @@ class IStrategyListener;
class Url; class Url;
class DonateStrategy : public IStrategy, public IClientListener class DonateStrategy : public IStrategy, public IStrategyListener
{ {
public: public:
DonateStrategy(const char *agent, IStrategyListener *listener); DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener);
~DonateStrategy();
public: public:
inline bool isActive() const override { return m_active; } inline bool isActive() const override { return m_active; }
@@ -52,22 +55,23 @@ public:
void tick(uint64_t now) override; void tick(uint64_t now) override;
protected: protected:
void onClose(Client *client, int failures) override; void onActive(IStrategy *strategy, Client *client) override;
void onJobReceived(Client *client, const Job &job) override; void onJob(IStrategy *strategy, Client *client, const Job &job) override;
void onLoginSuccess(Client *client) override; void onPause(IStrategy *strategy) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
private: private:
void idle(); void idle(uint64_t timeout);
void suspend(); void suspend();
static void onTimer(uv_timer_t *handle); static void onTimer(uv_timer_t *handle);
bool m_active; bool m_active;
Client *m_client;
const int m_donateTime; const int m_donateTime;
const int m_idleTime; const int m_idleTime;
IStrategy *m_strategy;
IStrategyListener *m_listener; IStrategyListener *m_listener;
std::vector<Url*> m_pools;
uv_timer_t m_timer; uv_timer_t m_timer;
}; };

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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,22 +25,37 @@
#include "interfaces/IStrategyListener.h" #include "interfaces/IStrategyListener.h"
#include "net/Client.h" #include "net/Client.h"
#include "net/strategies/FailoverStrategy.h" #include "net/strategies/FailoverStrategy.h"
#include "Options.h" #include "Platform.h"
FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, const char *agent, IStrategyListener *listener) : FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_quiet(quiet),
m_retries(retries),
m_retryPause(retryPause),
m_active(-1), m_active(-1),
m_index(0), m_index(0),
m_listener(listener) m_listener(listener)
{ {
for (const Url *url : urls) { for (const Url *url : urls) {
add(url, agent); add(url);
}
}
FailoverStrategy::~FailoverStrategy()
{
for (Client *client : m_pools) {
client->deleteLater();
} }
} }
int64_t FailoverStrategy::submit(const JobResult &result) int64_t FailoverStrategy::submit(const JobResult &result)
{ {
if (m_active == -1) {
return -1;
}
return m_pools[m_active]->submit(result); return m_pools[m_active]->submit(result);
} }
@@ -57,7 +72,7 @@ void FailoverStrategy::resume()
return; return;
} }
m_listener->onJob( m_pools[m_active], m_pools[m_active]->job()); m_listener->onJob(this, m_pools[m_active], m_pools[m_active]->job());
} }
@@ -93,7 +108,7 @@ void FailoverStrategy::onClose(Client *client, int failures)
m_listener->onPause(this); m_listener->onPause(this);
} }
if (m_index == 0 && failures < Options::i()->retries()) { if (m_index == 0 && failures < m_retries) {
return; return;
} }
@@ -106,7 +121,7 @@ void FailoverStrategy::onClose(Client *client, int failures)
void FailoverStrategy::onJobReceived(Client *client, const Job &job) void FailoverStrategy::onJobReceived(Client *client, const Job &job)
{ {
if (m_active == client->id()) { if (m_active == client->id()) {
m_listener->onJob(client, job); m_listener->onJob(this, client, job);
} }
} }
@@ -127,22 +142,23 @@ void FailoverStrategy::onLoginSuccess(Client *client)
if (active >= 0 && active != m_active) { if (active >= 0 && active != m_active) {
m_index = m_active = active; m_index = m_active = active;
m_listener->onActive(client); m_listener->onActive(this, client);
} }
} }
void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
{ {
m_listener->onResultAccepted(client, result, error); m_listener->onResultAccepted(this, client, result, error);
} }
void FailoverStrategy::add(const Url *url, const char *agent) void FailoverStrategy::add(const Url *url)
{ {
Client *client = new Client((int) m_pools.size(), agent, this); Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
client->setUrl(url); client->setUrl(url);
client->setRetryPause(Options::i()->retryPause() * 1000); client->setRetryPause(m_retryPause * 1000);
client->setQuiet(m_quiet);
m_pools.push_back(client); m_pools.push_back(client);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -40,7 +40,8 @@ class Url;
class FailoverStrategy : public IStrategy, public IClientListener class FailoverStrategy : public IStrategy, public IClientListener
{ {
public: public:
FailoverStrategy(const std::vector<Url*> &urls, const char *agent, IStrategyListener *listener); FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~FailoverStrategy();
public: public:
inline bool isActive() const override { return m_active >= 0; } inline bool isActive() const override { return m_active >= 0; }
@@ -58,8 +59,11 @@ protected:
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
private: private:
void add(const Url *url, const char *agent); void add(const Url *url);
const bool m_quiet;
const int m_retries;
const int m_retryPause;
int m_active; int m_active;
int m_index; int m_index;
IStrategyListener *m_listener; IStrategyListener *m_listener;

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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,16 +25,23 @@
#include "interfaces/IStrategyListener.h" #include "interfaces/IStrategyListener.h"
#include "net/Client.h" #include "net/Client.h"
#include "net/strategies/SinglePoolStrategy.h" #include "net/strategies/SinglePoolStrategy.h"
#include "Options.h" #include "Platform.h"
SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener) : SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet) :
m_active(false), m_active(false),
m_listener(listener) m_listener(listener)
{ {
m_client = new Client(0, agent, this); m_client = new Client(0, Platform::userAgent(), this);
m_client->setUrl(url); m_client->setUrl(url);
m_client->setRetryPause(Options::i()->retryPause() * 1000); m_client->setRetryPause(retryPause * 1000);
m_client->setQuiet(quiet);
}
SinglePoolStrategy::~SinglePoolStrategy()
{
m_client->deleteLater();
} }
@@ -56,7 +63,7 @@ void SinglePoolStrategy::resume()
return; return;
} }
m_listener->onJob(m_client, m_client->job()); m_listener->onJob(this, m_client, m_client->job());
} }
@@ -85,18 +92,18 @@ void SinglePoolStrategy::onClose(Client *client, int failures)
void SinglePoolStrategy::onJobReceived(Client *client, const Job &job) void SinglePoolStrategy::onJobReceived(Client *client, const Job &job)
{ {
m_listener->onJob(client, job); m_listener->onJob(this, client, job);
} }
void SinglePoolStrategy::onLoginSuccess(Client *client) void SinglePoolStrategy::onLoginSuccess(Client *client)
{ {
m_active = true; m_active = true;
m_listener->onActive(client); m_listener->onActive(this, client);
} }
void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
{ {
m_listener->onResultAccepted(client, result, error); m_listener->onResultAccepted(this, client, result, error);
} }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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
@@ -37,7 +37,8 @@ class Url;
class SinglePoolStrategy : public IStrategy, public IClientListener class SinglePoolStrategy : public IStrategy, public IClientListener
{ {
public: public:
SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener); SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false);
~SinglePoolStrategy();
public: public:
inline bool isActive() const override { return m_active; } inline bool isActive() const override { return m_active; }

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2018 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
@@ -27,15 +27,15 @@
#define APP_ID "xmrig" #define APP_ID "xmrig"
#define APP_NAME "XMRig" #define APP_NAME "XMRig"
#define APP_DESC "XMRig CPU miner" #define APP_DESC "XMRig CPU miner"
#define APP_VERSION "2.4.5" #define APP_VERSION "2.5.3"
#define APP_DOMAIN "xmrig.com" #define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com" #define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com"
#define APP_KIND "cpu" #define APP_KIND "cpu"
#define APP_VER_MAJOR 2 #define APP_VER_MAJOR 2
#define APP_VER_MINOR 4 #define APP_VER_MINOR 5
#define APP_VER_BUILD 5 #define APP_VER_BUILD 3
#define APP_VER_REV 0 #define APP_VER_REV 0
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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
@@ -85,7 +86,7 @@ void DoubleWorker::start()
*Job::nonce(m_state->blob) = ++m_state->nonce1; *Job::nonce(m_state->blob) = ++m_state->nonce1;
*Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2; *Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2;
CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx); CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx, m_state->job.variant());
if (*reinterpret_cast<uint64_t*>(m_hash + 24) < m_state->job.target()) { if (*reinterpret_cast<uint64_t*>(m_hash + 24) < m_state->job.target()) {
Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff())); Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff()));

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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,7 +26,6 @@
#define __DOUBLEWORKER_H__ #define __DOUBLEWORKER_H__
#include "align.h"
#include "net/Job.h" #include "net/Job.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "workers/Worker.h" #include "workers/Worker.h"

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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

View File

@@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* 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

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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

View File

@@ -83,10 +83,14 @@ void Workers::setEnabled(bool enabled)
} }
void Workers::setJob(const Job &job) void Workers::setJob(const Job &job, bool donate)
{ {
uv_rwlock_wrlock(&m_rwlock); uv_rwlock_wrlock(&m_rwlock);
m_job = job; m_job = job;
if (donate) {
m_job.setPoolId(-1);
}
uv_rwlock_wrunlock(&m_rwlock); uv_rwlock_wrunlock(&m_rwlock);
m_active = true; m_active = true;

View File

@@ -45,7 +45,7 @@ public:
static Job job(); static Job job();
static void printHashrate(bool detail); static void printHashrate(bool detail);
static void setEnabled(bool enabled); static void setEnabled(bool enabled);
static void setJob(const Job &job); static void setJob(const Job &job, bool donate);
static void start(int64_t affinity, int priority); static void start(int64_t affinity, int priority);
static void stop(); static void stop();
static void submit(const JobResult &result); static void submit(const JobResult &result);

View File

@@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 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,27 @@
* 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_H__
#define __ALIGN_H__ #define __XMRIG_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__ */ namespace xmrig
{
enum Algo {
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
};
enum Variant {
VARIANT_AUTO = -1,
VARIANT_NONE = 0,
VARIANT_V1 = 1
};
} /* xmrig */
#endif /* __XMRIG_H__ */