Backport changes from xmrig.

feature-cn-backend
XMRig 2017-08-17 07:24:06 +03:00
parent a8a06b858c
commit 0066ba4f30
16 changed files with 527 additions and 121 deletions

View File

@ -26,18 +26,19 @@ set(HEADERS
src/net/Job.h
src/net/JobResult.h
src/net/Network.h
src/net/SubmitResult.h
src/net/Url.h
src/net/strategies/DonateStrategy.h
src/net/strategies/FailoverStrategy.h
src/net/strategies/SinglePoolStrategy.h
src/net/SubmitResult.h
src/net/Url.h
src/Options.h
src/Platform.h
src/Summary.h
src/version.h
src/workers/CudaWorker.h
src/workers/GpuThread.h
src/workers/Handle.h
src/workers/Hashrate.h
src/workers/GpuThread.h
src/workers/Workers.h
)
@ -70,6 +71,7 @@ set(SOURCES
src/net/strategies/SinglePoolStrategy.cpp
src/net/Url.cpp
src/Options.cpp
src/Platform.cpp
src/Summary.cpp
src/workers/CudaWorker.cpp
src/workers/GpuThread.cpp
@ -95,7 +97,7 @@ if (WIN32)
res/app.rc
src/App_win.cpp
src/Cpu_win.cpp
src/net/Network_win.cpp
src/Platform_win.cpp
)
add_definitions(/DWIN32)
@ -104,18 +106,19 @@ elseif (APPLE)
set(SOURCES_OS
src/App_unix.cpp
src/Cpu_mac.cpp
src/net/Network_mac.cpp
src/Platform_mac.cpp
)
else()
set(SOURCES_OS
src/App_unix.cpp
src/Cpu_unix.cpp
src/net/Network_unix.cpp
src/Platform_unix.cpp
)
set(EXTRA_LIBS pthread)
endif()
add_definitions(/DXMRIG_NVIDIA_PROJECT)
add_definitions(/DUNICODE)
add_definitions(/DXMRIG_NO_LIBCPUID)
#add_definitions(/DAPP_DEBUG)

View File

@ -19,8 +19,11 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#elif defined(_MSC_VER)
# include <io.h>
#endif
#include "jansson.h"
@ -66,10 +69,13 @@ static int dump_to_file(const char *buffer, size_t size, void *data)
static int dump_to_fd(const char *buffer, size_t size, void *data)
{
int *dest = (int *)data;
#ifdef HAVE_UNISTD_H
# if defined(HAVE_UNISTD_H)
if(write(*dest, buffer, size) == (ssize_t)size)
return 0;
#endif
# elif (defined(_MSC_VER))
if (write(*dest, buffer, (unsigned int) size) == (int) size)
return 0;
# endif
return -1;
}

View File

@ -17,8 +17,13 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#elif defined(_MSC_VER)
# include <io.h>
# define HAVE_UNISTD_H
# define STDIN_FILENO 0
#endif
#include "jansson.h"

View File

@ -35,6 +35,7 @@
#include "log/Log.h"
#include "net/Network.h"
#include "Options.h"
#include "Platform.h"
#include "Summary.h"
#include "version.h"
#include "workers/Workers.h"
@ -79,6 +80,8 @@ App::App(int argc, char **argv) :
}
# endif
Platform::init(m_options->userAgent());
m_network = new Network(m_options);
uv_signal_init(uv_default_loop(), &m_signal);
@ -120,8 +123,10 @@ int App::exec()
uv_loop_close(uv_default_loop());
uv_tty_reset_mode();
free(m_network);
free(m_options);
delete m_network;
Options::release();
Platform::release();
return r;
}

View File

@ -39,6 +39,7 @@
#include "net/Url.h"
#include "nvidia/cryptonight.h"
#include "Options.h"
#include "Platform.h"
#include "version.h"
#include "workers/GpuThread.h"
@ -63,6 +64,7 @@ Options:\n\
-R, --retry-pause=N time to pause between retries (default: 5)\n\
--no-color disable colored output\n\
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
--user-agent set custom user-agent string for pool\n\
-B, --background run the miner in the background\n\
-c, --config=FILE load a JSON-format configuration file\n\
-l, --log-file=FILE log all output to a file\n"
@ -82,40 +84,44 @@ static char const short_options[] = "a:c:khBp:Px:r:R:s:T:o:u:O:Vl:S";
static struct option const options[] = {
{ "algo", 1, nullptr, 'a' },
{ "background", 0, nullptr, 'B' },
{ "config", 1, nullptr, 'c' },
{ "donate-level", 1, nullptr, 1003 },
{ "help", 0, nullptr, 'h' },
{ "keepalive", 0, nullptr ,'k' },
{ "log-file", 1, nullptr, 'l' },
{ "max-gpu-usage", 1, nullptr, 1004 },
{ "nicehash", 0, nullptr, 1006 },
{ "no-color", 0, nullptr, 1002 },
{ "pass", 1, nullptr, 'p' },
{ "print-time", 1, nullptr, 1007 },
{ "retries", 1, nullptr, 'r' },
{ "retry-pause", 1, nullptr, 'R' },
{ "syslog", 0, nullptr, 'S' },
{ "url", 1, nullptr, 'o' },
{ "user", 1, nullptr, 'u' },
{ "userpass", 1, nullptr, 'O' },
{ "version", 0, nullptr, 'V' },
{ "algo", 1, nullptr, 'a' },
{ "background", 0, nullptr, 'B' },
{ "config", 1, nullptr, 'c' },
{ "donate-level", 1, nullptr, 1003 },
{ "help", 0, nullptr, 'h' },
{ "keepalive", 0, nullptr ,'k' },
{ "log-file", 1, nullptr, 'l' },
{ "max-gpu-threads", 1, nullptr, 1200 },
{ "max-gpu-usage", 1, nullptr, 1004 },
{ "nicehash", 0, nullptr, 1006 },
{ "no-color", 0, nullptr, 1002 },
{ "pass", 1, nullptr, 'p' },
{ "print-time", 1, nullptr, 1007 },
{ "retries", 1, nullptr, 'r' },
{ "retry-pause", 1, nullptr, 'R' },
{ "syslog", 0, nullptr, 'S' },
{ "url", 1, nullptr, 'o' },
{ "user", 1, nullptr, 'u' },
{ "user-agent", 1, nullptr, 1008 },
{ "userpass", 1, nullptr, 'O' },
{ "version", 0, nullptr, 'V' },
{ 0, 0, 0, 0 }
};
static struct option const config_options[] = {
{ "algo", 1, nullptr, 'a' },
{ "background", 0, nullptr, 'B' },
{ "donate-level", 1, nullptr, 1003 },
{ "log-file", 1, nullptr, 'l' },
{ "max-gpu-usage", 1, nullptr, 1004 },
{ "print-time", 1, nullptr, 1007 },
{ "retries", 1, nullptr, 'r' },
{ "retry-pause", 1, nullptr, 'R' },
{ "syslog", 0, nullptr, 'S' },
{ "colors", 0, nullptr, 2000 },
{ "algo", 1, nullptr, 'a' },
{ "background", 0, nullptr, 'B' },
{ "colors", 0, nullptr, 2000 },
{ "donate-level", 1, nullptr, 1003 },
{ "log-file", 1, nullptr, 'l' },
{ "max-gpu-threads", 1, nullptr, 1200 },
{ "max-gpu-usage", 1, nullptr, 1004 },
{ "print-time", 1, nullptr, 1007 },
{ "retries", 1, nullptr, 'r' },
{ "retry-pause", 1, nullptr, 'R' },
{ "syslog", 0, nullptr, 'S' },
{ "user-agent", 1, nullptr, 1008 },
{ 0, 0, 0, 0 }
};
@ -149,34 +155,6 @@ static const char *algo_names[] = {
};
static char *defaultConfigName()
{
size_t size = 512;
char *buf = new char[size];
if (uv_exepath(buf, &size) < 0) {
delete [] buf;
return nullptr;
}
if (size < 500) {
# ifdef WIN32
char *p = strrchr(buf, '\\');
# else
char *p = strrchr(buf, '/');
# endif
if (p) {
strcpy(p + 1, "config.json");
return buf;
}
}
delete [] buf;
return nullptr;
}
Options *Options::parse(int argc, char **argv)
{
Options *options = new Options(argc, argv);
@ -190,6 +168,12 @@ Options *Options::parse(int argc, char **argv)
}
bool Options::save()
{
return false;
}
const char *Options::algoName() const
{
return algo_names[m_algo];
@ -202,10 +186,13 @@ Options::Options(int argc, char **argv) :
m_colors(true),
m_ready(false),
m_syslog(false),
m_configName(nullptr),
m_logFile(nullptr),
m_userAgent(nullptr),
m_algo(0),
m_algoVariant(0),
m_donateLevel(kDonateLevel),
m_maxGpuThreads(0),
m_maxGpuUsage(100),
m_printTime(60),
m_retries(5),
@ -233,9 +220,7 @@ Options::Options(int argc, char **argv) :
}
if (!m_pools[0]->isValid()) {
char *fileName = defaultConfigName();
parseConfig(fileName);
delete [] fileName;
parseConfig(Platform::defaultConfigName());
}
if (!m_pools[0]->isValid()) {
@ -314,16 +299,19 @@ bool Options::parseArg(int key, const char *arg)
case 1003: /* --donate-level */
case 1004: /* --max-gpu-usage */
case 1007: /* --print-time */
case 1200: /* --max-gpu-threads */
return parseArg(key, strtol(arg, nullptr, 10));
case 'B': /* --background */
case 'k': /* --keepalive */
case 'S': /* --syslog */
case 1002: /* --no-color */
case 1005: /* --safe */
case 1006: /* --nicehash */
return parseBoolean(key, true);
case 1002: /* --no-color */
return parseBoolean(key, false);
case 'V': /* --version */
showVersion();
return false;
@ -336,6 +324,11 @@ bool Options::parseArg(int key, const char *arg)
parseConfig(arg);
break;
case 1008: /* --user-agent */
free(m_userAgent);
m_userAgent = strdup(arg);
break;
default:
showUsage(1);
return false;
@ -402,6 +395,10 @@ bool Options::parseArg(int key, uint64_t arg)
m_printTime = (int) arg;
break;
case 1200: /* --max-gpu-threads */
m_maxGpuThreads = (int) arg;
break;
default:
break;
}
@ -461,8 +458,20 @@ Url *Options::parseUrl(const char *arg) const
void Options::parseConfig(const char *fileName)
{
uv_fs_t req;
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
if (fd < 0) {
fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd));
return;
}
uv_fs_req_cleanup(&req);
json_error_t err;
json_t *config = json_load_file(fileName, 0, &err);
json_t *config = json_loadfd(fd, 0, &err);
uv_fs_close(uv_default_loop(), &req, fd, nullptr);
uv_fs_req_cleanup(&req);
if (!json_is_object(config)) {
if (config) {
@ -480,6 +489,8 @@ void Options::parseConfig(const char *fileName)
return;
}
m_configName = strdup(fileName);
for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
parseJSON(&config_options[i], config);
}

View File

@ -60,15 +60,20 @@ public:
inline bool isAutoConf() const { return m_autoConf; }
inline bool syslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile; }
inline const char *userAgent() const { return m_userAgent; }
inline const std::vector<GpuThread*> &threads() const { return m_threads; }
inline const std::vector<Url*> &pools() const { return m_pools; }
inline int algo() const { return m_algo; }
inline int algoVariant() const { return m_algoVariant; }
inline int donateLevel() const { return m_donateLevel; }
inline int maxGpuThreads() const { return m_maxGpuThreads; }
inline int printTime() const { return m_printTime; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
inline static void release() { delete m_self; }
bool save();
const char *algoName() const;
private:
@ -96,10 +101,13 @@ private:
bool m_colors;
bool m_ready;
bool m_syslog;
char *m_configName;
char *m_logFile;
char *m_userAgent;
int m_algo;
int m_algoVariant;
int m_donateLevel;
int m_maxGpuThreads;
int m_maxGpuUsage;
int m_printTime;
int m_retries;

View File

@ -22,29 +22,41 @@
*/
#include <stdlib.h>
#include <string.h>
#include <uv.h>
#include "net/Network.h"
#include "version.h"
#include "Platform.h"
char *Network::userAgent()
char *Platform::m_defaultConfigName = nullptr;
char *Platform::m_userAgent = nullptr;
const char *Platform::defaultConfigName()
{
const size_t max = 128;
size_t size = 520;
char *buf = static_cast<char*>(malloc(max));
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
if (m_defaultConfigName == nullptr) {
m_defaultConfigName = new char[size];
}
# if defined(__x86_64__)
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# endif
if (uv_exepath(m_defaultConfigName, &size) < 0) {
return nullptr;
}
# ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
if (size < 500) {
# ifdef WIN32
char *p = strrchr(m_defaultConfigName, '\\');
# else
char *p = strrchr(m_defaultConfigName, '/');
# endif
return buf;
if (p) {
strcpy(p + 1, "config.json");
return m_defaultConfigName;
}
}
return nullptr;
}

View File

@ -21,19 +21,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "net/Network.h"
#include "version.h"
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
char *Network::userAgent()
class Platform
{
const size_t max = 128;
public:
static const char *defaultConfigName();
static void init(const char *userAgent);
static void release();
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);
char *buf = static_cast<char*>(malloc(max));
snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__);
static inline const char *userAgent() { return m_userAgent; }
return buf;
}
private:
static char *m_defaultConfigName;
static char *m_userAgent;
};
#endif /* __PLATFORM_H__ */

View File

@ -0,0 +1,108 @@
/* 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 <stdlib.h>
#include <sys/resource.h>
#include <uv.h>
#include "Platform.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
static inline char *createUserAgent()
{
const size_t max = 160;
char *buf = new char[max];
# ifdef XMRIG_NVIDIA_PROJECT
const int cudaVersion = cuda_get_runtime_version();
snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__);
# else
snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__);
# endif
return buf;
}
void Platform::init(const char *userAgent)
{
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
}
void Platform::release()
{
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
}
void Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
}
int prio = 19;
switch (priority)
{
case 1:
prio = 5;
break;
case 2:
prio = 0;
break;
case 3:
prio = -5;
break;
case 4:
prio = -10;
break;
case 5:
prio = -15;
break;
default:
break;
}
setpriority(PRIO_PROCESS, 0, prio);
}

View File

@ -0,0 +1,127 @@
/* 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 <sched.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <uv.h>
#include "Platform.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
static inline char *createUserAgent()
{
const size_t max = 160;
char *buf = new char[max];
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
# if defined(__x86_64__)
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
# 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__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# endif
return buf;
}
void Platform::init(const char *userAgent)
{
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
}
void Platform::release()
{
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
}
void Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
}
int prio = 19;
switch (priority)
{
case 1:
prio = 5;
break;
case 2:
prio = 0;
break;
case 3:
prio = -5;
break;
case 4:
prio = -10;
break;
case 5:
prio = -15;
break;
default:
break;
}
setpriority(PRIO_PROCESS, 0, prio);
if (priority == 0) {
sched_param param;
param.sched_priority = 0;
if (sched_setscheduler(0, SCHED_IDLE, &param) != 0) {
sched_setscheduler(0, SCHED_BATCH, &param);
}
}
}

View File

@ -24,12 +24,16 @@
#include <winsock2.h>
#include <windows.h>
#include <uv.h>
#include "net/Network.h"
#include "nvidia/cryptonight.h"
#include "Platform.h"
#include "version.h"
#ifdef XMRIG_NVIDIA_PROJECT
# include "nvidia/cryptonight.h"
#endif
static inline OSVERSIONINFOEX winOsVersion()
{
@ -49,19 +53,23 @@ static inline OSVERSIONINFOEX winOsVersion()
}
char *Network::userAgent()
static inline char *createUserAgent()
{
const auto osver = winOsVersion();
const size_t max = 160;
const int cudaVersion = cuda_get_runtime_version();
char *buf = new char[128];
char *buf = new char[max];
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
# if defined(__x86_64__) || defined(_M_AMD64)
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s CUDA/%d.%d", uv_version_string(), cudaVersion / 1000, cudaVersion % 100);
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string());
# else
length += snprintf(buf + length, max - length, ") libuv/%s CUDA/%d.%d", uv_version_string(), cudaVersion / 1000, cudaVersion % 100);
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
# 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__
@ -72,3 +80,91 @@ char *Network::userAgent()
return buf;
}
void Platform::init(const char *userAgent)
{
m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
}
void Platform::release()
{
delete [] m_defaultConfigName;
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
if (priority == -1) {
return;
}
DWORD prio = IDLE_PRIORITY_CLASS;
switch (priority)
{
case 1:
prio = BELOW_NORMAL_PRIORITY_CLASS;
break;
case 2:
prio = NORMAL_PRIORITY_CLASS;
break;
case 3:
prio = ABOVE_NORMAL_PRIORITY_CLASS;
break;
case 4:
prio = HIGH_PRIORITY_CLASS;
break;
case 5:
prio = REALTIME_PRIORITY_CLASS;
default:
break;
}
SetPriorityClass(GetCurrentProcess(), prio);
}
void Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
}
int prio = THREAD_PRIORITY_IDLE;
switch (priority)
{
case 1:
prio = THREAD_PRIORITY_BELOW_NORMAL;
break;
case 2:
prio = THREAD_PRIORITY_NORMAL;
break;
case 3:
prio = THREAD_PRIORITY_ABOVE_NORMAL;
break;
case 4:
prio = THREAD_PRIORITY_HIGHEST;
break;
case 5:
prio = THREAD_PRIORITY_TIME_CRITICAL;
break;
default:
break;
}
SetThreadPriority(GetCurrentThread(), prio);
}

View File

@ -127,7 +127,7 @@ void ConsoleLog::print(char *fmt, va_list args)
uv_buf_t buf;
buf.base = strdup(m_buf);
buf.len = (ULONG) strlen(buf.base);
buf.len = strlen(buf.base);
uv_write_t *req = new uv_write_t;
req->data = buf.base;

View File

@ -199,6 +199,28 @@ int64_t Client::submit(const JobResult &result)
}
bool Client::isCriticalError(const char *message)
{
if (!message) {
return false;
}
if (strncasecmp(message, "Unauthenticated", 15) == 0) {
return true;
}
if (strncasecmp(message, "your IP is banned", 17) == 0) {
return true;
}
if (strncasecmp(message, "IP Address currently banned", 27) == 0) {
return true;
}
return false;
}
bool Client::parseJob(const json_t *params, int *code)
{
if (!json_is_object(params)) {
@ -405,7 +427,7 @@ void Client::parseResponse(int64_t id, const json_t *result, const json_t *error
LOG_ERR("[%s:%u] error: \"%s\", code: %" PRId64, m_url.host(), m_url.port(), message, json_integer_value(json_object_get(error, "code")));
}
if (id == 1 || (message && strncasecmp(message, "Unauthenticated", 15) == 0)) {
if (id == 1 || isCriticalError(message)) {
close();
}
@ -501,7 +523,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
auto client = getClient(handle->data);
buf->base = &client->m_recvBuf.base[client->m_recvBufPos];
buf->len = client->m_recvBuf.len - (ULONG) client->m_recvBufPos;
buf->len = client->m_recvBuf.len - client->m_recvBufPos;
}

View File

@ -77,6 +77,7 @@ public:
private:
constexpr static size_t kRecvBufSize = 4096;
bool isCriticalError(const char *message);
bool parseJob(const json_t *params, int *code);
bool parseLogin(const json_t *result, int *code);
int resolve(const char *host);

View File

@ -38,6 +38,7 @@
#include "net/strategies/SinglePoolStrategy.h"
#include "net/Url.h"
#include "Options.h"
#include "Platform.h"
#include "workers/Workers.h"
@ -50,19 +51,18 @@ Network::Network(const Options *options) :
srand(time(0) ^ (uintptr_t) this);
Workers::setListener(this);
m_agent = userAgent();
const std::vector<Url*> &pools = options->pools();
if (pools.size() > 1) {
m_strategy = new FailoverStrategy(pools, m_agent, this);
m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this);
}
else {
m_strategy = new SinglePoolStrategy(pools.front(), m_agent, this);
m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this);
}
if (m_options->donateLevel() > 0) {
m_donate = new DonateStrategy(m_agent, this);
m_donate = new DonateStrategy(Platform::userAgent(), this);
}
m_timer.data = this;
@ -74,7 +74,6 @@ Network::Network(const Options *options) :
Network::~Network()
{
free(m_agent);
}

View File

@ -47,8 +47,6 @@ public:
void connect();
void stop();
static char *userAgent();
protected:
void onActive(Client *client) override;
void onJob(Client *client, const Job &job) override;
@ -64,7 +62,6 @@ private:
static void onTick(uv_timer_t *handle);
char *m_agent;
const Options *m_options;
IStrategy *m_donate;
IStrategy *m_strategy;