Merge from xmrig-2.8.0-rc
This commit is contained in:
commit
021cf75b10
86 changed files with 4366 additions and 1946 deletions
|
@ -26,6 +26,12 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_TLS
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
|
||||
|
@ -61,3 +67,23 @@ const char *Platform::defaultConfigName()
|
|||
*m_defaultConfigName = '\0';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Platform::init(const char *userAgent)
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
ERR_load_BIO_strings();
|
||||
ERR_load_crypto_strings();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_digests();
|
||||
# endif
|
||||
|
||||
if (userAgent) {
|
||||
m_userAgent = userAgent;
|
||||
}
|
||||
else {
|
||||
m_userAgent = createUserAgent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __PLATFORM_H__
|
||||
#define __PLATFORM_H__
|
||||
#ifndef XMRIG_PLATFORM_H
|
||||
#define XMRIG_PLATFORM_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -43,9 +43,11 @@ public:
|
|||
static inline const char *userAgent() { return m_userAgent.data(); }
|
||||
|
||||
private:
|
||||
static char *createUserAgent();
|
||||
|
||||
static char m_defaultConfigName[520];
|
||||
static xmrig::c_str m_userAgent;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __PLATFORM_H__ */
|
||||
#endif /* XMRIG_PLATFORM_H */
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
static inline char *createUserAgent()
|
||||
char *Platform::createUserAgent()
|
||||
{
|
||||
const size_t max = 160;
|
||||
|
||||
|
@ -65,17 +65,6 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
|
|||
}
|
||||
|
||||
|
||||
void Platform::init(const char *userAgent)
|
||||
{
|
||||
if (userAgent) {
|
||||
m_userAgent = userAgent;
|
||||
}
|
||||
else {
|
||||
m_userAgent = createUserAgent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Platform::setProcessPriority(int priority)
|
||||
{
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef cpuset_t cpu_set_t;
|
|||
#endif
|
||||
|
||||
|
||||
static inline char *createUserAgent()
|
||||
char *Platform::createUserAgent()
|
||||
{
|
||||
const size_t max = 160;
|
||||
|
||||
|
@ -92,23 +92,11 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
|
|||
}
|
||||
|
||||
|
||||
void Platform::init(const char *userAgent)
|
||||
{
|
||||
if (userAgent) {
|
||||
m_userAgent = userAgent;
|
||||
}
|
||||
else {
|
||||
m_userAgent = createUserAgent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Platform::setProcessPriority(int priority)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Platform::setThreadPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
|
|
|
@ -55,7 +55,7 @@ static inline OSVERSIONINFOEX winOsVersion()
|
|||
}
|
||||
|
||||
|
||||
static inline char *createUserAgent()
|
||||
char *Platform::createUserAgent()
|
||||
{
|
||||
const auto osver = winOsVersion();
|
||||
const size_t max = 160;
|
||||
|
@ -94,17 +94,6 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
|
|||
}
|
||||
|
||||
|
||||
void Platform::init(const char *userAgent)
|
||||
{
|
||||
if (userAgent) {
|
||||
m_userAgent = userAgent;
|
||||
}
|
||||
else {
|
||||
m_userAgent = createUserAgent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Platform::setProcessPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
|
|
|
@ -147,7 +147,7 @@ int xmrig::HttpRequest::end(int status, MHD_Response *rsp)
|
|||
MHD_add_response_header(rsp, "Content-Type", "application/json");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Origin", "*");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Methods", "GET, PUT");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization");
|
||||
MHD_add_response_header(rsp, "Access-Control-Allow-Headers", "Authorization, Content-Type");
|
||||
|
||||
const int ret = MHD_queue_response(m_connection, status, rsp);
|
||||
MHD_destroy_response(rsp);
|
||||
|
|
|
@ -30,12 +30,37 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_HTTPD
|
||||
# include <microhttpd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_TLS
|
||||
# include <openssl/opensslv.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_AMD_PROJECT
|
||||
# if defined(__APPLE__)
|
||||
# include <OpenCL/cl.h>
|
||||
# else
|
||||
# include "3rdparty/CL/cl.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_NVIDIA_PROJECT
|
||||
# include "nvidia/cryptonight.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "common/config/CommonConfig.h"
|
||||
#include "common/log/Log.h"
|
||||
#include "donate.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
xmrig::CommonConfig::CommonConfig() :
|
||||
|
@ -43,6 +68,7 @@ xmrig::CommonConfig::CommonConfig() :
|
|||
m_adjusted(false),
|
||||
m_apiIPv6(false),
|
||||
m_apiRestricted(true),
|
||||
m_autoSave(true),
|
||||
m_background(false),
|
||||
m_colors(true),
|
||||
m_dryRun(false),
|
||||
|
@ -72,8 +98,102 @@ xmrig::CommonConfig::CommonConfig() :
|
|||
}
|
||||
|
||||
|
||||
xmrig::CommonConfig::~CommonConfig()
|
||||
void xmrig::CommonConfig::printAPI()
|
||||
{
|
||||
# ifndef XMRIG_NO_API
|
||||
if (apiPort() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d")
|
||||
: " * %-13s%s:%d",
|
||||
"API BIND", isApiIPv6() ? "[::]" : "0.0.0.0", apiPort());
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CommonConfig::printPools()
|
||||
{
|
||||
for (size_t i = 0; i < m_activePools.size(); ++i) {
|
||||
if (!isColors()) {
|
||||
Log::i()->text(" * POOL #%-7zu%s variant=%s, TLS=%d",
|
||||
i + 1,
|
||||
m_activePools[i].url(),
|
||||
m_activePools[i].algorithm().variantName(),
|
||||
static_cast<int>(m_activePools[i].isTLS())
|
||||
);
|
||||
}
|
||||
else {
|
||||
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"),
|
||||
i + 1,
|
||||
m_activePools[i].isTLS() ? 32 : 36,
|
||||
m_activePools[i].url(),
|
||||
m_activePools[i].algorithm().variantName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
LOG_NOTICE("POOLS --------------------------------------------------------------------");
|
||||
for (const Pool &pool : m_activePools) {
|
||||
pool.print();
|
||||
}
|
||||
LOG_NOTICE("--------------------------------------------------------------------------");
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::CommonConfig::printVersions()
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
# if defined(__clang__)
|
||||
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s")
|
||||
: " * %-13s%s/%s %s",
|
||||
"ABOUT", APP_NAME, APP_VERSION, buf);
|
||||
|
||||
# if defined(XMRIG_AMD_PROJECT)
|
||||
# if CL_VERSION_2_0
|
||||
const char *ocl = "2.0";
|
||||
# elif CL_VERSION_1_2
|
||||
const char *ocl = "1.2";
|
||||
# elif CL_VERSION_1_1
|
||||
const char *ocl = "1.1";
|
||||
# elif CL_VERSION_1_0
|
||||
const char *ocl = "1.0";
|
||||
# else
|
||||
const char *ocl = "0.0";
|
||||
# endif
|
||||
int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl);
|
||||
# elif defined(XMRIG_NVIDIA_PROJECT)
|
||||
const int cudaVersion = cuda_get_runtime_version();
|
||||
int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100);
|
||||
# else
|
||||
memset(buf, 0, 16);
|
||||
int length = 0;
|
||||
# endif
|
||||
|
||||
# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT)
|
||||
{
|
||||
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
|
||||
length += snprintf(buf + length, (sizeof buf) - length, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
length += snprintf(buf + length, (sizeof buf) - length, "microhttpd/%s ", MHD_get_version());
|
||||
# endif
|
||||
|
||||
Log::i()->text(isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s")
|
||||
: " * %-13slibuv/%s %s",
|
||||
"LIBS", uv_version_string(), buf);
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,7 +221,7 @@ bool xmrig::CommonConfig::save()
|
|||
rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os);
|
||||
doc.Accept(writer);
|
||||
|
||||
fclose(fp);
|
||||
fflush(fp);
|
||||
|
||||
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
@ -129,6 +249,12 @@ bool xmrig::CommonConfig::finalize()
|
|||
pool.adjust(m_algorithm);
|
||||
|
||||
if (pool.isValid() && pool.algorithm().isValid()) {
|
||||
# ifdef XMRIG_NO_TLS
|
||||
if (pool.isTLS()) {
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
|
||||
m_activePools.push_back(std::move(pool));
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +286,10 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
|||
m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0);
|
||||
break;
|
||||
|
||||
case TlsKey: /* --tls */
|
||||
m_pools.back().setTLS(enable);
|
||||
break;
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
case NicehashKey: /* --nicehash */
|
||||
m_pools.back().setNicehash(enable);
|
||||
|
@ -182,7 +312,7 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
|||
m_apiRestricted = enable;
|
||||
break;
|
||||
|
||||
case IConfig::DryRunKey: /* --dry-run */
|
||||
case DryRunKey: /* --dry-run */
|
||||
m_dryRun = enable;
|
||||
break;
|
||||
|
||||
|
@ -190,6 +320,10 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
|||
m_calibrateAlgo = enable;
|
||||
break;
|
||||
|
||||
case AutoSaveKey:
|
||||
m_autoSave = enable;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -242,6 +376,10 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
|
|||
m_pools.back().setRigId(arg);
|
||||
break;
|
||||
|
||||
case FingerprintKey: /* --tls-fingerprint */
|
||||
m_pools.back().setFingerprint(arg);
|
||||
break;
|
||||
|
||||
case VariantKey: /* --variant */
|
||||
m_pools.back().algorithm().parseVariant(arg);
|
||||
break;
|
||||
|
@ -258,6 +396,10 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
|
|||
m_apiWorkerId = arg;
|
||||
break;
|
||||
|
||||
case ApiIdKey: /* --api-id */
|
||||
m_apiId = arg;
|
||||
break;
|
||||
|
||||
case UserAgentKey: /* --user-agent */
|
||||
m_userAgent = arg;
|
||||
break;
|
||||
|
@ -272,6 +414,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
|
|||
case SyslogKey: /* --syslog */
|
||||
case KeepAliveKey: /* --keepalive */
|
||||
case NicehashKey: /* --nicehash */
|
||||
case TlsKey: /* --tls */
|
||||
case ApiIPv6Key: /* --api-ipv6 */
|
||||
case DryRunKey: /* --dry-run */
|
||||
case CalibrateAlgoKey: /* --calibrate-algo */
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __COMMONCONFIG_H__
|
||||
#define __COMMONCONFIG_H__
|
||||
#ifndef XMRIG_COMMONCONFIG_H
|
||||
#define XMRIG_COMMONCONFIG_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
@ -42,16 +42,17 @@ class CommonConfig : public IConfig
|
|||
{
|
||||
public:
|
||||
CommonConfig();
|
||||
~CommonConfig();
|
||||
|
||||
inline bool isApiIPv6() const { return m_apiIPv6; }
|
||||
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||
inline bool isAutoSave() const { return m_autoSave; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isColors() const { return m_colors; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isCalibrateAlgo() const { return m_calibrateAlgo; }
|
||||
inline int calibrateAlgoTime() const { return m_calibrateAlgoTime; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *apiId() const { return m_apiId.data(); }
|
||||
inline const char *apiToken() const { return m_apiToken.data(); }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
|
||||
inline const char *logFile() const { return m_logFile.data(); }
|
||||
|
@ -71,6 +72,10 @@ public:
|
|||
|
||||
bool save() override;
|
||||
|
||||
void printAPI();
|
||||
void printPools();
|
||||
void printVersions();
|
||||
|
||||
protected:
|
||||
enum State {
|
||||
NoneState,
|
||||
|
@ -88,6 +93,7 @@ protected:
|
|||
bool m_adjusted;
|
||||
bool m_apiIPv6;
|
||||
bool m_apiRestricted;
|
||||
bool m_autoSave;
|
||||
bool m_background;
|
||||
bool m_colors;
|
||||
bool m_dryRun;
|
||||
|
@ -103,6 +109,7 @@ protected:
|
|||
State m_state;
|
||||
std::vector<Pool> m_activePools;
|
||||
std::vector<Pool> m_pools;
|
||||
xmrig::c_str m_apiId;
|
||||
xmrig::c_str m_apiToken;
|
||||
xmrig::c_str m_apiWorkerId;
|
||||
xmrig::c_str m_fileName;
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#endif
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_TLS
|
||||
# include <openssl/opensslv.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "common/config/ConfigLoader.h"
|
||||
#include "common/config/ConfigWatcher.h"
|
||||
#include "common/interfaces/IConfig.h"
|
||||
|
@ -313,6 +318,13 @@ void xmrig::ConfigLoader::showVersion()
|
|||
printf("\nlibuv/%s\n", uv_version_string());
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
printf("libmicrohttpd/%s\n", MHD_get_version());
|
||||
printf("microhttpd/%s\n", MHD_get_version());
|
||||
# endif
|
||||
|
||||
# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT)
|
||||
{
|
||||
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
|
||||
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
|
110
src/common/cpu/BasicCpuInfo.cpp
Normal file
110
src/common/cpu/BasicCpuInfo.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <intrin.h>
|
||||
#else
|
||||
# include <cpuid.h>
|
||||
#endif
|
||||
|
||||
#ifndef bit_AES
|
||||
# define bit_AES (1 << 25)
|
||||
#endif
|
||||
|
||||
|
||||
#include "common/cpu/BasicCpuInfo.h"
|
||||
|
||||
|
||||
#define VENDOR_ID (0)
|
||||
#define PROCESSOR_INFO (1)
|
||||
#define CACHE_TLB_DESCRIPTOR (2)
|
||||
#define EXTENDED_FEATURES (7)
|
||||
#define PROCESSOR_BRAND_STRING_1 (0x80000002)
|
||||
#define PROCESSOR_BRAND_STRING_2 (0x80000003)
|
||||
#define PROCESSOR_BRAND_STRING_3 (0x80000004)
|
||||
|
||||
#define EAX_Reg (0)
|
||||
#define EBX_Reg (1)
|
||||
#define ECX_Reg (2)
|
||||
#define EDX_Reg (3)
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static inline void cpuid(int level, int output[4]) {
|
||||
__cpuid(output, level);
|
||||
}
|
||||
#else
|
||||
static inline void cpuid(int level, int output[4]) {
|
||||
int a, b, c, d;
|
||||
__cpuid_count(level, 0, a, b, c, d);
|
||||
|
||||
output[0] = a;
|
||||
output[1] = b;
|
||||
output[2] = c;
|
||||
output[3] = d;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static inline void cpu_brand_string(char* s) {
|
||||
int cpu_info[4] = { 0 };
|
||||
cpuid(VENDOR_ID, cpu_info);
|
||||
|
||||
if (cpu_info[EAX_Reg] >= 4) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
cpuid(0x80000002 + i, cpu_info);
|
||||
memcpy(s, cpu_info, sizeof(cpu_info));
|
||||
s += 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline bool has_aes_ni()
|
||||
{
|
||||
int cpu_info[4] = { 0 };
|
||||
cpuid(PROCESSOR_INFO, cpu_info);
|
||||
|
||||
return (cpu_info[ECX_Reg] & bit_AES) != 0;
|
||||
}
|
||||
|
||||
|
||||
xmrig::BasicCpuInfo::BasicCpuInfo() :
|
||||
m_aes(has_aes_ni()),
|
||||
m_brand(),
|
||||
m_threads(std::thread::hardware_concurrency())
|
||||
{
|
||||
cpu_brand_string(m_brand);
|
||||
}
|
||||
|
||||
|
||||
size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
|
||||
{
|
||||
const size_t count = threads() / 2;
|
||||
|
||||
return count < 1 ? 1 : count;
|
||||
}
|
70
src/common/cpu/BasicCpuInfo.h
Normal file
70
src/common/cpu/BasicCpuInfo.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_BASICCPUINFO_H
|
||||
#define XMRIG_BASICCPUINFO_H
|
||||
|
||||
|
||||
#include "common/interfaces/ICpuInfo.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class BasicCpuInfo : public ICpuInfo
|
||||
{
|
||||
public:
|
||||
BasicCpuInfo();
|
||||
|
||||
protected:
|
||||
size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const override;
|
||||
|
||||
inline Assembly assembly() const override { return ASM_NONE; }
|
||||
inline bool hasAES() const override { return m_aes; }
|
||||
inline bool isSupported() const override { return true; }
|
||||
inline const char *brand() const override { return m_brand; }
|
||||
inline int32_t cores() const override { return -1; }
|
||||
inline int32_t L2() const override { return -1; }
|
||||
inline int32_t L3() const override { return -1; }
|
||||
inline int32_t nodes() const override { return -1; }
|
||||
inline int32_t sockets() const override { return 1; }
|
||||
inline int32_t threads() const override { return m_threads; }
|
||||
|
||||
# if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__)
|
||||
inline bool isX64() const override { return true; }
|
||||
# else
|
||||
inline bool isX64() const override { return false; }
|
||||
# endif
|
||||
|
||||
private:
|
||||
bool m_aes;
|
||||
char m_brand[64];
|
||||
int32_t m_threads;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_BASICCPUINFO_H */
|
47
src/common/cpu/BasicCpuInfo_arm.cpp
Normal file
47
src/common/cpu/BasicCpuInfo_arm.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "common/cpu/BasicCpuInfo.h"
|
||||
|
||||
|
||||
xmrig::BasicCpuInfo::BasicCpuInfo() :
|
||||
m_aes(false),
|
||||
m_brand(),
|
||||
m_threads(std::thread::hardware_concurrency())
|
||||
{
|
||||
memcpy(m_brand, "Unknown", 7);
|
||||
|
||||
# if __ARM_FEATURE_CRYPTO
|
||||
m_aes = true;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
size_t xmrig::BasicCpuInfo::optimalThreadsCount(size_t memSize, int maxCpuUsage) const
|
||||
{
|
||||
return threads();
|
||||
}
|
57
src/common/cpu/Cpu.cpp
Normal file
57
src/common/cpu/Cpu.cpp
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 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "common/cpu/BasicCpuInfo.h"
|
||||
#include "common/cpu/Cpu.h"
|
||||
|
||||
|
||||
static xmrig::ICpuInfo *cpuInfo = nullptr;
|
||||
|
||||
|
||||
xmrig::ICpuInfo *xmrig::Cpu::info()
|
||||
{
|
||||
assert(cpuInfo != nullptr);
|
||||
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Cpu::init()
|
||||
{
|
||||
assert(cpuInfo == nullptr);
|
||||
|
||||
cpuInfo = new BasicCpuInfo();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Cpu::release()
|
||||
{
|
||||
assert(cpuInfo != nullptr);
|
||||
|
||||
delete cpuInfo;
|
||||
cpuInfo = nullptr;
|
||||
}
|
46
src/common/cpu/Cpu.h
Normal file
46
src/common/cpu/Cpu.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_CPU_H
|
||||
#define XMRIG_CPU_H
|
||||
|
||||
|
||||
#include "common/interfaces/ICpuInfo.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Cpu
|
||||
{
|
||||
public:
|
||||
static ICpuInfo *info();
|
||||
static void init();
|
||||
static void release();
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_CPU_H */
|
|
@ -6,6 +6,7 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -61,6 +62,7 @@ static AlgoData const algorithms[] = {
|
|||
{ "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR },
|
||||
{ "cryptonight/xao", "cn/xao", xmrig::CRYPTONIGHT, xmrig::VARIANT_XAO },
|
||||
{ "cryptonight/rto", "cn/rto", xmrig::CRYPTONIGHT, xmrig::VARIANT_RTO },
|
||||
{ "cryptonight/2", "cn/2", xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
|
||||
|
@ -82,6 +84,8 @@ static AlgoData const algorithms[] = {
|
|||
static AlgoData const xmrStakAlgorithms[] = {
|
||||
{ "cryptonight-monerov7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
|
||||
{ "cryptonight_v7", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
|
||||
{ "cryptonight-monerov8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||
{ "cryptonight_v8", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_2 },
|
||||
{ "cryptonight_v7_stellite", nullptr, xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
|
||||
{ "cryptonight_lite", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
|
||||
{ "cryptonight-aeonv7", nullptr, xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
|
||||
|
@ -104,7 +108,8 @@ static const char *variants[] = {
|
|||
"msr",
|
||||
"xhv",
|
||||
"xao",
|
||||
"rto"
|
||||
"rto",
|
||||
"2",
|
||||
};
|
||||
|
||||
|
||||
|
@ -173,11 +178,21 @@ void xmrig::Algorithm::parseVariant(const char *variant)
|
|||
|
||||
void xmrig::Algorithm::parseVariant(int variant)
|
||||
{
|
||||
if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) {
|
||||
m_variant = static_cast<Variant>(variant);
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
assert(variant >= -1 && variant <= 2);
|
||||
|
||||
switch (variant) {
|
||||
case -1:
|
||||
case 0:
|
||||
case 1:
|
||||
m_variant = static_cast<Variant>(variant);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
m_variant = VARIANT_2;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -23,8 +24,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ALGORITHM_H__
|
||||
#define __ALGORITHM_H__
|
||||
#ifndef XMRIG_ALGORITHM_H
|
||||
#define XMRIG_ALGORITHM_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef KECCAK_H_
|
||||
#define KECCAK_H_
|
||||
#ifndef XMRIG_KECCAK_H
|
||||
#define XMRIG_KECCAK_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
@ -41,9 +41,15 @@ inline void keccak(const uint8_t *in, size_t inlen, uint8_t *md)
|
|||
keccak(in, static_cast<int>(inlen), md, 200);
|
||||
}
|
||||
|
||||
|
||||
inline void keccak(const char *in, size_t inlen, uint8_t *md)
|
||||
{
|
||||
keccak(reinterpret_cast<const uint8_t *>(in), static_cast<int>(inlen), md, 200);
|
||||
}
|
||||
|
||||
// update the state
|
||||
void keccakf(uint64_t st[25], int norounds);
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* KECCAK_H_ */
|
||||
#endif /* XMRIG_KECCAK_H */
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ICONFIG_H__
|
||||
#define __ICONFIG_H__
|
||||
#ifndef XMRIG_ICONFIG_H
|
||||
#define XMRIG_ICONFIG_H
|
||||
|
||||
|
||||
#include "common/crypto/Algorithm.h"
|
||||
|
@ -43,6 +43,7 @@ public:
|
|||
ApiPort = 4000,
|
||||
ApiRestrictedKey = 4004,
|
||||
ApiWorkerIdKey = 4002,
|
||||
ApiIdKey = 4005,
|
||||
BackgroundKey = 'B',
|
||||
ColorKey = 1002,
|
||||
ConfigKey = 'c',
|
||||
|
@ -63,6 +64,9 @@ public:
|
|||
VerboseKey = 1100,
|
||||
VersionKey = 'V',
|
||||
WatchKey = 1105,
|
||||
TlsKey = 1013,
|
||||
FingerprintKey = 1014,
|
||||
AutoSaveKey = 1016,
|
||||
|
||||
// xmrig common
|
||||
CPUPriorityKey = 1021,
|
||||
|
@ -80,12 +84,20 @@ public:
|
|||
SafeKey = 1005,
|
||||
ThreadsKey = 't',
|
||||
HardwareAESKey = 1011,
|
||||
AssemblyKey = 1015,
|
||||
|
||||
// xmrig amd
|
||||
OclPlatform = 1400,
|
||||
OclAffinity = 1401,
|
||||
OclDevices = 1402,
|
||||
OclLaunch = 1403,
|
||||
OclPlatformKey = 1400,
|
||||
OclAffinityKey = 1401,
|
||||
OclDevicesKey = 1402,
|
||||
OclLaunchKey = 1403,
|
||||
OclCacheKey = 1404,
|
||||
OclPrintKey = 1405,
|
||||
OclLoaderKey = 1406,
|
||||
OclSridedIndexKey = 1407,
|
||||
OclMemChunkKey = 1408,
|
||||
OclUnrollKey = 1409,
|
||||
OclCompModeKey = 1410,
|
||||
|
||||
// xmrig-proxy
|
||||
AccessLogFileKey = 'A',
|
||||
|
@ -97,6 +109,16 @@ public:
|
|||
PoolCoinKey = 'C',
|
||||
ReuseTimeoutKey = 1106,
|
||||
WorkersKey = 1103,
|
||||
WorkersAdvKey = 1107,
|
||||
|
||||
// xmrig nvidia
|
||||
CudaMaxThreadsKey = 1200,
|
||||
CudaBFactorKey = 1201,
|
||||
CudaBSleepKey = 1202,
|
||||
CudaDevicesKey = 1203,
|
||||
CudaLaunchKey = 1204,
|
||||
CudaAffinityKey = 1205,
|
||||
CudaMaxUsageKey = 1206,
|
||||
};
|
||||
|
||||
virtual ~IConfig() {}
|
||||
|
@ -118,4 +140,4 @@ public:
|
|||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONFIG_H__
|
||||
#endif // XMRIG_ICONFIG_H
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ICONTROLLERLISTENER_H__
|
||||
#define __ICONTROLLERLISTENER_H__
|
||||
#ifndef XMRIG_ICONTROLLERLISTENER_H
|
||||
#define XMRIG_ICONTROLLERLISTENER_H
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -43,4 +43,4 @@ public:
|
|||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONTROLLERLISTENER_H__
|
||||
#endif // XMRIG_ICONTROLLERLISTENER_H
|
||||
|
|
60
src/common/interfaces/ICpuInfo.h
Normal file
60
src/common/interfaces/ICpuInfo.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_CPUINFO_H
|
||||
#define XMRIG_CPUINFO_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "common/xmrig.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ICpuInfo
|
||||
{
|
||||
public:
|
||||
virtual ~ICpuInfo() {}
|
||||
|
||||
virtual bool hasAES() const = 0;
|
||||
virtual bool isSupported() const = 0;
|
||||
virtual bool isX64() const = 0;
|
||||
virtual const char *brand() const = 0;
|
||||
virtual int32_t cores() const = 0;
|
||||
virtual int32_t L2() const = 0;
|
||||
virtual int32_t L3() const = 0;
|
||||
virtual int32_t nodes() const = 0;
|
||||
virtual int32_t sockets() const = 0;
|
||||
virtual int32_t threads() const = 0;
|
||||
virtual size_t optimalThreadsCount(size_t memSize, int maxCpuUsage) const = 0;
|
||||
virtual xmrig::Assembly assembly() const = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // XMRIG_CPUINFO_H
|
89
src/common/log/BasicLog.cpp
Normal file
89
src/common/log/BasicLog.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "common/log/BasicLog.h"
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
BasicLog::BasicLog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BasicLog::message(Level level, const char* fmt, va_list args)
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
tm stime;
|
||||
|
||||
# ifdef _WIN32
|
||||
localtime_s(&stime, &now);
|
||||
# else
|
||||
localtime_r(&now, &stime);
|
||||
# endif
|
||||
|
||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
|
||||
stime.tm_year + 1900,
|
||||
stime.tm_mon + 1,
|
||||
stime.tm_mday,
|
||||
stime.tm_hour,
|
||||
stime.tm_min,
|
||||
stime.tm_sec,
|
||||
Log::colorByLevel(level, false),
|
||||
fmt,
|
||||
Log::endl(false)
|
||||
);
|
||||
|
||||
print(args);
|
||||
}
|
||||
|
||||
|
||||
void BasicLog::text(const char* fmt, va_list args)
|
||||
{
|
||||
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false));
|
||||
|
||||
print(args);
|
||||
}
|
||||
|
||||
|
||||
void BasicLog::print(va_list args)
|
||||
{
|
||||
if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
fputs(m_buf, stdout);
|
||||
fflush(stdout);
|
||||
}
|
55
src/common/log/BasicLog.h
Normal file
55
src/common/log/BasicLog.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 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 __BASICLOG_H__
|
||||
#define __BASICLOG_H__
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "common/interfaces/ILogBackend.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class BasicLog : public ILogBackend
|
||||
{
|
||||
public:
|
||||
BasicLog();
|
||||
|
||||
void message(Level level, const char *fmt, va_list args) override;
|
||||
void text(const char *fmt, va_list args) override;
|
||||
|
||||
private:
|
||||
bool isWritable() const;
|
||||
void print(va_list args);
|
||||
|
||||
char m_buf[kBufferSize];
|
||||
char m_fmt[256];
|
||||
};
|
||||
|
||||
#endif /* __BASICLOG_H__ */
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
|
||||
#include "common/interfaces/ILogBackend.h"
|
||||
#include "common/log/BasicLog.h"
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
|
@ -109,6 +110,14 @@ const char *Log::endl(bool isColors)
|
|||
}
|
||||
|
||||
|
||||
void Log::defaultInit()
|
||||
{
|
||||
m_self = new Log();
|
||||
|
||||
add(new BasicLog());
|
||||
}
|
||||
|
||||
|
||||
Log::~Log()
|
||||
{
|
||||
for (auto backend : m_backends) {
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
class Log
|
||||
{
|
||||
public:
|
||||
static inline Log* i() { assert(m_self != nullptr); return m_self; }
|
||||
static inline Log* i() { if (!m_self) { defaultInit(); } return m_self; }
|
||||
static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); }
|
||||
static inline void init() { if (!m_self) { new Log(); } }
|
||||
static inline void release() { assert(m_self != nullptr); delete m_self; }
|
||||
|
@ -46,6 +46,7 @@ public:
|
|||
|
||||
static const char *colorByLevel(ILogBackend::Level level, bool isColors = true);
|
||||
static const char *endl(bool isColors = true);
|
||||
static void defaultInit();
|
||||
|
||||
private:
|
||||
inline Log() {
|
||||
|
@ -68,6 +69,8 @@ private:
|
|||
#define RED(x) "\x1B[0;31m" x "\x1B[0m"
|
||||
#define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m"
|
||||
#define GREEN(x) "\x1B[0;32m" x "\x1B[0m"
|
||||
#define YELLOW(x) "\x1B[0;33m" x "\x1B[0m"
|
||||
#define YELLOW_BOLD(x) "\x1B[1;33m" x "\x1B[0m"
|
||||
#define MAGENTA_BOLD(x) "\x1B[1;35m" x "\x1B[0m"
|
||||
#define MAGENTA(x) "\x1B[0;35m" x "\x1B[0m"
|
||||
#define CYAN_BOLD(x) "\x1B[1;36m" x "\x1B[0m"
|
||||
|
|
|
@ -30,6 +30,13 @@
|
|||
#include <utility>
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_TLS
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
# include "common/net/Tls.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "common/interfaces/IClientListener.h"
|
||||
#include "common/log/Log.h"
|
||||
#include "common/net/Client.h"
|
||||
|
@ -51,6 +58,17 @@ int64_t Client::m_sequence = 1;
|
|||
xmrig::Storage<Client> Client::m_storage;
|
||||
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
static const char *states[] = {
|
||||
"unconnected",
|
||||
"host-lookup",
|
||||
"connecting",
|
||||
"connected",
|
||||
"closing"
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
m_ipv6(false),
|
||||
m_nicehash(false),
|
||||
|
@ -64,6 +82,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
|
|||
m_failures(0),
|
||||
m_recvBufPos(0),
|
||||
m_state(UnconnectedState),
|
||||
m_tls(nullptr),
|
||||
m_expire(0),
|
||||
m_jobs(0),
|
||||
m_keepAlive(0),
|
||||
|
@ -95,6 +114,12 @@ Client::~Client()
|
|||
|
||||
void Client::connect()
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (m_pool.isTLS()) {
|
||||
m_tls = new Tls(this);
|
||||
}
|
||||
# endif
|
||||
|
||||
resolve(m_pool.host());
|
||||
}
|
||||
|
||||
|
@ -125,6 +150,7 @@ void Client::deleteLater()
|
|||
}
|
||||
|
||||
|
||||
|
||||
void Client::setPool(const Pool &pool)
|
||||
{
|
||||
if (!pool.isValid()) {
|
||||
|
@ -163,6 +189,30 @@ bool Client::disconnect()
|
|||
}
|
||||
|
||||
|
||||
const char *Client::tlsFingerprint() const
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (isTLS() && m_pool.fingerprint() == nullptr) {
|
||||
return m_tls->fingerprint();
|
||||
}
|
||||
# endif
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const char *Client::tlsVersion() const
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (isTLS()) {
|
||||
return m_tls->version();
|
||||
}
|
||||
# endif
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
int64_t Client::submit(const JobResult &result)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
@ -248,6 +298,16 @@ bool Client::isCriticalError(const char *message)
|
|||
}
|
||||
|
||||
|
||||
bool Client::isTLS() const
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
return m_pool.isTLS() && m_tls;
|
||||
# else
|
||||
return false;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
||||
{
|
||||
if (!params.IsObject()) {
|
||||
|
@ -276,16 +336,16 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
const rapidjson::Value &variant = params["variant"];
|
||||
|
||||
if (variant.IsInt()) {
|
||||
job.algorithm().parseVariant(variant.GetInt());
|
||||
job.setVariant(variant.GetInt());
|
||||
}
|
||||
else if (variant.IsString()){
|
||||
job.algorithm().parseVariant(variant.GetString());
|
||||
job.setVariant(variant.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
// moved algo after variant parsing to override variant that is considered to be outdated now
|
||||
if (params.HasMember("algo")) {
|
||||
job.algorithm().parseAlgorithm(params["algo"].GetString());
|
||||
job.setAlgorithm(params["algo"].GetString());
|
||||
}
|
||||
|
||||
if (!verifyAlgorithm(job.algorithm())) {
|
||||
|
@ -337,6 +397,39 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code)
|
|||
}
|
||||
|
||||
|
||||
bool Client::send(BIO *bio)
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
uv_buf_t buf;
|
||||
buf.len = BIO_get_mem_data(bio, &buf.base);
|
||||
|
||||
if (buf.len == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_DEBUG("[%s] TLS send (%d bytes)", m_pool.url(), static_cast<int>(buf.len));
|
||||
|
||||
bool result = false;
|
||||
if (state() == ConnectedState && uv_is_writable(m_stream)) {
|
||||
result = uv_try_write(m_stream, &buf, 1) > 0;
|
||||
|
||||
if (!result) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state);
|
||||
}
|
||||
|
||||
(void) BIO_reset(bio);
|
||||
|
||||
return result;
|
||||
# else
|
||||
return false;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const
|
||||
{
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
|
@ -396,7 +489,9 @@ int64_t Client::send(const rapidjson::Document &doc)
|
|||
doc.Accept(writer);
|
||||
|
||||
const size_t size = buffer.GetSize();
|
||||
if (size > (sizeof(m_buf) - 2)) {
|
||||
if (size > (sizeof(m_sendBuf) - 2)) {
|
||||
LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", m_pool.url(), size, (sizeof(m_sendBuf) - 2));
|
||||
close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -411,16 +506,27 @@ int64_t Client::send(const rapidjson::Document &doc)
|
|||
int64_t Client::send(size_t size)
|
||||
{
|
||||
LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf);
|
||||
if (state() != ConnectedState || !uv_is_writable(m_stream)) {
|
||||
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state);
|
||||
return -1;
|
||||
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (isTLS()) {
|
||||
if (!m_tls->send(m_sendBuf, size)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
if (state() != ConnectedState || !uv_is_writable(m_stream)) {
|
||||
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", m_pool.url(), m_state);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size);
|
||||
uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size);
|
||||
|
||||
if (uv_try_write(m_stream, &buf, 1) < 0) {
|
||||
close();
|
||||
return -1;
|
||||
if (uv_try_write(m_stream, &buf, 1) < 0) {
|
||||
close();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
m_expire = uv_now(uv_default_loop()) + kResponseTimeout;
|
||||
|
@ -470,6 +576,22 @@ void Client::connect(sockaddr *addr)
|
|||
}
|
||||
|
||||
|
||||
void Client::handshake()
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (isTLS()) {
|
||||
m_expire = uv_now(uv_default_loop()) + kResponseTimeout;
|
||||
|
||||
m_tls->handshake();
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
login();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Client::login()
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
@ -528,6 +650,13 @@ void Client::onClose()
|
|||
m_socket = nullptr;
|
||||
setState(UnconnectedState);
|
||||
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (m_tls) {
|
||||
delete m_tls;
|
||||
m_tls = nullptr;
|
||||
}
|
||||
# endif
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
@ -682,6 +811,35 @@ void Client::ping()
|
|||
}
|
||||
|
||||
|
||||
void Client::read()
|
||||
{
|
||||
char* end;
|
||||
char* start = m_recvBuf.base;
|
||||
size_t remaining = m_recvBufPos;
|
||||
|
||||
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
|
||||
end++;
|
||||
size_t len = end - start;
|
||||
parse(start, len);
|
||||
|
||||
remaining -= len;
|
||||
start = end;
|
||||
}
|
||||
|
||||
if (remaining == 0) {
|
||||
m_recvBufPos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (start == m_recvBuf.base) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(m_recvBuf.base, start, remaining);
|
||||
m_recvBufPos = remaining;
|
||||
}
|
||||
|
||||
|
||||
void Client::reconnect()
|
||||
{
|
||||
if (!m_listener) {
|
||||
|
@ -706,7 +864,7 @@ void Client::reconnect()
|
|||
|
||||
void Client::setState(SocketState state)
|
||||
{
|
||||
LOG_DEBUG("[%s] state: %d", m_pool.url(), state);
|
||||
LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]);
|
||||
|
||||
if (m_state == state) {
|
||||
return;
|
||||
|
@ -774,7 +932,7 @@ void Client::onConnect(uv_connect_t *req, int status)
|
|||
uv_read_start(client->m_stream, Client::onAllocBuffer, Client::onRead);
|
||||
delete req;
|
||||
|
||||
client->login();
|
||||
client->handshake();
|
||||
}
|
||||
|
||||
|
||||
|
@ -806,30 +964,18 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
|||
|
||||
client->m_recvBufPos += nread;
|
||||
|
||||
char* end;
|
||||
char* start = client->m_recvBuf.base;
|
||||
size_t remaining = client->m_recvBufPos;
|
||||
# ifndef XMRIG_NO_TLS
|
||||
if (client->isTLS()) {
|
||||
LOG_DEBUG("[%s] TLS received (%d bytes)", client->m_pool.url(), static_cast<int>(nread));
|
||||
|
||||
while ((end = static_cast<char*>(memchr(start, '\n', remaining))) != nullptr) {
|
||||
end++;
|
||||
size_t len = end - start;
|
||||
client->parse(start, len);
|
||||
|
||||
remaining -= len;
|
||||
start = end;
|
||||
}
|
||||
|
||||
if (remaining == 0) {
|
||||
client->m_tls->read(client->m_recvBuf.base, client->m_recvBufPos);
|
||||
client->m_recvBufPos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (start == client->m_recvBuf.base) {
|
||||
return;
|
||||
else
|
||||
# endif
|
||||
{
|
||||
client->read();
|
||||
}
|
||||
|
||||
memcpy(client->m_recvBuf.base, start, remaining);
|
||||
client->m_recvBufPos = remaining;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CLIENT_H__
|
||||
#define __CLIENT_H__
|
||||
#ifndef XMRIG_CLIENT_H
|
||||
#define XMRIG_CLIENT_H
|
||||
|
||||
|
||||
#include <map>
|
||||
|
@ -44,6 +44,9 @@ class IClientListener;
|
|||
class JobResult;
|
||||
|
||||
|
||||
typedef struct bio_st BIO;
|
||||
|
||||
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
|
@ -55,12 +58,20 @@ public:
|
|||
ClosingState
|
||||
};
|
||||
|
||||
constexpr static int kResponseTimeout = 20 * 1000;
|
||||
constexpr static int kResponseTimeout = 20 * 1000;
|
||||
|
||||
# ifndef XMRIG_NO_TLS
|
||||
constexpr static int kInputBufferSize = 1024 * 16;
|
||||
# else
|
||||
constexpr static int kInputBufferSize = 1024 * 2;
|
||||
# endif
|
||||
|
||||
Client(int id, const char *agent, IClientListener *listener);
|
||||
~Client();
|
||||
|
||||
bool disconnect();
|
||||
const char *tlsFingerprint() const;
|
||||
const char *tlsVersion() const;
|
||||
int64_t submit(const JobResult &result);
|
||||
void connect();
|
||||
void connect(const Pool &pool);
|
||||
|
@ -80,6 +91,9 @@ public:
|
|||
inline void setRetryPause(int ms) { m_retryPause = ms; }
|
||||
|
||||
private:
|
||||
class Tls;
|
||||
|
||||
|
||||
enum Extensions {
|
||||
NicehashExt = 1,
|
||||
AlgoExt = 2
|
||||
|
@ -87,14 +101,17 @@ private:
|
|||
|
||||
bool close();
|
||||
bool isCriticalError(const char *message);
|
||||
bool isTLS() const;
|
||||
bool parseJob(const rapidjson::Value ¶ms, int *code);
|
||||
bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
bool send(BIO *bio);
|
||||
bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const;
|
||||
int resolve(const char *host);
|
||||
int64_t send(const rapidjson::Document &doc);
|
||||
int64_t send(size_t size);
|
||||
void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
|
||||
void connect(sockaddr *addr);
|
||||
void handshake();
|
||||
void login();
|
||||
void onClose();
|
||||
void parse(char *line, size_t len);
|
||||
|
@ -102,6 +119,7 @@ private:
|
|||
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 ping();
|
||||
void read();
|
||||
void reconnect();
|
||||
void setState(SocketState state);
|
||||
void startTimeout();
|
||||
|
@ -120,9 +138,9 @@ private:
|
|||
bool m_ipv6;
|
||||
bool m_nicehash;
|
||||
bool m_quiet;
|
||||
char m_buf[2048];
|
||||
char m_buf[kInputBufferSize];
|
||||
char m_ip[46];
|
||||
char m_sendBuf[768];
|
||||
char m_sendBuf[2048];
|
||||
const char *m_agent;
|
||||
IClientListener *m_listener;
|
||||
int m_extensions;
|
||||
|
@ -135,6 +153,7 @@ private:
|
|||
size_t m_recvBufPos;
|
||||
SocketState m_state;
|
||||
std::map<int64_t, SubmitResult> m_results;
|
||||
Tls *m_tls;
|
||||
uint64_t m_expire;
|
||||
uint64_t m_jobs;
|
||||
uint64_t m_keepAlive;
|
||||
|
@ -150,4 +169,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#endif /* __CLIENT_H__ */
|
||||
#endif /* XMRIG_CLIENT_H */
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -59,6 +60,7 @@ static inline char hf_bin2hex(unsigned char c)
|
|||
|
||||
|
||||
Job::Job() :
|
||||
m_autoVariant(false),
|
||||
m_nicehash(false),
|
||||
m_poolId(-2),
|
||||
m_threadId(-1),
|
||||
|
@ -70,7 +72,8 @@ Job::Job() :
|
|||
}
|
||||
|
||||
|
||||
Job::Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId) :
|
||||
Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) :
|
||||
m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO),
|
||||
m_nicehash(nicehash),
|
||||
m_poolId(poolId),
|
||||
m_threadId(-1),
|
||||
|
@ -113,6 +116,10 @@ bool Job::setBlob(const char *blob)
|
|||
m_nicehash = true;
|
||||
}
|
||||
|
||||
if (m_autoVariant) {
|
||||
m_algorithm.setVariant(variant());
|
||||
}
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
memset(m_rawBlob, 0, sizeof(m_rawBlob));
|
||||
memcpy(m_rawBlob, blob, m_size * 2);
|
||||
|
@ -170,25 +177,13 @@ bool Job::setTarget(const char *target)
|
|||
}
|
||||
|
||||
|
||||
xmrig::Variant Job::variant() const
|
||||
void Job::setAlgorithm(const char *algo)
|
||||
{
|
||||
if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) {
|
||||
return xmrig::VARIANT_1;
|
||||
}
|
||||
|
||||
if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) {
|
||||
return xmrig::VARIANT_1;
|
||||
}
|
||||
|
||||
if (m_algorithm.variant() == xmrig::VARIANT_XHV && m_blob[0] < 3) {
|
||||
return xmrig::VARIANT_0;
|
||||
}
|
||||
m_algorithm.parseAlgorithm(algo);
|
||||
|
||||
if (m_algorithm.variant() == xmrig::VARIANT_AUTO) {
|
||||
return m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY ? xmrig::VARIANT_0 : xmrig::VARIANT_1;
|
||||
m_algorithm.setVariant(variant());
|
||||
}
|
||||
|
||||
return m_algorithm.variant();
|
||||
}
|
||||
|
||||
|
||||
|
@ -236,3 +231,25 @@ bool Job::operator!=(const Job &other) const
|
|||
{
|
||||
return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Variant Job::variant() const
|
||||
{
|
||||
using namespace xmrig;
|
||||
|
||||
switch (m_algorithm.algo()) {
|
||||
case CRYPTONIGHT:
|
||||
return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return VARIANT_1;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return VARIANT_0;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return m_algorithm.variant();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -23,8 +24,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __JOB_H__
|
||||
#define __JOB_H__
|
||||
#ifndef XMRIG_JOB_H
|
||||
#define XMRIG_JOB_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
|
@ -39,7 +40,7 @@ class Job
|
|||
{
|
||||
public:
|
||||
Job();
|
||||
Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId);
|
||||
Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId);
|
||||
~Job();
|
||||
|
||||
bool setBlob(const char *blob);
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
bool setTarget(const char *target);
|
||||
// for algo benchmarking to set PoW variant
|
||||
void setAlgorithm(const xmrig::Algorithm& algorithm) { m_algorithm = algorithm; }
|
||||
xmrig::Variant variant() const;
|
||||
void setAlgorithm(const char *algo);
|
||||
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
|
@ -67,7 +68,8 @@ public:
|
|||
inline void setClientId(const xmrig::Id &id) { m_clientId = id; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); }
|
||||
inline void setVariant(int variant) { m_algorithm.parseVariant(variant); }
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
|
@ -87,6 +89,7 @@ public:
|
|||
bool operator!=(const Job &other) const;
|
||||
|
||||
private:
|
||||
bool m_autoVariant;
|
||||
bool m_nicehash;
|
||||
int m_poolId;
|
||||
int m_threadId;
|
||||
|
@ -104,4 +107,4 @@ private:
|
|||
# endif
|
||||
};
|
||||
|
||||
#endif /* __JOB_H__ */
|
||||
#endif /* XMRIG_JOB_H */
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -46,11 +47,13 @@
|
|||
|
||||
Pool::Pool() :
|
||||
m_nicehash(false),
|
||||
m_tls(false),
|
||||
m_keepAlive(0),
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
// here xmrig now resuts all possible supported algorithms
|
||||
m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_1));
|
||||
m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_2));
|
||||
m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_0));
|
||||
m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL));
|
||||
m_algorithms.push_back(xmrig::Algorithm(xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR));
|
||||
|
@ -79,6 +82,7 @@ Pool::Pool() :
|
|||
*/
|
||||
Pool::Pool(const char *url) :
|
||||
m_nicehash(false),
|
||||
m_tls(false),
|
||||
m_keepAlive(0),
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
|
@ -86,8 +90,9 @@ Pool::Pool(const char *url) :
|
|||
}
|
||||
|
||||
|
||||
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash) :
|
||||
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) :
|
||||
m_nicehash(nicehash),
|
||||
m_tls(tls),
|
||||
m_keepAlive(keepAlive),
|
||||
m_port(port),
|
||||
m_host(host),
|
||||
|
@ -128,15 +133,17 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
|
|||
|
||||
bool Pool::isEqual(const Pool &other) const
|
||||
{
|
||||
return (m_nicehash == other.m_nicehash
|
||||
&& m_keepAlive == other.m_keepAlive
|
||||
&& m_port == other.m_port
|
||||
&& m_algorithm == other.m_algorithm
|
||||
&& m_host == other.m_host
|
||||
&& m_password == other.m_password
|
||||
&& m_rigId == other.m_rigId
|
||||
&& m_url == other.m_url
|
||||
&& m_user == other.m_user);
|
||||
return (m_nicehash == other.m_nicehash
|
||||
&& m_tls == other.m_tls
|
||||
&& m_keepAlive == other.m_keepAlive
|
||||
&& m_port == other.m_port
|
||||
&& m_algorithm == other.m_algorithm
|
||||
&& m_fingerprint == other.m_fingerprint
|
||||
&& m_host == other.m_host
|
||||
&& m_password == other.m_password
|
||||
&& m_rigId == other.m_rigId
|
||||
&& m_url == other.m_url
|
||||
&& m_user == other.m_user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -148,7 +155,13 @@ bool Pool::parse(const char *url)
|
|||
const char *base = url;
|
||||
|
||||
if (p) {
|
||||
if (strncasecmp(url, "stratum+tcp://", 14)) {
|
||||
if (strncasecmp(url, "stratum+tcp://", 14) == 0) {
|
||||
m_tls = false;
|
||||
}
|
||||
else if (strncasecmp(url, "stratum+ssl://", 14) == 0) {
|
||||
m_tls = true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -227,6 +240,7 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
|||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_0:
|
||||
case xmrig::VARIANT_1:
|
||||
case xmrig::VARIANT_2:
|
||||
obj.AddMember("variant", m_algorithm.variant(), allocator);
|
||||
break;
|
||||
|
||||
|
@ -235,6 +249,9 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
|||
break;
|
||||
}
|
||||
|
||||
obj.AddMember("tls", isTLS(), allocator);
|
||||
obj.AddMember("tls-fingerprint", fingerprint() ? Value(StringRef(fingerprint())).Move() : Value(kNullType).Move(), allocator);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -353,7 +370,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint)
|
|||
if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) {
|
||||
m_algorithm.setVariant(VARIANT_0);
|
||||
}
|
||||
else {
|
||||
else if (m_algorithm.algo() == CRYPTONIGHT_LITE) {
|
||||
m_algorithm.setVariant(VARIANT_1);
|
||||
}
|
||||
# endif
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018 MoneroOcean <https://github.com/MoneroOcean>, <support@moneroocean.stream>
|
||||
*
|
||||
|
@ -22,8 +23,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __POOL_H__
|
||||
#define __POOL_H__
|
||||
#ifndef XMRIG_POOL_H
|
||||
#define XMRIG_POOL_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
@ -45,30 +46,35 @@ public:
|
|||
Pool();
|
||||
Pool(const char *url);
|
||||
Pool(const char *host,
|
||||
uint16_t port,
|
||||
const char *user = nullptr,
|
||||
const char *password = nullptr,
|
||||
int keepAlive = 0,
|
||||
bool nicehash = false
|
||||
uint16_t port,
|
||||
const char *user = nullptr,
|
||||
const char *password = nullptr,
|
||||
int keepAlive = 0,
|
||||
bool nicehash = false,
|
||||
bool tls = false
|
||||
);
|
||||
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||
inline const char *host() const { return m_host.data(); }
|
||||
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; }
|
||||
inline const char *rigId() const { return m_rigId.data(); }
|
||||
inline const char *url() const { return m_url.data(); }
|
||||
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const xmrig::Algorithms &algorithms() const { return m_algorithms; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPassword(const char *password) { m_password = password; }
|
||||
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||
inline void setUser(const char *user) { m_user = user; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isTLS() const { return m_tls; }
|
||||
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||
inline const char *fingerprint() const { return m_fingerprint.data(); }
|
||||
inline const char *host() const { return m_host.data(); }
|
||||
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; }
|
||||
inline const char *rigId() const { return m_rigId.data(); }
|
||||
inline const char *url() const { return m_url.data(); }
|
||||
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const xmrig::Algorithms &algorithms() const { return m_algorithms; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPassword(const char *password) { m_password = password; }
|
||||
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||
inline void setTLS(bool tls) { m_tls = tls; }
|
||||
inline void setUser(const char *user) { m_user = user; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
|
||||
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Pool &other) const { return isEqual(other); }
|
||||
|
@ -89,10 +95,12 @@ private:
|
|||
void adjustVariant(const xmrig::Variant variantHint);
|
||||
|
||||
bool m_nicehash;
|
||||
bool m_tls;
|
||||
int m_keepAlive;
|
||||
uint16_t m_port;
|
||||
xmrig::Algorithm m_algorithm;
|
||||
xmrig::Algorithms m_algorithms;
|
||||
xmrig::c_str m_fingerprint;
|
||||
xmrig::c_str m_host;
|
||||
xmrig::c_str m_password;
|
||||
xmrig::c_str m_rigId;
|
||||
|
@ -103,4 +111,4 @@ private:
|
|||
|
||||
typedef std::vector<Pool> Pools;
|
||||
|
||||
#endif /* __POOL_H__ */
|
||||
#endif /* XMRIG_POOL_H */
|
||||
|
|
190
src/common/net/Tls.cpp
Normal file
190
src/common/net/Tls.cpp
Normal file
|
@ -0,0 +1,190 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "common/net/Client.h"
|
||||
#include "common/net/Tls.h"
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define strncasecmp(x,y,z) _strnicmp(x,y,z)
|
||||
#endif
|
||||
|
||||
|
||||
Client::Tls::Tls(Client *client) :
|
||||
m_ready(false),
|
||||
m_buf(),
|
||||
m_fingerprint(),
|
||||
m_client(client),
|
||||
m_ssl(nullptr)
|
||||
{
|
||||
m_ctx = SSL_CTX_new(SSLv23_method());
|
||||
assert(m_ctx != nullptr);
|
||||
|
||||
if (!m_ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_writeBio = BIO_new(BIO_s_mem());
|
||||
m_readBio = BIO_new(BIO_s_mem());
|
||||
SSL_CTX_set_options(m_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
|
||||
}
|
||||
|
||||
|
||||
Client::Tls::~Tls()
|
||||
{
|
||||
if (m_ctx) {
|
||||
SSL_CTX_free(m_ctx);
|
||||
}
|
||||
|
||||
if (m_ssl) {
|
||||
SSL_free(m_ssl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Client::Tls::handshake()
|
||||
{
|
||||
m_ssl = SSL_new(m_ctx);
|
||||
assert(m_ssl != nullptr);
|
||||
|
||||
if (!m_ssl) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SSL_set_connect_state(m_ssl);
|
||||
SSL_set_bio(m_ssl, m_readBio, m_writeBio);
|
||||
SSL_do_handshake(m_ssl);
|
||||
|
||||
return send();
|
||||
}
|
||||
|
||||
|
||||
bool Client::Tls::send(const char *data, size_t size)
|
||||
{
|
||||
SSL_write(m_ssl, data, size);
|
||||
|
||||
return send();
|
||||
}
|
||||
|
||||
|
||||
const char *Client::Tls::fingerprint() const
|
||||
{
|
||||
return m_ready ? m_fingerprint : nullptr;
|
||||
}
|
||||
|
||||
|
||||
const char *Client::Tls::version() const
|
||||
{
|
||||
return m_ready ? SSL_get_version(m_ssl) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Client::Tls::read(const char *data, size_t size)
|
||||
{
|
||||
BIO_write(m_readBio, data, size);
|
||||
|
||||
if (!SSL_is_init_finished(m_ssl)) {
|
||||
const int rc = SSL_connect(m_ssl);
|
||||
|
||||
if (rc < 0 && SSL_get_error(m_ssl, rc) == SSL_ERROR_WANT_READ) {
|
||||
send();
|
||||
} else if (rc == 1) {
|
||||
X509 *cert = SSL_get_peer_certificate(m_ssl);
|
||||
if (!verify(cert)) {
|
||||
X509_free(cert);
|
||||
m_client->close();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
X509_free(cert);
|
||||
m_ready = true;
|
||||
m_client->login();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int bytes_read = 0;
|
||||
while ((bytes_read = SSL_read(m_ssl, m_buf, sizeof(m_buf))) > 0) {
|
||||
m_client->parse(m_buf, bytes_read);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Client::Tls::send()
|
||||
{
|
||||
return m_client->send(m_writeBio);
|
||||
}
|
||||
|
||||
|
||||
bool Client::Tls::verify(X509 *cert)
|
||||
{
|
||||
if (cert == nullptr) {
|
||||
LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!verifyFingerprint(cert)) {
|
||||
LOG_ERR("[%s] Failed to verify server certificate fingerprint", m_client->m_pool.url());
|
||||
|
||||
const char *fingerprint = m_client->m_pool.fingerprint();
|
||||
if (strlen(m_fingerprint) == 64 && fingerprint != nullptr) {
|
||||
LOG_ERR("\"%s\" was given", m_fingerprint);
|
||||
LOG_ERR("\"%s\" was configured", fingerprint);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Client::Tls::verifyFingerprint(X509 *cert)
|
||||
{
|
||||
const EVP_MD *digest = EVP_get_digestbyname("sha256");
|
||||
if (digest == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int dlen;
|
||||
|
||||
if (X509_digest(cert, digest, md, &dlen) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Job::toHex(md, 32, m_fingerprint);
|
||||
const char *fingerprint = m_client->m_pool.fingerprint();
|
||||
|
||||
return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0;
|
||||
}
|
62
src/common/net/Tls.h
Normal file
62
src/common/net/Tls.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TLS_H
|
||||
#define XMRIG_TLS_H
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
#include "common/net/Client.h"
|
||||
|
||||
|
||||
class Client::Tls
|
||||
{
|
||||
public:
|
||||
Tls(Client *client);
|
||||
~Tls();
|
||||
|
||||
bool handshake();
|
||||
bool send(const char *data, size_t size);
|
||||
const char *fingerprint() const;
|
||||
const char *version() const;
|
||||
void read(const char *data, size_t size);
|
||||
|
||||
private:
|
||||
bool send();
|
||||
bool verify(X509 *cert);
|
||||
bool verifyFingerprint(X509 *cert);
|
||||
|
||||
BIO *m_readBio;
|
||||
BIO *m_writeBio;
|
||||
bool m_ready;
|
||||
char m_buf[1024 * 2];
|
||||
char m_fingerprint[32 * 2 + 8];
|
||||
Client *m_client;
|
||||
SSL *m_ssl;
|
||||
SSL_CTX *m_ctx;
|
||||
};
|
||||
|
||||
|
||||
#endif /* XMRIG_TLS_H */
|
47
src/common/utils/timestamp.h
Normal file
47
src/common/utils/timestamp.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TIMESTAMP_H
|
||||
#define XMRIG_TIMESTAMP_H
|
||||
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static inline int64_t currentMSecsSinceEpoch()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
if (high_resolution_clock::is_steady) {
|
||||
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||
}
|
||||
|
||||
return time_point_cast<milliseconds>(steady_clock::now()).time_since_epoch().count();
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* XMRIG_TIMESTAMP_H */
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __XMRIG_H__
|
||||
#define __XMRIG_H__
|
||||
#ifndef XMRIG_XMRIG_H
|
||||
#define XMRIG_XMRIG_H
|
||||
|
||||
|
||||
namespace xmrig
|
||||
|
@ -34,7 +34,7 @@ enum Algo {
|
|||
INVALID_ALGO = -1,
|
||||
CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */
|
||||
CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (RYO) */
|
||||
ALGO_MAX
|
||||
};
|
||||
|
||||
|
@ -76,8 +76,9 @@ enum Variant {
|
|||
VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only)
|
||||
VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only)
|
||||
VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only)
|
||||
VARIANT_XAO = 6, // Modified CryptoNight variant 1 (Alloy only)
|
||||
VARIANT_XAO = 6, // Modified CryptoNight variant 0 (Alloy only)
|
||||
VARIANT_RTO = 7, // Modified CryptoNight variant 1 (Arto only)
|
||||
VARIANT_2 = 8, // CryptoNight variant 2
|
||||
VARIANT_MAX
|
||||
};
|
||||
|
||||
|
@ -95,7 +96,25 @@ enum AesMode {
|
|||
};
|
||||
|
||||
|
||||
enum OclVendor {
|
||||
OCL_VENDOR_UNKNOWN = -2,
|
||||
OCL_VENDOR_MANUAL = -1,
|
||||
OCL_VENDOR_AMD = 0,
|
||||
OCL_VENDOR_NVIDIA = 1,
|
||||
OCL_VENDOR_INTEL = 2
|
||||
};
|
||||
|
||||
|
||||
enum Assembly {
|
||||
ASM_NONE,
|
||||
ASM_AUTO,
|
||||
ASM_INTEL,
|
||||
ASM_RYZEN,
|
||||
ASM_MAX
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __XMRIG_H__ */
|
||||
#endif /* XMRIG_XMRIG_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue