mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-23 03:05:09 +00:00
Merge branch 'vtnerd-monero-v1-pow' into dev
# Conflicts: # src/api/Httpd.cpp # src/api/Httpd.h
This commit is contained in:
commit
3e2863dca5
29 changed files with 526 additions and 242 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
# v2.5.0
|
||||||
|
- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on March 28.**
|
||||||
|
- 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`.
|
||||||
|
|
|
@ -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
|
||||||
|
@ -57,6 +57,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
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
17
src/Mem.cpp
17
src/Mem.cpp
|
@ -4,8 +4,9 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-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
|
||||||
|
@ -46,10 +47,10 @@ cryptonight_ctx *Mem::create(int 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 +73,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
@ -46,7 +47,7 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||||
m_doubleHash = doubleHash;
|
m_doubleHash = doubleHash;
|
||||||
|
|
||||||
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||||
const size_t size = MEMORY * (threads * ratio + 1);
|
const size_t 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(size, 16));
|
||||||
|
@ -83,7 +84,7 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||||
|
|
||||||
void Mem::release()
|
void Mem::release()
|
||||||
{
|
{
|
||||||
const int size = MEMORY * (m_threads + 1);
|
const int size = MONERO_MEMORY * (m_threads + 1);
|
||||||
|
|
||||||
if (m_flags & HugepagesEnabled) {
|
if (m_flags & HugepagesEnabled) {
|
||||||
if (m_flags & Lock) {
|
if (m_flags & Lock) {
|
||||||
|
|
|
@ -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
|
||||||
|
@ -151,7 +152,7 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||||
m_doubleHash = doubleHash;
|
m_doubleHash = doubleHash;
|
||||||
|
|
||||||
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||||
const size_t size = MEMORY * (threads * ratio + 1);
|
const size_t 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(size, 16));
|
||||||
|
|
|
@ -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
|
||||||
|
@ -74,6 +74,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\
|
||||||
|
--no-monero disable Monero v7 PoW\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 +119,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 },
|
||||||
|
{ "no-monero", 0, 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' },
|
||||||
|
@ -158,11 +160,12 @@ static struct option const config_options[] = {
|
||||||
|
|
||||||
|
|
||||||
static struct option const pool_options[] = {
|
static struct option const pool_options[] = {
|
||||||
{ "url", 1, nullptr, 'o' },
|
|
||||||
{ "pass", 1, nullptr, 'p' },
|
{ "pass", 1, nullptr, 'p' },
|
||||||
|
{ "url", 1, nullptr, 'o' },
|
||||||
{ "user", 1, nullptr, 'u' },
|
{ "user", 1, nullptr, 'u' },
|
||||||
{ "userpass", 1, nullptr, 'O' },
|
{ "userpass", 1, nullptr, 'O' },
|
||||||
{ "keepalive", 0, nullptr ,'k' },
|
{ "keepalive", 0, nullptr ,'k' },
|
||||||
|
{ "monero", 0, nullptr, 1010 },
|
||||||
{ "nicehash", 0, nullptr, 1006 },
|
{ "nicehash", 0, nullptr, 1006 },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
@ -392,6 +395,7 @@ bool Options::parseArg(int key, const char *arg)
|
||||||
|
|
||||||
case 1002: /* --no-color */
|
case 1002: /* --no-color */
|
||||||
case 1009: /* --no-huge-pages */
|
case 1009: /* --no-huge-pages */
|
||||||
|
case 1010: /* --no-monero */
|
||||||
return parseBoolean(key, false);
|
return parseBoolean(key, false);
|
||||||
|
|
||||||
case 't': /* --threads */
|
case 't': /* --threads */
|
||||||
|
@ -557,6 +561,10 @@ bool Options::parseBoolean(int key, bool enable)
|
||||||
m_hugePages = enable;
|
m_hugePages = enable;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 1010: /* monero */
|
||||||
|
m_pools.back()->setMonero(enable);
|
||||||
|
break;
|
||||||
|
|
||||||
case 2000: /* colors */
|
case 2000: /* colors */
|
||||||
m_colors = enable;
|
m_colors = enable;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -4,8 +4,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
|
||||||
|
@ -32,25 +32,10 @@
|
||||||
|
|
||||||
|
|
||||||
Httpd::Httpd(int port, const char *accessToken) :
|
Httpd::Httpd(int port, const char *accessToken) :
|
||||||
m_idle(true),
|
m_accessToken(accessToken),
|
||||||
m_accessToken(accessToken ? strdup(accessToken) : nullptr),
|
|
||||||
m_port(port),
|
m_port(port),
|
||||||
m_daemon(nullptr)
|
m_daemon(nullptr)
|
||||||
{
|
{
|
||||||
uv_timer_init(uv_default_loop(), &m_timer);
|
|
||||||
m_timer.data = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Httpd::~Httpd()
|
|
||||||
{
|
|
||||||
uv_timer_stop(&m_timer);
|
|
||||||
|
|
||||||
if (m_daemon) {
|
|
||||||
MHD_stop_daemon(m_daemon);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete m_accessToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +47,14 @@ bool Httpd::start()
|
||||||
|
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
|
if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
|
||||||
flags |= MHD_USE_EPOLL_LINUX_ONLY;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
|
m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
|
||||||
|
@ -71,7 +63,6 @@ bool Httpd::start()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,22 +86,6 @@ int Httpd::auth(const char *header)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Httpd::run()
|
|
||||||
{
|
|
||||||
MHD_run(m_daemon);
|
|
||||||
|
|
||||||
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
|
|
||||||
if (m_idle && info->num_connections) {
|
|
||||||
uv_timer_set_repeat(&m_timer, kActiveInterval);
|
|
||||||
m_idle = false;
|
|
||||||
}
|
|
||||||
else if (!m_idle && !info->num_connections) {
|
|
||||||
uv_timer_set_repeat(&m_timer, kIdleInterval);
|
|
||||||
m_idle = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Httpd::done(MHD_Connection *connection, int status, MHD_Response *rsp)
|
int Httpd::done(MHD_Connection *connection, int status, MHD_Response *rsp)
|
||||||
{
|
{
|
||||||
if (!rsp) {
|
if (!rsp) {
|
||||||
|
@ -151,9 +126,3 @@ int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url
|
||||||
MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*) buf, MHD_RESPMEM_MUST_FREE);
|
MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*) buf, MHD_RESPMEM_MUST_FREE);
|
||||||
return done(connection, status, rsp);
|
return done(connection, status, rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Httpd::onTimer(uv_timer_t *handle)
|
|
||||||
{
|
|
||||||
static_cast<Httpd*>(handle->data)->run();
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-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
|
||||||
|
@ -37,25 +37,17 @@ class Httpd
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Httpd(int port, const char *accessToken);
|
Httpd(int port, const char *accessToken);
|
||||||
~Httpd();
|
|
||||||
bool start();
|
bool start();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr static const int kIdleInterval = 200;
|
|
||||||
constexpr static const int kActiveInterval = 50;
|
|
||||||
|
|
||||||
int auth(const char *header);
|
int auth(const char *header);
|
||||||
void run();
|
|
||||||
|
|
||||||
static int done(MHD_Connection *connection, int status, MHD_Response *rsp);
|
static int done(MHD_Connection *connection, int status, MHD_Response *rsp);
|
||||||
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
|
static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
|
||||||
static void onTimer(uv_timer_t *handle);
|
|
||||||
|
|
||||||
bool m_idle;
|
|
||||||
const char *m_accessToken;
|
const char *m_accessToken;
|
||||||
const int m_port;
|
const int m_port;
|
||||||
MHD_Daemon *m_daemon;
|
MHD_Daemon *m_daemon;
|
||||||
uv_timer_t m_timer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __HTTPD_H__ */
|
#endif /* __HTTPD_H__ */
|
||||||
|
|
|
@ -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
|
||||||
|
@ -36,58 +38,79 @@
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
|
|
||||||
void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr;
|
|
||||||
|
void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) = nullptr;
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx) {
|
static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx, uint8_t version) {
|
||||||
# if !defined(XMRIG_ARMv7)
|
# if !defined(XMRIG_ARMv7)
|
||||||
cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx);
|
if (version > 6) {
|
||||||
|
cryptonight_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false, true>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cryptonight_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false, false>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
# 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 void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
# if !defined(XMRIG_ARMv7)
|
# if !defined(XMRIG_ARMv7)
|
||||||
cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, false>(input, size, output, ctx);
|
if (version > 6) {
|
||||||
|
cryptonight_double_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false, true>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cryptonight_double_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false, false>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx) {
|
static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
cryptonight_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx);
|
if (version > 6) {
|
||||||
|
cryptonight_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true, true>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cryptonight_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true, true>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx) {
|
static void cryptonight_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
cryptonight_double_hash<0x80000, MEMORY, 0x1FFFF0, true>(input, size, output, ctx);
|
if (version > 6) {
|
||||||
|
cryptonight_double_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true, true>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cryptonight_double_hash<MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true, false>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#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 void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
# 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<AEON_ITER, AEON_MEMORY, AEON_MASK, false, false>(input, size, output, ctx, version);
|
||||||
# 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 void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
cryptonight_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx);
|
# if !defined(XMRIG_ARMv7)
|
||||||
|
cryptonight_double_hash<AEON_ITER, AEON_MEMORY, AEON_MASK, false, false>(input, size, output, ctx, version);
|
||||||
|
# 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 void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
cryptonight_double_hash<0x40000, MEMORY_LITE, 0xFFFF0, true>(input, size, output, ctx);
|
cryptonight_hash<AEON_ITER, AEON_MEMORY, AEON_MASK, true, false>(input, size, output, ctx, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = {
|
|
||||||
|
static void cryptonight_lite_av4_softaes_double(const void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t version) {
|
||||||
|
cryptonight_double_hash<AEON_ITER, AEON_MEMORY, AEON_MASK, true, false>(input, size, output, ctx, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t) = {
|
||||||
cryptonight_av1_aesni,
|
cryptonight_av1_aesni,
|
||||||
cryptonight_av2_aesni_double,
|
cryptonight_av2_aesni_double,
|
||||||
cryptonight_av3_softaes,
|
cryptonight_av3_softaes,
|
||||||
|
@ -98,7 +121,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 void *input, size_t size, void *output, cryptonight_ctx *ctx, uint8_t) = {
|
||||||
cryptonight_av1_aesni,
|
cryptonight_av1_aesni,
|
||||||
cryptonight_av2_aesni_double,
|
cryptonight_av2_aesni_double,
|
||||||
cryptonight_av3_softaes,
|
cryptonight_av3_softaes,
|
||||||
|
@ -109,7 +132,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.version());
|
||||||
|
|
||||||
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
|
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
|
||||||
}
|
}
|
||||||
|
@ -133,9 +156,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, uint8_t version)
|
||||||
{
|
{
|
||||||
cryptonight_hash_ctx(input, size, output, ctx);
|
cryptonight_hash_ctx(input, size, output, ctx, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,17 +169,25 @@ bool CryptoNight::selfTest(int algo) {
|
||||||
|
|
||||||
char output[64];
|
char 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);
|
||||||
|
|
||||||
|
# ifndef XMRIG_NO_AEON
|
||||||
|
bool rc = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
|
||||||
|
# else
|
||||||
|
bool rc = memcmp(output, test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (rc && algo == Options::ALGO_CRYPTONIGHT) {
|
||||||
|
cryptonight_hash_ctx(test_input, 76, output, ctx, 7);
|
||||||
|
|
||||||
|
rc = memcmp(output, test_output2, (Options::i()->doubleHash() ? 64 : 32)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
_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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -31,9 +32,13 @@
|
||||||
|
|
||||||
#include "align.h"
|
#include "align.h"
|
||||||
|
|
||||||
|
#define AEON_MEMORY 1048576
|
||||||
|
#define AEON_MASK 0xFFFF0
|
||||||
|
#define AEON_ITER 0x40000
|
||||||
|
|
||||||
#define MEMORY 2097152 /* 2 MiB */
|
#define MONERO_MEMORY 2097152
|
||||||
#define MEMORY_LITE 1048576 /* 1 MiB */
|
#define MONERO_MASK 0x1FFFF0
|
||||||
|
#define MONERO_ITER 0x80000
|
||||||
|
|
||||||
|
|
||||||
struct cryptonight_ctx {
|
struct cryptonight_ctx {
|
||||||
|
@ -52,7 +57,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, uint8_t version);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool selfTest(int algo);
|
static bool selfTest(int algo);
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,11 +332,13 @@ 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, bool MONERO>
|
||||||
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx, uint8_t version)
|
||||||
{
|
{
|
||||||
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
|
keccak(static_cast<const uint8_t*>(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);
|
||||||
|
|
||||||
const uint8_t* l0 = ctx->memory;
|
const uint8_t* l0 = 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;
|
||||||
|
@ -400,12 +393,15 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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, bool MONERO>
|
||||||
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 void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx, uint8_t version)
|
||||||
{
|
{
|
||||||
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
|
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
|
||||||
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200);
|
keccak((const uint8_t *) 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;
|
||||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||||
|
@ -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;
|
||||||
|
|
57
src/crypto/CryptoNight_monero.h
Normal file
57
src/crypto/CryptoNight_monero.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/* 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
|
||||||
|
#define VARIANT1_INIT(part) \
|
||||||
|
uint64_t tweak1_2_##part = 0; \
|
||||||
|
if (MONERO) { \
|
||||||
|
if (version > 6) { \
|
||||||
|
tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(reinterpret_cast<const uint8_t*>(input) + 35 + part * size) ^ \
|
||||||
|
*(reinterpret_cast<const uint64_t*>(ctx->state##part) + 24)); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define VARIANT1_1(p) \
|
||||||
|
if (MONERO) { \
|
||||||
|
if (version > 6) { \
|
||||||
|
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 (MONERO) { \
|
||||||
|
if (version > 6) { \
|
||||||
|
(p) ^= tweak1_2_##part; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __CRYPTONIGHT_MONERO_H__ */
|
|
@ -4,8 +4,9 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2018 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
|
||||||
|
@ -57,4 +58,13 @@ const static uint8_t test_output1[64] = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Monero v7
|
||||||
|
const static uint8_t test_output2[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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __CRYPTONIGHT_TEST_H__ */
|
#endif /* __CRYPTONIGHT_TEST_H__ */
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2018 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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,11 +309,13 @@ 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, bool MONERO>
|
||||||
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
inline bool cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx, uint8_t version)
|
||||||
{
|
{
|
||||||
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
|
keccak(static_cast<const uint8_t*>(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);
|
||||||
|
|
||||||
const uint8_t* l0 = ctx->memory;
|
const uint8_t* l0 = 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;
|
||||||
|
@ -357,15 +364,19 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
|
||||||
|
|
||||||
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, static_cast<char*>(output));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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, bool MONERO>
|
||||||
inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
inline bool cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx, uint8_t version)
|
||||||
{
|
{
|
||||||
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
|
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
|
||||||
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200);
|
keccak((const uint8_t *) 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;
|
||||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||||
|
@ -401,6 +412,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 +429,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 +445,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;
|
||||||
|
@ -446,6 +463,7 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
|
||||||
|
|
||||||
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
|
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
|
||||||
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32);
|
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __CRYPTONIGHT_X86_H__ */
|
#endif /* __CRYPTONIGHT_X86_H__ */
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
*
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -54,6 +54,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),
|
||||||
|
@ -71,7 +73,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,19 +111,6 @@ void Client::connect(const Url *url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Client::disconnect()
|
|
||||||
{
|
|
||||||
# ifndef XMRIG_PROXY_PROJECT
|
|
||||||
uv_timer_stop(&m_keepAliveTimer);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
m_expire = 0;
|
|
||||||
m_failures = -1;
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Client::setUrl(const Url *url)
|
void Client::setUrl(const Url *url)
|
||||||
{
|
{
|
||||||
if (!url || !url->isValid()) {
|
if (!url || !url->isValid()) {
|
||||||
|
@ -150,6 +139,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 +169,29 @@ 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);
|
||||||
|
|
||||||
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
|
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
|
||||||
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 +221,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Job job(m_id, m_url.isNicehash());
|
Job job(m_id, m_nicehash, m_url.isMonero());
|
||||||
if (!job.setId(params["job_id"].GetString())) {
|
if (!job.setId(params["job_id"].GetString())) {
|
||||||
*code = 3;
|
*code = 3;
|
||||||
return false;
|
return false;
|
||||||
|
@ -219,6 +237,10 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.HasMember("coin")) {
|
||||||
|
job.setCoin(params["coin"].GetString());
|
||||||
|
}
|
||||||
|
|
||||||
if (m_job == job) {
|
if (m_job == job) {
|
||||||
if (!m_quiet) {
|
if (!m_quiet) {
|
||||||
LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
|
LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
|
||||||
|
@ -235,14 +257,16 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||||
|
|
||||||
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));
|
m_nicehash = m_url.isNicehash();
|
||||||
memcpy(m_rpcId, id, strlen(id));
|
|
||||||
|
if (result.HasMember("extensions")) {
|
||||||
|
parseExtensions(result["extensions"]);
|
||||||
|
}
|
||||||
|
|
||||||
return parseJob(result["job"], code);
|
return parseJob(result["job"], code);
|
||||||
}
|
}
|
||||||
|
@ -291,21 +315,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);
|
||||||
|
|
||||||
|
@ -374,6 +402,11 @@ 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] != '{') {
|
||||||
|
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 +430,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 ¶ms, const rapidjson::Value &error)
|
void Client::parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error)
|
||||||
{
|
{
|
||||||
if (error.IsObject()) {
|
if (error.IsObject()) {
|
||||||
|
@ -456,7 +507,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,7 +528,7 @@ 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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -532,7 +584,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
|
||||||
auto client = getClient(handle->data);
|
auto client = getClient(handle->data);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -582,17 +634,19 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||||
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 +663,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,24 +682,27 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
|
||||||
|
|
||||||
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());
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -56,10 +58,10 @@ public:
|
||||||
Client(int id, const char *agent, IClientListener *listener);
|
Client(int id, const char *agent, IClientListener *listener);
|
||||||
~Client();
|
~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 setUrl(const Url *url);
|
void setUrl(const Url *url);
|
||||||
void tick(uint64_t now);
|
void tick(uint64_t now);
|
||||||
|
|
||||||
|
@ -74,15 +76,17 @@ public:
|
||||||
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool close();
|
||||||
bool isCriticalError(const char *message);
|
bool isCriticalError(const char *message);
|
||||||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
bool parseJob(const rapidjson::Value ¶ms, 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 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 ¶ms, const rapidjson::Value &error);
|
void parseNotification(const char *method, const rapidjson::Value ¶ms, 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 +103,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;
|
||||||
|
@ -120,6 +125,7 @@ private:
|
||||||
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;
|
||||||
|
|
|
@ -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()
|
||||||
{
|
{
|
||||||
memset(m_data, 0, sizeof(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__ */
|
|
@ -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,7 +56,8 @@ static inline char hf_bin2hex(unsigned char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Job::Job(int poolId, bool nicehash) :
|
Job::Job(int poolId, bool nicehash, bool monero) :
|
||||||
|
m_monero(monero),
|
||||||
m_nicehash(nicehash),
|
m_nicehash(nicehash),
|
||||||
m_poolId(poolId),
|
m_poolId(poolId),
|
||||||
m_threadId(-1),
|
m_threadId(-1),
|
||||||
|
@ -63,6 +65,7 @@ Job::Job(int poolId, bool nicehash) :
|
||||||
m_diff(0),
|
m_diff(0),
|
||||||
m_target(0)
|
m_target(0)
|
||||||
{
|
{
|
||||||
|
memset(m_coin, 0, sizeof(m_coin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,6 +149,18 @@ bool Job::setTarget(const char *target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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_monero = strcmp(m_coin, "XMR") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -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
|
||||||
|
@ -30,30 +31,34 @@
|
||||||
|
|
||||||
|
|
||||||
#include "align.h"
|
#include "align.h"
|
||||||
#include "net/JobId.h"
|
#include "net/Id.h"
|
||||||
|
|
||||||
|
|
||||||
class Job
|
class Job
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Job(int poolId = -2, bool nicehash = false);
|
Job(int poolId = -2, bool nicehash = false, bool monero = true);
|
||||||
~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);
|
||||||
|
|
||||||
|
inline bool isMonero() const { return m_monero; }
|
||||||
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 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 uint8_t version() const { return isMonero() ? m_blob[0] : 0; }
|
||||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||||
|
|
||||||
|
@ -72,13 +77,15 @@ public:
|
||||||
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.
|
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_monero;
|
||||||
bool m_nicehash;
|
bool m_nicehash;
|
||||||
|
char m_coin[5];
|
||||||
int m_poolId;
|
int m_poolId;
|
||||||
int m_threadId;
|
int m_threadId;
|
||||||
JobId m_id;
|
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
uint64_t m_diff;
|
uint64_t m_diff;
|
||||||
uint64_t m_target;
|
uint64_t m_target;
|
||||||
|
xmrig::Id m_id;
|
||||||
|
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
VAR_ALIGN(16, char m_rawBlob[169]);
|
VAR_ALIGN(16, char m_rawBlob[169]);
|
||||||
|
|
|
@ -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__ */
|
||||||
|
|
|
@ -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,10 +37,12 @@
|
||||||
|
|
||||||
Url::Url() :
|
Url::Url() :
|
||||||
m_keepAlive(false),
|
m_keepAlive(false),
|
||||||
|
m_monero(true),
|
||||||
m_nicehash(false),
|
m_nicehash(false),
|
||||||
m_host(nullptr),
|
m_host(nullptr),
|
||||||
m_password(nullptr),
|
m_password(nullptr),
|
||||||
m_user(nullptr),
|
m_user(nullptr),
|
||||||
|
m_url(nullptr),
|
||||||
m_port(kDefaultPort)
|
m_port(kDefaultPort)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -59,21 +61,25 @@ Url::Url() :
|
||||||
*/
|
*/
|
||||||
Url::Url(const char *url) :
|
Url::Url(const char *url) :
|
||||||
m_keepAlive(false),
|
m_keepAlive(false),
|
||||||
|
m_monero(true),
|
||||||
m_nicehash(false),
|
m_nicehash(false),
|
||||||
m_host(nullptr),
|
m_host(nullptr),
|
||||||
m_password(nullptr),
|
m_password(nullptr),
|
||||||
m_user(nullptr),
|
m_user(nullptr),
|
||||||
|
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, bool monero) :
|
||||||
m_keepAlive(keepAlive),
|
m_keepAlive(keepAlive),
|
||||||
|
m_monero(monero),
|
||||||
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_url(nullptr),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
{
|
{
|
||||||
m_host = strdup(host);
|
m_host = strdup(host);
|
||||||
|
@ -85,6 +91,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 +115,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 +126,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,6 +152,19 @@ bool Url::setUserpass(const char *userpass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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::applyExceptions()
|
void Url::applyExceptions()
|
||||||
{
|
{
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
|
@ -178,9 +204,24 @@ void Url::setUser(const char *user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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_monero = other->m_monero;
|
||||||
m_nicehash = other->m_nicehash;
|
m_nicehash = other->m_nicehash;
|
||||||
m_port = other->m_port;
|
m_port = other->m_port;
|
||||||
|
|
||||||
|
@ -190,5 +231,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;
|
||||||
|
}
|
||||||
|
|
|
@ -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,10 +37,11 @@ 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, bool monero = true);
|
||||||
~Url();
|
~Url();
|
||||||
|
|
||||||
inline bool isKeepAlive() const { return m_keepAlive; }
|
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||||
|
inline bool isMonero() const { return m_monero; }
|
||||||
inline bool isNicehash() const { return m_nicehash; }
|
inline bool isNicehash() const { return m_nicehash; }
|
||||||
inline bool isValid() const { return m_host && m_port > 0; }
|
inline bool isValid() const { return m_host && m_port > 0; }
|
||||||
inline const char *host() const { return m_host; }
|
inline const char *host() const { return m_host; }
|
||||||
|
@ -48,22 +49,29 @@ public:
|
||||||
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
||||||
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 setMonero(bool monero) { m_monero = monero; }
|
||||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
|
|
||||||
bool parse(const char *url);
|
bool parse(const char *url);
|
||||||
bool setUserpass(const char *userpass);
|
bool setUserpass(const char *userpass);
|
||||||
|
const char *url() const;
|
||||||
void applyExceptions();
|
void applyExceptions();
|
||||||
void setPassword(const char *password);
|
void setPassword(const char *password);
|
||||||
void setUser(const char *user);
|
void setUser(const char *user);
|
||||||
|
|
||||||
|
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_monero;
|
||||||
bool m_nicehash;
|
bool m_nicehash;
|
||||||
char *m_host;
|
char *m_host;
|
||||||
char *m_password;
|
char *m_password;
|
||||||
char *m_user;
|
char *m_user;
|
||||||
|
mutable char *m_url;
|
||||||
uint16_t m_port;
|
uint16_t m_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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.version());
|
||||||
|
|
||||||
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()));
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue