Update base.

This commit is contained in:
XMRig 2020-04-29 14:17:33 +07:00
parent b38046db46
commit 46e49cde0b
No known key found for this signature in database
GPG key ID: 446A53638BE94409
40 changed files with 162 additions and 244 deletions

View file

@ -32,7 +32,7 @@
#include "backend/cpu/Cpu.h" #include "backend/cpu/Cpu.h"
#include "base/io/Console.h" #include "base/io/Console.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/Signals.h" #include "base/io/Signals.h"
#include "base/kernel/Platform.h" #include "base/kernel/Platform.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "core/Controller.h" #include "core/Controller.h"

View file

@ -28,7 +28,7 @@
#include "backend/cuda/wrappers/CudaLib.h" #include "backend/cuda/wrappers/CudaLib.h"
#include "base/kernel/Env.h" #include "base/io/Env.h"
#include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxAlgo.h"

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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,8 +31,8 @@
#include "backend/opencl/wrappers/OclLib.h" #include "backend/opencl/wrappers/OclLib.h"
#include "backend/common/Tags.h" #include "backend/common/Tags.h"
#include "backend/opencl/wrappers/OclError.h" #include "backend/opencl/wrappers/OclError.h"
#include "base/io/Env.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/Env.h"
#if defined(OCL_DEBUG_REFERENCE_COUNT) #if defined(OCL_DEBUG_REFERENCE_COUNT)

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -31,9 +31,9 @@
#include "base/api/interfaces/IApiListener.h" #include "base/api/interfaces/IApiListener.h"
#include "base/api/requests/HttpApiRequest.h" #include "base/api/requests/HttpApiRequest.h"
#include "base/crypto/keccak.h" #include "base/crypto/keccak.h"
#include "base/io/Env.h"
#include "base/io/json/Json.h" #include "base/io/json/Json.h"
#include "base/kernel/Base.h" #include "base/kernel/Base.h"
#include "base/kernel/Env.h"
#include "base/tools/Buffer.h" #include "base/tools/Buffer.h"
#include "base/tools/Chrono.h" #include "base/tools/Chrono.h"
#include "core/config/Config.h" #include "core/config/Config.h"

View file

@ -4,6 +4,7 @@ set(HEADERS_BASE
src/base/crypto/Coin.h src/base/crypto/Coin.h
src/base/crypto/keccak.h src/base/crypto/keccak.h
src/base/io/Console.h src/base/io/Console.h
src/base/io/Env.h
src/base/io/json/Json.h src/base/io/json/Json.h
src/base/io/json/JsonChain.h src/base/io/json/JsonChain.h
src/base/io/json/JsonRequest.h src/base/io/json/JsonRequest.h
@ -11,12 +12,12 @@ set(HEADERS_BASE
src/base/io/log/backends/FileLog.h src/base/io/log/backends/FileLog.h
src/base/io/log/FileLogWriter.h src/base/io/log/FileLogWriter.h
src/base/io/log/Log.h src/base/io/log/Log.h
src/base/io/Signals.h
src/base/io/Watcher.h src/base/io/Watcher.h
src/base/kernel/Base.h src/base/kernel/Base.h
src/base/kernel/config/BaseConfig.h src/base/kernel/config/BaseConfig.h
src/base/kernel/config/BaseTransform.h src/base/kernel/config/BaseTransform.h
src/base/kernel/Entry.h src/base/kernel/Entry.h
src/base/kernel/Env.h
src/base/kernel/interfaces/IBaseListener.h src/base/kernel/interfaces/IBaseListener.h
src/base/kernel/interfaces/IClient.h src/base/kernel/interfaces/IClient.h
src/base/kernel/interfaces/IClientListener.h src/base/kernel/interfaces/IClientListener.h
@ -34,7 +35,6 @@ set(HEADERS_BASE
src/base/kernel/interfaces/IWatcherListener.h src/base/kernel/interfaces/IWatcherListener.h
src/base/kernel/Platform.h src/base/kernel/Platform.h
src/base/kernel/Process.h src/base/kernel/Process.h
src/base/kernel/Signals.h
src/base/net/dns/Dns.h src/base/net/dns/Dns.h
src/base/net/dns/DnsRecord.h src/base/net/dns/DnsRecord.h
src/base/net/http/Http.h src/base/net/http/Http.h
@ -70,6 +70,7 @@ set(SOURCES_BASE
src/base/crypto/Coin.cpp src/base/crypto/Coin.cpp
src/base/crypto/keccak.cpp src/base/crypto/keccak.cpp
src/base/io/Console.cpp src/base/io/Console.cpp
src/base/io/Env.cpp
src/base/io/json/Json.cpp src/base/io/json/Json.cpp
src/base/io/json/JsonChain.cpp src/base/io/json/JsonChain.cpp
src/base/io/json/JsonRequest.cpp src/base/io/json/JsonRequest.cpp
@ -77,15 +78,14 @@ set(SOURCES_BASE
src/base/io/log/backends/FileLog.cpp src/base/io/log/backends/FileLog.cpp
src/base/io/log/FileLogWriter.cpp src/base/io/log/FileLogWriter.cpp
src/base/io/log/Log.cpp src/base/io/log/Log.cpp
src/base/io/Signals.cpp
src/base/io/Watcher.cpp src/base/io/Watcher.cpp
src/base/kernel/Base.cpp src/base/kernel/Base.cpp
src/base/kernel/config/BaseConfig.cpp src/base/kernel/config/BaseConfig.cpp
src/base/kernel/config/BaseTransform.cpp src/base/kernel/config/BaseTransform.cpp
src/base/kernel/Entry.cpp src/base/kernel/Entry.cpp
src/base/kernel/Env.cpp
src/base/kernel/Platform.cpp src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp src/base/kernel/Process.cpp
src/base/kernel/Signals.cpp
src/base/net/dns/Dns.cpp src/base/net/dns/Dns.cpp
src/base/net/dns/DnsRecord.cpp src/base/net/dns/DnsRecord.cpp
src/base/net/http/Http.cpp src/base/net/http/Http.cpp

View file

@ -23,7 +23,7 @@
*/ */
#include "base/kernel/Env.h" #include "base/io/Env.h"
#include "base/kernel/Process.h" #include "base/kernel/Process.h"
#include "version.h" #include "version.h"
@ -57,6 +57,8 @@ static std::map<String, String> variables;
static void createVariables() static void createVariables()
{ {
variables.insert({ "XMRIG_VERSION", APP_VERSION }); variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_KIND", APP_KIND });
variables.insert({ "XMRIG_HOSTNAME", Env::hostname() });
variables.insert({ "XMRIG_EXE", Process::exepath() }); variables.insert({ "XMRIG_EXE", Process::exepath() });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) }); variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) }); variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });

View file

@ -26,8 +26,8 @@
#include <uv.h> #include <uv.h>
#include "base/io/Signals.h"
#include "base/kernel/interfaces/ISignalListener.h" #include "base/kernel/interfaces/ISignalListener.h"
#include "base/kernel/Signals.h"
#include "base/tools/Handle.h" #include "base/tools/Handle.h"

View file

@ -18,7 +18,7 @@
#include "base/io/log/FileLogWriter.h" #include "base/io/log/FileLogWriter.h"
#include "base/kernel/Env.h" #include "base/io/Env.h"
#include <cassert> #include <cassert>

View file

@ -141,7 +141,9 @@ private:
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) #define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) #define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_V(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#define LOG_VV(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
#ifdef APP_DEBUG #ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)

View file

@ -48,9 +48,7 @@ public:
} }
static bool setThreadAffinity(uint64_t cpu_id); static bool setThreadAffinity(uint64_t cpu_id);
static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent); static void init(const char *userAgent);
static void restoreTimerResolution();
static void setProcessPriority(int priority); static void setProcessPriority(int priority);
static void setThreadPriority(int priority); static void setThreadPriority(int priority);

View file

@ -34,10 +34,6 @@
#include "base/kernel/Platform.h" #include "base/kernel/Platform.h"
#include "version.h" #include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
char *xmrig::Platform::createUserAgent() char *xmrig::Platform::createUserAgent()
{ {
@ -46,11 +42,6 @@ char *xmrig::Platform::createUserAgent()
char *buf = new char[max](); char *buf = new char[max]();
int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string());
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __clang__ # ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__) # elif defined(__GNUC__)
@ -75,17 +66,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
#endif #endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void xmrig::Platform::restoreTimerResolution()
{
}
void xmrig::Platform::setProcessPriority(int) void xmrig::Platform::setProcessPriority(int)
{ {
} }

View file

@ -43,10 +43,6 @@
#include "base/kernel/Platform.h" #include "base/kernel/Platform.h"
#include "version.h" #include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
#ifdef __FreeBSD__ #ifdef __FreeBSD__
typedef cpuset_t cpu_set_t; typedef cpuset_t cpu_set_t;
@ -70,11 +66,6 @@ char *xmrig::Platform::createUserAgent()
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif # endif
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __clang__ # ifdef __clang__
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
# elif defined(__GNUC__) # elif defined(__GNUC__)
@ -104,17 +95,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
#endif #endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void xmrig::Platform::restoreTimerResolution()
{
}
void xmrig::Platform::setProcessPriority(int) void xmrig::Platform::setProcessPriority(int)
{ {
} }

View file

@ -29,23 +29,12 @@
#include "base/kernel/Platform.h" #include "base/kernel/Platform.h"
#include "base/io/log/Log.h"
#include "version.h" #include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
#ifdef XMRIG_AMD_PROJECT
static uint32_t timerResolution = 0;
#endif
static inline OSVERSIONINFOEX winOsVersion() static inline OSVERSIONINFOEX winOsVersion()
{ {
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); using RtlGetVersionFunction = NTSTATUS (*)(LPOSVERSIONINFO);
OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0}; OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
@ -75,11 +64,6 @@ char *xmrig::Platform::createUserAgent()
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string()); length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
# endif # endif
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
# endif
# ifdef __GNUC__ # ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif _MSC_VER # elif _MSC_VER
@ -93,10 +77,6 @@ char *xmrig::Platform::createUserAgent()
#ifndef XMRIG_FEATURE_HWLOC #ifndef XMRIG_FEATURE_HWLOC
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{ {
if (cpu_id >= 64) {
LOG_ERR("Unable to set affinity. Windows supports only affinity up to 63.");
}
const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0); const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0);
Sleep(1); Sleep(1);
return result; return result;
@ -104,34 +84,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
#endif #endif
uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution)
{
# ifdef XMRIG_AMD_PROJECT
TIMECAPS tc;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
return 0;
}
timerResolution = std::min<uint32_t>(std::max<uint32_t>(tc.wPeriodMin, resolution), tc.wPeriodMax);
return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0;
# else
return resolution;
# endif
}
void xmrig::Platform::restoreTimerResolution()
{
# ifdef XMRIG_AMD_PROJECT
if (timerResolution) {
timeEndPeriod(timerResolution);
}
# endif
}
void xmrig::Platform::setProcessPriority(int priority) void xmrig::Platform::setProcessPriority(int priority)
{ {
if (priority == -1) { if (priority == -1) {

View file

@ -115,7 +115,27 @@ xmrig::Process::Process(int argc, char **argv) :
{ {
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this))); srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
setDataDir(m_arguments.value("--data-dir")); setDataDir(m_arguments.value("--data-dir", "-d"));
}
int xmrig::Process::pid()
{
# if UV_VERSION_HEX >= 0x011200
return uv_os_getpid();
# else
return 0;
# endif
}
int xmrig::Process::ppid()
{
# if UV_VERSION_HEX >= 0x011000
return uv_os_getppid();
# else
return 0;
# endif
} }

View file

@ -51,6 +51,8 @@ public:
Process(int argc, char **argv); Process(int argc, char **argv);
static int pid();
static int ppid();
static String exepath(); static String exepath();
static String location(Location location, const char *fileName = nullptr); static String location(Location location, const char *fileName = nullptr);

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View file

@ -26,6 +26,9 @@
#define XMRIG_ILINELISTENER_H #define XMRIG_ILINELISTENER_H
#include "base/tools/Object.h"
#include <cstdint> #include <cstdint>
@ -35,7 +38,10 @@ namespace xmrig {
class ILineListener class ILineListener
{ {
public: public:
virtual ~ILineListener() = default; XMRIG_DISABLE_COPY_MOVE(ILineListener)
ILineListener() = default;
virtual ~ILineListener() = default;
virtual void onLine(char *line, size_t size) = 0; virtual void onLine(char *line, size_t size) = 0;
}; };

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -23,9 +23,8 @@
*/ */
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/dns/Dns.h" #include "base/net/dns/Dns.h"
#include "base/tools/Handle.h" #include "base/kernel/interfaces/IDnsListener.h"
namespace xmrig { namespace xmrig {
@ -35,10 +34,7 @@ namespace xmrig {
xmrig::Dns::Dns(IDnsListener *listener) : xmrig::Dns::Dns(IDnsListener *listener) :
m_hints(), m_listener(listener)
m_listener(listener),
m_status(0),
m_resolver(nullptr)
{ {
m_key = m_storage.add(this); m_key = m_storage.add(this);
@ -134,11 +130,11 @@ void xmrig::Dns::onResolved(int status, addrinfo *res)
addrinfo *ptr = res; addrinfo *ptr = res;
while (ptr != nullptr) { while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) { if (ptr->ai_family == AF_INET) {
m_ipv4.push_back(ptr); m_ipv4.emplace_back(ptr);
} }
if (ptr->ai_family == AF_INET6) { if (ptr->ai_family == AF_INET6) {
m_ipv6.push_back(ptr); m_ipv6.emplace_back(ptr);
} }
ptr = ptr->ai_next; ptr = ptr->ai_next;

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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,6 +32,7 @@
#include "base/net/dns/DnsRecord.h" #include "base/net/dns/DnsRecord.h"
#include "base/net/tools/Storage.h" #include "base/net/tools/Storage.h"
#include "base/tools/Object.h"
#include "base/tools/String.h" #include "base/tools/String.h"
@ -44,6 +45,8 @@ class IDnsListener;
class Dns class Dns
{ {
public: public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns)
Dns(IDnsListener *listener); Dns(IDnsListener *listener);
~Dns(); ~Dns();
@ -62,14 +65,14 @@ private:
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res); static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
addrinfo m_hints; addrinfo m_hints{};
IDnsListener *m_listener; IDnsListener *m_listener;
int m_status; int m_status = 0;
std::vector<DnsRecord> m_ipv4; std::vector<DnsRecord> m_ipv4;
std::vector<DnsRecord> m_ipv6; std::vector<DnsRecord> m_ipv6;
String m_host; String m_host;
uintptr_t m_key; uintptr_t m_key;
uv_getaddrinfo_t *m_resolver; uv_getaddrinfo_t *m_resolver = nullptr;
static Storage<Dns> m_storage; static Storage<Dns> m_storage;
}; };

View file

@ -18,12 +18,11 @@
#include "base/net/http/Fetch.h" #include "base/net/http/Fetch.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/stringbuffer.h"
#include "3rdparty/rapidjson/writer.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/http/HttpClient.h" #include "base/net/http/HttpClient.h"
#include "base/net/stratum/Pool.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#ifdef XMRIG_FEATURE_TLS #ifdef XMRIG_FEATURE_TLS
@ -45,7 +44,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
} }
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls, bool quiet) : xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
quiet(quiet), quiet(quiet),
tls(tls), tls(tls),
method(method), method(method),
@ -55,42 +54,10 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
{ {
assert(port > 0); assert(port > 0);
setBody(doc); setBody(value);
} }
xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, bool quiet, const char *data, size_t size, const char *contentType) :
quiet(quiet),
tls(pool.isTLS()),
method(static_cast<http_method>(method)),
fingerprint(pool.fingerprint()),
host(pool.host()),
path(path),
port(pool.port())
{
assert(pool.isValid());
setBody(data, size, contentType);
}
xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet) :
quiet(quiet),
tls(pool.isTLS()),
method(static_cast<http_method>(method)),
fingerprint(pool.fingerprint()),
host(pool.host()),
path(path),
port(pool.port())
{
assert(pool.isValid());
setBody(doc);
}
void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *contentType) void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *contentType)
{ {
if (!data) { if (!data) {
@ -110,7 +77,7 @@ void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *con
} }
void xmrig::FetchRequest::setBody(const rapidjson::Document &doc) void xmrig::FetchRequest::setBody(const rapidjson::Value &value)
{ {
assert(method != HTTP_GET && method != HTTP_HEAD); assert(method != HTTP_GET && method != HTTP_HEAD);
@ -122,7 +89,7 @@ void xmrig::FetchRequest::setBody(const rapidjson::Document &doc)
StringBuffer buffer(nullptr, 512); StringBuffer buffer(nullptr, 512);
Writer<StringBuffer> writer(buffer); Writer<StringBuffer> writer(buffer);
doc.Accept(writer); value.Accept(writer);
setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str()); setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str());
} }

View file

@ -22,8 +22,8 @@
#include "3rdparty/http-parser/http_parser.h" #include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/String.h" #include "base/tools/String.h"
#include "rapidjson/fwd.h"
#include <map> #include <map>
@ -35,7 +35,6 @@ namespace xmrig {
class IHttpListener; class IHttpListener;
class Pool;
class FetchRequest class FetchRequest
@ -43,12 +42,10 @@ class FetchRequest
public: public:
FetchRequest() = default; FetchRequest() = default;
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr); FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls = false, bool quiet = false); FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
FetchRequest(int method, const Pool &pool, const String &path, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet = false);
void setBody(const char *data, size_t size, const char *contentType = nullptr); void setBody(const char *data, size_t size, const char *contentType = nullptr);
void setBody(const rapidjson::Document &doc); void setBody(const rapidjson::Value &value);
inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); } inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); }

View file

@ -26,6 +26,19 @@ namespace xmrig {
const std::string HttpData::kApplicationJson = "application/json"; const std::string HttpData::kApplicationJson = "application/json";
const std::string HttpData::kContentType = "Content-Type"; const std::string HttpData::kContentType = "Content-Type";
const std::string HttpData::kContentTypeL = "content-type"; const std::string HttpData::kContentTypeL = "content-type";
const std::string HttpData::kTextPlain = "text/plain";
} // namespace xmrig } // namespace xmrig
bool xmrig::HttpData::isJSON() const
{
if (!headers.count(kContentTypeL)) {
return false;
}
auto &type = headers.at(kContentTypeL);
return type == kApplicationJson || type == kTextPlain;
}

View file

@ -46,12 +46,13 @@ public:
static const std::string kApplicationJson; static const std::string kApplicationJson;
static const std::string kContentType; static const std::string kContentType;
static const std::string kContentTypeL; static const std::string kContentTypeL;
static const std::string kTextPlain;
inline HttpData(uint64_t id) : m_id(id) {} inline HttpData(uint64_t id) : m_id(id) {}
virtual ~HttpData() = default; virtual ~HttpData() = default;
inline uint64_t id() const { return m_id; } inline uint64_t id() const { return m_id; }
virtual bool isRequest() const = 0; virtual bool isRequest() const = 0;
virtual const char *host() const = 0; virtual const char *host() const = 0;
@ -61,6 +62,8 @@ public:
virtual uint16_t port() const = 0; virtual uint16_t port() const = 0;
virtual void write(std::string &&data, bool close) = 0; virtual void write(std::string &&data, bool close) = 0;
bool isJSON() const;
int method = 0; int method = 0;
int status = 0; int status = 0;
int userType = 0; int userType = 0;

View file

@ -27,11 +27,11 @@ void xmrig::HttpListener::onHttpData(const HttpData &data)
{ {
# ifdef APP_DEBUG # ifdef APP_DEBUG
if (!data.isRequest()) { if (!data.isRequest()) {
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"), LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(), m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
data.status >= 400 ? 31 : 32, data.status, data.body.size()); (data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.headers.count(HttpData::kContentTypeL) && data.headers.at(HttpData::kContentTypeL) == HttpData::kApplicationJson) { if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast<int>(data.body.size()), data.body.c_str()); Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast<int>(data.body.size()), data.body.c_str());
} }
} }

View file

@ -29,12 +29,13 @@ namespace xmrig {
class HttpListener : public IHttpListener class HttpListener : public IHttpListener
{ {
public: public:
inline HttpListener(IHttpListener *listener) : m_listener(listener) {} inline HttpListener(IHttpListener *listener, const char *tag = nullptr) : m_tag(tag), m_listener(listener) {}
protected: protected:
void onHttpData(const HttpData &data) override; void onHttpData(const HttpData &data) override;
private: private:
const char *m_tag;
IHttpListener *m_listener; IHttpListener *m_listener;
}; };

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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,10 +24,10 @@
#include "base/net/stratum/BaseClient.h" #include "base/net/stratum/BaseClient.h"
#include "base/kernel/Env.h" #include "3rdparty/rapidjson/document.h"
#include "base/io/Env.h"
#include "base/kernel/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
#include "base/net/stratum/SubmitResult.h" #include "base/net/stratum/SubmitResult.h"
#include "rapidjson/document.h"
namespace xmrig { namespace xmrig {

View file

@ -328,7 +328,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc) int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc)
{ {
FetchRequest req(HTTP_POST, m_pool, kJsonRPC, doc, isQuiet()); FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet());
fetch(std::move(req), m_httpListener); fetch(std::move(req), m_httpListener);
return m_sequence++; return m_sequence++;
@ -355,7 +355,7 @@ void xmrig::DaemonClient::retry()
void xmrig::DaemonClient::send(const char *path) void xmrig::DaemonClient::send(const char *path)
{ {
FetchRequest req(HTTP_GET, m_pool, path, isQuiet()); FetchRequest req(HTTP_GET, m_pool.host(), m_pool.port(), path, m_pool.isTLS(), isQuiet());
fetch(std::move(req), m_httpListener); fetch(std::move(req), m_httpListener);
} }

View file

@ -25,10 +25,10 @@
#include "base/net/tls/TlsConfig.h" #include "base/net/tls/TlsConfig.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h" #include "base/io/json/Json.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/tls/TlsGen.h" #include "base/net/tls/TlsGen.h"
#include "rapidjson/document.h"
namespace xmrig { namespace xmrig {
@ -86,7 +86,7 @@ xmrig::TlsConfig::TlsConfig(const rapidjson::Value &value)
generate(); generate();
} }
} }
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_FORCE_TLS
else if (value.IsNull()) { else if (value.IsNull()) {
generate(); generate();
} }

View file

@ -27,8 +27,8 @@
#define XMRIG_TLSCONFIG_H #define XMRIG_TLSCONFIG_H
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/String.h" #include "base/tools/String.h"
#include "rapidjson/fwd.h"
namespace xmrig { namespace xmrig {

View file

@ -25,8 +25,8 @@
#include "base/net/tls/TlsContext.h" #include "base/net/tls/TlsContext.h"
#include "base/io/Env.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/Env.h"
#include "base/net/tls/TlsConfig.h" #include "base/net/tls/TlsConfig.h"

View file

@ -1,10 +1,4 @@
/* XMRig /* 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-2020 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
@ -48,10 +42,10 @@ public:
} }
inline static void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); } inline void *ptr(uintptr_t id) { return reinterpret_cast<void *>(id); }
inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); } inline TYPE *get(const void *id) const { return get(reinterpret_cast<uintptr_t>(id)); }
inline TYPE *get(uintptr_t id) const inline TYPE *get(uintptr_t id) const
{ {
assert(m_data.count(id) > 0); assert(m_data.count(id) > 0);
@ -63,19 +57,16 @@ public:
} }
inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); } inline void remove(const void *id) { delete release(reinterpret_cast<uintptr_t>(id)); }
inline void remove(uintptr_t id) { delete release(id); } inline void remove(uintptr_t id) { delete release(id); }
inline TYPE *release(const void *id) { release(reinterpret_cast<uintptr_t>(id)); } inline TYPE *release(const void *id) { return release(reinterpret_cast<uintptr_t>(id)); }
inline TYPE *release(uintptr_t id) inline TYPE *release(uintptr_t id)
{ {
TYPE *obj = get(id); auto obj = get(id);
if (obj != nullptr) { if (obj != nullptr) {
auto it = m_data.find(id); m_data.erase(id);
if (it != m_data.end()) {
m_data.erase(it);
}
} }
return obj; return obj;
@ -84,7 +75,7 @@ public:
private: private:
std::map<uintptr_t, TYPE *> m_data; std::map<uintptr_t, TYPE *> m_data;
uint64_t m_counter = 0; uintptr_t m_counter = 0;
}; };

View file

@ -52,7 +52,7 @@ bool xmrig::Arguments::hasArg(const char *name) const
} }
const char *xmrig::Arguments::value(const char *key) const const char *xmrig::Arguments::value(const char *key1, const char *key2) const
{ {
const size_t size = m_data.size(); const size_t size = m_data.size();
if (size < 3) { if (size < 3) {
@ -60,7 +60,7 @@ const char *xmrig::Arguments::value(const char *key) const
} }
for (size_t i = 1; i < size - 1; ++i) { for (size_t i = 1; i < size - 1; ++i) {
if (m_data[i] == key) { if (m_data[i] == key1 || (key2 && m_data[i] == key2)) {
return m_data[i + 1]; return m_data[i + 1];
} }
} }

View file

@ -41,7 +41,7 @@ public:
Arguments(int argc, char **argv); Arguments(int argc, char **argv);
bool hasArg(const char *name) const; bool hasArg(const char *name) const;
const char *value(const char *key) const; const char *value(const char *key1, const char *key2 = nullptr) const;
inline char **argv() const { return m_argv; } inline char **argv() const { return m_argv; }
inline const std::vector<String> &data() const { return m_data; } inline const std::vector<String> &data() const { return m_data; }

View file

@ -23,11 +23,11 @@
*/ */
#include <ctype.h>
#include "base/tools/String.h" #include "base/tools/String.h"
#include "rapidjson/document.h" #include "3rdparty/rapidjson/document.h"
#include <cctype>
xmrig::String::String(const char *str) : xmrig::String::String(const char *str) :

View file

@ -5,8 +5,8 @@
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,13 +26,13 @@
#define XMRIG_STRING_H #define XMRIG_STRING_H
#include "3rdparty/rapidjson/fwd.h"
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "rapidjson/fwd.h"
namespace xmrig { namespace xmrig {
@ -85,11 +85,11 @@ public:
rapidjson::Value toJSON() const; rapidjson::Value toJSON() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
std::vector<xmrig::String> split(char sep) const; std::vector<String> split(char sep) const;
String &toLower(); String &toLower();
String &toUpper(); String &toUpper();
static String join(const std::vector<xmrig::String> &vec, char sep); static String join(const std::vector<String> &vec, char sep);
private: private:
void copy(const char *str); void copy(const char *str);

View file

@ -1,12 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -23,22 +17,20 @@
*/ */
#include "base/tools/Timer.h"
#include "base/kernel/interfaces/ITimerListener.h" #include "base/kernel/interfaces/ITimerListener.h"
#include "base/tools/Handle.h" #include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Timer::Timer(ITimerListener *listener) : xmrig::Timer::Timer(ITimerListener *listener) :
m_listener(listener), m_listener(listener)
m_timer(nullptr)
{ {
init(); init();
} }
xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) : xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) :
m_listener(listener), m_listener(listener)
m_timer(nullptr)
{ {
init(); init();
start(timeout, repeat); start(timeout, repeat);
@ -63,6 +55,15 @@ void xmrig::Timer::setRepeat(uint64_t repeat)
} }
void xmrig::Timer::singleShot(uint64_t timeout, int id)
{
m_id = id;
stop();
start(timeout, 0);
}
void xmrig::Timer::start(uint64_t timeout, uint64_t repeat) void xmrig::Timer::start(uint64_t timeout, uint64_t repeat)
{ {
uv_timer_start(m_timer, onTimer, timeout, repeat); uv_timer_start(m_timer, onTimer, timeout, repeat);
@ -71,6 +72,7 @@ void xmrig::Timer::start(uint64_t timeout, uint64_t repeat)
void xmrig::Timer::stop() void xmrig::Timer::stop()
{ {
setRepeat(0);
uv_timer_stop(m_timer); uv_timer_stop(m_timer);
} }
@ -85,7 +87,7 @@ void xmrig::Timer::init()
void xmrig::Timer::onTimer(uv_timer_t *handle) void xmrig::Timer::onTimer(uv_timer_t *handle)
{ {
const Timer *timer = static_cast<Timer *>(handle->data); const auto timer = static_cast<Timer *>(handle->data);
timer->m_listener->onTimer(timer); timer->m_listener->onTimer(timer);
} }

View file

@ -1,12 +1,6 @@
/* XMRig /* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org> * Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,10 +20,13 @@
#define XMRIG_TIMER_H #define XMRIG_TIMER_H
#include <stdint.h> using uv_timer_t = struct uv_timer_s;
typedef struct uv_timer_s uv_timer_t; #include "base/tools/Object.h"
#include <cstdint>
namespace xmrig { namespace xmrig {
@ -41,12 +38,17 @@ class ITimerListener;
class Timer class Timer
{ {
public: public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Timer);
Timer(ITimerListener *listener); Timer(ITimerListener *listener);
Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat); Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat);
~Timer(); ~Timer();
inline int id() const { return m_id; }
uint64_t repeat() const; uint64_t repeat() const;
void setRepeat(uint64_t repeat); void setRepeat(uint64_t repeat);
void singleShot(uint64_t timeout, int id = 0);
void start(uint64_t timeout, uint64_t repeat); void start(uint64_t timeout, uint64_t repeat);
void stop(); void stop();
@ -55,8 +57,9 @@ private:
static void onTimer(uv_timer_t *handle); static void onTimer(uv_timer_t *handle);
int m_id = 0;
ITimerListener *m_listener; ITimerListener *m_listener;
uv_timer_t *m_timer; uv_timer_t *m_timer = nullptr;
}; };