1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-26 14:02:53 -05:00

Merge xmrig v6.7.0 into master

This commit is contained in:
MoneroOcean
2020-12-23 06:03:02 +00:00
249 changed files with 6814 additions and 6134 deletions

View File

@@ -1,12 +1,6 @@
/* 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 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,12 +1,6 @@
/* 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 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,12 +1,6 @@
/* 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 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,12 +1,6 @@
/* 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 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -95,7 +95,7 @@ void xmrig::FetchRequest::setBody(const rapidjson::Value &value)
}
void xmrig::fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type)
void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type, uint64_t rpcId)
{
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
@@ -109,14 +109,15 @@ void xmrig::fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listen
HttpClient *client;
# ifdef XMRIG_FEATURE_TLS
if (req.tls) {
client = new HttpsClient(std::move(req), listener);
client = new HttpsClient(tag, std::move(req), listener);
}
else
# endif
{
client = new HttpClient(std::move(req), listener);
client = new HttpClient(tag, std::move(req), listener);
}
client->userType = type;
client->rpcId = rpcId;
client->connect();
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -58,10 +58,11 @@ public:
String host;
String path;
uint16_t port = 0;
uint64_t timeout = 0;
};
void fetch(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type = 0);
void fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener, int type = 0, uint64_t rpcId = 0);
} // namespace xmrig

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -30,6 +24,7 @@
#include "base/kernel/Platform.h"
#include "base/net/dns/Dns.h"
#include "base/net/tools/NetBuffer.h"
#include "base/tools/Timer.h"
#include <sstream>
@@ -44,21 +39,20 @@ static const char *kCRLF = "\r\n";
} // namespace xmrig
xmrig::HttpClient::HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
HttpContext(HTTP_RESPONSE, listener),
m_tag(tag),
m_req(std::move(req))
{
method = m_req.method;
url = std::move(m_req.path);
body = std::move(m_req.body);
headers = std::move(m_req.headers);
m_dns = new Dns(this);
}
m_dns = std::make_shared<Dns>(this);
xmrig::HttpClient::~HttpClient()
{
delete m_dns;
if (m_req.timeout) {
m_timer = std::make_shared<Timer>(this, m_req.timeout, 0);
}
}
@@ -74,7 +68,7 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status)
if (status < 0 && dns.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), port(), uv_strerror(status));
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
}
return;
@@ -91,6 +85,12 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status)
}
void xmrig::HttpClient::onTimer(const Timer *)
{
close(UV_ETIMEDOUT);
}
void xmrig::HttpClient::handshake()
{
headers.insert({ "Host", host() });
@@ -135,8 +135,12 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
}
if (status < 0) {
if (status == UV_ECANCELED) {
status = UV_ETIMEDOUT;
}
if (!client->isQuiet()) {
LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(status));
LOG_ERR("%s " RED("connect error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(status));
}
return client->close(status);
@@ -151,7 +155,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status)
client->read(buf->base, static_cast<size_t>(nread));
} else {
if (!client->isQuiet() && nread != UV_EOF) {
LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(static_cast<int>(nread)));
LOG_ERR("%s " RED("read error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(static_cast<int>(nread)));
}
client->close(static_cast<int>(nread));

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -29,6 +23,7 @@
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/net/http/Fetch.h"
#include "base/net/http/HttpContext.h"
#include "base/tools/Object.h"
@@ -40,22 +35,24 @@ namespace xmrig {
class String;
class HttpClient : public HttpContext, public IDnsListener
class HttpClient : public HttpContext, public IDnsListener, public ITimerListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpClient);
HttpClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
~HttpClient() override;
HttpClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
~HttpClient() override = default;
inline bool isQuiet() const { return m_req.quiet; }
inline const char *host() const override { return m_req.host; }
inline const char *tag() const { return m_tag; }
inline uint16_t port() const override { return m_req.port; }
bool connect();
protected:
void onResolved(const Dns &dns, int status) override;
void onTimer(const Timer *timer) override;
virtual void handshake();
virtual void read(const char *data, size_t size);
@@ -66,8 +63,10 @@ protected:
private:
static void onConnect(uv_connect_t *req, int status);
Dns *m_dns;
const char *m_tag;
FetchRequest m_req;
std::shared_ptr<Dns> m_dns;
std::shared_ptr<Timer> m_timer;
};

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -160,6 +154,10 @@ uint64_t xmrig::HttpContext::elapsed() const
void xmrig::HttpContext::close(int status)
{
if (!get(id())) {
return;
}
auto listener = httpListener();
if (status < 0 && listener) {
@@ -262,7 +260,7 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
settings->on_body = [](http_parser *parser, const char *at, size_t len) -> int
{
static_cast<HttpContext*>(parser->data)->body += std::string(at, len);
static_cast<HttpContext*>(parser->data)->body.append(at, len);
return 0;
};

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -31,7 +25,7 @@
#include "base/net/https/HttpsClient.h"
#include "base/io/log/Log.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
#ifdef _MSC_VER
@@ -39,8 +33,8 @@
#endif
xmrig::HttpsClient::HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
HttpClient(std::move(req), listener)
xmrig::HttpsClient::HttpsClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener) :
HttpClient(tag, std::move(req), listener)
{
m_ctx = SSL_CTX_new(SSLv23_method());
assert(m_ctx != nullptr);
@@ -182,7 +176,7 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert)
return false;
}
Buffer::toHex(md, 32, m_fingerprint);
Cvt::toHex(m_fingerprint, sizeof(m_fingerprint), md, 32);
return req().fingerprint.isNull() || strncasecmp(m_fingerprint, req().fingerprint.data(), 64) == 0;
}

View File

@@ -1,13 +1,7 @@
/* 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 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -46,7 +40,7 @@ class HttpsClient : public HttpClient
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsClient)
HttpsClient(FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
HttpsClient(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttpListener> &listener);
~HttpsClient() override;
const char *tlsFingerprint() const override;

View File

@@ -50,7 +50,7 @@
#include "base/net/dns/Dns.h"
#include "base/net/stratum/Socks5.h"
#include "base/net/tools/NetBuffer.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
#include "base/tools/Chrono.h"
#include "net/JobResult.h"
@@ -204,11 +204,8 @@ int64_t xmrig::Client::submit(const JobResult &result)
char *nonce = m_sendBuf.data();
char *data = m_sendBuf.data() + 16;
Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
nonce[8] = '\0';
Buffer::toHex(result.result(), 32, data);
data[64] = '\0';
Cvt::toHex(nonce, sizeof(uint32_t) * 2 + 1, reinterpret_cast<const uint8_t *>(&result.nonce), sizeof(uint32_t));
Cvt::toHex(data, 65, result.result(), 32);
# endif
Document doc(kObjectType);

View File

@@ -36,7 +36,7 @@
#include "base/net/http/HttpData.h"
#include "base/net/http/HttpListener.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
#include "base/tools/Timer.h"
#include "net/JobResult.h"
@@ -54,7 +54,7 @@ static const char *kHash = "hash";
static const char *kHeight = "height";
static const char *kJsonRPC = "/json_rpc";
static const size_t BlobReserveSize = 8;
static constexpr size_t kBlobReserveSize = 8;
}
@@ -104,7 +104,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
# ifdef XMRIG_PROXY_PROJECT
memcpy(data + 78, result.nonce, 8);
# else
Buffer::toHex(reinterpret_cast<const uint8_t *>(&result.nonce), 4, data + 78);
Cvt::toHex(data + 78, 9, reinterpret_cast<const uint8_t *>(&result.nonce), 4);
# endif
using namespace rapidjson;
@@ -227,7 +227,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
m_blockhashingblob = Json::getString(params, "blockhashing_blob");
if (m_apiVersion == API_DERO) {
const uint64_t offset = Json::getUint64(params, "reserved_offset");
Buffer::toHex(Buffer::randomBytes(BlobReserveSize).data(), BlobReserveSize, m_blockhashingblob.data() + offset * 2);
Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2 + 1, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
}
if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) {
@@ -315,10 +315,10 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
Value params(kObjectType);
params.AddMember("wallet_address", m_user.toJSON(), allocator);
if (m_apiVersion == API_DERO) {
params.AddMember("reserve_size", static_cast<uint64_t>(BlobReserveSize), allocator);
params.AddMember("reserve_size", static_cast<uint64_t>(kBlobReserveSize), allocator);
}
else {
params.AddMember("extra_nonce", Buffer::randomBytes(BlobReserveSize).toHex().toJSON(doc), allocator);
params.AddMember("extra_nonce", Cvt::toHex(Cvt::randomBytes(kBlobReserveSize)).toJSON(doc), allocator);
}
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);
@@ -330,7 +330,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc)
{
FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet());
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
return m_sequence++;
}
@@ -357,7 +357,7 @@ void xmrig::DaemonClient::retry()
void xmrig::DaemonClient::send(const char *path)
{
FetchRequest req(HTTP_GET, m_pool.host(), m_pool.port(), path, m_pool.isTLS(), isQuiet());
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
}

View File

@@ -31,6 +31,7 @@
#include "base/net/stratum/Job.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
@@ -59,11 +60,13 @@ bool xmrig::Job::setBlob(const char *blob)
}
m_size /= 2;
if (m_size < 76 || m_size >= sizeof(m_blob)) {
const size_t minSize = nonceOffset() + nonceSize();
if (m_size < minSize || m_size >= sizeof(m_blob)) {
return false;
}
if (!Buffer::fromHex(blob, m_size * 2, m_blob)) {
if (!Cvt::fromHex(m_blob, sizeof(m_blob), blob, m_size * 2)) {
return false;
}
@@ -90,9 +93,9 @@ bool xmrig::Job::setSeedHash(const char *hash)
m_rawSeedHash = hash;
# endif
m_seed = Buffer::fromHex(hash, kMaxSeedSize * 2);
m_seed = Cvt::fromHex(hash, kMaxSeedSize * 2);
return !m_seed.isEmpty();
return !m_seed.empty();
}
@@ -102,27 +105,14 @@ bool xmrig::Job::setTarget(const char *target)
return false;
}
const size_t len = strlen(target);
const auto raw = Cvt::fromHex(target, strlen(target));
const size_t size = raw.size();
if (len <= 8) {
uint32_t tmp = 0;
char str[8];
memcpy(str, target, len);
if (!Buffer::fromHex(str, 8, reinterpret_cast<uint8_t *>(&tmp)) || tmp == 0) {
return false;
}
m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / static_cast<uint64_t>(tmp));
if (size == 4) {
m_target = 0xFFFFFFFFFFFFFFFFULL / (0xFFFFFFFFULL / uint64_t(*reinterpret_cast<const uint32_t *>(raw.data())));
}
else if (len <= 16) {
m_target = 0;
char str[16];
memcpy(str, target, len);
if (!Buffer::fromHex(str, 16, reinterpret_cast<uint8_t *>(&m_target)) || m_target == 0) {
return false;
}
else if (size == 8) {
m_target = *reinterpret_cast<const uint64_t *>(raw.data());
}
else {
return false;

View File

@@ -154,7 +154,7 @@ void xmrig::SelfSelectClient::getBlockTemplate()
JsonRequest::create(doc, m_sequence++, "getblocktemplate", params);
FetchRequest req(HTTP_POST, pool().daemon().host(), pool().daemon().port(), "/json_rpc", doc, pool().daemon().isTLS(), isQuiet());
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
}

View File

@@ -27,7 +27,7 @@
#include "base/net/stratum/Tls.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Client.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
#ifdef _MSC_VER
@@ -183,7 +183,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
return false;
}
Buffer::toHex(md, 32, m_fingerprint);
Cvt::toHex(m_fingerprint, sizeof(m_fingerprint), md, 32);
const char *fingerprint = m_client->m_pool.fingerprint();
return fingerprint == nullptr || strncasecmp(m_fingerprint, fingerprint, 64) == 0;

View File

@@ -31,6 +31,7 @@
#include "base/net/http/HttpData.h"
#include "base/net/http/HttpListener.h"
#include "base/net/stratum/benchmark/BenchConfig.h"
#include "base/tools/Cvt.h"
#include "version.h"
@@ -217,7 +218,7 @@ bool xmrig::BenchClient::setSeed(const char *seed)
return false;
}
if (!Buffer::fromHex(seed, size * 2, m_job.blob())) {
if (!Cvt::fromHex(m_job.blob(), m_job.size(), seed, size * 2)) {
return false;
}
@@ -321,7 +322,7 @@ void xmrig::BenchClient::send(Request request)
case GET_BENCH:
{
FetchRequest req(HTTP_GET, m_ip, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_job.id()).c_str(), BenchConfig::kApiTLS, true);
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
}
break;
@@ -335,7 +336,7 @@ void xmrig::BenchClient::send(Request request)
doc.AddMember("cpu", Cpu::toJSON(doc), allocator);
FetchRequest req(HTTP_POST, m_ip, BenchConfig::kApiPort, "/1/benchmark", doc, BenchConfig::kApiTLS, true);
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
}
break;
@@ -374,6 +375,6 @@ void xmrig::BenchClient::update(const rapidjson::Value &body)
FetchRequest req(HTTP_PATCH, m_ip, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_job.id()).c_str(), body, BenchConfig::kApiTLS, true);
req.headers.insert({ "Authorization", fmt::format("Bearer {}", m_token)});
fetch(std::move(req), m_httpListener);
fetch(tag(), std::move(req), m_httpListener);
}
#endif

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -20,6 +20,7 @@
#include "base/net/tls/ServerTls.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <openssl/ssl.h>
@@ -39,11 +40,23 @@ xmrig::ServerTls::~ServerTls()
}
bool xmrig::ServerTls::isHTTP(const char *data, size_t size)
{
assert(size > 0);
static const char test[6] = "GET /";
return size > 0 && memcmp(data, test, std::min(size, sizeof(test) - 1)) == 0;
}
bool xmrig::ServerTls::isTLS(const char *data, size_t size)
{
assert(size > 0);
static const uint8_t test[3] = { 0x16, 0x03, 0x01 };
return size >= sizeof(test) && memcmp(data, test, sizeof(test)) == 0;
return size > 0 && memcmp(data, test, std::min(size, sizeof(test))) == 0;
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -41,6 +41,7 @@ public:
ServerTls(SSL_CTX *ctx);
virtual ~ServerTls();
static bool isHTTP(const char *data, size_t size);
static bool isTLS(const char *data, size_t size);
bool send(const char *data, size_t size);

View File

@@ -19,8 +19,9 @@
#include "base/net/tools/LineReader.h"
#include "base/net/tools/NetBuffer.h"
#include "base/kernel/constants.h"
#include "base/kernel/interfaces/ILineListener.h"
#include "base/net/tools/NetBuffer.h"
#include <cassert>
#include <cstring>
@@ -55,8 +56,8 @@ void xmrig::LineReader::reset()
void xmrig::LineReader::add(const char *data, size_t size)
{
if (size > NetBuffer::kChunkSize - m_pos) {
// it breakes correctness silently for long lines
if (size + m_pos > XMRIG_NET_BUFFER_CHUNK_SIZE) {
// it breaks correctness silently for long lines
return;
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -20,10 +20,11 @@
#define XMRIG_MEMPOOL_H
#include <map>
#include <set>
#include <array>
#include <cassert>
#include <cstddef>
#include <map>
#include <set>
namespace xmrig {

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -17,8 +17,9 @@
*/
#include "base/net/tools/MemPool.h"
#include "base/net/tools/NetBuffer.h"
#include "base/kernel/constants.h"
#include "base/net/tools/MemPool.h"
#include <cassert>
@@ -28,14 +29,13 @@
namespace xmrig {
static constexpr size_t kInitSize = 4;
static MemPool<NetBuffer::kChunkSize, kInitSize> *pool = nullptr;
static MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS> *pool = nullptr;
inline MemPool<NetBuffer::kChunkSize, kInitSize> *getPool()
inline MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS> *getPool()
{
if (!pool) {
pool = new MemPool<NetBuffer::kChunkSize, kInitSize>();
pool = new MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS>();
}
return pool;
@@ -67,17 +67,25 @@ void xmrig::NetBuffer::destroy()
void xmrig::NetBuffer::onAlloc(uv_handle_t *, size_t, uv_buf_t *buf)
{
buf->base = getPool()->allocate();
buf->len = kChunkSize;
buf->len = XMRIG_NET_BUFFER_CHUNK_SIZE;
}
void xmrig::NetBuffer::release(const char *buf)
{
if (buf == nullptr) {
return;
}
getPool()->deallocate(buf);
}
void xmrig::NetBuffer::release(const uv_buf_t *buf)
{
if (buf->base == nullptr) {
return;
}
getPool()->deallocate(buf->base);
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 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
@@ -33,8 +33,6 @@ namespace xmrig {
class NetBuffer
{
public:
static constexpr size_t kChunkSize = 16 * 1024;
static char *allocate();
static void destroy();
static void onAlloc(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);