Skip to content

Commit

Permalink
Merge branch 'master-xmrig'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendr0id committed May 23, 2024
2 parents 48e4233 + 704060b commit 03d57fe
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 50 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 2.8)
project(xmrigcc-proxy)
cmake_minimum_required(VERSION 3.5)
project(xmrig-proxy)


option(WITH_GOOGLE_BREAKPAD "Use Google Breakpad" OFF)
Expand Down Expand Up @@ -120,7 +120,7 @@ if (WIN32)
)

add_definitions(/DWIN32)
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv dbghelp)
elseif (APPLE)
set(SOURCES_OS
"${SOURCES_OS}"
Expand Down
7 changes: 7 additions & 0 deletions cmake/os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ elseif(XMRIG_OS_UNIX)
add_definitions(/DXMRIG_OS_FREEBSD)
endif()
endif()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(XMRIG_64_BIT ON)
add_definitions(-DXMRIG_64_BIT)
else()
set(XMRIG_64_BIT OFF)
endif()
33 changes: 25 additions & 8 deletions src/base/api/Api.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2024 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand All @@ -25,6 +25,8 @@
#include "base/crypto/keccak.h"
#include "base/io/Env.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/kernel/Base.h"
#include "base/tools/Chrono.h"
#include "base/tools/Cvt.h"
Expand Down Expand Up @@ -91,7 +93,11 @@ xmrig::Api::Api(Base *base) :
xmrig::Api::~Api()
{
# ifdef XMRIG_FEATURE_HTTP
delete m_httpd;
if (m_httpd) {
m_httpd->stop();
delete m_httpd;
m_httpd = nullptr; // Ensure the pointer is set to nullptr after deletion
}
# endif
}

Expand All @@ -109,30 +115,41 @@ void xmrig::Api::start()
genWorkerId(m_base->config()->apiWorkerId());

# ifdef XMRIG_FEATURE_HTTP
m_httpd = new Httpd(m_base);
m_httpd->start();
if (!m_httpd) {
m_httpd = new Httpd(m_base);
if (!m_httpd->start()) {
LOG_ERR("%s " RED_BOLD("HTTP API server failed to start."), Tags::network());

delete m_httpd; // Properly handle failure to start
m_httpd = nullptr;
}
}
# endif
}


void xmrig::Api::stop()
{
# ifdef XMRIG_FEATURE_HTTP
m_httpd->stop();
if (m_httpd) {
m_httpd->stop();
}
# endif
}


void xmrig::Api::tick()
{
# ifdef XMRIG_FEATURE_HTTP
if (m_httpd->isBound() || !m_base->config()->http().isEnabled()) {
if (!m_httpd || !m_base->config()->http().isEnabled() || m_httpd->isBound()) {
return;
}

if (++m_ticks % 10 == 0) {
m_ticks = 0;
m_httpd->start();
if (m_httpd) {
m_httpd->start();
}
}
# endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/base/api/Api.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2024 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down
1 change: 1 addition & 0 deletions src/base/crypto/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static const CoinInfo coinInfo[] = {
{ Algorithm::RX_LOZZ, "LOZZ", "Lozzax", 120, 1000000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " lozzax ") },
{ Algorithm::RX_XDAG, "XDAG", "Xdagger", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " xdagger ") },
{ Algorithm::RX_0, "ZEPH", "Zephyr", 120, 1000000000000, BLUE_BG_BOLD( WHITE_BOLD_S " zephyr ") },
{ Algorithm::RX_0, "Townforge","Townforge", 30, 100000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " townforge ") },
};


Expand Down
1 change: 1 addition & 0 deletions src/base/crypto/Coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Coin
LOZZAX,
XDAG,
ZEPHYR,
TOWNFORGE,
MAX
};

Expand Down
74 changes: 60 additions & 14 deletions src/base/io/log/FileLogWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


#include <cassert>
#include <uv.h>


namespace xmrig {
Expand All @@ -40,6 +39,32 @@ static void fsWriteCallback(uv_fs_t *req)
} // namespace xmrig


xmrig::FileLogWriter::FileLogWriter()
{
init();
}

xmrig::FileLogWriter::FileLogWriter(const char* fileName)
{
init();
open(fileName);
}

xmrig::FileLogWriter::~FileLogWriter()
{
uv_close(reinterpret_cast<uv_handle_t*>(&m_flushAsync), nullptr);

uv_mutex_destroy(&m_buffersLock);
}

void xmrig::FileLogWriter::init()
{
uv_mutex_init(&m_buffersLock);

uv_async_init(uv_default_loop(), &m_flushAsync, on_flush);
m_flushAsync.data = this;
}

bool xmrig::FileLogWriter::open(const char *fileName)
{
assert(fileName != nullptr);
Expand Down Expand Up @@ -77,30 +102,51 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
uv_buf_t buf = uv_buf_init(new char[size], size);
memcpy(buf.base, data, size);

auto req = new uv_fs_t;
req->data = buf.base;
uv_mutex_lock(&m_buffersLock);

uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback);
m_pos += size;
m_buffers.emplace_back(buf);
uv_async_send(&m_flushAsync);

uv_mutex_unlock(&m_buffersLock);

return true;
}


bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
{
const uv_buf_t buf[2] = {
uv_buf_init(new char[size], size),
uv_buf_init(const_cast<char *>(m_endl), sizeof(m_endl) - 1)
};
if (!isOpen()) {
return false;
}

constexpr size_t N = sizeof(m_endl) - 1;

uv_buf_t buf = uv_buf_init(new char[size + N], size + N);
memcpy(buf.base, data, size);
memcpy(buf.base + size, m_endl, N);

memcpy(buf[0].base, data, size);
uv_mutex_lock(&m_buffersLock);

auto req = new uv_fs_t;
req->data = buf[0].base;
m_buffers.emplace_back(buf);
uv_async_send(&m_flushAsync);

uv_fs_write(uv_default_loop(), req, m_file, buf, 2, m_pos, fsWriteCallback);
m_pos += (buf[0].len + buf[1].len);
uv_mutex_unlock(&m_buffersLock);

return true;
}

void xmrig::FileLogWriter::flush()
{
uv_mutex_lock(&m_buffersLock);

for (uv_buf_t buf : m_buffers) {
uv_fs_t* req = new uv_fs_t;
req->data = buf.base;

uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback);
m_pos += buf.len;
}
m_buffers.clear();

uv_mutex_unlock(&m_buffersLock);
}
18 changes: 16 additions & 2 deletions src/base/io/log/FileLogWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <cstddef>
#include <cstdint>
#include <vector>
#include <uv.h>


namespace xmrig {
Expand All @@ -30,8 +32,10 @@ namespace xmrig {
class FileLogWriter
{
public:
FileLogWriter() = default;
FileLogWriter(const char *fileName) { open(fileName); }
FileLogWriter();
FileLogWriter(const char* fileName);

~FileLogWriter();

inline bool isOpen() const { return m_file >= 0; }
inline int64_t pos() const { return m_pos; }
Expand All @@ -49,6 +53,16 @@ class FileLogWriter

int m_file = -1;
int64_t m_pos = 0;

uv_mutex_t m_buffersLock;
std::vector<uv_buf_t> m_buffers;

uv_async_t m_flushAsync;

void init();

static void on_flush(uv_async_t* async) { reinterpret_cast<FileLogWriter*>(async->data)->flush(); }
void flush();
};


Expand Down
7 changes: 3 additions & 4 deletions src/base/net/http/HttpApiResponse.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2024 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand All @@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "base/net/http/HttpApiResponse.h"
#include "3rdparty/rapidjson/prettywriter.h"
#include "3rdparty/rapidjson/stringbuffer.h"
Expand Down Expand Up @@ -65,7 +64,7 @@ void xmrig::HttpApiResponse::end()
}
}

if (!m_doc.MemberCount()) {
if (m_doc.IsObject() && m_doc.ObjectEmpty()) {
return HttpResponse::end();
}

Expand Down
8 changes: 4 additions & 4 deletions src/base/net/stratum/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 jtgrassie <https://github.com/jtgrassie>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2024 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -609,7 +609,7 @@ bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code)

parseExtensions(result);

const bool rc = parseJob(result["job"], code);
const bool rc = parseJob(Json::getObject(result, "job"), code);
m_jobs = 0;

return rc;
Expand Down Expand Up @@ -844,7 +844,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
m_listener->onLoginSuccess(this);

if (m_job.isValid()) {
m_listener->onJobReceived(this, m_job, result["job"]);
m_listener->onJobReceived(this, m_job, Json::getObject(result, "job"));
}

return;
Expand Down
12 changes: 6 additions & 6 deletions src/base/net/stratum/Pool.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <[email protected]>
* Copyright (c) 2018-2024 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2024 XMRig <https://github.com/xmrig>, <[email protected]>
*
* 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
Expand Down Expand Up @@ -59,7 +59,7 @@ class Pool
static const char *kCoin;
static const char *kDaemon;
static const char *kDaemonPollInterval;
static const char* kDaemonJobTimeout;
static const char *kDaemonJobTimeout;
static const char *kEnabled;
static const char *kFingerprint;
static const char *kKeepalive;
Expand All @@ -70,11 +70,11 @@ class Pool
static const char *kSOCKS5;
static const char *kSubmitToOrigin;
static const char *kTls;
static const char* kSni;
static const char *kSni;
static const char *kUrl;
static const char *kUser;
static const char* kSpendSecretKey;
static const char* kDaemonZMQPort;
static const char *kSpendSecretKey;
static const char *kDaemonZMQPort;
static const char *kNicehashHost;

constexpr static int kKeepAliveTimeout = 60;
Expand Down
Loading

0 comments on commit 03d57fe

Please sign in to comment.