From c80ef54b60a7a832009f70e47ee14b886c60d19e Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 4 Mar 2020 12:31:27 +0700 Subject: [PATCH 1/8] v5.8.2-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index a45051fd0..b90266992 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "5.8.1" +#define APP_VERSION "5.8.2-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2020 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 5 #define APP_VER_MINOR 8 -#define APP_VER_PATCH 1 +#define APP_VER_PATCH 2 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From b0dda2b5b33473c9c1ed41f1a583bdb8e9970790 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 4 Mar 2020 18:30:53 +0700 Subject: [PATCH 2/8] http-parser updated to latest version. --- src/3rdparty/http-parser/http_parser.c | 128 ++++++++++++++++++------- src/3rdparty/http-parser/http_parser.h | 7 +- 2 files changed, 101 insertions(+), 34 deletions(-) diff --git a/src/3rdparty/http-parser/http_parser.c b/src/3rdparty/http-parser/http_parser.c index e2fc5d2ee..0f76b6aca 100644 --- a/src/3rdparty/http-parser/http_parser.c +++ b/src/3rdparty/http-parser/http_parser.c @@ -381,7 +381,10 @@ enum header_states , h_transfer_encoding , h_upgrade + , h_matching_transfer_encoding_token_start , h_matching_transfer_encoding_chunked + , h_matching_transfer_encoding_token + , h_matching_connection_token_start , h_matching_connection_keep_alive , h_matching_connection_close @@ -1257,9 +1260,9 @@ reexecute: switch (parser->header_state) { case h_general: { - size_t limit = data + len - p; - limit = MIN(limit, max_header_size); - while (p+1 < data + limit && TOKEN(p[1])) { + size_t left = data + len - p; + const char* pe = p + MIN(left, max_header_size); + while (p+1 < pe && TOKEN(p[1])) { p++; } break; @@ -1335,6 +1338,7 @@ reexecute: parser->header_state = h_general; } else if (parser->index == sizeof(TRANSFER_ENCODING)-2) { parser->header_state = h_transfer_encoding; + parser->flags |= F_TRANSFER_ENCODING; } break; @@ -1416,10 +1420,14 @@ reexecute: if ('c' == c) { parser->header_state = h_matching_transfer_encoding_chunked; } else { - parser->header_state = h_general; + parser->header_state = h_matching_transfer_encoding_token; } break; + /* Multi-value `Transfer-Encoding` header */ + case h_matching_transfer_encoding_token_start: + break; + case h_content_length: if (UNLIKELY(!IS_NUM(ch))) { SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); @@ -1496,28 +1504,25 @@ reexecute: switch (h_state) { case h_general: - { - const char* p_cr; - const char* p_lf; - size_t limit = data + len - p; + { + size_t left = data + len - p; + const char* pe = p + MIN(left, max_header_size); - limit = MIN(limit, max_header_size); - - p_cr = (const char*) memchr(p, CR, limit); - p_lf = (const char*) memchr(p, LF, limit); - if (p_cr != NULL) { - if (p_lf != NULL && p_cr >= p_lf) - p = p_lf; - else - p = p_cr; - } else if (UNLIKELY(p_lf != NULL)) { - p = p_lf; - } else { - p = data + len; + for (; p != pe; p++) { + ch = *p; + if (ch == CR || ch == LF) { + --p; + break; + } + if (!lenient && !IS_HEADER_CHAR(ch)) { + SET_ERRNO(HPE_INVALID_HEADER_TOKEN); + goto error; + } + } + if (p == data + len) + --p; + break; } - --p; - break; - } case h_connection: case h_transfer_encoding: @@ -1566,16 +1571,41 @@ reexecute: goto error; /* Transfer-Encoding: chunked */ + case h_matching_transfer_encoding_token_start: + /* looking for 'Transfer-Encoding: chunked' */ + if ('c' == c) { + h_state = h_matching_transfer_encoding_chunked; + } else if (STRICT_TOKEN(c)) { + /* TODO(indutny): similar code below does this, but why? + * At the very least it seems to be inconsistent given that + * h_matching_transfer_encoding_token does not check for + * `STRICT_TOKEN` + */ + h_state = h_matching_transfer_encoding_token; + } else if (c == ' ' || c == '\t') { + /* Skip lws */ + } else { + h_state = h_general; + } + break; + case h_matching_transfer_encoding_chunked: parser->index++; if (parser->index > sizeof(CHUNKED)-1 || c != CHUNKED[parser->index]) { - h_state = h_general; + h_state = h_matching_transfer_encoding_token; } else if (parser->index == sizeof(CHUNKED)-2) { h_state = h_transfer_encoding_chunked; } break; + case h_matching_transfer_encoding_token: + if (ch == ',') { + h_state = h_matching_transfer_encoding_token_start; + parser->index = 0; + } + break; + case h_matching_connection_token_start: /* looking for 'Connection: keep-alive' */ if (c == 'k') { @@ -1634,7 +1664,7 @@ reexecute: break; case h_transfer_encoding_chunked: - if (ch != ' ') h_state = h_general; + if (ch != ' ') h_state = h_matching_transfer_encoding_token; break; case h_connection_keep_alive: @@ -1768,12 +1798,17 @@ reexecute: REEXECUTE(); } - /* Cannot use chunked encoding and a content-length header together - per the HTTP specification. */ - if ((parser->flags & F_CHUNKED) && + /* Cannot us transfer-encoding and a content-length header together + per the HTTP specification. (RFC 7230 Section 3.3.3) */ + if ((parser->flags & F_TRANSFER_ENCODING) && (parser->flags & F_CONTENTLENGTH)) { - SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH); - goto error; + /* Allow it for lenient parsing as long as `Transfer-Encoding` is + * not `chunked` + */ + if (!lenient || (parser->flags & F_CHUNKED)) { + SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH); + goto error; + } } UPDATE_STATE(s_headers_done); @@ -1848,8 +1883,31 @@ reexecute: UPDATE_STATE(NEW_MESSAGE()); CALLBACK_NOTIFY(message_complete); } else if (parser->flags & F_CHUNKED) { - /* chunked encoding - ignore Content-Length header */ + /* chunked encoding - ignore Content-Length header, + * prepare for a chunk */ UPDATE_STATE(s_chunk_size_start); + } else if (parser->flags & F_TRANSFER_ENCODING) { + if (parser->type == HTTP_REQUEST && !lenient) { + /* RFC 7230 3.3.3 */ + + /* If a Transfer-Encoding header field + * is present in a request and the chunked transfer coding is not + * the final encoding, the message body length cannot be determined + * reliably; the server MUST respond with the 400 (Bad Request) + * status code and then close the connection. + */ + SET_ERRNO(HPE_INVALID_TRANSFER_ENCODING); + RETURN(p - data); /* Error */ + } else { + /* RFC 7230 3.3.3 */ + + /* If a Transfer-Encoding header field is present in a response and + * the chunked transfer coding is not the final encoding, the + * message body length is determined by reading the connection until + * it is closed by the server. + */ + UPDATE_STATE(s_body_identity_eof); + } } else { if (parser->content_length == 0) { /* Content-Length header given but zero: Content-Length: 0\r\n */ @@ -2103,6 +2161,12 @@ http_message_needs_eof (const http_parser *parser) return 0; } + /* RFC 7230 3.3.3, see `s_headers_almost_done` */ + if ((parser->flags & F_TRANSFER_ENCODING) && + (parser->flags & F_CHUNKED) == 0) { + return 1; + } + if ((parser->flags & F_CHUNKED) || parser->content_length != ULLONG_MAX) { return 0; } diff --git a/src/3rdparty/http-parser/http_parser.h b/src/3rdparty/http-parser/http_parser.h index 880ed278e..983d88a91 100644 --- a/src/3rdparty/http-parser/http_parser.h +++ b/src/3rdparty/http-parser/http_parser.h @@ -27,7 +27,7 @@ extern "C" { /* Also update SONAME in the Makefile whenever you change these. */ #define HTTP_PARSER_VERSION_MAJOR 2 #define HTTP_PARSER_VERSION_MINOR 9 -#define HTTP_PARSER_VERSION_PATCH 0 +#define HTTP_PARSER_VERSION_PATCH 3 #include #if defined(_WIN32) && !defined(__MINGW32__) && \ @@ -225,6 +225,7 @@ enum flags , F_UPGRADE = 1 << 5 , F_SKIPBODY = 1 << 6 , F_CONTENTLENGTH = 1 << 7 + , F_TRANSFER_ENCODING = 1 << 8 }; @@ -271,6 +272,8 @@ enum flags "unexpected content-length header") \ XX(INVALID_CHUNK_SIZE, \ "invalid character in chunk size header") \ + XX(INVALID_TRANSFER_ENCODING, \ + "request has invalid transfer-encoding") \ XX(INVALID_CONSTANT, "invalid constant string") \ XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\ XX(STRICT, "strict mode assertion failed") \ @@ -293,11 +296,11 @@ enum http_errno { struct http_parser { /** PRIVATE **/ unsigned int type : 2; /* enum http_parser_type */ - unsigned int flags : 8; /* F_* values from 'flags' enum; semi-public */ unsigned int state : 7; /* enum state from http_parser.c */ unsigned int header_state : 7; /* enum header_state from http_parser.c */ unsigned int index : 7; /* index into current matcher */ unsigned int lenient_http_headers : 1; + unsigned int flags : 16; /* F_* values from 'flags' enum; semi-public */ uint32_t nread; /* # bytes read in various scenarios */ uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */ From 5486300db751168b5711ad4b56871acd970d3096 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 4 Mar 2020 21:00:49 +0700 Subject: [PATCH 3/8] Code cleanup. --- src/base/net/dns/DnsRecord.cpp | 11 ++++--- src/base/net/dns/DnsRecord.h | 8 ++--- src/base/net/http/HttpClient.cpp | 53 ++++++++++++------------------- src/base/net/http/HttpsClient.cpp | 5 +-- src/base/net/http/HttpsClient.h | 14 ++++---- 5 files changed, 39 insertions(+), 52 deletions(-) diff --git a/src/base/net/dns/DnsRecord.cpp b/src/base/net/dns/DnsRecord.cpp index 7a85799b2..e722ad6a6 100644 --- a/src/base/net/dns/DnsRecord.cpp +++ b/src/base/net/dns/DnsRecord.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -50,13 +50,14 @@ xmrig::DnsRecord::DnsRecord(const addrinfo *addr) : sockaddr *xmrig::DnsRecord::addr(uint16_t port) const { if (m_type == A) { - sockaddr_in *addr = new sockaddr_in(); + auto addr = new sockaddr_in(); uv_ip4_addr(m_ip.data(), port, addr); return reinterpret_cast(addr); } - else if (m_type == AAAA) { - sockaddr_in6 *addr = new sockaddr_in6(); + + if (m_type == AAAA) { + auto addr = new sockaddr_in6(); uv_ip6_addr(m_ip.data(), port, addr); return reinterpret_cast(addr); diff --git a/src/base/net/dns/DnsRecord.h b/src/base/net/dns/DnsRecord.h index 71d1e9c84..82932bb93 100644 --- a/src/base/net/dns/DnsRecord.h +++ b/src/base/net/dns/DnsRecord.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -45,7 +45,7 @@ public: AAAA }; - inline DnsRecord() : m_type(Unknown) {} + DnsRecord() = default; DnsRecord(const addrinfo *addr); sockaddr *addr(uint16_t port = 0) const; @@ -55,7 +55,7 @@ public: inline Type type() const { return m_type; } private: - Type m_type; + Type m_type = Unknown; String m_ip; }; diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index 364b3248a..a21f72d16 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -24,53 +24,45 @@ */ -#include - - +#include "base/net/http/HttpClient.h" #include "3rdparty/http-parser/http_parser.h" #include "base/io/log/Log.h" #include "base/kernel/Platform.h" #include "base/net/dns/Dns.h" -#include "base/net/http/HttpClient.h" #include "base/tools/Baton.h" +#include + + namespace xmrig { + static const char *kCRLF = "\r\n"; -class ClientWriteBaton : public Baton +class HttpClientWriteBaton : public Baton { public: - inline ClientWriteBaton(const std::string &header, std::string &&body) : + inline HttpClientWriteBaton(const std::string &header, std::string &&body) : m_body(std::move(body)), m_header(header) { - bufs[0].len = m_header.size(); - bufs[0].base = const_cast(m_header.c_str()); - - if (!m_body.empty()) { - bufs[1].len = m_body.size(); - bufs[1].base = const_cast(m_body.c_str()); - } - else { - bufs[1].base = nullptr; - bufs[1].len = 0; - } + m_bufs[0] = uv_buf_init(const_cast(m_header.c_str()), m_header.size()); + m_bufs[1] = m_body.empty() ? uv_buf_init(nullptr, 0) : uv_buf_init(const_cast(m_body.c_str()), m_body.size()); } - - inline size_t count() const { return bufs[1].base == nullptr ? 1 : 2; } - inline size_t size() const { return bufs[0].len + bufs[1].len; } - inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast(req->data); } - - - uv_buf_t bufs[2]{}; + void write(uv_stream_t *stream) + { + uv_write(&req, stream, m_bufs, nbufs(), [](uv_write_t *req, int) { delete reinterpret_cast(req->data); }); + } private: + inline size_t nbufs() const { return m_bufs[1].len > 0 ? 2 : 1; } + std::string m_body; std::string m_header; + uv_buf_t m_bufs[2]{}; }; @@ -129,6 +121,8 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status) req->data = this; uv_tcp_connect(req, m_tcp, addr, onConnect); + + delete addr; } @@ -167,8 +161,8 @@ void xmrig::HttpClient::read(const char *data, size_t size) void xmrig::HttpClient::write(const std::string &header) { - auto baton = new ClientWriteBaton(header, std::move(body)); - uv_write(&baton->req, stream(), baton->bufs, baton->count(), ClientWriteBaton::onWrite); + auto baton = new HttpClientWriteBaton(header, std::move(body)); + baton->write(stream()); } @@ -194,12 +188,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status) [](uv_handle_t *, size_t suggested_size, uv_buf_t *buf) { buf->base = new char[suggested_size]; - -# ifdef _WIN32 - buf->len = static_cast(suggested_size); -# else - buf->len = suggested_size; -# endif + buf->len = suggested_size; }, [](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf) { diff --git a/src/base/net/http/HttpsClient.cpp b/src/base/net/http/HttpsClient.cpp index 7bebb3bd0..cdc4629b4 100644 --- a/src/base/net/http/HttpsClient.cpp +++ b/src/base/net/http/HttpsClient.cpp @@ -29,8 +29,8 @@ #include -#include "base/io/log/Log.h" #include "base/net/http/HttpsClient.h" +#include "base/io/log/Log.h" #include "base/tools/Buffer.h" @@ -41,9 +41,6 @@ xmrig::HttpsClient::HttpsClient(int method, const String &url, const std::weak_ptr &listener, const char *data, size_t size, const String &fingerprint) : HttpClient(method, url, listener, data, size), - m_ready(false), - m_buf(), - m_ssl(nullptr), m_fp(fingerprint) { m_ctx = SSL_CTX_new(SSLv23_method()); diff --git a/src/base/net/http/HttpsClient.h b/src/base/net/http/HttpsClient.h index 13eb5f679..b15eee3e4 100644 --- a/src/base/net/http/HttpsClient.h +++ b/src/base/net/http/HttpsClient.h @@ -62,13 +62,13 @@ private: bool verifyFingerprint(X509 *cert); void flush(); - BIO *m_readBio; - BIO *m_writeBio; - bool m_ready; - char m_buf[1024 * 2]; - char m_fingerprint[32 * 2 + 8]; - SSL *m_ssl; - SSL_CTX *m_ctx; + BIO *m_readBio = nullptr; + BIO *m_writeBio = nullptr; + bool m_ready = false; + char m_buf[1024 * 2]{}; + char m_fingerprint[32 * 2 + 8]{}; + SSL *m_ssl = nullptr; + SSL_CTX *m_ctx = nullptr; String m_fp; }; From eeadea53e2ee0841927e23fbf97bd26848b8dc86 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Thu, 5 Mar 2020 12:20:21 +0100 Subject: [PATCH 4/8] AstroBWT 20-50% speedup Skips hashes with large stage 2 size. Added configurable `astrobwt-max-size` parameter, default value is 550, min 400, max 1200, optimal value ranges from 500 to 600 depending on CPU. - Intel CPUs get 20-25% speedup - 1st- and 2nd-gen Ryzens get 30% speedup - 3rd-gen Ryzens get up to 50% speedup --- src/backend/cpu/CpuBackend.cpp | 4 ++++ src/backend/cpu/CpuConfig.cpp | 22 +++++++++++++++++++++- src/backend/cpu/CpuConfig.h | 2 ++ src/backend/cpu/CpuLaunchData.cpp | 3 ++- src/backend/cpu/CpuLaunchData.h | 1 + src/backend/cpu/CpuWorker.cpp | 27 +++++++++++++++++++++------ src/backend/cpu/CpuWorker.h | 1 + src/config.json | 1 + src/core/config/Config_default.h | 1 + src/crypto/astrobwt/AstroBWT.cpp | 10 ++++++++-- src/crypto/astrobwt/AstroBWT.h | 1 + 11 files changed, 63 insertions(+), 10 deletions(-) diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 9ada16376..1efc1eafe 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -416,6 +416,10 @@ rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const out.AddMember("argon2-impl", argon2::Impl::name().toJSON(), allocator); # endif +# ifdef XMRIG_ALGO_ASTROBWT + out.AddMember("astrobwt-max-size", cpu.astrobwtMaxSize(), allocator); +# endif + out.AddMember("hugepages", d_ptr->hugePages(2, doc), allocator); out.AddMember("memory", static_cast(d_ptr->algo.isValid() ? (d_ptr->ways() * d_ptr->algo.l3()) : 0), allocator); diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index 31921f183..3a17dc1f4 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -28,6 +28,7 @@ #include "backend/cpu/Cpu.h" #include "base/io/json/Json.h" #include "rapidjson/document.h" +#include namespace xmrig { @@ -48,6 +49,11 @@ static const char *kAsm = "asm"; static const char *kArgon2Impl = "argon2-impl"; #endif +#ifdef XMRIG_ALGO_ASTROBWT +static const char* kAstroBWTMaxSize = "astrobwt-max-size"; +#endif + + extern template class Threads; } @@ -85,6 +91,10 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const obj.AddMember(StringRef(kArgon2Impl), m_argon2Impl.toJSON(), allocator); # endif +# ifdef XMRIG_ALGO_ASTROBWT + obj.AddMember(StringRef(kAstroBWTMaxSize), m_astrobwtMaxSize, allocator); +# endif + m_threads.toJSON(obj, doc); return obj; @@ -136,6 +146,16 @@ void xmrig::CpuConfig::read(const rapidjson::Value &value) m_argon2Impl = Json::getString(value, kArgon2Impl); # endif +# ifdef XMRIG_ALGO_ASTROBWT + const auto& obj = Json::getValue(value, kAstroBWTMaxSize); + if (obj.IsNull() || !obj.IsInt()) { + m_shouldSave = true; + } + else { + m_astrobwtMaxSize = std::min(std::max(obj.GetInt(), 400), 1200); + } +# endif + m_threads.read(value); generate(); @@ -167,7 +187,7 @@ void xmrig::CpuConfig::generate() count += xmrig::generate(m_threads, m_limit); count += xmrig::generate(m_threads, m_limit); - m_shouldSave = count > 0; + m_shouldSave |= count > 0; } diff --git a/src/backend/cpu/CpuConfig.h b/src/backend/cpu/CpuConfig.h index a9c408069..090b7e6dd 100644 --- a/src/backend/cpu/CpuConfig.h +++ b/src/backend/cpu/CpuConfig.h @@ -58,6 +58,7 @@ public: inline bool isYield() const { return m_yield; } inline const Assembly &assembly() const { return m_assembly; } inline const String &argon2Impl() const { return m_argon2Impl; } + inline int astrobwtMaxSize() const { return m_astrobwtMaxSize; } inline const Threads &threads() const { return m_threads; } inline int priority() const { return m_priority; } inline uint32_t limit() const { return m_limit; } @@ -78,6 +79,7 @@ private: int m_memoryPool = 0; int m_priority = -1; String m_argon2Impl; + int m_astrobwtMaxSize = 550; Threads m_threads; uint32_t m_limit = 100; }; diff --git a/src/backend/cpu/CpuLaunchData.cpp b/src/backend/cpu/CpuLaunchData.cpp index 76da267c1..111adea30 100644 --- a/src/backend/cpu/CpuLaunchData.cpp +++ b/src/backend/cpu/CpuLaunchData.cpp @@ -42,7 +42,8 @@ xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorit priority(config.priority()), affinity(thread.affinity()), miner(miner), - intensity(std::min(thread.intensity(), algorithm.maxIntensity())) + intensity(std::min(thread.intensity(), algorithm.maxIntensity())), + astrobwtMaxSize(config.astrobwtMaxSize()) { } diff --git a/src/backend/cpu/CpuLaunchData.h b/src/backend/cpu/CpuLaunchData.h index 6a1ee30e4..37814e686 100644 --- a/src/backend/cpu/CpuLaunchData.h +++ b/src/backend/cpu/CpuLaunchData.h @@ -65,6 +65,7 @@ public: const int64_t affinity; const Miner *miner; const uint32_t intensity; + const int astrobwtMaxSize; }; diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index e74ee6ff9..b0934aad1 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -32,6 +32,7 @@ #include "core/Miner.h" #include "crypto/cn/CnCtx.h" #include "crypto/cn/CryptoNight_test.h" +#include "crypto/cn/CryptoNight.h" #include "crypto/common/Nonce.h" #include "crypto/common/VirtualMemory.h" #include "crypto/rx/Rx.h" @@ -76,6 +77,7 @@ xmrig::CpuWorker::CpuWorker(size_t id, const CpuLaunchData &data) : Worker(id, data.affinity, data.priority), m_algorithm(data.algorithm), m_assembly(data.assembly), + m_astrobwtMaxSize(data.astrobwtMaxSize * 1000), m_hwAES(data.hwAES), m_yield(data.yield), m_av(data.av()), @@ -240,6 +242,8 @@ void xmrig::CpuWorker::start() current_job_nonces[i] = *m_job.nonce(i); } + bool valid = true; + # ifdef XMRIG_ALGO_RANDOMX if (job.algorithm().family() == Algorithm::RANDOM_X) { if (first) { @@ -256,20 +260,31 @@ void xmrig::CpuWorker::start() else # endif { - fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height()); +# ifdef XMRIG_ALGO_ASTROBWT + if (job.algorithm().family() == Algorithm::ASTROBWT) { + if (!astrobwt::astrobwt_dero(m_job.blob(), job.size(), m_ctx[0]->memory, m_hash, m_astrobwtMaxSize)) + valid = false; + } + else +# endif + { + fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height()); + } + if (!nextRound(m_job)) { break; }; } - for (size_t i = 0; i < N; ++i) { - if (*reinterpret_cast(m_hash + (i * 32) + 24) < job.target()) { - JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32)); + if (valid) { + for (size_t i = 0; i < N; ++i) { + if (*reinterpret_cast(m_hash + (i * 32) + 24) < job.target()) { + JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32)); + } } + m_count += N; } - m_count += N; - if (m_yield) { std::this_thread::yield(); } diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h index d9528cf95..1e715357b 100644 --- a/src/backend/cpu/CpuWorker.h +++ b/src/backend/cpu/CpuWorker.h @@ -70,6 +70,7 @@ private: const Algorithm m_algorithm; const Assembly m_assembly; + const int m_astrobwtMaxSize; const bool m_hwAES; const bool m_yield; const CnHash::AlgoVariant m_av; diff --git a/src/config.json b/src/config.json index c2ea92199..70096cf7c 100644 --- a/src/config.json +++ b/src/config.json @@ -31,6 +31,7 @@ "max-threads-hint": 100, "asm": true, "argon2-impl": null, + "astrobwt-max-size": 550, "cn/0": false, "cn-lite/0": false }, diff --git a/src/core/config/Config_default.h b/src/core/config/Config_default.h index 3db93a82f..8b37d1c0c 100644 --- a/src/core/config/Config_default.h +++ b/src/core/config/Config_default.h @@ -63,6 +63,7 @@ R"===( "max-threads-hint": 100, "asm": true, "argon2-impl": null, + "astrobwt-max-size": 550, "cn/0": false, "cn-lite/0": false }, diff --git a/src/crypto/astrobwt/AstroBWT.cpp b/src/crypto/astrobwt/AstroBWT.cpp index b4595f87a..f86a42cc5 100644 --- a/src/crypto/astrobwt/AstroBWT.cpp +++ b/src/crypto/astrobwt/AstroBWT.cpp @@ -30,6 +30,7 @@ #include "AstroBWT.h" #include "sha3.h" #include "crypto/cn/CryptoNight.h" +#include constexpr int STAGE1_SIZE = 147253; constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63)); @@ -152,7 +153,7 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi } } -void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash) +bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size) { uint8_t key[32]; uint8_t* scratchpad_ptr = (uint8_t*)(scratchpad) + 64; @@ -178,6 +179,9 @@ void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad sha3_HashBuffer(256, SHA3_FLAGS_NONE, stage1_result, STAGE1_SIZE + 1, key, sizeof(key)); const int stage2_size = STAGE1_SIZE + (*(uint32_t*)(key) & 0xfffff); + if (stage2_size > stage2_max_size) + return false; + Salsa20_XORKeyStream(key, stage2_output, stage2_size); sort_indices(stage2_size + 1, stage2_output, indices, tmp_indices); @@ -198,10 +202,12 @@ void astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad } sha3_HashBuffer(256, SHA3_FLAGS_NONE, stage2_result, stage2_size + 1, output_hash, 32); + + return true; } template<> void xmrig::astrobwt::single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t) { - astrobwt_dero(input, static_cast(size), ctx[0]->memory, output); + astrobwt_dero(input, static_cast(size), ctx[0]->memory, output, std::numeric_limits::max()); } diff --git a/src/crypto/astrobwt/AstroBWT.h b/src/crypto/astrobwt/AstroBWT.h index 66a69cd5a..7a3734708 100644 --- a/src/crypto/astrobwt/AstroBWT.h +++ b/src/crypto/astrobwt/AstroBWT.h @@ -34,6 +34,7 @@ struct cryptonight_ctx; namespace xmrig { namespace astrobwt { +bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size); template void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t); From cad5fef1eafdee877a2637b34f2911920e80b8fb Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 6 Mar 2020 12:38:09 +0700 Subject: [PATCH 5/8] HTTP subsystem refactoring. --- src/base/api/Httpd.cpp | 5 +- src/base/base.cmake | 4 + src/base/io/json/JsonRequest.cpp | 42 +++++- src/base/io/json/JsonRequest.h | 7 +- src/base/io/log/Log.cpp | 6 +- src/base/io/log/Log.h | 6 +- src/base/net/http/Fetch.cpp | 155 ++++++++++++++++++++++ src/base/net/http/Fetch.h | 74 +++++++++++ src/base/net/http/HttpApiResponse.cpp | 9 +- src/base/net/http/HttpApiResponse.h | 4 +- src/base/net/http/HttpClient.cpp | 46 +++---- src/base/net/http/HttpClient.h | 18 +-- src/base/net/http/HttpContext.cpp | 6 + src/base/net/http/HttpContext.h | 10 +- src/base/net/http/HttpData.cpp | 31 +++++ src/base/net/http/HttpData.h | 27 +++- src/base/net/http/HttpListener.cpp | 41 ++++++ src/base/net/http/HttpListener.h | 2 +- src/base/net/http/HttpsClient.cpp | 21 ++- src/base/net/http/HttpsClient.h | 7 +- src/base/net/stratum/DaemonClient.cpp | 93 +++---------- src/base/net/stratum/DaemonClient.h | 6 +- src/base/net/stratum/SelfSelectClient.cpp | 55 +------- src/base/net/stratum/SelfSelectClient.h | 2 - src/base/net/tools/Storage.h | 13 +- 25 files changed, 474 insertions(+), 216 deletions(-) create mode 100644 src/base/net/http/Fetch.cpp create mode 100644 src/base/net/http/Fetch.h create mode 100644 src/base/net/http/HttpData.cpp create mode 100644 src/base/net/http/HttpListener.cpp diff --git a/src/base/api/Httpd.cpp b/src/base/api/Httpd.cpp index 36f046164..37db1ad67 100644 --- a/src/base/api/Httpd.cpp +++ b/src/base/api/Httpd.cpp @@ -38,7 +38,6 @@ namespace xmrig { static const char *kAuthorization = "authorization"; -static const char *kContentType = "content-type"; #ifdef _WIN32 static const char *favicon = nullptr; @@ -138,7 +137,7 @@ void xmrig::Httpd::onHttpData(const HttpData &data) # ifdef _WIN32 if (favicon != nullptr) { HttpResponse response(data.id()); - response.setHeader("Content-Type", "image/x-icon"); + response.setHeader(HttpData::kContentType, "image/x-icon"); return response.end(favicon, faviconSize); } @@ -161,7 +160,7 @@ void xmrig::Httpd::onHttpData(const HttpData &data) return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end(); } - if (!data.headers.count(kContentType) || data.headers.at(kContentType) != "application/json") { + if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) { return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end(); } } diff --git a/src/base/base.cmake b/src/base/base.cmake index 33ec9954f..b57622651 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -34,6 +34,7 @@ set(HEADERS_BASE src/base/kernel/Signals.h src/base/net/dns/Dns.h src/base/net/dns/DnsRecord.h + src/base/net/http/Fetch.h src/base/net/http/Http.h src/base/net/http/HttpListener.h src/base/net/stratum/BaseClient.h @@ -80,7 +81,10 @@ set(SOURCES_BASE src/base/kernel/Signals.cpp src/base/net/dns/Dns.cpp src/base/net/dns/DnsRecord.cpp + src/base/net/http/Fetch.cpp src/base/net/http/Http.cpp + src/base/net/http/HttpData.cpp + src/base/net/http/HttpListener.cpp src/base/net/stratum/BaseClient.cpp src/base/net/stratum/Client.cpp src/base/net/stratum/Job.cpp diff --git a/src/base/io/json/JsonRequest.cpp b/src/base/io/json/JsonRequest.cpp index 4556f3f08..d66040a7b 100644 --- a/src/base/io/json/JsonRequest.cpp +++ b/src/base/io/json/JsonRequest.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -27,12 +27,40 @@ #include "rapidjson/document.h" -void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value ¶ms) +namespace xmrig { + + +static const char *k2_0 = "2.0"; +static const char *kId = "id"; +static const char *kJsonRPC = "jsonrpc"; +static const char *kMethod = "method"; +const char *JsonRequest::kParams = "params"; + + +} // namespace xmrig + + +rapidjson::Document xmrig::JsonRequest::create(int64_t id, const char *method) { + using namespace rapidjson; + Document doc(kObjectType); auto &allocator = doc.GetAllocator(); - doc.AddMember("id", id, allocator); - doc.AddMember("jsonrpc", "2.0", allocator); - doc.AddMember("method", rapidjson::StringRef(method), allocator); - doc.AddMember("params", params, allocator); + doc.AddMember(StringRef(kId), id, allocator); + doc.AddMember(StringRef(kJsonRPC), StringRef(k2_0), allocator); + doc.AddMember(StringRef(kMethod), StringRef(method), allocator); + + return doc; +} + + +void xmrig::JsonRequest::create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value ¶ms) +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + doc.AddMember(StringRef(kId), id, allocator); + doc.AddMember(StringRef(kJsonRPC), StringRef(k2_0), allocator); + doc.AddMember(StringRef(kMethod), StringRef(method), allocator); + doc.AddMember(StringRef(kParams), params, allocator); } diff --git a/src/base/io/json/JsonRequest.h b/src/base/io/json/JsonRequest.h index e98c0baec..b2e0b156e 100644 --- a/src/base/io/json/JsonRequest.h +++ b/src/base/io/json/JsonRequest.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -35,6 +35,9 @@ namespace xmrig { class JsonRequest { public: + static const char *kParams; + + static rapidjson::Document create(int64_t id, const char *method); static void create(rapidjson::Document &doc, int64_t id, const char *method, rapidjson::Value ¶ms); }; diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index a091f923f..2c2b2d14c 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2019 Spudz76 - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -189,7 +189,7 @@ private: } - char m_buf[4096]{}; + char m_buf[Log::kMaxBufferSize]{}; std::mutex m_mutex; std::vector m_backends; }; diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index 3181f9342..7d52e8ebd 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2019 Spudz76 - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -52,6 +52,8 @@ public: DEBUG, // debug-level messages }; + constexpr static size_t kMaxBufferSize = 16384; + static void add(ILogBackend *backend); static void destroy(); static void print(const char *fmt, ...); diff --git a/src/base/net/http/Fetch.cpp b/src/base/net/http/Fetch.cpp new file mode 100644 index 000000000..361769e9d --- /dev/null +++ b/src/base/net/http/Fetch.cpp @@ -0,0 +1,155 @@ +/* XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , + * + * 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 . + */ + + +#include "base/net/http/Fetch.h" +#include "base/io/log/Log.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 +# include "base/net/http/HttpsClient.h" +#endif + + +xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) : + quiet(quiet), + tls(tls), + method(method), + host(host), + path(path), + port(port) +{ + assert(port > 0); + + setBody(data, size, contentType); +} + + +xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls, bool quiet) : + quiet(quiet), + tls(tls), + method(method), + host(host), + path(path), + port(port) +{ + assert(port > 0); + + setBody(doc); +} + + +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(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(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) +{ + if (!data) { + return; + } + + assert(method != HTTP_GET && method != HTTP_HEAD); + + if (method == HTTP_GET || method == HTTP_HEAD) { + return; + } + + body = size ? std::string(data, size) : data; + if (contentType) { + headers.insert({ HttpData::kContentType, contentType }); + } +} + + +void xmrig::FetchRequest::setBody(const rapidjson::Document &doc) +{ + assert(method != HTTP_GET && method != HTTP_HEAD); + + if (method == HTTP_GET || method == HTTP_HEAD) { + return; + } + + using namespace rapidjson; + + StringBuffer buffer(nullptr, 512); + Writer writer(buffer); + doc.Accept(writer); + + setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str()); +} + + +void xmrig::fetch(FetchRequest &&req, const std::weak_ptr &listener, int type) +{ +# ifdef APP_DEBUG + LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"), + req.tls ? "s" : "", req.host.data(), req.port, http_method_str(req.method), req.path.data(), req.body.size()); + + if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) { + Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast(req.body.size()), req.body.c_str()); + } +# endif + + HttpClient *client; +# ifdef XMRIG_FEATURE_TLS + if (req.tls) { + client = new HttpsClient(std::move(req), listener); + } + else +# endif + { + client = new HttpClient(std::move(req), listener); + } + + client->userType = type; + client->connect(); +} diff --git a/src/base/net/http/Fetch.h b/src/base/net/http/Fetch.h new file mode 100644 index 000000000..db1e899b6 --- /dev/null +++ b/src/base/net/http/Fetch.h @@ -0,0 +1,74 @@ +/* XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , + * + * 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 . + */ + + +#ifndef XMRIG_FETCH_H +#define XMRIG_FETCH_H + + +#include "3rdparty/http-parser/http_parser.h" +#include "base/tools/String.h" +#include "rapidjson/fwd.h" + + +#include +#include +#include + + +namespace xmrig { + + +class IHttpListener; +class Pool; + + +class FetchRequest +{ +public: + 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, const rapidjson::Document &doc, 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 rapidjson::Document &doc); + + inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); } + + bool quiet = false; + bool tls = false; + http_method method = HTTP_GET; + std::map headers; + std::string body; + String fingerprint; + String host; + String path; + uint16_t port = 0; +}; + + +void fetch(FetchRequest &&req, const std::weak_ptr &listener, int type = 0); + + +} // namespace xmrig + + +#endif // XMRIG_FETCH_H + diff --git a/src/base/net/http/HttpApiResponse.cpp b/src/base/net/http/HttpApiResponse.cpp index 5fe926368..6bf23c45b 100644 --- a/src/base/net/http/HttpApiResponse.cpp +++ b/src/base/net/http/HttpApiResponse.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2014-2019 heapwolf - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -24,8 +24,9 @@ */ -#include "3rdparty/http-parser/http_parser.h" #include "base/net/http/HttpApiResponse.h" +#include "3rdparty/http-parser/http_parser.h" +#include "base/net/http/HttpData.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" @@ -75,7 +76,7 @@ void xmrig::HttpApiResponse::end() return HttpResponse::end(); } - setHeader("Content-Type", "application/json"); + setHeader(HttpData::kContentType, HttpData::kApplicationJson); StringBuffer buffer(nullptr, 4096); PrettyWriter writer(buffer); diff --git a/src/base/net/http/HttpApiResponse.h b/src/base/net/http/HttpApiResponse.h index bbaf132ed..a50707354 100644 --- a/src/base/net/http/HttpApiResponse.h +++ b/src/base/net/http/HttpApiResponse.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2014-2019 heapwolf - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index a21f72d16..b684ddae0 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -69,17 +69,15 @@ private: } // namespace xmrig -xmrig::HttpClient::HttpClient(int method, const String &url, const std::weak_ptr &listener, const char *data, size_t size) : - HttpContext(HTTP_RESPONSE, listener) +xmrig::HttpClient::HttpClient(FetchRequest &&req, const std::weak_ptr &listener) : + HttpContext(HTTP_RESPONSE, listener), + m_req(std::move(req)) { - this->method = method; - this->url = url; - - if (data) { - body = size ? std::string(data, size) : data; - } - - m_dns = new Dns(this); + 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); } @@ -89,17 +87,9 @@ xmrig::HttpClient::~HttpClient() } -bool xmrig::HttpClient::connect(const String &host, uint16_t port) +bool xmrig::HttpClient::connect() { - m_port = port; - - return m_dns->resolve(host); -} - - -const xmrig::String &xmrig::HttpClient::host() const -{ - return m_dns->host(); + return m_dns->resolve(m_req.host); } @@ -108,14 +98,14 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status) this->status = status; if (status < 0 && dns.isEmpty()) { - if (!m_quiet) { - LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), m_port, uv_strerror(status)); + if (!isQuiet()) { + LOG_ERR("[%s:%d] DNS error: \"%s\"", dns.host().data(), port(), uv_strerror(status)); } return; } - sockaddr *addr = dns.get().addr(m_port); + sockaddr *addr = dns.get().addr(port()); auto req = new uv_connect_t; req->data = this; @@ -128,7 +118,7 @@ void xmrig::HttpClient::onResolved(const Dns &dns, int status) void xmrig::HttpClient::handshake() { - headers.insert({ "Host", m_dns->host().data() }); + headers.insert({ "Host", host() }); headers.insert({ "Connection", "close" }); headers.insert({ "User-Agent", Platform::userAgent() }); @@ -175,8 +165,8 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status) } if (status < 0) { - if (!client->m_quiet) { - LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->m_port, uv_strerror(status)); + if (!client->isQuiet()) { + LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(status)); } delete req; @@ -197,8 +187,8 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status) if (nread >= 0) { client->read(buf->base, static_cast(nread)); } else { - if (!client->m_quiet && nread != UV_EOF) { - LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->m_port, uv_strerror(static_cast(nread))); + if (!client->isQuiet() && nread != UV_EOF) { + LOG_ERR("[%s:%d] read error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(static_cast(nread))); } client->close(static_cast(nread)); diff --git a/src/base/net/http/HttpClient.h b/src/base/net/http/HttpClient.h index 62ac72977..b54882a0e 100644 --- a/src/base/net/http/HttpClient.h +++ b/src/base/net/http/HttpClient.h @@ -28,8 +28,9 @@ #define XMRIG_HTTPCLIENT_H -#include "base/net/http/HttpContext.h" #include "base/kernel/interfaces/IDnsListener.h" +#include "base/net/http/Fetch.h" +#include "base/net/http/HttpContext.h" #include "base/tools/Object.h" @@ -44,14 +45,14 @@ class HttpClient : public HttpContext, public IDnsListener public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpClient); - HttpClient(int method, const String &url, const std::weak_ptr &listener, const char *data = nullptr, size_t size = 0); + HttpClient(FetchRequest &&req, const std::weak_ptr &listener); ~HttpClient() override; - inline uint16_t port() const { return m_port; } - inline void setQuiet(bool quiet) { m_quiet = quiet; } + inline bool isQuiet() const { return m_req.quiet; } + inline const char *host() const override { return m_req.host; } + inline uint16_t port() const override { return m_req.port; } - bool connect(const String &host, uint16_t port); - const String &host() const; + bool connect(); protected: void onResolved(const Dns &dns, int status) override; @@ -60,13 +61,14 @@ protected: virtual void read(const char *data, size_t size); virtual void write(const std::string &header); - bool m_quiet = false; +protected: + inline const FetchRequest &req() const { return m_req; } private: static void onConnect(uv_connect_t *req, int status); Dns *m_dns; - uint16_t m_port = 0; + FetchRequest m_req; }; diff --git a/src/base/net/http/HttpContext.cpp b/src/base/net/http/HttpContext.cpp index 81479f2aa..66a25d6a1 100644 --- a/src/base/net/http/HttpContext.cpp +++ b/src/base/net/http/HttpContext.cpp @@ -75,6 +75,12 @@ xmrig::HttpContext::~HttpContext() } +bool xmrig::HttpContext::isRequest() const +{ + return m_parser->type == HTTP_REQUEST; +} + + size_t xmrig::HttpContext::parse(const char *data, size_t size) { return http_parser_execute(m_parser, &http_settings, data, size); diff --git a/src/base/net/http/HttpContext.h b/src/base/net/http/HttpContext.h index 5091c24bc..784bb7ed1 100644 --- a/src/base/net/http/HttpContext.h +++ b/src/base/net/http/HttpContext.h @@ -55,13 +55,19 @@ public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpContext) HttpContext(int parser_type, const std::weak_ptr &listener); - virtual ~HttpContext(); + ~HttpContext() override; inline uv_stream_t *stream() const { return reinterpret_cast(m_tcp); } inline uv_handle_t *handle() const { return reinterpret_cast(m_tcp); } + inline const char *host() const override { return nullptr; } + inline const char *tlsFingerprint() const override { return nullptr; } + inline const char *tlsVersion() const override { return nullptr; } + inline uint16_t port() const override { return 0; } + + bool isRequest() const override; size_t parse(const char *data, size_t size); - std::string ip() const; + std::string ip() const override; uint64_t elapsed() const; void close(int status = 0); diff --git a/src/base/net/http/HttpData.cpp b/src/base/net/http/HttpData.cpp new file mode 100644 index 000000000..5aa575a80 --- /dev/null +++ b/src/base/net/http/HttpData.cpp @@ -0,0 +1,31 @@ +/* XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , + * + * 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 . + */ + + +#include "base/net/http/HttpData.h" + + +namespace xmrig { + + +const std::string HttpData::kApplicationJson = "application/json"; +const std::string HttpData::kContentType = "Content-Type"; +const std::string HttpData::kContentTypeL = "content-type"; + + +} // namespace xmrig diff --git a/src/base/net/http/HttpData.h b/src/base/net/http/HttpData.h index 1705e8816..cd852639c 100644 --- a/src/base/net/http/HttpData.h +++ b/src/base/net/http/HttpData.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2014-2019 heapwolf - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -28,6 +28,9 @@ #define XMRIG_HTTPDATA_H +#include "base/tools/Object.h" + + #include #include @@ -38,12 +41,28 @@ namespace xmrig { class HttpData { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpData) + + static const std::string kApplicationJson; + static const std::string kContentType; + static const std::string kContentTypeL; + + inline HttpData(uint64_t id) : m_id(id) {} + virtual ~HttpData() = default; inline uint64_t id() const { return m_id; } - int method = 0; - int status = 0; + virtual bool isRequest() const = 0; + virtual const char *host() const = 0; + virtual const char *tlsFingerprint() const = 0; + virtual const char *tlsVersion() const = 0; + virtual std::string ip() const = 0; + virtual uint16_t port() const = 0; + + int method = 0; + int status = 0; + int userType = 0; std::map headers; std::string body; std::string url; diff --git a/src/base/net/http/HttpListener.cpp b/src/base/net/http/HttpListener.cpp new file mode 100644 index 000000000..e58d5e55e --- /dev/null +++ b/src/base/net/http/HttpListener.cpp @@ -0,0 +1,41 @@ +/* XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , + * + * 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 . + */ + + +#include "base/net/http/HttpListener.h" +#include "3rdparty/http-parser/http_parser.h" +#include "base/io/log/Log.h" +#include "base/net/http/HttpData.h" + + +void xmrig::HttpListener::onHttpData(const HttpData &data) +{ +# ifdef APP_DEBUG + 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"), + data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast(data.method)), data.url.data(), + data.status >= 400 ? 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) { + Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast(data.body.size()), data.body.c_str()); + } + } +# endif + + m_listener->onHttpData(data); +} diff --git a/src/base/net/http/HttpListener.h b/src/base/net/http/HttpListener.h index 428f9c49a..36975db48 100644 --- a/src/base/net/http/HttpListener.h +++ b/src/base/net/http/HttpListener.h @@ -32,7 +32,7 @@ public: inline HttpListener(IHttpListener *listener) : m_listener(listener) {} protected: - inline void onHttpData(const HttpData &data) override { m_listener->onHttpData(data); }; + void onHttpData(const HttpData &data) override; private: IHttpListener *m_listener; diff --git a/src/base/net/http/HttpsClient.cpp b/src/base/net/http/HttpsClient.cpp index cdc4629b4..96162e9c4 100644 --- a/src/base/net/http/HttpsClient.cpp +++ b/src/base/net/http/HttpsClient.cpp @@ -39,9 +39,8 @@ #endif -xmrig::HttpsClient::HttpsClient(int method, const String &url, const std::weak_ptr &listener, const char *data, size_t size, const String &fingerprint) : - HttpClient(method, url, listener, data, size), - m_fp(fingerprint) +xmrig::HttpsClient::HttpsClient(FetchRequest &&req, const std::weak_ptr &listener) : + HttpClient(std::move(req), listener) { m_ctx = SSL_CTX_new(SSLv23_method()); assert(m_ctx != nullptr); @@ -68,13 +67,13 @@ xmrig::HttpsClient::~HttpsClient() } -const char *xmrig::HttpsClient::fingerprint() const +const char *xmrig::HttpsClient::tlsFingerprint() const { return m_ready ? m_fingerprint : nullptr; } -const char *xmrig::HttpsClient::version() const +const char *xmrig::HttpsClient::tlsVersion() const { return m_ready ? SSL_get_version(m_ssl) : nullptr; } @@ -91,7 +90,7 @@ void xmrig::HttpsClient::handshake() SSL_set_connect_state(m_ssl); SSL_set_bio(m_ssl, m_readBio, m_writeBio); - SSL_set_tlsext_host_name(m_ssl, host().data()); + SSL_set_tlsext_host_name(m_ssl, host()); SSL_do_handshake(m_ssl); @@ -147,12 +146,12 @@ bool xmrig::HttpsClient::verify(X509 *cert) } if (!verifyFingerprint(cert)) { - if (!m_quiet) { - LOG_ERR("[%s:%d] Failed to verify server certificate fingerprint", host().data(), port()); + if (!isQuiet()) { + LOG_ERR("[%s:%d] Failed to verify server certificate fingerprint", host(), port()); - if (strlen(m_fingerprint) == 64 && !m_fp.isNull()) { + if (strlen(m_fingerprint) == 64 && !req().fingerprint.isNull()) { LOG_ERR("\"%s\" was given", m_fingerprint); - LOG_ERR("\"%s\" was configured", m_fp.data()); + LOG_ERR("\"%s\" was configured", req().fingerprint.data()); } } @@ -179,7 +178,7 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert) Buffer::toHex(md, 32, m_fingerprint); - return m_fp.isNull() || strncasecmp(m_fingerprint, m_fp.data(), 64) == 0; + return req().fingerprint.isNull() || strncasecmp(m_fingerprint, req().fingerprint.data(), 64) == 0; } diff --git a/src/base/net/http/HttpsClient.h b/src/base/net/http/HttpsClient.h index b15eee3e4..afac6e018 100644 --- a/src/base/net/http/HttpsClient.h +++ b/src/base/net/http/HttpsClient.h @@ -46,11 +46,11 @@ class HttpsClient : public HttpClient public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpsClient) - HttpsClient(int method, const String &url, const std::weak_ptr &listener, const char *data, size_t size, const String &fingerprint); + HttpsClient(FetchRequest &&req, const std::weak_ptr &listener); ~HttpsClient() override; - const char *fingerprint() const; - const char *version() const; + const char *tlsFingerprint() const override; + const char *tlsVersion() const override; protected: void handshake() override; @@ -69,7 +69,6 @@ private: char m_fingerprint[32 * 2 + 8]{}; SSL *m_ssl = nullptr; SSL_CTX *m_ctx = nullptr; - String m_fp; }; diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index c54596826..df4869156 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -30,20 +30,14 @@ #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IClientListener.h" -#include "base/net/http/HttpClient.h" +#include "base/net/http/Fetch.h" +#include "base/net/http/HttpData.h" #include "base/net/stratum/SubmitResult.h" #include "base/tools/Buffer.h" #include "base/tools/Timer.h" #include "net/JobResult.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" - - -#ifdef XMRIG_FEATURE_TLS -# include "base/net/http/HttpsClient.h" -#endif #include @@ -65,8 +59,7 @@ static const size_t BlobReserveSize = 8; xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) : - BaseClient(id, listener), - m_apiVersion(API_MONERO) + BaseClient(id, listener) { m_httpListener = std::make_shared(this); m_timer = new Timer(this); @@ -133,9 +126,7 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result) m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend); # endif - send(HTTP_POST, kJsonRPC, doc); - - return m_sequence++; + return rpcSend(doc); } @@ -163,15 +154,11 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data) return retry(); } - LOG_DEBUG("[%s:%d] received (%d bytes): \"%.*s\"", m_pool.host().data(), m_pool.port(), static_cast(data.body.size()), static_cast(data.body.size()), data.body.c_str()); - - m_ip = static_cast(data).ip().c_str(); + m_ip = data.ip().c_str(); # ifdef XMRIG_FEATURE_TLS - if (isTLS()) { - m_tlsVersion = static_cast(data).version(); - m_tlsFingerprint = static_cast(data).fingerprint(); - } + m_tlsVersion = data.tlsVersion(); + m_tlsFingerprint = data.tlsFingerprint(); # endif rapidjson::Document doc; @@ -188,7 +175,7 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data) if (!doc.HasMember(kHash)) { m_apiVersion = API_CRYPTONOTE_DEFAULT; - return send(HTTP_GET, kGetInfo); + return send(kGetInfo); } if (isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, kHash))) { @@ -215,19 +202,10 @@ void xmrig::DaemonClient::onTimer(const Timer *) } else if (m_state == ConnectedState) { if (m_apiVersion == API_DERO) { - using namespace rapidjson; - Document doc(kObjectType); - auto& allocator = doc.GetAllocator(); - - doc.AddMember("id", m_sequence, allocator); - doc.AddMember("jsonrpc", "2.0", allocator); - doc.AddMember("method", "get_info", allocator); - - send(HTTP_POST, kJsonRPC, doc); - ++m_sequence; + rpcSend(JsonRequest::create(m_sequence, "get_info")); } else { - send(HTTP_GET, (m_apiVersion == API_MONERO) ? kGetHeight : kGetInfo); + send((m_apiVersion == API_MONERO) ? kGetHeight : kGetInfo); } } } @@ -344,7 +322,14 @@ int64_t xmrig::DaemonClient::getBlockTemplate() JsonRequest::create(doc, m_sequence, "getblocktemplate", params); - send(HTTP_POST, kJsonRPC, doc); + return rpcSend(doc); +} + + +int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc) +{ + FetchRequest req(HTTP_POST, m_pool, kJsonRPC, doc, isQuiet()); + fetch(std::move(req), m_httpListener); return m_sequence++; } @@ -368,46 +353,10 @@ void xmrig::DaemonClient::retry() } -void xmrig::DaemonClient::send(int method, const char *url, const char *data, size_t size) +void xmrig::DaemonClient::send(const char *path) { - LOG_DEBUG("[%s:%d] " MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD_S " send (%zu bytes): \"%.*s\"", - m_pool.host().data(), - m_pool.port(), - http_method_str(static_cast(method)), - url, - size, - static_cast(size), - data); - - HttpClient *client; -# ifdef XMRIG_FEATURE_TLS - if (m_pool.isTLS()) { - client = new HttpsClient(method, url, m_httpListener, data, size, m_pool.fingerprint()); - } - else -# endif - { - client = new HttpClient(method, url, m_httpListener, data, size); - } - - client->setQuiet(isQuiet()); - client->connect(m_pool.host(), m_pool.port()); - - if (method != HTTP_GET) { - client->headers.insert({ "Content-Type", "application/json" }); - } -} - - -void xmrig::DaemonClient::send(int method, const char *url, const rapidjson::Document &doc) -{ - using namespace rapidjson; - - StringBuffer buffer(nullptr, 512); - Writer writer(buffer); - doc.Accept(writer); - - send(method, url, buffer.GetString(), buffer.GetSize()); + FetchRequest req(HTTP_GET, m_pool, path, isQuiet()); + fetch(std::move(req), m_httpListener); } diff --git a/src/base/net/stratum/DaemonClient.h b/src/base/net/stratum/DaemonClient.h index 0b14f5dda..0c3df6a1b 100644 --- a/src/base/net/stratum/DaemonClient.h +++ b/src/base/net/stratum/DaemonClient.h @@ -71,16 +71,16 @@ private: bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error); int64_t getBlockTemplate(); + int64_t rpcSend(const rapidjson::Document &doc); void retry(); - void send(int method, const char *url, const char *data = nullptr, size_t size = 0); - void send(int method, const char *url, const rapidjson::Document &doc); + void send(const char *path); void setState(SocketState state); enum { API_CRYPTONOTE_DEFAULT, API_MONERO, API_DERO, - } m_apiVersion; + } m_apiVersion = API_MONERO; std::shared_ptr m_httpListener; String m_blocktemplate; diff --git a/src/base/net/stratum/SelfSelectClient.cpp b/src/base/net/stratum/SelfSelectClient.cpp index d69bc0fb8..6fdcf14d6 100644 --- a/src/base/net/stratum/SelfSelectClient.cpp +++ b/src/base/net/stratum/SelfSelectClient.cpp @@ -29,17 +29,11 @@ #include "base/io/json/Json.h" #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" -#include "base/net/http/HttpClient.h" +#include "base/net/http/Fetch.h" +#include "base/net/http/HttpData.h" #include "base/net/stratum/Client.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" - - -#ifdef XMRIG_FEATURE_TLS -# include "base/net/http/HttpsClient.h" -#endif namespace xmrig { @@ -159,7 +153,8 @@ void xmrig::SelfSelectClient::getBlockTemplate() JsonRequest::create(doc, m_sequence++, "getblocktemplate", params); - send(HTTP_POST, "/json_rpc", doc); + FetchRequest req(HTTP_POST, pool().daemon().host(), pool().daemon().port(), "/json_rpc", doc, pool().daemon().isTLS(), isQuiet()); + fetch(std::move(req), m_httpListener); } @@ -169,44 +164,6 @@ void xmrig::SelfSelectClient::retry() } -void xmrig::SelfSelectClient::send(int method, const char *url, const char *data, size_t size) -{ - LOG_DEBUG("[%s] " MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD_S " send (%zu bytes): \"%.*s\"", - pool().daemon().url().data(), - http_method_str(static_cast(method)), - url, - size, - static_cast(size), - data); - - HttpClient *client; -# ifdef XMRIG_FEATURE_TLS - if (pool().daemon().isTLS()) { - client = new HttpsClient(method, url, m_httpListener, data, size, String()); - } - else -# endif - { - client = new HttpClient(method, url, m_httpListener, data, size); - } - - client->setQuiet(isQuiet()); - client->connect(pool().daemon().host(), pool().daemon().port()); -} - - -void xmrig::SelfSelectClient::send(int method, const char *url, const rapidjson::Document &doc) -{ - using namespace rapidjson; - - StringBuffer buffer(nullptr, 512); - Writer writer(buffer); - doc.Accept(writer); - - send(method, url, buffer.GetString(), buffer.GetSize()); -} - - void xmrig::SelfSelectClient::setState(State state) { if (m_state == state) { @@ -256,7 +213,7 @@ void xmrig::SelfSelectClient::submitBlockTemplate(rapidjson::Value &result) JsonRequest::create(doc, sequence(), "block_template", params); - send(doc, [this](const rapidjson::Value &result, bool success, uint64_t elapsed) { + send(doc, [this](const rapidjson::Value &result, bool success, uint64_t) { if (!success) { if (!isQuiet()) { LOG_ERR("[%s] error: " RED_BOLD("\"%s\"") RED_S ", code: %d", pool().daemon().url().data(), Json::getString(result, "message"), Json::getInt(result, "code")); @@ -285,8 +242,6 @@ void xmrig::SelfSelectClient::onHttpData(const HttpData &data) return retry(); } - LOG_DEBUG("[%s] received (%d bytes): \"%.*s\"", pool().daemon().url().data(), static_cast(data.body.size()), static_cast(data.body.size()), data.body.c_str()); - rapidjson::Document doc; if (doc.Parse(data.body.c_str()).HasParseError()) { if (!isQuiet()) { diff --git a/src/base/net/stratum/SelfSelectClient.h b/src/base/net/stratum/SelfSelectClient.h index 5c9431c76..c54cf8dff 100644 --- a/src/base/net/stratum/SelfSelectClient.h +++ b/src/base/net/stratum/SelfSelectClient.h @@ -102,8 +102,6 @@ private: bool parseResponse(int64_t id, rapidjson::Value &result, const rapidjson::Value &error); void getBlockTemplate(); void retry(); - void send(int method, const char *url, const char *data = nullptr, size_t size = 0); - void send(int method, const char *url, const rapidjson::Document &doc); void setState(State state); void submitBlockTemplate(rapidjson::Value &result); diff --git a/src/base/net/tools/Storage.h b/src/base/net/tools/Storage.h index aff624816..0af4db263 100644 --- a/src/base/net/tools/Storage.h +++ b/src/base/net/tools/Storage.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -26,7 +26,7 @@ #define XMRIG_STORAGE_H -#include +#include #include @@ -37,10 +37,7 @@ template class Storage { public: - inline Storage() : - m_counter(0) - { - } + inline Storage() = default; inline uintptr_t add(TYPE *ptr) @@ -87,7 +84,7 @@ public: private: std::map m_data; - uint64_t m_counter; + uint64_t m_counter = 0; }; From 7bf12dc81f6d8c11a1875c249a9684f733ca81e4 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 6 Mar 2020 12:51:16 +0700 Subject: [PATCH 6/8] #1581 Fixed macOS build. --- src/base/net/stratum/DaemonClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index df4869156..bdf6d5ca1 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -314,7 +314,7 @@ 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", BlobReserveSize, allocator); + params.AddMember("reserve_size", static_cast(BlobReserveSize), allocator); } else { params.AddMember("extra_nonce", Buffer::randomBytes(BlobReserveSize).toHex().toJSON(doc), allocator); From 6a45d5dcc99a4e6a1d75f7c96223011fc67d720b Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 6 Mar 2020 12:57:21 +0700 Subject: [PATCH 7/8] Update year. --- src/backend/cpu/CpuConfig.cpp | 5 +++-- src/backend/cpu/CpuConfig.h | 4 ++-- src/backend/cpu/CpuLaunchData.cpp | 9 ++++----- src/backend/cpu/CpuLaunchData.h | 6 +++--- src/backend/cpu/CpuWorker.cpp | 2 +- src/backend/cpu/CpuWorker.h | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index 3a17dc1f4..0f156e926 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -28,6 +28,7 @@ #include "backend/cpu/Cpu.h" #include "base/io/json/Json.h" #include "rapidjson/document.h" + #include diff --git a/src/backend/cpu/CpuConfig.h b/src/backend/cpu/CpuConfig.h index 090b7e6dd..ba2b84100 100644 --- a/src/backend/cpu/CpuConfig.h +++ b/src/backend/cpu/CpuConfig.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 diff --git a/src/backend/cpu/CpuLaunchData.cpp b/src/backend/cpu/CpuLaunchData.cpp index 111adea30..dbc7e5c5c 100644 --- a/src/backend/cpu/CpuLaunchData.cpp +++ b/src/backend/cpu/CpuLaunchData.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -25,7 +25,6 @@ #include "backend/cpu/CpuLaunchData.h" - #include "backend/common/Tags.h" #include "backend/cpu/CpuConfig.h" @@ -39,11 +38,11 @@ xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorit hugePages(config.isHugePages()), hwAES(config.isHwAES()), yield(config.isYield()), + astrobwtMaxSize(config.astrobwtMaxSize()), priority(config.priority()), affinity(thread.affinity()), miner(miner), - intensity(std::min(thread.intensity(), algorithm.maxIntensity())), - astrobwtMaxSize(config.astrobwtMaxSize()) + intensity(std::min(thread.intensity(), algorithm.maxIntensity())) { } diff --git a/src/backend/cpu/CpuLaunchData.h b/src/backend/cpu/CpuLaunchData.h index 37814e686..0ba8ad7f9 100644 --- a/src/backend/cpu/CpuLaunchData.h +++ b/src/backend/cpu/CpuLaunchData.h @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 XMRig , * * 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 @@ -61,11 +61,11 @@ public: const bool hugePages; const bool hwAES; const bool yield; + const int astrobwtMaxSize; const int priority; const int64_t affinity; const Miner *miner; const uint32_t intensity; - const int astrobwtMaxSize; }; diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index b0934aad1..0740cca2c 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -77,10 +77,10 @@ xmrig::CpuWorker::CpuWorker(size_t id, const CpuLaunchData &data) : Worker(id, data.affinity, data.priority), m_algorithm(data.algorithm), m_assembly(data.assembly), - m_astrobwtMaxSize(data.astrobwtMaxSize * 1000), m_hwAES(data.hwAES), m_yield(data.yield), m_av(data.av()), + m_astrobwtMaxSize(data.astrobwtMaxSize * 1000), m_miner(data.miner), m_ctx() { diff --git a/src/backend/cpu/CpuWorker.h b/src/backend/cpu/CpuWorker.h index 1e715357b..8d2c583fe 100644 --- a/src/backend/cpu/CpuWorker.h +++ b/src/backend/cpu/CpuWorker.h @@ -70,10 +70,10 @@ private: const Algorithm m_algorithm; const Assembly m_assembly; - const int m_astrobwtMaxSize; const bool m_hwAES; const bool m_yield; const CnHash::AlgoVariant m_av; + const int m_astrobwtMaxSize; const Miner *m_miner; cryptonight_ctx *m_ctx[N]; uint8_t m_hash[N * 32]{ 0 }; From 44f0daf384bc1ab612d829a936ca6889b5c3e955 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 6 Mar 2020 12:59:30 +0700 Subject: [PATCH 8/8] Fixed Linux build. --- src/base/io/log/Log.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index 7d52e8ebd..45183d1ce 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -27,6 +27,7 @@ #define XMRIG_LOG_H +#include #include