diff --git a/CHANGELOG.md b/CHANGELOG.md index b00b1f1d..ab31e698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ +# 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 March 28.** +- [#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. diff --git a/README.md b/README.md index 0330f83f..962408e9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # XMRig + +:warning: **You must update miners to version 2.5 before April 6 due [Monero PoW change](https://getmonero.org/2018/02/11/PoW-change-and-key-reuse.html).** + [![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 Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/releases) @@ -63,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) --no-huge-pages disable huge pages support --no-color disable colored output + --variant algorithm PoW variant --donate-level=N donate level, default 5% (5 minutes in 100 minutes) --user-agent set custom user-agent string for pool -B, --background run the miner in the background -c, --config=FILE load a JSON-format configuration file -l, --log-file=FILE log all output to a file + -S, --syslog use system log for output messages --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75) --safe safe adjust threads and av settings for current CPU --nicehash enable nicehash/xmrig-proxy support @@ -119,10 +124,10 @@ Please note performance is highly dependent on system load. The numbers above ar ## Release checksums ### SHA-256 ``` -232ea929f7219c8de81c7e6fcae7437d40d8128cf55b597a6e1fca0cd77f9f5b xmrig-2.5.0-xenial-amd64.tar.gz/xmrig-2.5.0/xmrig -6149ffed21e740cac12aa61b2fdd17248cbd3e51bab2289d2766aad1d29df910 xmrig-2.5.0-gcc-win32.zip/xmrig.exe -9c89f80e21db906439a7a1b333b8215dbe07d8e42f98a63f6c10c954288a7108 xmrig-2.5.0-gcc-win64.zip/xmrig.exe -b50773c5a74ca9921597a1152e2469ec266cc89eb9765038db7e876f0bcece73 xmrig-2.5.0-msvc-win64.zip/xmrig.exe +b070d06a3615f3db67ad3beab43d6d21f3c88026aa2b4726a93df47145cd30ec xmrig-2.5.2-xenial-amd64.tar.gz/xmrig-2.5.2/xmrig +4852135d3f04fd450ba39abce51ca40ff9131d222220c8b30804be05f6679295 xmrig-2.5.2-gcc-win32.zip/xmrig.exe +284309d07f08261af19c937ece6d2031910d9124a7359c207ded65890b2d7c5f xmrig-2.5.2-gcc-win64.zip/xmrig.exe +e1dc46158a578fb030538fb06e5663a6acc5763545fb447a00ce0a6b388c5226 xmrig-2.5.2-msvc-win64.zip/xmrig.exe ``` ## Contacts diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 488f1236..13e50564 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -6,6 +6,10 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "") set(CMAKE_BUILD_TYPE Release) endif() +if (CMAKE_BUILD_TYPE STREQUAL "Release") + add_definitions(/DNDEBUG) +endif() + if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing") diff --git a/res/app.ico b/res/app.ico index 7ab97bae..8c3d628f 100644 Binary files a/res/app.ico and b/res/app.ico differ diff --git a/src/App_unix.cpp b/src/App_unix.cpp index 66957208..674a53e6 100644 --- a/src/App_unix.cpp +++ b/src/App_unix.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,6 +36,8 @@ void App::background() { + signal(SIGPIPE, SIG_IGN); + if (m_options->affinity() != -1L) { Cpu::setAffinity(-1, m_options->affinity()); } diff --git a/src/api/Httpd.cpp b/src/api/Httpd.cpp index a604b5de..861086ed 100644 --- a/src/api/Httpd.cpp +++ b/src/api/Httpd.cpp @@ -45,17 +45,17 @@ bool Httpd::start() return false; } - unsigned int flags = 0; + 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; } - else { - flags = MHD_USE_SELECT_INTERNALLY; - } if (MHD_is_feature_supported(MHD_FEATURE_IPv6)) { flags |= MHD_USE_DUAL_STACK; } +# endif m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END); if (!m_daemon) { diff --git a/src/config.json b/src/config.json index 7813d4b9..858435d2 100644 --- a/src/config.json +++ b/src/config.json @@ -16,11 +16,12 @@ "threads": null, // number of miner threads "pools": [ { - "url": "pool.minemonero.pro:5555", // URL of mining server - "user": "", // username for mining server - "pass": "x", // password for mining server - "keepalive": true, // send keepalived for prevent timeout (need pool support) - "nicehash": false // enable nicehash/xmrig-proxy support + "url": "failover.xmrig.com:443", // URL of mining server + "user": "YOUR_WALLET", // username for mining server + "pass": "x", // password for mining server + "keepalive": true, // send keepalived for prevent timeout (need pool support) + "nicehash": false, // enable nicehash/xmrig-proxy support + "variant": -1 // algorithm PoW variant } ], "api": { diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index 996622c4..b605bfb8 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -39,7 +39,7 @@ #include "xmrig.h" -void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = nullptr; +void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr; #define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \ @@ -55,55 +55,55 @@ void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, crypt } -static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx, int variant) { +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) CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false) # endif } -static void cryptonight_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +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) CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false) # endif } -static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) { 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, int variant) { +static void cryptonight_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) { CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true) } #ifndef XMRIG_NO_AEON -static void cryptonight_lite_av1_aesni(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +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(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false) # endif } -static void cryptonight_lite_av2_aesni_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +static void cryptonight_lite_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) { # if !defined(XMRIG_ARMv7) CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false) # endif } -static void cryptonight_lite_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) { CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true) } -static void cryptonight_lite_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) { +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 void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = { +void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = { cryptonight_av1_aesni, cryptonight_av2_aesni_double, cryptonight_av3_softaes, @@ -114,7 +114,7 @@ void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_lite_av4_softaes_double }; #else -void (*cryptonight_variations[4])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = { +void (*cryptonight_variations[4])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = { cryptonight_av1_aesni, cryptonight_av2_aesni_double, cryptonight_av3_softaes, @@ -160,7 +160,7 @@ bool CryptoNight::selfTest(int algo) { return false; } - char output[64]; + uint8_t output[64]; struct cryptonight_ctx *ctx = static_cast(_mm_malloc(sizeof(cryptonight_ctx), 16)); ctx->memory = static_cast(_mm_malloc(MONERO_MEMORY * 2, 16)); diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index 6b214d66..18408536 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -49,27 +49,27 @@ extern "C" } -static inline void do_blake_hash(const void* input, size_t len, char* output) { - blake256_hash(reinterpret_cast(output), static_cast(input), len); +static inline void do_blake_hash(const uint8_t *input, size_t len, uint8_t *output) { + blake256_hash(output, input, len); } -static inline void do_groestl_hash(const void* input, size_t len, char* output) { - groestl(static_cast(input), len * 8, reinterpret_cast(output)); +static inline void do_groestl_hash(const uint8_t *input, size_t len, uint8_t *output) { + groestl(input, len * 8, output); } -static inline void do_jh_hash(const void* input, size_t len, char* output) { - jh_hash(32 * 8, static_cast(input), 8 * len, reinterpret_cast(output)); +static inline void do_jh_hash(const uint8_t *input, size_t len, 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) { - xmr_skein(static_cast(input), reinterpret_cast(output)); +static inline void do_skein_hash(const uint8_t *input, size_t len, 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) @@ -333,9 +333,9 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) template -inline void cryptonight_single_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(input), (int) size, ctx->state0, 200); + keccak(input, (int) size, ctx->state0, 200); VARIANT1_INIT(0); @@ -389,15 +389,15 @@ inline void cryptonight_single_hash(const void *__restrict__ input, size_t size, cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state0); keccakf(h0, 24); - extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast(output)); + extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output); } template -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((const uint8_t *) input + size, (int) size, ctx->state1, 200); + keccak(input, (int) size, ctx->state0, 200); + keccak(input + size, (int) size, ctx->state1, 200); VARIANT1_INIT(0); VARIANT1_INIT(1); @@ -488,8 +488,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, keccakf(h0, 24); keccakf(h1, 24); - extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast(output)); - extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast(output) + 32); + extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output); + extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32); } #endif /* __CRYPTONIGHT_ARM_H__ */ diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 3c6146ac..a667a3b3 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -27,12 +27,22 @@ // VARIANT ALTERATIONS -#define VARIANT1_INIT(part) \ +#ifndef XMRIG_ARM +# define VARIANT1_INIT(part) \ uint64_t tweak1_2_##part = 0; \ if (VARIANT > 0) { \ - tweak1_2_##part = (*reinterpret_cast(reinterpret_cast(input) + 35 + part * size) ^ \ + tweak1_2_##part = (*reinterpret_cast(input + 35 + part * size) ^ \ *(reinterpret_cast(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(input + 35 + part * size); \ + volatile const uint64_t b = *(reinterpret_cast(ctx->state##part) + 24); \ + tweak1_2_##part = a ^ b; \ + } +#endif #define VARIANT1_1(p) \ if (VARIANT > 0) { \ diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 1e5190d8..b7544dcc 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -49,27 +49,27 @@ extern "C" } -static inline void do_blake_hash(const void* input, size_t len, char* output) { - blake256_hash(reinterpret_cast(output), static_cast(input), len); +static inline void do_blake_hash(const uint8_t *input, size_t len, uint8_t *output) { + blake256_hash(output, input, len); } -static inline void do_groestl_hash(const void* input, size_t len, char* output) { - groestl(static_cast(input), len * 8, reinterpret_cast(output)); +static inline void do_groestl_hash(const uint8_t *input, size_t len, uint8_t *output) { + groestl(input, len * 8, output); } -static inline void do_jh_hash(const void* input, size_t len, char* output) { - jh_hash(32 * 8, static_cast(input), 8 * len, reinterpret_cast(output)); +static inline void do_jh_hash(const uint8_t *input, size_t len, 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) { - xmr_skein(static_cast(input), reinterpret_cast(output)); +static inline void do_skein_hash(const uint8_t *input, size_t len, 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}; @@ -310,9 +310,9 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) template -inline void cryptonight_single_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(input), (int) size, ctx->state0, 200); + keccak(input, (int) size, ctx->state0, 200); VARIANT1_INIT(0); @@ -363,15 +363,15 @@ inline void cryptonight_single_hash(const void *__restrict__ input, size_t size, cn_implode_scratchpad((__m128i*) ctx->memory, (__m128i*) ctx->state0); keccakf(h0, 24); - extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast(output)); + extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output); } template -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((const uint8_t *) input + size, (int) size, ctx->state1, 200); + keccak(input, (int) size, ctx->state0, 200); + keccak(input + size, (int) size, ctx->state1, 200); VARIANT1_INIT(0); VARIANT1_INIT(1); @@ -460,8 +460,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, keccakf(h0, 24); keccakf(h1, 24); - extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast(output)); - extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast(output) + 32); + extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output); + extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32); } #endif /* __CRYPTONIGHT_X86_H__ */ diff --git a/src/donate.h b/src/donate.h index 3a000948..e8230b87 100644 --- a/src/donate.h +++ b/src/donate.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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. * 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. + * 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. * * If you plan on changing this setting to 0 please consider making a one off donation to my wallet: diff --git a/src/interfaces/IStrategy.h b/src/interfaces/IStrategy.h index 660529ea..9f2795f9 100644 --- a/src/interfaces/IStrategy.h +++ b/src/interfaces/IStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/interfaces/IStrategyListener.h b/src/interfaces/IStrategyListener.h index 60f95734..9f2c4487 100644 --- a/src/interfaces/IStrategyListener.h +++ b/src/interfaces/IStrategyListener.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,10 +39,10 @@ class IStrategyListener public: virtual ~IStrategyListener() {} - virtual void onActive(Client *client) = 0; - virtual void onJob(Client *client, const Job &job) = 0; - virtual void onPause(IStrategy *strategy) = 0; - virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; + virtual void onActive(IStrategy *strategy, Client *client) = 0; + virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0; + virtual void onPause(IStrategy *strategy) = 0; + virtual void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) = 0; }; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index f6543b4e..c8a93f24 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -21,6 +21,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -65,6 +66,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_recvBufPos(0), m_state(UnconnectedState), m_expire(0), + m_jobs(0), m_stream(nullptr), m_socket(nullptr) { @@ -111,6 +113,20 @@ void Client::connect(const Url *url) } +void Client::deleteLater() +{ + if (!m_listener) { + return; + } + + m_listener = nullptr; + + if (!disconnect()) { + delete this; + } +} + + void Client::setUrl(const Url *url) { if (!url || !url->isValid()) { @@ -171,7 +187,12 @@ int64_t Client::submit(const JobResult &result) 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.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()); +# endif + return send(size); } @@ -184,7 +205,28 @@ bool Client::close() setState(ClosingState); - if (uv_is_closing(reinterpret_cast(m_socket)) == 0) { + uv_stream_t *stream = reinterpret_cast(m_socket); + + if (uv_is_readable(stream) == 1) { + uv_read_stop(stream); + } + + if (uv_is_writable(stream) == 1) { + const int rc = uv_shutdown(new uv_shutdown_t, stream, [](uv_shutdown_t* req, int status) { + if (uv_is_closing(reinterpret_cast(req->handle)) == 0) { + uv_close(reinterpret_cast(req->handle), Client::onClose); + } + + delete req; + }); + + assert(rc == 0); + + if (rc != 0) { + onClose(); + } + } + else { uv_close(reinterpret_cast(m_socket), Client::onClose); } @@ -221,7 +263,14 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } +# 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())) { *code = 3; return false; @@ -245,17 +294,22 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) job.setVariant(params["variant"].GetInt()); } - if (m_job == job) { - if (!m_quiet) { - LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); - } + if (m_job != job) { + m_jobs++; + m_job = std::move(job); + return true; + } - close(); + if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459 return false; } - m_job = std::move(job); - return true; + if (!m_quiet) { + LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); + } + + close(); + return false; } @@ -266,13 +320,18 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) return false; } +# ifndef XMRIG_PROXY_PROJECT m_nicehash = m_url.isNicehash(); +# endif if (result.HasMember("extensions")) { parseExtensions(result["extensions"]); } - return parseJob(result["job"], code); + const bool rc = parseJob(result["job"], code); + m_jobs = 0; + + return rc; } @@ -287,7 +346,7 @@ int Client::resolve(const char *host) 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 (!m_quiet) { LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r)); @@ -398,6 +457,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) { startTimeout(); @@ -407,7 +478,10 @@ void Client::parse(char *line, size_t len) LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line); if (len < 32 || line[0] != '{') { - LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port()); + if (!m_quiet) { + LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port()); + } + return; } @@ -538,6 +612,12 @@ void Client::ping() void Client::reconnect() { + if (!m_listener) { + delete this; + + return; + } + setState(ConnectingState); # ifndef XMRIG_PROXY_PROJECT @@ -586,6 +666,9 @@ void Client::startTimeout() void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { auto client = getClient(handle->data); + if (!client) { + return; + } buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; buf->len = client->m_recvBuf.len - client->m_recvBufPos; @@ -595,20 +678,21 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t void Client::onClose(uv_handle_t *handle) { auto client = getClient(handle->data); + if (!client) { + return; + } - delete client->m_socket; - - client->m_stream = nullptr; - client->m_socket = nullptr; - client->setState(UnconnectedState); - - client->reconnect(); + client->onClose(); } void Client::onConnect(uv_connect_t *req, int status) { auto client = getClient(req->data); + if (!client) { + return; + } + if (status < 0) { if (!client->m_quiet) { LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); @@ -633,6 +717,10 @@ void Client::onConnect(uv_connect_t *req, int status) void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { auto client = getClient(stream->data); + if (!client) { + return; + } + if (nread < 0) { if (nread != UV_EOF && !client->m_quiet) { LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); @@ -679,8 +767,15 @@ 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) { auto client = getClient(req->data); + if (!client) { + return; + } + 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(); } @@ -701,7 +796,9 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) } if (ipv4.empty() && ipv6.empty()) { - LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) 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(); diff --git a/src/net/Client.h b/src/net/Client.h index a927bd19..fff7a156 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -56,12 +56,12 @@ public: constexpr static int kKeepAliveTimeout = 60 * 1000; Client(int id, const char *agent, IClientListener *listener); - ~Client(); bool disconnect(); int64_t submit(const JobResult &result); void connect(); void connect(const Url *url); + void deleteLater(); void setUrl(const Url *url); void tick(uint64_t now); @@ -76,6 +76,8 @@ public: inline void setRetryPause(int ms) { m_retryPause = ms; } private: + ~Client(); + bool close(); bool isCriticalError(const char *message); bool parseJob(const rapidjson::Value ¶ms, int *code); @@ -85,6 +87,7 @@ private: void connect(const std::vector &ipv4, const std::vector &ipv6); void connect(sockaddr *addr); void login(); + void onClose(); void parse(char *line, size_t len); void parseExtensions(const rapidjson::Value &value); void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error); @@ -120,6 +123,7 @@ private: static int64_t m_sequence; std::map m_results; uint64_t m_expire; + uint64_t m_jobs; Url m_url; uv_buf_t m_recvBuf; uv_getaddrinfo_t m_resolver; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 48e73a52..7d137fac 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -210,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; } + + +bool Job::operator!=(const Job &other) const +{ + return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0; +} diff --git a/src/net/Job.h b/src/net/Job.h index d981ed37..b8b9d6bc 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -61,6 +61,7 @@ public: inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } static bool fromHex(const char* in, unsigned int len, unsigned char* out); @@ -69,6 +70,7 @@ public: static void toHex(const unsigned char* in, unsigned int len, char* out); bool operator==(const Job &other) const; + bool operator!=(const Job &other) const; private: bool m_nicehash; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index e0f65497..ede3f8b4 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,7 +40,6 @@ #include "net/SubmitResult.h" #include "net/Url.h" #include "Options.h" -#include "Platform.h" #include "workers/Workers.h" @@ -55,14 +54,14 @@ Network::Network(const Options *options) : const std::vector &pools = options->pools(); if (pools.size() > 1) { - m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this); + m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this); } else { - m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this); + m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this); } 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; @@ -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"); 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; } - 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); @@ -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()) { 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(); - Workers::setJob(job); + Workers::setJob(job, donate); } diff --git a/src/net/Network.h b/src/net/Network.h index fe13d9b7..fae5c563 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,16 +49,16 @@ public: void stop(); protected: - void onActive(Client *client) override; - void onJob(Client *client, const Job &job) override; + void onActive(IStrategy *strategy, Client *client) override; + void onJob(IStrategy *strategy, Client *client, const Job &job) override; void onJobResult(const JobResult &result) 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: constexpr static int kTickInterval = 1 * 1000; - void setJob(Client *client, const Job &job); + void setJob(Client *client, const Job &job, bool donate); void tick(); static void onTick(uv_timer_t *handle); diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 84d1e4da..ae707e21 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -26,7 +26,8 @@ #include "net/Client.h" #include "net/Job.h" #include "net/strategies/DonateStrategy.h" -#include "Options.h" +#include "net/strategies/FailoverStrategy.h" +#include "Platform.h" #include "xmrig.h" @@ -36,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_donateTime(Options::i()->donateLevel() * 60 * 1000), - m_idleTime((100 - Options::i()->donateLevel()) * 60 * 1000), + m_donateTime(level * 60 * 1000), + m_idleTime((100 - level) * 60 * 1000), + m_strategy(nullptr), m_listener(listener) { uint8_t hash[200]; char userId[65] = { 0 }; - const char *user = Options::i()->pools().front()->user(); keccak(reinterpret_cast(user), static_cast(strlen(user)), hash, sizeof(hash)); Job::toHex(hash, 32, userId); - Url *url = new Url("thanks.xmrig.com", Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT_LITE ? 5555 : 80, 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_client->setUrl(url); - m_client->setRetryPause(Options::i()->retryPause() * 1000); - m_client->setQuiet(true); - - delete url; + m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true); m_timer.data = this; 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) { - return m_client->submit(result); + return m_strategy->submit(result); } void DonateStrategy::connect() { - m_client->connect(); + m_strategy->connect(); } void DonateStrategy::stop() { uv_timer_stop(&m_timer); - m_client->disconnect(); + m_strategy->stop(); } void DonateStrategy::tick(uint64_t now) { - m_client->tick(now); + m_strategy->tick(now); } -void DonateStrategy::onClose(Client *client, int failures) -{ -} - - -void DonateStrategy::onJobReceived(Client *client, const Job &job) -{ - m_listener->onJob(client, job); -} - - -void DonateStrategy::onLoginSuccess(Client *client) +void DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); } 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() { - m_client->disconnect(); + m_strategy->stop(); m_active = false; m_listener->onPause(this); - idle(); + idle(m_idleTime); } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 07011053..4ef29958 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -26,10 +26,12 @@ #include +#include #include "interfaces/IClientListener.h" #include "interfaces/IStrategy.h" +#include "interfaces/IStrategyListener.h" class Client; @@ -37,10 +39,11 @@ class IStrategyListener; class Url; -class DonateStrategy : public IStrategy, public IClientListener +class DonateStrategy : public IStrategy, public IStrategyListener { public: - DonateStrategy(const char *agent, IStrategyListener *listener); + DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener); + ~DonateStrategy(); public: inline bool isActive() const override { return m_active; } @@ -52,22 +55,23 @@ public: void tick(uint64_t now) override; protected: - void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; - void onLoginSuccess(Client *client) override; - void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; + void onActive(IStrategy *strategy, Client *client) override; + void onJob(IStrategy *strategy, Client *client, const Job &job) override; + void onPause(IStrategy *strategy) override; + void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; private: - void idle(); + void idle(uint64_t timeout); void suspend(); static void onTimer(uv_timer_t *handle); bool m_active; - Client *m_client; const int m_donateTime; const int m_idleTime; + IStrategy *m_strategy; IStrategyListener *m_listener; + std::vector m_pools; uv_timer_t m_timer; }; diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 47d390b0..dbfeb311 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,22 +25,37 @@ #include "interfaces/IStrategyListener.h" #include "net/Client.h" #include "net/strategies/FailoverStrategy.h" -#include "Options.h" +#include "Platform.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, const char *agent, IStrategyListener *listener) : +FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : + m_quiet(quiet), + m_retries(retries), + m_retryPause(retryPause), m_active(-1), m_index(0), m_listener(listener) { 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) { + if (m_active == -1) { + return -1; + } + return m_pools[m_active]->submit(result); } @@ -57,7 +72,7 @@ void FailoverStrategy::resume() 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); } - if (m_index == 0 && failures < Options::i()->retries()) { + if (m_index == 0 && failures < m_retries) { return; } @@ -106,7 +121,7 @@ void FailoverStrategy::onClose(Client *client, int failures) void FailoverStrategy::onJobReceived(Client *client, const Job &job) { 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) { 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) { - 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->setRetryPause(Options::i()->retryPause() * 1000); + client->setRetryPause(m_retryPause * 1000); + client->setQuiet(m_quiet); m_pools.push_back(client); } diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h index 963d3157..8ad767ca 100644 --- a/src/net/strategies/FailoverStrategy.h +++ b/src/net/strategies/FailoverStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,7 +40,8 @@ class Url; class FailoverStrategy : public IStrategy, public IClientListener { public: - FailoverStrategy(const std::vector &urls, const char *agent, IStrategyListener *listener); + FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); + ~FailoverStrategy(); public: 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; 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_index; IStrategyListener *m_listener; diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp index 997dc00b..fc7f209e 100644 --- a/src/net/strategies/SinglePoolStrategy.cpp +++ b/src/net/strategies/SinglePoolStrategy.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,16 +25,23 @@ #include "interfaces/IStrategyListener.h" #include "net/Client.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_listener(listener) { - m_client = new Client(0, agent, this); + m_client = new Client(0, Platform::userAgent(), this); 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; } - 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) { - m_listener->onJob(client, job); + m_listener->onJob(this, client, job); } void SinglePoolStrategy::onLoginSuccess(Client *client) { m_active = true; - m_listener->onActive(client); + m_listener->onActive(this, client); } void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { - m_listener->onResultAccepted(client, result, error); + m_listener->onResultAccepted(this, client, result, error); } diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h index 95e21547..d5682cf7 100644 --- a/src/net/strategies/SinglePoolStrategy.h +++ b/src/net/strategies/SinglePoolStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,8 @@ class Url; class SinglePoolStrategy : public IStrategy, public IClientListener { public: - SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener); + SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false); + ~SinglePoolStrategy(); public: inline bool isActive() const override { return m_active; } diff --git a/src/version.h b/src/version.h index cfaf7e9c..060edcb7 100644 --- a/src/version.h +++ b/src/version.h @@ -27,7 +27,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig CPU miner" -#define APP_VERSION "2.5.0" +#define APP_VERSION "2.5.2" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com" @@ -35,7 +35,7 @@ #define APP_VER_MAJOR 2 #define APP_VER_MINOR 5 -#define APP_VER_BUILD 0 +#define APP_VER_BUILD 2 #define APP_VER_REV 0 #ifdef _MSC_VER diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 02646ced..7a7ff986 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/workers/Worker.h b/src/workers/Worker.h index 11c4a198..08a0551f 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 039a1793..f0aef448 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -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); m_job = job; + + if (donate) { + m_job.setPoolId(-1); + } uv_rwlock_wrunlock(&m_rwlock); m_active = true; diff --git a/src/workers/Workers.h b/src/workers/Workers.h index e76d0a62..1c85089a 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -45,7 +45,7 @@ public: static Job job(); static void printHashrate(bool detail); 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 stop(); static void submit(const JobResult &result);